X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=nxtOSEK%2Flejos_nxj%2Fsrc%2Fjava%2Fclasses%2Fjava%2Fio%2FFile.java;fp=nxtOSEK%2Flejos_nxj%2Fsrc%2Fjava%2Fclasses%2Fjava%2Fio%2FFile.java;h=79c0b23ab45dadad03f11ed8aa2898aa7f42f146;hb=02b55ed885bb3a3127d172ffe12a89eef34ef839;hp=9a83598a4fca35cf12bc762f40986874a41e8296;hpb=815664f1648545c25bb41fd4c99117bf488c7735;p=nxt-jsp%2Flejos_nxj.git diff --git a/nxtOSEK/lejos_nxj/src/java/classes/java/io/File.java b/nxtOSEK/lejos_nxj/src/java/classes/java/io/File.java index 9a83598..79c0b23 100644 --- a/nxtOSEK/lejos_nxj/src/java/classes/java/io/File.java +++ b/nxtOSEK/lejos_nxj/src/java/classes/java/io/File.java @@ -1,7 +1,21 @@ package java.io; +//import lejos.nxt.comm.RConsole; import lejos.nxt.Flash; -import java.io.IOException; + +/* + * DEVELOPER NOTES: + * - Requirement is for all files to be contiguous (unfragmented) so + * that they can be executed. + * - Files are stored in the flash memory one file after another. + * - If a user opens a file and wants to write to it, the file system + * shuffles the file to the end so that it has open space to write. + * - This File system is currently unthreaded, so all functions are + * blocked until each call completes. If someone starts writing to + * a file and it needs to be shuffled, a significant pause can + * occur to shuffle files around. If this was threaded it might be + * possible to avoid this pause. + */ /** * Implements a file system using pages of flash memory. @@ -14,6 +28,16 @@ public class File { //static int count; Used for anything? // CONSTANTS: /** + * MS-DOS File attribute constants: + */ + private static final byte READ_ONLY_ATTR = 0x01; + private static final byte HIDDEN_ATTR = 0x02; + //private static final byte SYSTEM_ATTR = 0x04; // System file + //private static final byte VOLUME_LABEL_ATTR = 0x08; + //private static final byte DIRECTORY_ATTR = 0x10; + //private static final byte ARCHIVE_ATTR = 0x20; + + /** * Number of files the file system can store. * Defines the size of the files array. If leJOS gets a garbage * collector we can get rid of this limitation. @@ -33,17 +57,17 @@ public class File { * version number/string, the users file system will reformat automatically. * (i.e. Restarting file system and erasing their current stored classes) */ - private static final String TABLE_ID = "V_0.3"; + private static final String TABLE_ID = "V_0.4"; /** * Indicates the starting page of the file table. */ - private static byte TABLE_START_PAGE = 0; + private static byte TABLE_START_PAGE = 1; /** * Number of pages reserved for storing file table information. * If we want to allow more files to be stored in system, increase - * this number. (!! File table data currently only writes to page 0.) + * this number. */ private static byte FILE_TABLE_PAGES = 2; @@ -110,6 +134,13 @@ public class File { boolean exists = false; /** + * Byte that stores bit-wise data of file attributes, like hidden, + * locked, compressed, delete on exit, etc... + * See file attribute constants above + */ + byte file_attributes; + + /** * Creates a new File object. If this file exists on disk it will * represent that file. If the file does not exist, you will need to * use createNewFile() before writing to the file. @@ -235,6 +266,23 @@ public class File { public boolean exists() { return exists; } + + public boolean canRead() { + return true; // All files can be read in NXJ + } + + public boolean canWrite() { + return !((file_attributes & READ_ONLY_ATTR) == READ_ONLY_ATTR); + } + + public boolean isHidden() { + return (file_attributes & HIDDEN_ATTR) == HIDDEN_ATTR; + } + + public boolean setReadOnly() { + file_attributes = (byte)(file_attributes | READ_ONLY_ATTR); + return true; // Supposed to return false if unsuccessful + } /** * Reads the file information in the table from flash memory and @@ -255,7 +303,7 @@ public class File { for(int i=0;i>8)); writeNextByte((byte)(files[arrayIndex].file_length>>16)); writeNextByte((byte)(files[arrayIndex].file_length>>24)); + // Write file attributes: + writeNextByte(files[arrayIndex].file_attributes); // Write length of name: writeNextByte((byte)(files[arrayIndex].file_name.length())); // Write name: @@ -381,8 +432,10 @@ public class File { writeBufftoFlash(); ++page_pointer; // Throw exception here if > FILE_TABLE_PAGES - 1: - if(page_pointer >= FILE_TABLE_PAGES) + if(page_pointer >= FILE_TABLE_PAGES){ + File.dumpFileTable(); throw new IOException("File table is full. Try deleting some files."); + } byte_pointer = 0; } @@ -391,6 +444,35 @@ public class File { } /** + * Debugger method. Comment out when no longer buggy. + * + */ + public static void dumpFileTable() { + if(files == null) listFiles(); // Fill list + /* + RConsole.print("byte_pointer = " + byte_pointer + "\n"); + RConsole.print("page_pointer = " + page_pointer + "\n"); + RConsole.print("FILE_TABLE_PAGES = " + FILE_TABLE_PAGES + "\n"); + RConsole.print("files.length = " + files.length + "\n"); + RConsole.print("totalFiles = " + totalFiles + "\n"); + + for(int i=TABLE_START_PAGE;i