53 | | For the '''File-Caches''', 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 if required, 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 last reference is closed, using the dirty flag implemented in each cluster descriptor. |
| 53 | For the '''File-Caches''', 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 if required, 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 last reference is closed, using the dirty flag implemented in each buffer descriptor. |
61 | | The following functions implement the FAT related system calls. |
| 61 | === __int '''_fat_ioc_access'''( unsigned int use_irq , unsigned int to_mem , unsigned int lba , unsigned int buf_vaddr , unsigned int count )__ === |
| 62 | This function transfers one or several blocks between the block device and a memory buffer by calling the relevant driver. The <use_irq> boolean argument forces the descheduling mode if supported by the IOC driver. |
| 63 | The <to_mem> boolean argument defines the transfer direction (from block device to memory if non zero). The |
| 64 | <lba> argument is the first block address on the block device. The <buf_vaddr> argument is the memory buffer virtual address. The <count> argument is the number of blocks to be transferred. |
| 65 | |
| 66 | It returns 0 on success, or a negative value on failure. |
65 | | * in '''boot mode''' (kernel_mode == 0), it initializes only the statically defined Fat-Descriptor, using informations found in the boot sector and FS-INFO sector, that are loaded in the FAT descriptor 512 bytes buffer. In this mode, it is used by the boot code to load the ''kernel.elf'' file, and the various ''application.elf'' files, into memory by accessing directly to the block device. |
| 70 | The <kernel_mode> argument defines the initialization mode: |
| 71 | * in '''boot mode''' (kernel_mode == 0), it initializes only the statically defined Fat-Descriptor, using informations found in the BOOT sector, that is loaded in the FAT descriptor 512 bytes buffer. In this mode, it is used by the boot code to load the ''kernel.elf'' file, and the various ''application.elf'' files, into memory by accessing directly to the block device. |
73 | | This function implements the giet_fat_open() system call. |
74 | | The semantic is similar to the UNIX open() function, but only the O_CREATE, O_RDONLY and O_TRUNCATE flags are supported. The UNIX access rights are not supported. |
75 | | If the file does not exist in the specified directory, it is created, and the Inode-Tree, |
76 | | the Fat-Cache and the FAT region on device are updated. |
77 | | If the specified directory does not exist, an error is returned. |
78 | | It allocates a file descriptor to the calling task, for the file identified |
79 | | by "pathname". If several tasks try to open the same file, each task |
80 | | obtains a private file descriptor and the reference count is updated. |
81 | | A node name (file or directory) cannot be larger than 31 characters. |
82 | | * '''pathname''' : defines both the specified directory and the file name. |
83 | | * '''flags''' : O_CREATE, O_RDONLY, O_TRUNCATE (can be OR'ed). |
84 | | Returns a file descriptor index on success. Returns a negative value on error: |
85 | | * GIET_FAT32_NOT_INITIALIZED, |
86 | | * GIET_FAT32_FILE_NOT_FOUND, |
87 | | * GIET_FAT32_NAME_TOO_LONG, |
88 | | * GIET_FAT32_IO_ERROR, |
89 | | * GIET_FAT32_TOO_MANY_OPEN_FILES |
| 77 | This function implements the ''giet_fat_open()'' system call. It allocates a file descriptor to the calling task, for the file identified by the <pathname> argument. |
| 78 | The semantic is similar to the UNIX ''open()'' function, but only the O_CREAT, O_RDONLY and O_TRUNCATE <flags> are supported. The UNIX access rights are not supported. |
| 79 | If the file does not exist in the specified directory, it is created, and the Inode-Tree, the Fat-Cache and the FAT region on device are updated. If the specified directory does not exist, an error is returned. |
| 80 | If several tasks try to open the same file, each task obtains a private file descriptor and the reference count is updated. |
| 81 | WARNING : A node name (file or directory) cannot be larger than 31 characters. |
| 82 | |
| 83 | Returns a file descriptor index on success. Returns a negative value on error. |
105 | | This function implements the giet_fat_file_info() system call. |
106 | | It returns the size, offset value and is_dir info for a file identified by the "fd_id" argument. |
107 | | * '''fd_id''' : file descriptor index |
108 | | * '''info''' : pointer to the fat_file_info_s struct storing the values (return buffer) |
109 | | Returns GIET_FAT32_OK on success. Returns a negative value on error: |
110 | | * GIET_FAT32_NOT_INITIALIZED, |
111 | | * GIET_FAT32_INVALID_FD, |
112 | | * GIET_FAT32_NOT_OPEN |
113 | | |
114 | | === __int '''_fat_read'''( unsigned int fd_id , paddr_t buffer , unsigned int count, unsigned int phys )__ === |
115 | | This function implements the "giet_fat_read()" system call. |
116 | | It accesses the File_Cache associated to the file identified by the file descriptor, and transfers "count" bytes from the cache to the user buffer, starting from the current file offset. |
| 95 | This function implements the ''giet_fat_file_info()'' system call. |
| 96 | It returns in the <info> argument, the size, offset, and is_dir attributes for a file identified by the <fd_id> argument. |
| 97 | |
| 98 | Returns GIET_FAT32_OK on success. Returns a negative value on error. |
| 99 | |
| 100 | === __int '''_fat_read'''( unsigned int fd_id , unsigned int vaddr , unsigned int count, unsigned int extend, unsigned int offset , unsigned int modes )__ === |
| 101 | This function implements the ''giet_fat_read()'' system call. |
| 102 | It accesses the File_Cache associated to the file identified by the <fd_id> argument, and transfers <count> bytes from the cache to the buffer defined by the <vaddr> argument, starting from the current file offset. |
| 103 | The <modes> argument define the special access modes: |
| 104 | If FAT_PADDR_MODE is set, the <extend> argument defines the physical address extension. |
| 105 | If FAT_FORCED_OFFSET is set, the <offset> argument define the actual file offset. |
118 | | * '''fd_id''' : file descriptor index |
119 | | * '''buffer''' : pointer to the memory buffer |
120 | | * '''count''' : number of bytes |
121 | | * '''phys''' : use _physical_memcpy instead of memcpy |
122 | | Returns the number of bytes actually transferred. Returns a negative value on error: |
123 | | * GIET_FAT32_NOT_INITIALIZED, |
124 | | * GIET_FAT32_INVALID_FD, |
125 | | * GIET_FAT32_NOT_OPEN, |
126 | | * GIET_FAT32_IO_ERROR |
127 | | |
128 | | === __int '''_fat_write'''( unsigned int fd_id , void* buffer , unsigned int count )__ === |
129 | | This function implements the "giet_fat_write()" system call. |
130 | | It accesses the File-Cache associated to the file identified by the file descriptor, and transfers count bytes from the user buffer, to the cache, starting from the current file offset. It loads all involved clusters into cache if required. If (offset + count) is larger than the current file size, the file size will be increased. It allocates new clusters if required, and updates the Fat-Cache and the FAT region on block device. As it implements a Write-Back policy, the DATA region on block device is not updated, but the modified clusters are marked dirty. |
131 | | * '''fd_id''' : file descriptor index |
132 | | * '''buffer''' : pointer on the memory buffer |
133 | | * '''count''' : number of bytes |
134 | | Returns number of bytes actually written on success. Returns a negative value on error: |
135 | | * GIET_FAT32_NOT_INITIALIZED, |
136 | | * GIET_FAT32_INVALID_FD, |
137 | | * GIET_FAT32_NOT_OPEN, |
138 | | * GIET_FAT32_READ_ONLY, |
139 | | * GIET_FAT32_NO_FREE_SPACE, |
140 | | * GIET_FAT32_IO_ERROR |
| 107 | |
| 108 | Returns the number of bytes actually transferred. Returns a negative value on error. |
| 109 | |
| 110 | === __int '''_fat_write'''( unsigned int fd_id , unsigned int vaddr , unsigned int count , unsigned int extend , unsigned int modes )__ === |
| 111 | This function implements the ''giet_fat_write()'' system call. |
| 112 | It accesses the File_Cache associated to the file identified by the <fd_id> argument, and transfers <count> bytes from the buffer defined by the <vaddr> argument to the cache, starting from the current file offset. |
| 113 | The <modes> argument define the special access modes: |
| 114 | If FAT_PADDR_MODE is set, the <extend> argument defines the physical address extension. |
| 115 | It loads all involved clusters into cache if required. If (offset + count) is larger than the current file size, the file size is increased. It allocates new clusters if required, and updates the Fat-Cache. The FAT region and the FS-INFO sector are updated on block device. As it implements a Write-Back policy, the DATA region on block device is not updated, but the modified clusters are marked dirty. |
| 116 | |
| 117 | Returns number of bytes actually written on success. Returns a negative value on error. |
164 | | * '''pathname''' : complete pathname |
165 | | Returns GIET_FAT32_OK on success. Returns a negative value on error: |
166 | | * GIET_FAT32_NOT_INITIALIZED, |
167 | | * GIET_FAT32_FILE_NOT_FOUND, |
168 | | * GIET_FAT32_NAME_TOO_LONG, |
169 | | * GIET_FAT32_FILE_EXISTS, |
170 | | * GIET_FAT32_NO_FREE_SPACE, |
171 | | * GIET_FAT32_IO_ERROR |
| 134 | |
| 135 | Returns GIET_FAT32_OK on success. Returns a negative value on error. |
174 | | This function implements the giet_fat_unlink() system call, that has the same semantic as the UNIX ''unlink()'' function. |
175 | | It removes the file identified by the pathname argument from the File System. An error is returned if the number of references |
176 | | (number of open file descriptors) is not zero. |
177 | | All clusters allocated to this file in the DATA region are released. |
178 | | The FAT region is updated on the block device and the Fat-Cache is updated. |
| 138 | This function implements the ''giet_fat_unlink()'' system call, that has the same semantic as the UNIX ''unlink()'' function. |
| 139 | It removes the file or directory identified by the <pathname> argument from the File System. An error is returned if the number of references (number of open file descriptors, or number of entries for a directory) is not zero. |
| 140 | All clusters allocated to this file in the DATA region are released and the Fat-Cache is updated.. |
| 141 | The FAT region and the FS-INFO sector are updated on the block device. |
181 | | * '''pathname''' : directory complete pathname |
182 | | Returns GIET_FAT32_OK on success. Returns a negative value on error: |
183 | | * GIET_FAT32_NOT_INITIALIZED, |
184 | | * GIET_FAT32_FILE_NOT_FOUND, |
185 | | * GIET_FAT32_NAME_TOO_LONG, |
186 | | * GIET_FAT32_IS_DIRECTORY, |
187 | | * GIET_FAT32_NOT_A_DIRECTORY, |
188 | | * GIET_FAT32_IS_OPEN, |
189 | | * GIET_FAT32_IO_ERROR, |
190 | | * GIET_FAT32_DIRECTORY_NOT_EMPTY |
| 144 | |
| 145 | Returns GIET_FAT32_OK on success. Returns a negative value on error. |
200 | | * '''old_path''' : old path-name (from root). |
201 | | * '''new_path''' : new path-name (from root). |
202 | | Returns GIET_FAT32_OK on success. Returns a negative value on error: |
203 | | * GIET_FAT32_NOT_INITIALIZED, |
204 | | * GIET_FAT32_FILE_NOT_FOUND, |
205 | | * GIET_FAT32_MOVE_INTO_SUBDIR, |
206 | | * GIET_FAT32_IO_ERROR, |
207 | | * GIET_FAT32_DIRECTORY_NOT_EMPTY, |
208 | | * GIET_FAT32_IS_OPEN |
| 154 | |
| 155 | Returns GIET_FAT32_OK on success. Returns a negative value on error. |
211 | | This function implements the giet_fat_opendir() system call. |
212 | | The semantic is similar to the UNIX opendir() function. If the specified directory does not exist, an error is returned. It allocates a file descriptor to the calling task, for the directory identified by "pathname". If several tasks try to open the same directory, each task obtains a private file descriptor. A node name cannot be larger than 31 characters. |
213 | | * '''pathname''' : directory complete pathname |
214 | | Returns a file descriptor for the directory index on success. |
215 | | Returns a negative value on error: |
216 | | * GIET_FAT32_NOT_INITIALIZED, |
217 | | * GIET_FAT32_NAME_TOO_LONG, |
218 | | * GIET_FAT32_FILE_NOT_FOUND, |
219 | | * GIET_FAT32_TOO_MANY_OPEN_FILES, |
220 | | * GIET_FAT32_NOT_A_DIRECTORY |
| 158 | This function implements the ''giet_fat_opendir()'' system call. |
| 159 | The semantic is similar to the UNIX ''opendir()'' function. If the directory specified by the <pathname> argument does not exist, an error is returned. It allocates a file descriptor to the calling task. If several tasks try to open the same directory, each task obtains a private file descriptor. A node name cannot be larger than 31 characters. |
| 160 | |
| 161 | Returns a file descriptor for the directory index on success. Returns a negative value on error. |
233 | | This function implements the "giet_fat_readdir()" system call. |
234 | | It reads one directory entry from the file descriptor opened by "giet_fat_opendir()" and writes its info to the "entry" argument. This includes the cluster, size, is_dir and name info for each entry. |
235 | | * '''fd_id''' : file descriptor index |
236 | | * '''entry''' : pointer to write |
237 | | Returns GIET_FAT32_OK on success. Returns a negative value on error: |
238 | | * GIET_FAT32_NOT_INITIALIZED, |
239 | | * GIET_FAT32_INVALID_FD, |
240 | | * GIET_FAT32_NOT_OPEN, |
241 | | * GIET_FAT32_NOT_A_DIRECTORY, |
242 | | * GIET_FAT32_IO_ERROR, |
243 | | * GIET_FAT32_NO_MORE_ENTRIES |
244 | | |
245 | | === __int '''_fat_read_no_cache'''( char* pathname , unsigned int buffer_vbase , unsigned int buffer_size )__ === |
246 | | This function loads a file identified by the pathname argument into the memory buffer defined by the buffer_vbase / buffer_size arguments. It is intended to be called by the boot-loader, as it uses neither the dynamically allocated FAT structures (Inode-Tree, Fat_Cache or File-Cache), nor the File-Descriptor-Array. It uses only the 4096 bytes buffer defined in the FAT descriptor. |
247 | | * '''pathname''' : file complete pathname |
248 | | * '''buffer_vbase''' : memory buffer virtual address |
249 | | * '''buffer_size''' : buffer size (bytes) |
250 | | Returns GIET_FAT32_OK on success. Returns negative value on error: |
251 | | * GIET_FAT32_NOT_INITIALIZED |
252 | | * GIET_FAT32_FILE_NOT_FOUND |
253 | | * GIET_FAT32_BUFFER_TOO_SMALL |
254 | | * GIET_FAT32_IO_ERROR |
| 170 | This function implements the ''giet_fat_readdir()'' system call. |
| 171 | It reads one directory entry from the directory identified by the <fd_id> argument provided by ''giet_fat_opendir()''. It returns the following attributes in the <entry> argument : cluster , size , is_dir , and name. |
| 172 | |
| 173 | Returns GIET_FAT32_OK on success. Returns a negative value on error. |
| 174 | |
| 175 | === __int '''_fat_load_no_cache'''( char* pathname , unsigned int buffer_vbase , unsigned int buffer_size )__ === |
| 176 | This function load a file identified by the <pathname> argument into the memory buffer defined by the <buffer_vbase> and <buffer_size> arguments. It is intended to be called by the boot-loader, as it uses neither the dynamically allocated FAT structures (Inode-Tree, Fat_Cache or File-Cache), nor the File-Descriptor-Array. It uses only the 512 bytes buffer defined in the FAT descriptor. |
| 177 | |
| 178 | Returns GIET_FAT32_OK on success. Returns negative value on error. |
264 | | It returns GIET_FAT32_OK on success, and returns a negative value on error: |
265 | | * GIET_FAT32_NOT_INITIALIZED |
266 | | * GIET_FAT32_INVALID_ARG |
267 | | * GIET_FAT32_IO_ERROR |
| 188 | |
| 189 | It returns GIET_FAT32_OK on success, and returns a negative value on error. |
| 190 | |
| 191 | === __int '''_get_fat_cache_buffer'''( unsigned int cluster_id , fat_cache_desc** desc )__ === |
| 192 | This function returns in the <desc> argument a pointer on a buffer descriptor contained in the Fat_Cache. |
| 193 | The <cluster_id> argument is the buffer index in the FAT_Cache. |
| 194 | In case of miss, a 4 Kbytes buffer and a buffer descriptor are allocated from the local heap, and the missing cluster is loaded in the Fat_Cache. |
| 195 | |
| 196 | It returns GIET_FAT32_OK on success, and returns a negative value on error. |