167 | | The Giet-VM supports a FAT32 file system. |
168 | | |
169 | | === 1) int '''giet_fat_open'''( const char* pathname, unsigned int flags ) === |
170 | | This function open a file identified by the ''pathname'' argument. The read/write ''flags'' are not supported yet: no effect. Return -1 in case or error. |
171 | | |
172 | | === 2) void '''giet_fat_read'''( unsigned int fd, void* buffer, unsigned int count, unsigned int offset ) === |
173 | | Read ''count'' sectors from a file identified by the ''fd'' argument, skipping ''offset'' sectors in file, and writing into the user memory ''buffer''. The user buffer base address should be 64 bytes aligned. |
174 | | In case or error, it makes a giet_exit(). |
175 | | |
176 | | === 3) void '''giet_fat_write'''( unsigned int fd, void* buffer, unsigned int count, unsigned int offset ) === |
177 | | Write ''count'' sectors into a file identified by the ''fd'' argument, skipping ''offset'' sectors in file, and reading from the user memory ''buffer''. The user buffer base address should be 64 bytes aligned. |
178 | | In case or error, it makes a giet_exit(). |
179 | | |
180 | | === 4) void '''giet_fat_close'''( unsigned int fd ) === |
181 | | Close a file identified by the ''fd'' file descriptor. |
182 | | |
| 167 | The Giet-VM supports a FAT32 file system, and uses distributed data structures to access the file system: |
| 168 | * The Inode-Tree (distributed on all clusters) is the internal representation of the File System tree. |
| 169 | * The Fat-Cache (distributed on all clusters) is used to cache the FAT region of the block device. |
| 170 | * The Fat-Cache (distributed on all clusters / one cache per open file) is used to cache the DATA region of the block device. |
| 171 | * The File-Descriptor-Array (in cluster[0,0]) contains the open files descriptors. |
| 172 | * The Fat-Descriptor (in cluster[0,0] contains the FAT32 general information. |
| 173 | |
| 174 | === 1) int '''giet_fat_open'''( char* pathname ) === |
| 175 | This function allocates a file descriptor to the calling task, for the file identified by its absolute "pathname". |
| 176 | If several tasks try to open the same file, each task obtains a private file descriptor. |
| 177 | The semantic is similar to the UNIX open() function, but the UNIX oflags and the UNIX access rights are not supported. |
| 178 | If the file does not exist in the specified directory, it is created. |
| 179 | If the specified directory does not exist, an error is returned. |
| 180 | |
| 181 | WARNING: A node name (file or directory) cannot be larger than 30 characters. |
| 182 | |
| 183 | Returns the file descriptor index if success |
| 184 | Returns -1 if error. |
| 185 | |
| 186 | === 2) '''void giet_fat_close'''( unsigned int fd_id ) === |
| 187 | Close a file identified by the ''fd_id'' file descriptor. |
| 188 | It decrements the reference count in the inode associated to the file, and release the fd_id entry in the file descriptors array. |
| 189 | If the reference count is zero, it writes all dirty clusters on block device, and releases the memory allocated to the file_cache. |
| 190 | |
| 191 | === 3) '''void get_fat_file_info'''( unsigned int fd_id , unsigned int* size , unsigned int* offset ) === |
| 192 | This function returns the "size" and the current "offset" value for a file identified by the "fd_id" argument. |
| 193 | |
| 194 | === 4) int '''giet_fat_read'''( unsigned int fd_id , void* buffer , unsigned int count ) === |
| 195 | This function has the same semantic as the UNIX "read()" function. It transfers "count" bytes from the kernel File_Cache associated to the file identified by "fd_id", to the user "buffer", starting from the current file offset. The offset value is incremented by count. |
| 196 | In case of miss in the File_Cache, it loads all involved clusters into cache. |
| 197 | |
| 198 | Returns number of bytes actually transferred if success. |
| 199 | Returns 0 if (offset + count) is larger than the file size. |
| 200 | Returns -1 if error. |
| 201 | |
| 202 | === 5) int '''giet_fat_write'''( unsigned int fd_id , void* buffer, unsigned int count ) === |
| 203 | This function has the same semantic as the UNIX "write()" function. It transfers "count" bytes from the user "buffer" to the kernel File_Cache associated to the file identified by "fd_id", starting from the current file offset. The offset value is incremented by count. It increases the file size and allocate new clusters if (count + offset) is larger than the current file size. Then it loads and updates all involved clusters in the cache. |
| 204 | The FAT region on block device is updated if new clusters are allocated, but the block device DATA region is NOT updated. |
| 205 | |
| 206 | Returns number of bytes actually transferred if success. |
| 207 | Returns -1 if error. |
| 208 | |
| 209 | === int '''giet_fat_lseek'''( unsigned int fd_id , unsigned int offset , unsigned int whence ) === |
| 210 | This function has the same semantic as the UNIX lseek() function. |
| 211 | It repositions the offset in the file descriptor "fd_id", according to the "offset" and "whence" arguments. |
| 212 | The two accepted values for the whence argument are SEEK_SET (new_offset <= offset), and SEEK_CUR (new_offset <= current_offset + offset). |
| 213 | |
| 214 | Returns new offset value (bytes) if success. |
| 215 | Returns -1 if error. |
| 216 | |
| 217 | === int '''giet_fat_rm'''( char* pathname ) === |
| 218 | This function has the same semantic as the UNIX unlink() function. |
| 219 | It deletes a file identified by the absolute "pathname" argument from the sile system. |
| 220 | AN error is reported if the references count (number of open file descriptor) is not zero. |
| 221 | All clusters allocated to this file in the block device DATA region are released. |
| 222 | The Inode-Tree is updated. |
| 223 | the Fat-Cache is updated, and the FAT region is updated on the block device. |
| 224 | The memory allocated for the associated File_Cache is released. |
| 225 | |
| 226 | Returns 0 if success. |
| 227 | Returns -1 if error. |
| 228 | |
| 229 | === int '''get_fat_mkdir( char* pathname ) === |
| 230 | This function has the same semantic as the UNIX mkdir() function. |
| 231 | It creates in the file system the directory specified by the absolute "pathname" argument. |
| 232 | The Inode-Tree is updated. |
| 233 | One cluster is allocated to the new directory, containing the "." and ".." entries. |
| 234 | The associated File-Cache is created. |
| 235 | The Fat-Cache is updated, and the FAT region on block device is updated. |
| 236 | The DATA region on block device is updated. |
| 237 | |
| 238 | Returns 0 if success. |
| 239 | Returns -1 if error. |
| 240 | |
| 241 | === void '''get_fat_rmdir'''( char* pathname ) === |
| 242 | This function has the same semantic as the UNIX mkdir() function. |
| 243 | It deletes the directory specified by the absolute "pathname" argument from the file system. |
| 244 | The Fat-Cache is updated, and the FAT region on block device is updated. |
| 245 | The Inode-Tree is updated. |
| 246 | The memory allocated to the File-Cache is released. |
| 247 | |
| 248 | Returns 0 if success. |
| 249 | Returns -1 if error. |