1 /* 2 This file is part of UFFS, the Ultra-low-cost Flash File System. 3 4 Copyright (C) 2005-2009 Ricky Zheng <[email protected]> 5 6 UFFS is free software; you can redistribute it and/or modify it under 7 the GNU Library General Public License as published by the Free Software 8 Foundation; either version 2 of the License, or (at your option) any 9 later version. 10 11 UFFS is distributed in the hope that it will be useful, but WITHOUT 12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 or GNU Library General Public License, as applicable, for more details. 15 16 You should have received a copy of the GNU General Public License 17 and GNU Library General Public License along with UFFS; if not, write 18 to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 Boston, MA 02110-1301, USA. 20 21 As a special exception, if other files instantiate templates or use 22 macros or inline functions from this file, or you compile this file 23 and link it with other works to produce a work based on this file, 24 this file does not by itself cause the resulting work to be covered 25 by the GNU General Public License. However the source code for this 26 file must still be made available in accordance with section (3) of 27 the GNU General Public License v2. 28 29 This exception does not invalidate any other reasons why a work based 30 on this file might be covered by the GNU General Public License. 31 */ 32 33 /** 34 * \file uffs_fd.h 35 * \brief PISIX like file operations 36 * \author Ricky Zheng, created 8th Jun, 2005 37 */ 38 39 #ifndef _UFFS_FD_H_ 40 #define _UFFS_FD_H_ 41 42 #ifdef __cplusplus 43 extern "C"{ 44 #endif 45 46 #include "uffs/uffs.h" 47 48 /** 49 * \brief definitions for uffs_stat::st_mode 50 */ 51 #define US_IFMT 0xF000 /* file type make */ 52 #define US_IFREG 0x8000 /* regular */ 53 #define US_IFLNK 0xA000 /* symbolic link */ 54 #define US_IFDIR 0x4000 /* directory */ 55 #define US_IREAD 0000400 /* read permission */ 56 #define US_IWRITE 0000200 /* write permission */ 57 58 #define US_IRWXU 00700 /* RWX owner */ 59 #define US_IRUSR 00400 /* R owner */ 60 #define US_IWUSR 00200 /* W owner */ 61 #define US_IXUSR 00100 /* X owner */ 62 #define US_IRWXG 00070 /* RWX group */ 63 #define US_IRGRP 00040 /* R group */ 64 #define US_IWGRP 00020 /* W group */ 65 #define US_IXGRP 00010 /* X group */ 66 #define US_IRWXO 00007 /* RWX other */ 67 #define US_IROTH 00004 /* R other */ 68 #define US_IWOTH 00002 /* W other */ 69 #define US_IXOTH 00001 /* X other */ 70 71 /** 72 * \brief POSIX dirent 73 */ 74 struct uffs_dirent { 75 int d_ino; /* inode number (serial number of this object) */ 76 int d_off; /* offset to this dirent */ 77 unsigned short int d_reclen; /* length of this uffs_dirent */ 78 unsigned short int d_namelen; /* length of this d_name */ 79 unsigned char d_type; /* type of this record */ 80 char d_name[256]; /* name of this object */ 81 }; 82 83 struct uffs_dirSt; 84 typedef struct uffs_dirSt uffs_DIR; 85 86 /** 87 * \brief POSIX stat 88 */ 89 struct uffs_stat { 90 int st_dev; /* ID of device containing file */ 91 int st_ino; /* inode number */ 92 int st_mode; /* protection */ 93 int st_nlink; /* number of hard links */ 94 int st_uid; /* user ID of owner */ 95 int st_gid; /* group ID of owner */ 96 int st_rdev; /* device ID (if special file) */ 97 long st_size; /* total size, in bytes */ 98 int st_blksize; /* blocksize for filesystem I/O */ 99 int st_blocks; /* number of blocks allocated */ 100 unsigned int st_atime; /* time of last access */ 101 unsigned int st_mtime; /* time of last modification */ 102 unsigned int st_ctime; /* time of last status change */ 103 }; 104 105 /* POSIX complaint file system APIs */ 106 107 int uffs_open(const char *name, int oflag, ...); 108 int uffs_close(int fd); 109 int uffs_read(int fd, void *data, int len); 110 int uffs_write(int fd, const void *data, int len); 111 long uffs_seek(int fd, long offset, int origin); 112 long uffs_tell(int fd); 113 int uffs_eof(int fd); 114 int uffs_flush(int fd); 115 int uffs_rename(const char *old_name, const char *new_name); 116 int uffs_remove(const char *name); 117 int uffs_ftruncate(int fd, long remain); 118 119 int uffs_mkdir(const char *name, ...); 120 int uffs_rmdir(const char *name); 121 122 int uffs_stat(const char *name, struct uffs_stat *buf); 123 int uffs_lstat(const char *name, struct uffs_stat *buf); 124 int uffs_fstat(int fd, struct uffs_stat *buf); 125 126 int uffs_closedir(uffs_DIR *dirp); 127 uffs_DIR * uffs_opendir(const char *path); 128 struct uffs_dirent * uffs_readdir(uffs_DIR *dirp); 129 130 void uffs_rewinddir(uffs_DIR *dirp); 131 132 133 int uffs_get_error(void); 134 int uffs_set_error(int err); 135 136 int uffs_version(void); 137 int uffs_format(const char *mount_point); 138 139 long uffs_space_total(const char *mount_point); 140 long uffs_space_used(const char *mount_point); 141 long uffs_space_free(const char *mount_point); 142 143 void uffs_flush_all(const char *mount_point); 144 145 #ifdef __cplusplus 146 } 147 #endif 148 #endif 149 150 151 152