FreeCalypso > hg > freecalypso-sw
view ffstools/tiffs-rd/ls.c @ 234:024042383a26
tiffs IVA: ls reports file sizes
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Sun, 26 Jan 2014 11:47:13 +0000 |
parents | ae9ff2d1e3da |
children | e17bb8818318 |
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); } void ls_callback(pathname, ino, depth) char *pathname; { struct inode_info *inf = inode_info[ino]; u_long size; switch (inf->type) { case 0xE1: case 0xF1: size = get_file_size(ino, 0); printf("f %7lu %s\n", size, pathname); return; case 0xF2: printf("d %s\n", pathname); return; case 0xF3: printf("l %s\n", pathname); return; default: fprintf(stderr, "BUG: bad inode byte %02X reached ls_callback()\n", inf->type); exit(1); } } cmd_ls() { read_ffs_image(); find_inode_block(); alloc_inode_table(); find_root_inode(); traverse_visible_tree(ls_callback); exit(0); }