changeset 35:f806eec33c45

Added a very hacked together (and barely functional) start to a filesystem
author Jonathan Pevarnek <pevarnj@gmail.com>
date Thu, 07 Apr 2011 23:07:46 -0400
parents 720e29b26c81
children 3acc1f944c7b
files Makefile hercules/fs.cnf src/fs.c
diffstat 3 files changed, 99 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Wed Apr 06 17:18:00 2011 -0400
+++ b/Makefile	Thu Apr 07 23:07:46 2011 -0400
@@ -10,10 +10,11 @@
 CXXFLAGS=$(CFLAGS)
 LDFLAGS=-m elf64_s390
 
-BINS=sarpn dynamic
+BINS=sarpn dynamic fs
 
 sarpn_OBJS=src/sarpn.o arch/io.o src/std.o src/stack.o src/operations.o src/math.o
 dynamic_OBJS=src/dynamic.o arch/io.o src/std.o src/stack.o
+fs_OBJS=src/fs.o arch/io.o src/std.o
 
 .PHONY: all build clean tags
 
@@ -35,6 +36,8 @@
 	$(LD) $(LDFLAGS) -T scripts/linker.script -o $@ $^
 dynamic: $(dynamic_OBJS)
 	$(LD) $(LDFLAGS) -T scripts/linker.script -o $@ $^
+fs: $(fs_OBJS)
+	$(LD) $(LDFLAGS) -T scripts/linker.script -o $@ $^
 
 %.o: %.S
 	$(AS) -m64 -o $@ $<
@@ -84,6 +87,7 @@
 
 src/date.o: include/tod.h include/std.h
 src/dynamic.o: include/std.h include/operations.h include/stack.h
+src/fs.o: include/std.h
 src/operations.o: include/operations.h include/std.h include/stack.h
 src/operations.o: include/math.h
 src/sarpn.o: include/std.h include/operations.h include/stack.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hercules/fs.cnf	Thu Apr 07 23:07:46 2011 -0400
@@ -0,0 +1,20 @@
+CPUSERIAL 314359        # CPU serial number
+CPUMODEL  2097          # CPU model number
+MAINSIZE  128           # Main storage size in megabytes
+XPNDSIZE  0             # Expanded storage size in megabytes
+CNSLPORT  3270          # TCP port number to which consoles connect
+NUMCPU    1             # Number of CPUs
+#OSTAILOR  QUIET         # OS tailoring
+OSTAILOR  NULL          # OS tailoring
+PANRATE   SLOW          # Panel refresh rate
+
+# .-----------------------Device number
+# |     .-----------------Device type
+# |     |       .---------File name and parameters
+# |     |       |
+# V     V       V
+#---    ----    --------------------
+0009	3215	
+000C    3505	../loader.bin ../fs ebcdic multifile eof
+
+0100	9336	disk.img
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/fs.c	Thu Apr 07 23:07:46 2011 -0400
@@ -0,0 +1,74 @@
+#include <std.h>
+
+struct SUPERBLOCK {
+	u32 magic;              // == 0x42420374
+	u32 root_inode;         // the disk block containing the root inode
+	u32 nblocks;            // number of block on the disk
+	u32 _pad[253];          // unused (should be '\0' filled)
+};
+typedef struct SUPERBLOCK Superblock;
+
+struct INODE {
+	u32 size;               // file length in bytes
+	u32 _pad0;              // unused (should be 0)
+	u64 ctime;              // creation time stamp
+	u64 mtime;              // last modification time stamp
+	u16 nblocks;            // number of data blocks in this file
+	u16 _pad1;              // unused (should be 0)
+	u32 _pad2;              // unused (should be 0)
+	u32 blocks[248];        // file block ptrs
+};
+typedef struct INODE Inode;
+
+struct DIRENTRY { //32 bytes
+	char fname[28];
+	u32 inode;
+};
+typedef struct DIRENTRY Direntry;
+
+int readFSBlock(u32 dev, u32 blkno, void *fsBlock)
+{
+	if(fba_read_blk(dev, blkno*2, fsBlock)) return 1;
+	if(fba_read_blk(dev, blkno*2 + 1, fsBlock + 512)) return 1;
+	return 0;
+}
+
+void start(u64 __memsize)
+{
+	sPrint(""); //I have no idea why I would possibly need this...
+//	char buffer[256];
+	
+	u32 dev = find_dev(0x100);
+	Superblock sb;
+	if(readFSBlock(dev, 1, &sb)) {
+		sPrint("ERROR\n");
+		goto END;
+	}
+	Inode root;
+	if(readFSBlock(dev, sb.root_inode, &root)) {
+		sPrint("ERROR\n");
+		goto END;
+	}
+	int nFiles = root.size/sizeof(Direntry);
+		//calculate how many files (assume less than 32 for the moment)
+		//TODO get rid of assumption
+	Direntry direntries[32];
+	if(readFSBlock(dev, root.blocks[0], direntries)) {
+		sPrint("ERROR\n");
+		goto END;
+	}
+	
+	//Prints off the name of each file
+	Direntry *dp;
+	for(dp = direntries; dp - direntries < nFiles; dp++) {
+		putline(dp->fname, 28), sPrint("\n");
+	}
+
+END:
+	sPrint("DONE\n");
+	for(;;) {
+		char buffer[1];
+		sGet(buffer, 0);
+	}
+}
+