357 | | |
358 | | |
359 | | |
360 | | ////////////////////////////////////////////////////////////////////////////////// |
361 | | // This function computes the length and the number of LFN entries required |
362 | | // to store a node name in the "length" and "nb_lfn" arguments. |
363 | | // Short name (less than 13 characters) require 1 LFN entry. |
364 | | // Medium names (from 14 to 26 characters require 2 LFN entries. |
365 | | // Large names (up to 31 characters) require 3 LFN entries. |
366 | | // It returns 0 on success. |
367 | | // It returns 1 if length larger than 31 characters. |
368 | | ////////////////////////////////////////////////////////////////////////////////// |
369 | | |
370 | | static unsigned int _check_name_length( char* name, |
371 | | unsigned int* length, |
372 | | unsigned int* nb_lfn ); |
373 | | |
374 | | ////////////////////////////////////////////////////////////////////////////////// |
375 | | // For a node identified by the "inode" argument, this function updates the |
376 | | // "size" and "cluster" values in the entry of the parent directory File-Cache. |
377 | | // It set the dirty bit in the modified buffer of the parent directory File-Cache. |
378 | | ////////////////////////////////////////////////////////////////////////////////// |
379 | | |
380 | | static unsigned int _update_dir_entry( fat_inode_t* inode ); |
381 | | |
382 | | ////////////////////////////////////////////////////////////////////////////////// |
383 | | // The following function add new "child" in Cache-File of "parent" directory. |
384 | | // It accesses the File_Cache associated to the parent directory, and scan the |
385 | | // clusters allocated to this directory to find the NO_MORE entry. |
386 | | // This entry will be the first modified entry in the directory. |
387 | | // Regarding the name storage, it uses LFN entries for all names. |
388 | | // Therefore, it writes 1, 2, or 3 LFN entries (depending on the child name |
389 | | // actual length, it writes one NORMAL entry, and writes the new NOMORE entry. |
390 | | // It updates the dentry field in the child inode. |
391 | | // It set the dirty bit for all modified File-Cache buffers. |
392 | | // The block device is not modified by this function. |
393 | | ////////////////////////////////////////////////////////////////////////////////// |
394 | | |
395 | | static unsigned int _add_dir_entry( fat_inode_t* child, |
396 | | fat_inode_t* parent ); |
397 | | |
398 | | ////////////////////////////////////////////////////////////////////////////////// |
399 | | // The following function invalidates all dir_entries associated to the "inode" |
400 | | // argument from its parent directory. |
401 | | // It set the dirty bit for all modified buffers in parent directory Cache-File. |
402 | | // The inode itself is not modified by this function. |
403 | | // The block device is not modified by this function. |
404 | | ////////////////////////////////////////////////////////////////////////////////// |
405 | | |
406 | | static unsigned int _remove_dir_entry( fat_inode_t* inode ); |
407 | | |
408 | | ////////////////////////////////////////////////////////////////////////////////// |
409 | | // The following function add the special entries "." and ".." in the File-Cache |
410 | | // of the directory identified by the "child" argument. |
411 | | // The parent directory is defined by the "parent" argument. |
412 | | // The child directory File-Cache is supposed to be empty. |
413 | | // We use two NORMAL entries for these "." and ".." entries. |
414 | | // The block device is not modified by this function. |
415 | | ////////////////////////////////////////////////////////////////////////////////// |
416 | | |
417 | | static void _add_special_directories( fat_inode_t* child, |
418 | | fat_inode_t* parent ); |
419 | | |
420 | | ////////////////////////////////////////////////////////////////////////////////// |
421 | | // The following function releases all clusters allocated to a file or directory, |
422 | | // from the cluster index defined by the <cluster> argument, until the end |
423 | | // of the FAT linked list. |
424 | | // It calls _get_fat_entry() and _set_fat_entry() functions to scan the FAT, |
425 | | // and to update the clusters chaining. |
426 | | // The FAT region on block device is updated. |
427 | | // It returns 0 on success. |
428 | | // It returns 1 on error. |
429 | | ////////////////////////////////////////////////////////////////////////////////// |
430 | | |
431 | | static unsigned int _clusters_release( unsigned int cluster ); |
432 | | |
433 | | ////////////////////////////////////////////////////////////////////////////////// |
434 | | // This function allocate one cluster in FAT to a file (or directory) identified |
435 | | // by the <inode> pointer. The allocated cluster index is returned in the |
436 | | // <cluster> argument. |
437 | | // It allocates also the associated buffers and buffer descriptors in Cache-File. |
438 | | // It calls _get_fat_entry() and _set_fat_entry() functions to update the |
439 | | // clusters chaining in the Cache-Fat. The FAT region on block device is updated. |
440 | | // It returns 0 on success. |
441 | | // It returns 1 on error. |
442 | | ////////////////////////////////////////////////////////////////////////////////// |
443 | | |
444 | | static unsigned int _cluster_allocate( fat_inode_t* inode, |
445 | | unsigned int* cluster ); |
| 357 | === __unsigned int '''_check_name_length'''( char* name , unsigned int* length , unsigned int* nb_lfn )__ === |
| 358 | 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. |
| 359 | * Short name (less than 13 characters) require 1 LFN entry. |
| 360 | * Medium names (from 14 to 26 characters require 2 LFN entries. |
| 361 | * Large names (up to 31 characters) require 3 LFN entries. |
| 362 | It returns 0 on success. It returns 1 if length larger than 31 characters. |
| 363 | |
| 364 | === __unsigned int '''_update_dir_entry'''( fat_inode_t* inode )__ === |
| 365 | For a node identified by the <inode> argument, this function updates the "size" and "cluster" values in the parent directory entry File-Cache. |
| 366 | It set the dirty bit in the modified buffer of the parent directory File-Cache. |
| 367 | |
| 368 | === __unsigned int '''_add_dir_entry'''( fat_inode_t* child , fat_inode_t* parent )__ === |
| 369 | |
| 370 | The following function add new <child> in the Cache-File of the <parent> directory. |
| 371 | It accesses the File_Cache associated to the parent directory, and scan the clusters allocated to this directory to find the NO_MORE entry. |
| 372 | This entry will be the first modified entry in the parent directory. Regarding the name storage, it uses LFN entries for all names. |
| 373 | Therefore, it writes 1, 2, or 3 LFN entries (depending on the child name actual length, it writes one NORMAL entry, and writes the new NOMORE entry. |
| 374 | It updates the dentry field in the child inode. |
| 375 | It set the dirty bit for all modified File-Cache buffers. |
| 376 | The block device is not modified by this function. |
| 377 | |
| 378 | === __unsigned int '''_remove_dir_entry'''( fat_inode_t* inode )__ === |
| 379 | This function invalidates all dir_entries associated to the <inode> argument from its parent directory. |
| 380 | It set the dirty bit for all modified buffers in parent directory Cache-File. |
| 381 | The inode itself is not modified by this function. |
| 382 | The block device is not modified by this function. |
| 383 | |
| 384 | === __void '''_add_special_directories'''( fat_inode_t* child , fat_inode_t* parent )__ === |
| 385 | This function adds the special entries "." and ".." in the File-Cache of the directory identified by the <child> argument. |
| 386 | The parent directory is defined by the <parent> argument. The child directory File-Cache is supposed to be empty. |
| 387 | We use two NORMAL entries for these "." and ".." entries. |
| 388 | The block device is not modified by this function. |
| 389 | |
| 390 | === __unsigned int '''_clusters_release'''( unsigned int cluster )__ === |
| 391 | The following function releases all clusters allocated to a file or directory, from the cluster index defined by the <cluster> argument, until the end of the FAT linked list. It calls _get_fat_entry() and _set_fat_entry() functions to scan the FAT, and to update the clusters chaining. |
| 392 | The FAT region on block device is updated. |
| 393 | It returns 0 on success. It returns 1 on error. |
| 394 | |
| 395 | === __unsigned int '''_cluster_allocate'''( fat_inode_t* inode , unsigned int* cluster )__ === |
| 396 | This function allocates one cluster in FAT to a file (or directory) identified by the <inode> pointer. The allocated cluster index is returned in the |
| 397 | <cluster> argument. It allocates also the associated buffers and buffer descriptors in Cache-File. It calls _get_fat_entry() and _set_fat_entry() functions to update the clusters chaining in the Cache-Fat. |
| 398 | The FAT region on block device is updated. |
| 399 | It returns 0 on success. It returns 1 on error. |
| 400 | |
| 401 | |