Main Page | Modules | Data Structures | Directories | File List | Data Fields | Globals

# filesys.h

Go to the documentation of this file.

    00001 /*
    00002  *  Copyright (c) 2004, Dennis Kuschel.
    00003  *  All rights reserved.
    00004  *
    00005  *  Redistribution and use in source and binary forms, with or without
    00006  *  modification, are permitted provided that the following conditions
    00007  *  are met:
    00008  *
    00009  *   1. Redistributions of source code must retain the above copyright
    00010  *      notice, this list of conditions and the following disclaimer.
    00011  *   2. Redistributions in binary form must reproduce the above copyright
    00012  *      notice, this list of conditions and the following disclaimer in the
    00013  *      documentation and/or other materials provided with the distribution.
    00014  *   3. The name of the author may not be used to endorse or promote
    00015  *      products derived from this software without specific prior written
    00016  *      permission.
    00017  *
    00018  *  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
    00019  *  OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
    00020  *  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    00021  *  ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
    00022  *  INDIRECT,  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    00023  *  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
    00024  *  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    00025  *  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
    00026  *  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    00027  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
    00028  *  OF THE POSSIBILITY OF SUCH DAMAGE.
    00029  *
    00030  */
    00031
    00041 #ifndef _FILESYS_H
    00042 #define _FILESYS_H
    00043 #define HAVE_EMBEDDED_FILESYSTEM  1
    00044
    00045 #include "sys.h"
    00046
    00049 #ifndef FS_MAXFILES
    00050
    00054 #define FS_MAXFILES             10
    00055 #endif
    00056
    00057 #ifndef FS_STANDARD_API
    00058
    00062 #define FS_STANDARD_API         0
    00063 #endif
    00064
    00065 #ifndef FS_SUBDIRECTORIES
    00066
    00070 #define FS_SUBDIRECTORIES       1
    00071 #endif
    00072
    00073 #ifndef FS_MAXFNAMELEN
    00074
    00077 #define FS_MAXFNAMELEN          256
    00078 #endif
    00079
    00080 /* Flags used with fsys_open */
    00081 #define FSO_RDWR        0x000
    00082 #define FSO_RDONLY      0x001
    00083 #define FSO_WRONLY      0x002
    00084 #define FSO_CREAT       0x004
    00085 #define FSO_TRUNC       0x008
    00086 #define FSO_SEQUENTIAL  0x000
    00087 #define FSO_RANDOM      0x010
    00088 #define FSO_BINARY      0x000
    00089 #define FSO_TEXT        0x020
    00090 #define FSO_EXCL        0x040
    00091 #define FSO_APPEND      0x080
    00093 /* Flags used with fsys_stat */
    00094 #define FSS_IFMT        0x00170000
    00095 #define FSS_IFDIR       0x00040000
    00096 #define FSS_IFCHR       0x00020000
    00097 #define FSS_IFIFO       0x00010000
    00098 #define FSS_IFREG       0x00100000
    00099 #define FSS_IREAD       0x00000400
    00100 #define FSS_IWRITE      0x00000200
    00101 #define FSS_IEXEC       0x00000100
    00103 /* Attributes used with by the structure struct fsys_finddata */
    00104 #define FSA_NORMAL      0x00
    00105 #define FSA_RDONLY      0x01
    00106 #define FSA_HIDDEN      0x02
    00107 #define FSA_SYSTEM      0x04
    00108 #define FSA_SUBDIR      0x08
    00109 #define FSA_ARCH        0x10
    00111 /* Flags used with fsys_seek */
    00112 #define FSSEEK_SET      0
    00113 #define FSSEEK_CUR      1
    00114 #define FSSEEK_END      2
    00117 /* Define macros to match the standard I/O API */
    00118 #if FS_STANDARD_API
    00119
    00120 #define O_RDWR          FSO_RDWR
    00121 #define O_RDONLY        FSO_RDONLY
    00122 #define O_WRONLY        FSO_WRONLY
    00123 #define O_CREAT         FSO_CREAT
    00124 #define O_TRUNC         FSO_TRUNC
    00125 #define O_SEQUENTIAL    FSO_SEQUENTIAL
    00126 #define O_RANDOM        FSO_RANDOM
    00127 #define O_BINARY        FSO_BINARY
    00128 #define O_TEXT          FSO_TEXT
    00129 #define O_EXCL          FSO_EXCL
    00130 #define O_APPEND        FSO_APPEND
    00131
    00132 #define S_IFMT          FSS_IFMT
    00133 #define S_IFDIR         FSS_IFDIR
    00134 #define S_IFCHR         FSS_IFCHR
    00135 #define S_IFIFO         FSS_IFIFO
    00136 #define S_IFREG         FSS_IFREG
    00137 #define S_IREAD         FSS_IREAD
    00138 #define S_IWRITE        FSS_IWRITE
    00139 #define S_IEXEC         FSS_IEXEC
    00140
    00141 #define A_NORMAL        FSA_NORMAL
    00142 #define A_RDONLY        FSA_RDONLY
    00143 #define A_HIDDEN        FSA_HIDDEN
    00144 #define A_SYSTEM        FSA_SYSTEM
    00145 #define A_SUBDIR        FSA_SUBDIR
    00146 #define A_ARCH          FSA_ARCH
    00147
    00148 #define open(a,b)       fsys_open(a,b)
    00149 #define close(a)        fsys_close(a)
    00150 #define read(a,b,c)     fsys_read(a,b,c)
    00151 #define write(a,b,c)    fsys_write(a,b,c)
    00152 #define eof(a)          fsys_eof(a)
    00153 #define seek(a,b,c)     fsys_seek(a,b,c)
    00154 #define tell(a)         fsys_tell(a)
    00155 #define stat            fsys_stat
    00156 #define findfirst(a,b)  fsys_findfirst(a,b)
    00157 #define findnext(a,b)   fsys_findnext(a,b)
    00158 #define findclose(a)    fsys_findclose(a)
    00159 #define rename(a,b)     fsys_rename(a,b)
    00160 #define remove(a)       fsys_remove(a)
    00161
    00162 #endif
    00163
    00164
    00165 /* file time */
    00166 struct fsys_time
    00167 {
    00168   u16_t  year;
    00169   u8_t   month;
    00170   u8_t   day;
    00171   u8_t   hour;
    00172   u8_t   min;
    00173   u8_t   sec;
    00174   u8_t   spare;  /* not used  */
    00175 };
    00176
    00177 /* file status */
    00178 struct fsys_stat
    00179 {
    00180   u32_t             st_mode;
    00181   sint_t            st_size;
    00182   struct fsys_time  st_time;
    00183 };
    00184
    00185 /* file find data */
    00186 struct fsys_finddata
    00187 {
    00188   u32_t             attrib;
    00189   struct fsys_time  time;
    00190   u32_t             size;
    00191   char              name[(FS_MAXFNAMELEN+3)&~3];
    00192 };
    00193
    00194
    00231 sint_t  fsys_open(const char *filename, const sint_t mode);
    00232
    00233
    00250 sint_t  fsys_opent(char *filename, const sint_t mode);
    00251
    00252
    00259 void    fsys_close(const sint_t file);
    00260
    00261
    00273 sint_t  fsys_write(const sint_t file, const char *buf, const sint_t count);
    00274
    00275
    00288 sint_t  fsys_read(const sint_t file, const char *buf, const sint_t count);
    00289
    00290
    00299 sint_t  fsys_eof(const sint_t file);
    00300
    00301
    00322 sint_t  fsys_seek(const sint_t file, const sint_t position,
    00323                   const sint_t origin);
    00324
    00325
    00326 /* Get current file pointer position.
    00327  * This function is equivalent to the one from the runtime library.
    00328  * @param file      Handle to an open file.
    00329  * @return The current file pointer position on success or -1 when the
    00330  *         function failed.
    00331  */
    00332 sint_t  fsys_tell(const sint_t file);
    00333
    00334
    00344 sint_t  fsys_stat(const char *fname, struct fsys_stat *stat);
    00345
    00346
    00361 sint_t  fsys_findfirst(char *filespec, struct fsys_finddata *fileinfo);
    00362
    00363
    00377 sint_t  fsys_findnext(sint_t handle, struct fsys_finddata *fileinfo);
    00378
    00379
    00389 sint_t  fsys_findclose(sint_t handle);
    00390
    00391
    00398 sint_t  fsys_remove(const char *filename);
    00399
    00400
    00408 sint_t  fsys_rename(const char *from, const char *to);
    00409
    00410
    00432 sint_t  fsys_replace(const char *oldfile, const char *newfile);
    00433
    00434
    00435 #if FS_SUBDIRECTORIES
    00436
    00444 sint_t  fsys_mkdir(const char *pathname);
    00445
    00446
    00454 sint_t  fsys_rmdir(const char *pathname);
    00455
    00456
    00468 sint_t  fsys_buildPathName(char *outbuf, const char *pathname,
    00469                            const char *filename);
    00470
    00471 #endif /* FS_SUBDIRECTORIES */
    00472
    00473
    00489 sint_t  fsys_format(u32_t blocksize, u32_t maxFilenameLength);
    00490
    00491
    00496 u32_t   fsys_free(void);
    00497
    00498
    00507 u32_t   fsys_shrinkImage(void *image);
    00508
    00509
    00525 sint_t  fsys_addDriveImage(void *img, sint_t readonly);
    00526
    00527
    00546 sint_t  fsys_init(u32_t size, u32_t blocksize, u32_t maxFilenameLength);
    00547
    00548
    00555 sint_t  fsys_term(void);
    00556
    00557
    00568 void*  fsys_lockAndGetImage(u32_t *size);
    00569
    00570
    00576 void   fsys_unlockImage(void);
    00577
    00578
    00580 #endif