aboutsummaryrefslogtreecommitdiffstats
path: root/disklab.c
diff options
context:
space:
mode:
Diffstat (limited to 'disklab.c')
-rw-r--r--disklab.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/disklab.c b/disklab.c
new file mode 100644
index 0000000..a3abe36
--- /dev/null
+++ b/disklab.c
@@ -0,0 +1,41 @@
+#include <stdio.h>
+#include <malloc.h>
+
+
+extern int fd;
+
+void * getonesec(int sector)
+{
+ void *data;
+ int bytes_read;
+
+ if ( lseek(fd, sector * 512, SEEK_SET) < 0) {/* ... */
+ printf("seek file ext2.img error....\n");
+ return NULL;
+ }
+
+
+ data = malloc(512);
+
+ if ( (bytes_read = read(fd, data, 512)) < 512 )
+ printf("read %d bytes less than 512B...\n", bytes_read);
+
+
+ return data;
+}
+
+
+void getlinsec(char *buf, int sector, int sector_cnt)
+{
+ int bytes_read;
+
+ if ( lseek(fd, sector*512, SEEK_SET) < 0 ) {
+ printf("seek file ext2.img error ....\n");
+ return;
+ }
+
+ if ( (bytes_read = read(fd, buf, 512*sector_cnt)) < 512*sector_cnt)
+ printf("read %d bytes less than %d bytes..\n",
+ bytes_read, 512 * sector_cnt);
+
+}