Changes between Version 23 and Version 24 of file_system


Ignore:
Timestamp:
Jul 28, 2015, 3:54:56 PM (9 years ago)
Author:
guerin
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • file_system

    v23 v24  
    44
    55The [source:soft/giet_vm/giet_fat32/fat32.c  fat32.c] and [source:soft/giet_vm/giet_fat32/fat32.h fat32.h]
    6 files define the GIET_VM File System, that respect the FAT32 standard.
     6files define the GIET_VM File System, that complies to the FAT32 standard.
    77
    88== 1) General Principles ==
     
    6565=== __int '''_fat_init'''( unsigned int kernel_mode )__ ===
    6666This function initializes the  FAT structures. It is called twice, by the boot-loader, and by the kernel_init.
    67  *  in '''boot mode''' (kernel_mode == 0), it initialises 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,
    68 into memory by accessing directly to the block device.
    69  *  in '''kernel mode''' (kernel_mode != 0), it uses the distributed kernel heap to initialises the dynamically allocated structures such as the Inode-Tree, the Fat-Cache, and the File-Cache for the root directory.
    70 
    71 It returns 0 if success /  It returns -1 if failure.
     67 *  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.
     68 *  in '''kernel mode''' (kernel_mode != 0), it uses the distributed kernel heap to initialize the dynamically allocated structures such as the Inode-Tree, the Fat-Cache, and the File-Cache for the root directory.
     69
     70Returns GIET_FAT32_OK on success. Returns a negative value on error:
     71 * GIET_FAT32_IO_ERROR,
     72 * GIET_FAT32_INVALID_BOOT_SECTOR
    7273
    7374=== __int '''_fat_open'''( char* pathname , unsigned int flags )__ ===
    7475This function implements the giet_fat_open() system call.
    75 The semantic is similar to the UNIX open() function,  but only the O_CREATE
    76 and O_RDONLY flags are supported. The UNIX access rights are not supported.
     76The 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.
    7777If the file does not exist in the specified directory, it is created, and the Inode-Tree,
    7878the Fat-Cache and the FAT region on device are updated.
     
    8282obtains a private file descriptor and the reference count is updated.
    8383A node name (file or directory) cannot be larger than 31 characters.
    84  * '''pathname''' : define both the specified directory and the file name.
    85  * '''flags''' :  O_CREATE and O_RDONLY can be ored.
    86 It returns the file descriptor index if success.
    87 It returns a negative value if error:
    88  *   -1  :  "fat not initialised"
    89  *   -2  :  "path to parent not found"
    90  *   -3  :  "one name in path too long"
    91  *   -4  :  "file not found"
    92  *   -5  :  "Cannot update parent directory"
    93  *   -6  :  "Cannot update DATA region"
    94  *   -7  :  "Cannot update FAT region"
    95  *   -8  :  "Cannot update FS_INFO sector"
    96  *   -9  :  "file descriptor array full"
     84 * '''pathname''' : defines both the specified directory and the file name.
     85 * '''flags''' :  O_CREATE, O_RDONLY, O_TRUNCATE (can be OR'ed).
     86Returns a file descriptor index on success. Returns a negative value on error:
     87 * GIET_FAT32_NOT_INITIALIZED,
     88 * GIET_FAT32_FILE_NOT_FOUND,
     89 * GIET_FAT32_NAME_TOO_LONG,
     90 * GIET_FAT32_IO_ERROR,
     91 * GIET_FAT32_TOO_MANY_OPEN_FILES
    9792
    9893=== __int '''_fat_close'''( unsigned int fd_id  )__ ===
    9994This function implements the "giet_fat_close()" system call.
    10095The semantic is similar to the UNIX "close()" function.
    101 It decrements the inode reference count, and release the fd_id entry in the file descriptors array.
     96It decrements the inode reference count, and releases the fd_id entry in the file descriptors array.
    10297If the reference count is zero, it writes all dirty clusters on block device, and releases the memory allocated to the file_cache:
    10398The cache 64-Tree infrastructure (depending on file size) is kept, but all buffers and all buffer descriptors are released.
    10499 * '''fd_id''' : file descriptor index
    105 It returns 0 if success. It returns a negative value if error:
    106  *  -1  : "FAT not initialised"
    107  *  -2  : "Illegal file descriptor"
    108  *  -3  : "File not open"
    109  *  -4  : "Cannot update DATA regions"
    110  *  -5  : "Cannot release memory"
    111 
    112 === __int '''_fat_file_info'''( unsigned int fd_id , struct fat_file_info_s* info )__ ===
     100Returns GIET_FAT32_OK on success. Returns a negative value on error:
     101 * GIET_FAT32_NOT_INITIALIZED,
     102 * GIET_FAT32_INVALID_FD,
     103 * GIET_FAT32_NOT_OPEN,
     104 * GIET_FAT32_IO_ERROR
     105
     106=== __int '''_fat_file_info'''( unsigned int fd_id , fat_file_info_t* info )__ ===
    113107This function implements the giet_fat_file_info() system call.
    114108It returns the size, offset value and is_dir info for a file identified by the "fd_id" argument.
    115109 * '''fd_id''' : file descriptor index
    116110 * '''info''' : pointer to the fat_file_info_s struct storing the values (return buffer)
    117 It returns 0 if success. It returns a negative value if error:
    118  *  -1  : "FAT not initialised"
    119  *  -2  : "Illegal file descriptor"
    120  *  -3  : "File not open"
     111Returns GIET_FAT32_OK on success. Returns a negative value on error:
     112 * GIET_FAT32_NOT_INITIALIZED,
     113 * GIET_FAT32_INVALID_FD,
     114 * GIET_FAT32_NOT_OPEN
    121115
    122116=== __int '''_fat_read'''( unsigned int fd_id , void* buffer , unsigned int count )__ ===
    123117This function implements the "giet_fat_read()" system call.
    124 It access 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.
     118It 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.
    125119In case of miss in the File_Cache, it loads all involved clusters into the cache.
    126120 * '''fd_id''' : file descriptor index
    127121 * '''buffer''' : pointer on the memory buffer
    128122 * '''count''' : number of bytes
    129 It returns the number of bytes actually transfered if success. It returns 0 if (offset + count > file_size). It returns a negative value if error:
    130  *  -1  : "FAT not initialised"
    131  *  -2  : "Illegal file descriptor"
    132  *  -3  : "File not open"
    133  *  -4  : "Cannot load file from device"
     123Returns the number of bytes actually transfered on success. Returns 0 if EOF is encountered (offset + count > file_size). Returns a negative value on error:
     124 * GIET_FAT32_NOT_INITIALIZED,
     125 * GIET_FAT32_INVALID_FD,
     126 * GIET_FAT32_NOT_OPEN,
     127 * GIET_FAT32_IO_ERROR
    134128
    135129=== __int '''_fat_write'''( unsigned int fd_id , void* buffer , unsigned int count )__ ===
    136130This function implements the "giet_fat_write()" system call.
    137 It access the File-Cache associated to the file identified by the file descriptor, and transfers count bytes from the user buffer,
    138 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, it increases the file size. 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.
     131It 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.
    139132 * '''fd_id''' : file descriptor index
    140133 * '''buffer''' : pointer on the memory buffer
    141134 * '''count''' : number of bytes
    142 It returns the number of bytes actually transfered if success. It returns a negative value if error.
    143  *   -1 :  "FAT not initialised"
    144  *   -2 :  "Illegal file descriptor"
    145  *   -3 :  "File not open"
    146  *   -4 :  "File not writable"
    147  *   -5 :  "No free clusters"
    148  *   -6 :  "Cannot update parent directory entry"
    149  *   -7 :  "Cannot access File-Cache"
     135Returns number of bytes actually written on success. Returns a negative value on error:
     136 * GIET_FAT32_NOT_INITIALIZED,
     137 * GIET_FAT32_INVALID_FD,
     138 * GIET_FAT32_NOT_OPEN,
     139 * GIET_FAT32_READ_ONLY,
     140 * GIET_FAT32_NO_FREE_SPACE,
     141 * GIET_FAT32_IO_ERROR
    150142
    151143=== __int '''_fat_lseek'''( unsigned int fd_id , unsigned int offset , unsigned int whence )__ ===
     
    159151 * '''offset''' : pointer on the memory buffer
    160152 * '''count''' : number of bytes
    161 It returns new offset value (bytes) if success. It returns a negative value if error:
    162  *   -1  : "FAT not initialised"
    163  *   -2  : "Illegal file descriptor"
    164  *   -3  : "File not open"
    165  *   -4  : "Illegal whence argument"
     153Returns new seek value (in bytes) on success. Returns a negative value on error:
     154 * GIET_FAT32_NOT_INITIALIZED,
     155 * GIET_FAT32_INVALID_FD,
     156 * GIET_FAT32_NOT_OPEN,
     157 * GIET_FAT32_INVALID_ARG
    166158
    167159=== __int '''_fat_mkdir'''( char* pathname )__ ===
     
    171163The Inode-Tree is updated.
    172164 * '''pathname''' : complete pathname
    173 It returns 0 if success.  It returns a negative value if error:
    174  *   -1  : "Fat not initialised"
    175  *   -2  : "Path to parent not found"
    176  *   -3  : "One name in path too long"
    177  *   -4  : "Directory already exist"
    178  *   -5  : "No free cluster"
    179  *   -6  : "Cannot update parent directory"
    180  *   -7  : "Cannot update parent DATA region"
    181  *   -8  : "Cannot update FAT region"
    182  *   -9  : "Cannot update FS-INFO"
    183  *   -10 : "Cannot update directory DATA region"
     165Returns 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
    184172
    185173=== __int '''_fat_remove'''( char* pathname , unsigned int should_be_dir )__ ===
     
    192180The Inode-Tree is updated.
    193181 * '''pathname''' : directory complete pathname
    194 It returns 0 if success.  It returns a negative value if error:
    195  *   -1  : "FAT not initialised"
    196  *   -2  : "File/Directory not found"
    197  *   -3  : "Name too long in path"
    198  *   -4  : "Has the wrong type"
    199  *   -5  : "File still open"
    200  *   -6  : "Cannot scan directory"
    201  *   -7  : "Directory not empty"
    202  *   -8  : "Cannot remove file/dir from FS"
     182Returns 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
    203191
    204192=== __int '''_fat_rename'''( char* old_path , new_path )__ ===
     
    212200 * '''old_path''' : old path-name (from root).
    213201 * '''new_path''' : new path-name (from root).
    214 It returns 0 if success.  It returns a negative value if error:
    215  *  -1  : "FAT not initialised"
    216  *  -2  : "old_path not found"
    217  *  -3  : "new_path not found"
    218  *  -4  : "cannot  scan to_remove directory"
    219  *  -5  : "to_remove directory not empty"
    220  *  -6  : "to_remove file still referenced"
    221  *  -7  : "cannot add new node to new_parent directory"
    222  *  -8  : "cannot update new_parent directory on device"
    223  *  -9  : "cannot remove old node from old_parent directory"
    224  *  -10 : "cannot update old_parent directory on device"
    225  *  -11 : "cannot remove to_remove node from FS"
     202Returns 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
    226209
    227210=== __int '''_fat_opendir'''( char* pathname )__ ===
     
    261244
    262245=== __int '''_fat_read_no_cache'''( char* pathname , unsigned int buffer_vbase , unsigned int buffer_size )__ ===
    263 This functiond load 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.
     246This 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.
    264247 * '''pathname''' : file complete pathname
    265248 * '''buffer_vbase''' : memory buffer virtual address
    266249 * '''buffer_size''' : buffer size (bytes)
    267 It returns 0 if success. It returns a negative value if error.
    268  *  -1  : "FAT not initialised"
    269  *  -2  : "File not found"
    270  *  -3  : "Buffer too small"
    271  *  -4  : "Cannot access block device"
    272  *  -5  : "Cannot access FAT on block device"
     250Returns 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
    273255
    274256== 5) Internal functions ==