diff 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 diff
--- a/ffstools/tiffs-rd/ls.c	Sun Jan 26 10:54:42 2014 +0000
+++ b/ffstools/tiffs-rd/ls.c	Sun Jan 26 11:47:13 2014 +0000
@@ -2,6 +2,7 @@
  * This C module implements the ls command.
  */
 
+#include <sys/types.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -11,31 +12,56 @@
 #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];
-	char type;
+	u_long size;
 
 	switch (inf->type) {
 	case 0xE1:
 	case 0xF1:
-		type = 'f';
-		break;
+		size = get_file_size(ino, 0);
+		printf("f %7lu %s\n", size, pathname);
+		return;
 	case 0xF2:
-		type = 'd';
-		break;
+		printf("d         %s\n", pathname);
+		return;
 	case 0xF3:
-		type = 'l';
-		break;
+		printf("l         %s\n", pathname);
+		return;
 	default:
 		fprintf(stderr,
 			"BUG: bad inode byte %02X reached ls_callback()\n",
 			inf->type);
 		exit(1);
 	}
-	printf("%c %s\n", type, pathname);
 }
 
 cmd_ls()