FreeCalypso > hg > freecalypso-sw
view ffstools/tiffs-rd/ls.c @ 236:254de9560ef3
tiffs ls -v implemented
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Sun, 26 Jan 2014 19:03:33 +0000 |
parents | e17bb8818318 |
children | 317936902be4 |
line wrap: on
line source
/* * This C module implements the ls command. */ #include <sys/types.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <strings.h> #include "types.h" #include "struct.h" #include "globals.h" #include "pathname.h" static void segment_size_callback(inf, opaque) struct inode_info *inf; u_long opaque; { size_t *accump = (size_t *) opaque; struct chunkinfo chi; size_extra_chunk(inf, &chi); *accump += chi.len; } size_t get_file_size(seghead_ino, deleted) { struct chunkinfo chi; size_t accum; size_head_chunk(inode_info[seghead_ino], &chi); accum = chi.len; iterate_seg_file(seghead_ino, segment_size_callback, (u_long) &accum, deleted); return(accum); } static void segment_ls_callback(inf, opaque) struct inode_info *inf; u_long opaque; { struct chunkinfo chi; size_extra_chunk(inf, &chi); printf("seg #%04x length=%lu\n", inf->ino, (u_long) chi.len); } ls_seg_file(seghead_ino, deleted) { struct inode_info *inf = inode_info[seghead_ino]; struct chunkinfo chi; size_head_chunk(inf, &chi); printf("%lu bytes in seghead\n", (u_long) chi.len); iterate_seg_file(seghead_ino, segment_ls_callback, 0L, deleted); } void ls_callback(pathname, ino, depth) char *pathname; { struct inode_info *inf = inode_info[ino]; u_long size; char readonly; if (inf->type & 0x10) readonly = ' '; else readonly = 'r'; switch (inf->type) { case 0xE1: case 0xF1: size = get_file_size(ino, 0); printf("f%c %7lu %s\n", readonly, size, pathname); if (verbose2) ls_seg_file(ino, 0); return; case 0xE2: case 0xF2: printf("d%c %s\n", readonly, pathname); return; case 0xE3: case 0xF3: printf("l%c %s\n", readonly, pathname); return; default: fprintf(stderr, "BUG: bad inode byte %02X reached ls_callback()\n", inf->type); exit(1); } } ls_visible_tree() { read_ffs_image(); find_inode_block(); alloc_inode_table(); find_root_inode(); traverse_visible_tree(ls_callback); exit(0); } cmd_ls(argc, argv) char **argv; { char **ap; ap = argv + 1; if (*ap && !strcmp(*ap, "-v")) { verbose2++; ap++; } if (!*ap) return ls_visible_tree(); fprintf(stderr, "ls of individual files not yet implemented\n"); exit(1); }