diff ffstools/tiffs-rd/ls.c @ 233:ae9ff2d1e3da

tiffs IVA: basic ls integrated
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sun, 26 Jan 2014 10:54:42 +0000
parents
children 024042383a26
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ffstools/tiffs-rd/ls.c	Sun Jan 26 10:54:42 2014 +0000
@@ -0,0 +1,49 @@
+/*
+ * This C module implements the ls command.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+#include "types.h"
+#include "struct.h"
+#include "globals.h"
+#include "pathname.h"
+
+void
+ls_callback(pathname, ino, depth)
+	char *pathname;
+{
+	struct inode_info *inf = inode_info[ino];
+	char type;
+
+	switch (inf->type) {
+	case 0xE1:
+	case 0xF1:
+		type = 'f';
+		break;
+	case 0xF2:
+		type = 'd';
+		break;
+	case 0xF3:
+		type = 'l';
+		break;
+	default:
+		fprintf(stderr,
+			"BUG: bad inode byte %02X reached ls_callback()\n",
+			inf->type);
+		exit(1);
+	}
+	printf("%c %s\n", type, pathname);
+}
+
+cmd_ls()
+{
+	read_ffs_image();
+	find_inode_block();
+	alloc_inode_table();
+	find_root_inode();
+	traverse_visible_tree(ls_callback);
+	exit(0);
+}