comparison ffstools/tiffs-rd/ls.c @ 239:28ea957a9d8a

tiffs lsino of specific inodes implemented
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Mon, 27 Jan 2014 01:50:22 +0000
parents 0b13839f782c
children acedd4c88d2e
comparison
equal deleted inserted replaced
238:0b13839f782c 239:28ea957a9d8a
241 last_ino = ino; 241 last_ino = ino;
242 } 242 }
243 exit(0); 243 exit(0);
244 } 244 }
245 245
246 void
247 lsino_one(ino, assume_file)
248 {
249 struct inode_info *inf;
250 char pathname[PATHNAME_BUF_SIZE], *type;
251
252 if (!validate_inode(ino)) {
253 fprintf(stderr, "lsino: specified inode number is invalid\n");
254 exit(1);
255 }
256 printf("inode #%x\n", ino);
257 inf = inode_info[ino];
258 if (pathname_of_inode(ino, pathname) >= 0)
259 printf("Pathname: %s\n", pathname);
260 else
261 printf("No pathname found\n");
262 inf = inode_info[ino];
263 switch (inf->type) {
264 case 0x00:
265 type = "deleted";
266 break;
267 case 0xE1:
268 type = "read-only file";
269 break;
270 case 0xF1:
271 type = "file";
272 break;
273 case 0xF2:
274 type = "directory";
275 break;
276 case 0xF3:
277 type = "symlink";
278 break;
279 default:
280 type = "???";
281 }
282 printf("object type %02X (%s)\n", inf->type, type);
283 if (!inf->len) {
284 printf("This inode has been reclaimed\n\n");
285 return;
286 }
287 if (validate_obj_name(ino, 1))
288 printf("object name: %s\n", inf->dataptr);
289 else {
290 printf("No valid object name in the chunk\n\n");
291 return;
292 }
293 if (inf->type == 0xF1 || inf->type == 0xE1 ||
294 !inf->type && assume_file) {
295 printf("total size: %lu bytes\n",
296 (u_long) get_file_size(ino, !inf->type));
297 if (verbose2)
298 ls_seg_file(ino, !inf->type);
299 }
300 putchar('\n');
301 }
302
246 cmd_lsino(argc, argv) 303 cmd_lsino(argc, argv)
247 char **argv; 304 char **argv;
248 { 305 {
249 extern int optind; 306 extern int optind;
250 int c; 307 int c, assume_file = 0, ino;
251 308
252 read_ffs_image(); 309 read_ffs_image();
253 find_inode_block(); 310 find_inode_block();
254 alloc_inode_table(); 311 alloc_inode_table();
255 find_root_inode(); 312 find_root_inode();
256 treewalk_all(); 313 treewalk_all();
257 314
258 optind = 0; 315 optind = 0;
259 while ((c = getopt(argc, argv, "v")) != EOF) 316 while ((c = getopt(argc, argv, "fv")) != EOF)
260 switch (c) { 317 switch (c) {
318 case 'f':
319 assume_file++;
320 continue;
261 case 'v': 321 case 'v':
262 verbose2++; 322 verbose2++;
263 continue; 323 continue;
264 default: 324 default:
265 fprintf(stderr, "usage: lsino [-v[v]] [ino...]\n"); 325 fprintf(stderr, "usage: lsino [-v[v]] [ino...]\n");
266 exit(1); 326 exit(1);
267 } 327 }
268 if (optind >= argc) 328 if (optind >= argc)
269 return lsino_all(); 329 return lsino_all();
270 fprintf(stderr, "lsino of specific inodes not implemented yet\n"); 330 for (; optind < argc; optind++) {
271 exit(1); 331 ino = strtoul(argv[optind], 0, 16);
272 } 332 lsino_one(ino, assume_file);
333 }
334 exit(0);
335 }