Changes between Version 43 and Version 44 of file_system
- Timestamp:
- Feb 2, 2016, 11:45:42 PM (9 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
file_system
v43 v44 29 29 To support various block device peripheral, this FAT32 implementation defines a generic function to transparently access various physical block devices, using the driver specified in the ''hard_config.h'' file. Five drivers are presently supported ( IOC_BDV / IOC_HBA / IOC_SDC / IOC_SPI / IOC_RDK ). 30 30 31 WARNING 1: A node name (file or directory) cannot be larger than 31 characters.32 33 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 if the heap defined in the mapping is too small...31 '''WARNING 1''': A node name (file or directory) cannot be larger than 31 characters. 32 33 '''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 if the heap defined in the mapping is too small for the File-Caches... 34 34 35 35 == 2) Cache Structure & Write Policy == … … 198 198 == 5) Internal functions == 199 199 200 The following functions can be used to implement new system calls if required. 201 202 === __int '''_fat_ioc_access'''( unsigned int use_irq , unsigned int to_mem , unsigned int lba , unsigned int buf_vaddr , unsigned int count )__ === 203 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. 204 The <to_mem> boolean argument defines the transfer direction (from block device to memory if non zero). The 205 <lba> argument is the logical 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. 206 It returns 0 on success, or -1 on failure. 207 208 === __void '''_display_one_block'''( unsigned char* buf , char* string , unsigned int block_id )__ === 209 This debug function displays the content of a 512 bytes buffer <buf>, with an identifier defined by the <string> and <block_id> arguments. 200 === __void '''_display_cluster_list'''()__ === 201 This debug function displays the list of clusters allocated to one file or directory. 210 202 211 203 === __void '''_display_fat_descriptor'''()__ === 212 204 This debug function displays the FAT descriptor content. 213 205 214 === __unsigned int '''_get_fat_cache_buffer'''( unsigned int cluster_id , fat_cache_desc_t** desc )__ === 215 This function returns in the <desc> argument a pointer on a buffer descriptor contained in the Fat_Cache. 216 The <cluster_id> argument is the buffer index in the FAT_Cache. 217 In case of miss, a 4 Kbytesbuffer and a buffer descriptor are allocated from the local heap, and the missing cluster is loaded in the Fat_Cache. 218 It returns 0 on success. It returns 1 on error.=== __void '''_get_name_from_long'''( unsigned char* buffer , char* name )__ === 206 === __void '''_get_name_from_long'''( unsigned char* buffer , char* name )__ === 219 207 This function extract a (partial) name from a LFN directory entry. 220 208 221 209 === __void '''_get_name_from_short'''( unsigned char* buffer , char* name )__ === 222 This function extract a namefrom a NORMAL directory entry.210 This function extract a <name> from a NORMAL directory entry. 223 211 224 212 === __unsigned int '''_get_levels_from_size'''( unsigned int size )__ === 225 This function returns the number of levels of a File-Cache from the sizeof the file.213 This function returns the number of levels of a File-Cache from the <size> of the file. 226 214 227 215 === __unsigned int '''_get_name_from_path'''( char* pathname , char* name , unsigned int* nb_read )__ === 228 216 This function analyses the <pathname> argument, from the character defined by the <nb_read> argument. 229 217 It copies the found name in the <name> buffer (without '/'), and updates the <nb_read"> argument. 218 230 219 It returns 0 on success. It returns 1 if one name length > NAME_MAX_SIZE characters. 231 220 232 221 === __unsigned int '''_get_last_name'''( char* pathname , char* name )__ === 233 This function scan the "pathname" argument, and copies in the <name> buffer the last name in <pathname>. 222 This function scan the <pathname> argument, and copies in the <name> buffer the last name in the <pathname>. 223 234 224 It returns 0 on success.It returns 1 if one name length > NAME_MAX_SIZE characters. 235 225 236 226 === __unsigned int '''_get_fat_entry'''( unsigned int cluster , unsigned int* value )__ === 237 This function accesses the Fat-Cache and returns in the <value> argument the content of the FAT slot identified by the <cluster> argument. It loads the missing cluster from block device in the Fat-Cache in case of miss. It returns 0 on success. It returns 1 on error. 227 This function accesses the Fat-Cache and returns in the <value> argument the content of the FAT slot identified by the <cluster> argument. It loads the missing cluster from block device in the Fat-Cache in case of miss. 228 229 It returns 0 on success. It returns 1 on error. 238 230 239 231 === __unsigned int '''_set_fat_entry'''( unsigned int cluster , unsigned int value )__ === 240 232 This function writes a new <value> in the Fat-Cache, in the slot identified by the <cluster> argument. 241 233 It loads the missing cluster from block device in the Fat-Cache in case of miss. 234 242 235 It returns 0 on success, It returns 1 on error. 243 236 244 237 === __void '''_add_inode_in_tree'''( fat_inode_t* child , fat_inode_t* parent )__ === 245 This function introduces the inode identified by the <child> argument as a new child for the <parent> inode in the Inode-Tree. 246 All checking are supposed to be done by the caller. Nor the File-Cache, neither the block device are modified. 238 This function introduces the inode identified by the <child> argument as a new child for the <parent> inode in the Inode-Tree. All checking are supposed to be done by the caller. Nor the File-Cache, neither the block device are modified. 247 239 248 240 === __void '''_remove_inode_from_tree'''( fat_inode_t* inode )__ === … … 251 243 === __unsigned int '''_update_device_from_cache'''( unsigned int levels , fat_cache_node_t* root , char* string )__ === 252 244 This recursive function scan one File-Cache (or the Fat-Cache) from root to leaves, to writes all dirty clusters to block device, and reset the dirty bits. The cache is identified by the <root> an <levels> arguments. 253 The <string> argument is only used for debug. It returns 0 on success. It returns 1 on error. 245 The <string> argument is only used for debug. 246 247 It returns 0 on success. It returns 1 on error. 254 248 255 249 === __unsigned int '''_update_fs_info()'''__ === 256 250 This function accesses directly the FS_INFO block on the block device, to update the "first_free_cluster" and "free_clusters_number" values, using only the Fat-Descriptor single block buffer. 251 257 252 It return 0 on success. It return 1 on error. 258 253 … … 265 260 266 261 === __unsigned int '''_get_nb_entries'''( fat_inode_t* inode , unsigned int* nb_entries )__ === 267 This function returns in the <nb_entries> argument the number of entries contained in a directory identified by the <inode> pointer. It returns 0 on success. It returns 1 on error. 262 This function returns in the <nb_entries> argument the number of entries contained in a directory identified by the <inode> pointer. 263 264 It returns 0 on success. It returns 1 on error. 268 265 269 266 === __unsigned int '''_get_child_from_parent'''( fat_inode_t* parent , char* name , fat_inode_t** inode )__ === 270 This function search in the directory identified by the <parent> inode pointer a child (file or directory) identified by its <name>. 271 It returns in the <inode> argument the searched child inode pointer. 267 This function search in the directory identified by the <parent> inode pointer a child (file or directory) identified by its <name>. It returns in the <inode> argument the searched child inode pointer. 272 268 If the searched name is not found in the Inode-Tree, the function accesses the File-cache associated to the parent directory. 273 269 If the child exists on block device, the Inode-Tree is updated, and a success code is returned. 274 270 If the file/dir does not exist on block device, a error code is returned. 271 275 272 It returns 0 if inode found. It returns 1 if inode not found. It returns 2 in case of error in cache access. 276 273 … … 278 275 For a file (or a directory) identified by the <pathname> argument, this function returns in the <inode> argument the inode pointer associated to the searched file (or directory), with code (0). 279 276 If the searched file (or directory) is not found, but the parent directory is found, it returns in the <inode> argument the pointer on the parent inode, with code (1). Code (2) and code (3) are error codes. Both the Inode-Tree and the involved Cache-Files are updated from the block device in case of miss on one inode during the search. Neither the Fat-Cache, nor the block device are updated. 277 280 278 It returns 0 if searched inode found It returns 1 if searched inode not found but parent directory found. It returns 2 if searched inode not found and parent directory not found. It returns 3 if one name too long 281 279 282 280 === __unsigned int '''_is_ancestor'''( fat_inode_t* a , fat_inode_t* b )__ === 283 281 This function checks if inode <a> is an ancestor of inode <b>. 284 It returns 0 on failure. It returns 1 otherwise. 285 286 === __unsigned int '''_check_name_length'''( char* name , unsigned int* length , unsigned int* nb_lfn )__ === 287 This function computes the length and the number of LFN entries required to store a node name, and return the values in the <length> and <nb_lfn> arguments. 282 283 It returns 1 if it is true. 284 285 === __unsigned int '''_get_sfn_name'''( char* name , unsigned int* length , unsigned int* nb_lfn, char* sfn , unsigned char* checksum )__ === 286 This function returns in the <length> and <nb_lfn> arguments the name length and the number of LFN entries required to store the <name> string. It returns in the <sfn> argument a legal SFN name extracted from the <name> string (upper case and 8-3 format). It returns in the <checksum> argument the SFN checksum. 288 287 * Short name (less than 13 characters) require 1 LFN entry. 289 288 * Medium names (from 14 to 26 characters require 2 LFN entries. 290 289 * Large names (up to 31 characters) require 3 LFN entries. 291 It returns 0 on success. It returns 1 if length larger than 31 characters. 292 293 === __unsigned int '''_update_dir_entry'''( fat_inode_t* inode )__ === 294 For a node identified by the <inode> argument, this function updates the "size" and "cluster" values in the parent directory entry File-Cache. 295 It set the dirty bit in the modified buffer of the parent directory File-Cache.290 291 It returns 0 on success. It returns 1 if the name length is larger than 31 characters. 292 293 === __void '''_update_dir_entry'''( fat_inode_t* inode )__ === 294 For a node identified by the <inode> argument, this function updates the "size" and "cluster" values in the parent directory entry File-Cache. It set the dirty bit in the modified buffer of the parent directory File-Cache. 296 295 297 296 === __unsigned int '''_add_dir_entry'''( fat_inode_t* child , fat_inode_t* parent )__ === 298 The following function add new <child> entry in the Cache-File of the <parent> directory. It accesses the File_Cache associated to the parent directory, 299 and scan the clusters allocated to this directory to find the NO_MORE entry, that will be the first modified entry in the directory. 300 Regarding the name storage, it uses LFN entries for all names, but computes a legal (upper case / 8.3) SFN name that will be stored in the NORMAL entry. 297 This function add a new <child> entry in the Cache-File of the <parent> directory. It accesses the File_Cache associated to the parent directory, and scan the clusters allocated to this directory to find the NO_MORE entry, that will be the first modified entry in the directory. 298 Regarding the name storage, it uses LFN entries for all names, but computes a legal (upper case / 8-3) SFN name that will be stored in the NORMAL entry. 301 299 It writes 1, 2, or 3 LFN entries (depending on the child name actual length), writes one NORMAL entry, and writes the new NO_MORE entry. 302 300 It updates the dentry field in the child inode. It set the dirty bit for all modified File-Cache buffers. 303 301 The block device is not modified by this function. 302 303 It returns 0 on success. It returns 1 in case of error. 304 304 305 305 === __unsigned int '''_remove_dir_entry'''( fat_inode_t* inode )__ === … … 309 309 The block device is not modified by this function. 310 310 311 It returns 0 on success. It returns 1 in case of error. 312 311 313 === __void '''_add_special_directories'''( fat_inode_t* child , fat_inode_t* parent )__ === 312 314 This function adds the special entries "." and ".." in the File-Cache of the directory identified by the <child> argument.