// ECE3055, Spring 2003 // File System Implementation, Lab Assignment // Definitions // George F. Riley import java.io.*; class filesys { // Declare class for Open File table here // Definitions // Max length of file name public static final int MAX_FILE_NAME = 8; // We only track 128 total files public static final int MAX_FILES = 128; // We only have 10 open files at once public static final int MAX_FILESOPEN = 10; // You will likely need some static variables to represent // the Directory, FAT, and OpenFile table. // Static data private static int[] FAT = new int[FAT_SIZE_INT]; // The FAT Table private static dirent[] DIR = new dirent[MAX_FILES]; // The directory //private static OpenFile[] files = new OpenFile[MAX_FILESOPEN]; private static int FAT_UNLINKED = 0xffffffff; // Unlinked FAT entry // Private static functions // FAT Helpers private static int LoadFAT() throws IOException { byte f[] = new byte[NUMBER_CLUSTERS * 4]; // Each FAT entry four bytes physical.ReadData(f, 0, FAT_SECTORS); ByteArrayInputStream bi = new ByteArrayInputStream(f); DataInputStream di = new DataInputStream(bi); int i; for (i = 0; i < NUMBER_CLUSTERS; ++i) { FAT[i] = di.readInt(); } return 0; } private static int StoreFAT() throws IOException { ByteArrayOutputStream bo = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(bo); int i; for (i = 0; i < NUMBER_CLUSTERS; ++i) { dos.writeInt(FAT[i]); } byte f[] = bo.toByteArray(); physical.WriteData(f, 0, FAT_SECTORS); return 0; } // Directory Helpers private static int LoadDIR() throws IOException { byte f[] = new byte[DIR_BYTES]; physical.ReadData(f, 0, DIR_SECTORS); ByteArrayInputStream bi = new ByteArrayInputStream(f); DataInputStream di = new DataInputStream(bi); for (int i = 0; i < MAX_FILES; ++i) { //System.out.println("NewDirent " + i + " maxf " + MAX_FILES); //System.out.println("available " + bi.available()); DIR[i] = new dirent(); try { DIR[i].readExternal(di); } catch (Exception e) { } } return 0; } private static int StoreDIR() throws IOException { ByteArrayOutputStream bo = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(bo); for (int i = 0; i < MAX_FILES; ++i) { //System.out.println("StoreDir " + i); DIR[i].writeExternal(dos); } byte f[] = bo.toByteArray(); physical.WriteData(f, FAT_SECTORS, DIR_SECTORS); return 0; }