20 | | This implementation uses memory caches implemented in the distributed kernel heap. |
21 | | There is actually one cache per file (called '''file_cache'''), and one cache for the FAT itself (called '''fat_cache'''). |
22 | | The cache size is not fixed: it is dynamically increased from the kernel heap as required by the read / write access to the files or to the FAT itself. The memory allocated to a given cache_file is only released when the file is closed. |
| 20 | This implementation uses define four data structures: |
| 21 | * The '''File-Cache''' and '''Fat-Cache''' are dynamically allocated memory caches, implemented in the distributed kernel heap. |
| 22 | There is actually one cache per file (File_Cache), and one cache for the FAT itself (called '''Fat_Cache'''). The cache size is not fixed: it is dynamically increased from the kernel heap as required by the read / write access to the files or to the FAT itself. The memory allocated to a given cache_file is only released when the file is closed. |
24 | | In the present implementation, there is no rescue mechanism in case of heap overflow: The system crash |
25 | | with a nice error message on the kernel terminal... |
| 24 | * The '''Inode-Tree''' is an internal representation of the FAT. It is a sub-tree of the File System tree. Each node define a file or a directory, and contains a pointer on the associated File-Cache. This Inode-Tree is dynamically increased from the distributed kernel heap when a file or a directory is accessed. The memory allocated to the Inode-Tree is only released in case of system crash. |
| 25 | |
| 26 | * The '''File-Descriptor-Array''' is a statically defined array of file descriptors. According to the UNIX semantic, a private file descriptor is allocated to a task requiring to open a file, and contains mainly the current file pointer (called ''offset''). The max number of file descriptors is defined by the GIET_OPEN_FILES_MAX global variable (in the ''get_config.h'' file). |
| 27 | |
| 28 | * The global Fat_Descriptor contains general information such as the FAT region lba and size, the DATA region lba and size, and pointers on the Fat-Cache or Inode-Tree. |
| 29 | |
| 30 | WARNING 1: A node name (file or directory) cannot be larger than 38 characters. |
| 31 | |
| 32 | WARNING 2: There is no rescue mechanism at the moment in case of heap overflow: The system crash with a nice error message on the kernel terminal... |
45 | | For a '''file_cache''', the GIET_VM implements a WRITE-BACK policy. The data are always modified in the cache. In case of miss, new clusters are allocated to the target file, the cache is updated from the block device, and the data are modified in the cache, but not in the block device. The modified clusters are written on the block device only when the file is closed, using the dirty flag implemented in each cluster descriptor. |
| 52 | For the '''File_Cache''', the GIET_VM implements a WRITE-BACK policy. In case of write, the data are always modified in the cache. In case of miss, new clusters are allocated to the target file, the cache is updated from the block device, and the data are modified in the cache, but not on the block device. The modified clusters are written on the block device only when the file is closed, using the dirty flag implemented in each cluster descriptor. |
60 | | * ''' count''' : number of blocks to be transfered |
| 67 | * ''' count''' : number of blocks to be transferred |
| 68 | |
| 69 | == 5) Access Functions == |
| 70 | |
| 71 | === int '''_fat_init'''( unsigned int use_irq ) === |
| 72 | This function initializes the statically defined FAT structures: |
| 73 | * Fat-Descriptor |
| 74 | * File-Descriptors-Array |
| 75 | * Fat_Cache root |
| 76 | * Inode_Tree root |
| 77 | As is called by the boot-loader, and by the kernel_init, it does not use dynamic memory allocation. |
| 78 | The polling/descheduling mode is defined by the '''use_irq''' argument. |
| 79 | It use informations found in the boot sector and FS-INFO sector, that are loaded in the FAT 512 bytes buffer. |
| 80 | It returns 0 if success / It returns -1 if failure. |
| 81 | |
| 82 | === int '''_fat_open'''( unsigned int use_irq , char* pathname ) === |
| 83 | This function implements the giet_fat_open() system call. |
| 84 | The semantic is similar to the UNIX open() function, but the UNIX flags and access rights are not supported. |
| 85 | If the file does not exist in the specified directory, it is created, and both the Inode-Tree, the Fat-Cache and the FAT region |
| 86 | on device true are updated.. |
| 87 | If the specified directory does not exist, an error is returned. |
| 88 | In case of success, It allocates a private file descriptor to the calling task, and the reference count is updated. |
| 89 | * '''use_irq''' : boolean (use descheduling mode if supported by the IOC driver) |
| 90 | * '''pathname''' : define both the specified directory and the file name. |
| 91 | It returns the file descriptor index if success / It returns -1 if failure. |
| 92 | |
| 93 | === int '''_fat_close'''( unsigned int fd_id ) === |
| 94 | This function implements the "giet_fat_close()" system call. |
| 95 | The semantic is similar to the UNIX "close()" function. |
| 96 | It decrements the inode reference count, and release the fd_id entry in the file descriptors array. |
| 97 | If the reference count is zero, it writes all dirty clusters on block device, and releases the memory allocated to the file_cache. |
| 98 | * '''fd_id''' : file descriptor index |
| 99 | It returns 0 if success / It returns -1 if failure. |
| 100 | |
| 101 | |