Main Page   Modules   Data Structures   File List   Data Fields   Globals   Related Pages   Examples  

flashfs.h

00001 #ifndef _FS_FLASHFS_H_
00002 #define _FS_FLASHFS_H_
00003 
00004 #include <avr/pgmspace.h>
00005 #include <sys/types.h>
00006 #include <dev/flash.h>
00007 
00025 #define TYPE_DIRECTORY 1
00026 
00030 #define TYPE_FILE 2
00031 
00035 #define TYPE_NULL 0
00036 
00040 #define MAX_FILE_NAME 50
00041 
00045 #define NUMBER_OF_FILES 50
00046 
00047 /*
00048  * Number of flash pages where is stored filenames.
00049  */
00050 #define NUMBER_OF_ROOT_PAGE ((sizeof(FILENODEINFS)*NUMBER_OF_FILES+sizeof(FLASHFS))/PAGE_SIZE + 1)
00051 
00052 /*
00053  * First flkash page for storing root pages.
00054  */
00055 #define ROOT_PAGE 0
00056 
00057 /*
00058  * Defines magic string for filesystem.
00059  */
00060 #define MAGIC "edunetFS"
00061 
00062 /*
00063  * Name of root catalog.
00064  */
00065 #define ROOT_CATALOG "/"
00066 
00067 /*
00068  * Maximum number of flash pages allocated to filesystem.
00069  */
00070 #define MAX_PAGE_NUMBER 8000
00071 
00072 /*
00073  * Number of pages contains information about free pages for files is stored.
00074  */
00075 #define NUMBER_OF_FAT_PAGE (MAX_PAGE_NUMBER/(PAGE_SIZE*8) + 1)
00076 
00077 /*
00078  * Number of needed bytes for stor information about free and empty pages in flash for filesystem.
00079  */
00080 #define NUMBER_OF_PACK_UNIT ((MAX_PAGE_NUMBER/(PAGE_SIZE*8) + 1) * PAGE_SIZE)
00081 
00082 /*
00083  * First flash page where files data will be stored.
00084  * start(root page) + nr of root p + nr of fat p + 1
00085  */
00086 #define FIRST_FILE_PAGE \
00087         (ROOT_PAGE \
00088         + ((sizeof(FILENODEINFS)*NUMBER_OF_FILES+sizeof(FLASHFS))/PAGE_SIZE + 1) \
00089         + MAX_PAGE_NUMBER/(PAGE_SIZE*8) + 1 \
00090         + 1)
00091 
00092 /*
00093  * Defines thet flash page is used to stor data.
00094  */
00095 #define NOT_CLEAR 1
00096 
00097 /*
00098  * Defines that flash page is clear.
00099  */
00100 #define CLEAR 0
00101 
00102 /*
00103  * Index of pointer to next page in flash page witch contains file data.
00104  */
00105 #define NEXT_PAGE PAGE_SIZE - sizeof(u_short)
00106 
00110 #define EOF 0
00111 
00112 typedef struct _FLASHFS FLASHFS;
00113 typedef struct _FILENODE FILENODE;
00114 typedef struct _FILENODEINFS FILENODEINFS;
00119 typedef struct _FILE FILE;
00120 typedef struct _FATINMEMORY FATINMEMORY;
00121 
00122 /*
00123  * Information about file stored in ram memory.
00124  */
00125 struct _FILENODE {
00126     /*
00127      * Pointer to next fileNode/
00128      */
00129     FILENODE*   fileNodeNext;
00130     /*
00131      * Name of file.
00132      */
00133     u_char      fileName[MAX_FILE_NAME];
00134     /*
00135      * Number of file bytes.
00136      */
00137     u_long      fileSize;
00138     /*
00139      * Number of first page in flash.
00140      */
00141     u_short     firstPage;
00142     /*
00143      * Identyfier defines on which mode file was open.
00144      */
00145     u_char        operationType;
00146 };
00147 
00148 /*
00149  * Information about file stored in filesystem.
00150  * Information is stored in root pages.
00151  */
00152 struct _FILENODEINFS {
00153     /*
00154      * Name of file.
00155      */
00156     u_char      fileName[MAX_FILE_NAME];    
00157     /*
00158      * Number of file bytes.
00159      */
00160     u_long      fileSize;
00161     /*
00162      * Number of first page in flash.
00163      */
00164     u_short     firstPage;
00165 };
00166 
00167 /*
00168  * File descriptor used by read and write function.
00169  * Created when file is open.
00170  */
00171 struct _FILE {
00172     /*
00173      * Pinter to file information.
00174      */
00175     FILENODE    *fileNode;
00176     /*
00177      * Current position on page.
00178      */
00179     u_short     positionOnPage;
00180     /*
00181      * Current page number.
00182      */
00183     u_short     pageNumber;
00184 };
00185 
00186 /*
00187  * Information about filesystem stored in flash.
00188  */
00189 struct _FLASHFS {
00190     /*
00191      * Mugic string.
00192      */
00193         char magic[sizeof(MAGIC)];
00194     /*
00195      * Number of used flash pages.
00196      */
00197         u_short numberOfPage;
00198 };
00199 
00200 /*
00201  * Fat information stored in ram.
00202  * Defines which page is used for file data.
00203  */
00204 struct _FATINMEMORY {
00205     /*
00206      * Compresed information about used page.
00207      * One bit - one flash page.
00208      */
00209         u_char packUnit[NUMBER_OF_PACK_UNIT];
00210 };
00211 
00218 extern int InitFlashFs(void);
00219 
00231 extern FILE* fileOpen(char* name, char type);
00232 
00244 extern int fileWrite(FILE *file, void *data, u_int size);
00245 
00253 extern int fileClose(FILE *file);
00254 
00266 extern int fileRead(FILE *file, void *data, u_int size);
00267 
00275 extern u_long fileSize(FILE *file);
00276 
00286 extern int fileSeek(FILE *file, u_long pos);
00287 
00296 extern int remove(char* name);
00297 
00309 extern char* ls(char* dir, char* ret, char* param);
00310 
00311 /*
00312  * Changes current directory.
00313  * (not implemented)
00314  *
00315  * \param dir - directory path.
00316  *
00317  * \return 0 on succes -1 on fail.
00318  */
00319 extern int cd(char* dir);
00320 
00321 /*
00322  * Print current working directory.
00323  * (not implemented)
00324  * 
00325  * \param ret - pointer to buffor where output will be stored.
00326  *
00327  * \return pointer to buffor where output will be stored.
00328  */
00329 extern char* pwd(char* ret);
00330 
00337 extern int format(void);
00338 
00339 #endif

Generated on Thu Jan 30 22:30:45 2003 for EduNet by doxygen1.2.18