Mercurial > xfs_ino_scan
comparison ino_scan.c @ 12:bce7ecd3523c
make copying data conditional
author | Josef 'Jeff' Sipek <jeffpc@josefsipek.net> |
---|---|
date | Sat, 22 Mar 2008 18:08:53 -0400 |
parents | 3bf4a4f40d43 |
children | 93863bd2be09 |
comparison
equal
deleted
inserted
replaced
11:3bf4a4f40d43 | 12:bce7ecd3523c |
---|---|
25 #define DUMPDIR "dump" | 25 #define DUMPDIR "dump" |
26 #define BLKSIZE 4096 | 26 #define BLKSIZE 4096 |
27 #define BLKDEV_SIZE (104857600 / BLKSIZE) | 27 #define BLKDEV_SIZE (104857600 / BLKSIZE) |
28 #define INOSIZE 256 | 28 #define INOSIZE 256 |
29 | 29 |
30 /* | |
31 * Should inode data be copied off the device into DUMPDIR? | |
32 * | |
33 * defined: yes | |
34 * undefined: no | |
35 */ | |
36 //#define COPY_DATA | |
37 | |
30 int fd; /* device fd */ | 38 int fd; /* device fd */ |
31 int ffd = 0; /* file fd */ | 39 int ffd = 0; /* file fd */ |
32 | 40 |
33 static inline __uint16_t swap16(__uint16_t in) | 41 static inline __uint16_t swap16(__uint16_t in) |
34 { | 42 { |
89 irec->br_blockcount = (tmp) & 0x1fffffULL; | 97 irec->br_blockcount = (tmp) & 0x1fffffULL; |
90 } | 98 } |
91 | 99 |
92 void copy_extent_data(struct xfs_bmbt_irec *irec) | 100 void copy_extent_data(struct xfs_bmbt_irec *irec) |
93 { | 101 { |
102 #ifdef COPY_DATA | |
94 char buf[BLKSIZE]; | 103 char buf[BLKSIZE]; |
95 int ret; | 104 int ret; |
96 int i; | 105 int i; |
97 | 106 |
98 for(i=0; i<irec->br_blockcount; i++) { | 107 for(i=0; i<irec->br_blockcount; i++) { |
102 | 111 |
103 ret = pwrite64(ffd, buf, BLKSIZE, (irec->br_startoff + i) * BLKSIZE); | 112 ret = pwrite64(ffd, buf, BLKSIZE, (irec->br_startoff + i) * BLKSIZE); |
104 if (ret == -1) | 113 if (ret == -1) |
105 die(); | 114 die(); |
106 } | 115 } |
116 #endif | |
107 } | 117 } |
108 | 118 |
109 void process_reclist(xfs_bmbt_rec_t *rec, __uint32_t nexts) | 119 void process_reclist(xfs_bmbt_rec_t *rec, __uint32_t nexts) |
110 { | 120 { |
111 struct xfs_bmbt_irec irec; | 121 struct xfs_bmbt_irec irec; |
217 } | 227 } |
218 } | 228 } |
219 | 229 |
220 void print_inode(off_t blk) | 230 void print_inode(off_t blk) |
221 { | 231 { |
232 #ifdef COPY_DATA | |
222 char fname[PATH_MAX]; | 233 char fname[PATH_MAX]; |
234 #endif | |
223 unsigned char buf[INOSIZE]; | 235 unsigned char buf[INOSIZE]; |
224 struct xfs_dinode *inode = (void*) buf; | 236 struct xfs_dinode *inode = (void*) buf; |
225 off_t off; | 237 off_t off; |
226 int ret; | 238 int ret; |
227 | 239 |
234 return; | 246 return; |
235 } | 247 } |
236 | 248 |
237 printf("Inode @ block %lu, inode within blk %lu\n", blk, off); | 249 printf("Inode @ block %lu, inode within blk %lu\n", blk, off); |
238 | 250 |
251 #ifdef COPY_DATA | |
239 if (swap16(inode->di_core.di_mode) & S_IFREG) { | 252 if (swap16(inode->di_core.di_mode) & S_IFREG) { |
240 snprintf(fname, PATH_MAX, "%s/%08lx-%08lx", DUMPDIR, blk, off); | 253 snprintf(fname, PATH_MAX, "%s/%08lx-%08lx", DUMPDIR, blk, off); |
241 ffd = open(fname, O_CREAT | O_LARGEFILE | O_WRONLY, swap16(inode->di_core.di_mode) & 0777); | 254 ffd = open(fname, O_CREAT | O_LARGEFILE | O_WRONLY, swap16(inode->di_core.di_mode) & 0777); |
242 if (ffd == -1) | 255 if (ffd == -1) |
243 die(); | 256 die(); |
244 } | 257 } |
258 #endif | |
245 | 259 |
246 do_print_inode(inode); | 260 do_print_inode(inode); |
247 | 261 |
262 #ifdef COPY_DATA | |
248 if (swap16(inode->di_core.di_mode) & S_IFREG) { | 263 if (swap16(inode->di_core.di_mode) & S_IFREG) { |
249 ret = ftruncate(ffd, swap64(inode->di_core.di_size)); | 264 ret = ftruncate(ffd, swap64(inode->di_core.di_size)); |
250 if (ret == -1) | 265 if (ret == -1) |
251 die(); | 266 die(); |
252 | 267 |
253 ret = close(ffd); | 268 ret = close(ffd); |
254 if (ret == -1) | 269 if (ret == -1) |
255 die(); | 270 die(); |
256 ffd = 0; | 271 ffd = 0; |
257 } | 272 } |
273 #endif | |
258 } | 274 } |
259 } | 275 } |
260 | 276 |
261 int main(int argc, char **argv) | 277 int main(int argc, char **argv) |
262 { | 278 { |