#include <sw_types.h>Go to the source code of this file.
Classes | |
| struct | lfn_entry |
| Structure of the long file name slot. More... | |
| struct | f_info |
| Structure of a file containing its basic information required for many operations. More... | |
| struct | file_stat |
| Structure containing the basic details of a file/directory. More... | |
Typedefs | |
| typedef struct f_info | file_info |
Functions | |
| struct | __attribute__ ((__packed__)) |
| Structure of the boot sector. More... | |
| int | mount_file_system (u8 *dev) |
| Mount the FAT file system and retrieve its basic information. More... | |
| bool | chk_fat32_file_system (u8 *file_sys_type) |
| Verify the type of FAT file system. More... | |
| void | cal_region_offsets (boot_sector *bs, u8 *dev) |
| Function to calculate all the region offsets. More... | |
| int | file_open (const char *file_path, int flags) |
| Function to open a specific file mentioned in the path based on the incoming modes. More... | |
| bool | get_dir_entry (char *fname, dir_entry **entry, u8 *strt, u32 strt_clus, bool is_lfn) |
| Function to check whether a given file name exists in the file system and if so retrieve the corresponding short file name directory entry. More... | |
| int | lfn_entry_to_name (lfn_entry *entry, char *lfname, int *index) |
| Function to get the long file name correspoding to a directory slot. More... | |
| u8 * | cluster_to_memory_addr (u32 cluster) |
| Function to get the corresponding physical address from the given cluster. More... | |
| int | retrieve_file_info (file_info *finfo, dir_entry *entry, u8 mode, u8 *dir_offset, const char *path) |
| Function to assign a file descriptor and necessary information to a file structure inorder to pursue subsequent operations. More... | |
| u32 | get_fat_table_entry (u32 cluster) |
| Function to retrieve the next cluster value in a cluster chain from the FAT table. More... | |
| void | convert_to_uppercase (char *file_name) |
| Function to convert the incoming short file name to its corresponding upper case letters. More... | |
| int | find_depth (const char *file_path) |
| Function to calculate the number of iterations needed to reach the file from the given starting path. More... | |
| int | create_file (char *lfname, char *shrt_name, u32 clus, dir_entry **entry) |
| Function to create a file if the file doesnt exists and the create flag is set. More... | |
| int | file_read (int fd, char *buffer, int bytes_to_read) |
| Function to read the contents of a file. More... | |
| int | file_write (int fd, const char *buffer, int bytes_to_write) |
| Function to write into the given file with the contents given. More... | |
| u32 | allocate_cluster () |
| Function to find an unused cluster from the FAT table. More... | |
| void | write_fat_table (u32 cluster, u32 value) |
| Function to write into the FAT table after assigning an empty cluster to a file. More... | |
| void | get_short_file_name (char *lfname, char *sfname, char seq_num) |
| Function to extract the short file name given its long file name. More... | |
| void | fill_lng_fname_entries (char *fname, u8 *entry, u8 chk_sum, int count) |
| Function to put the long file name entries into the respective allocated region. More... | |
| u8 | calc_check_sum (u8 *dir_entry) |
| Function to calculate the checksum for the long file name based on its short name entry. More... | |
| int | file_close (int fd) |
| Close the opened file based on the file descriptor and free the file structure pointer. More... | |
| int | file_seek (int fd, int offset, int whence) |
| Function to seek the opened file pointer to the desired location so that subsequent read and write operations are performed from the new value. More... | |
| int | get_seek_off (file_info *file_ptr, u32 strt_cluster, int offset) |
| Function to move the current cluster and its offset value to the value specified in the offset from the starting cluster provided. More... | |
| int | get_long_file_name (char *fname, u8 **dir_strt, int *count) |
| Function to retrieve the long file name given its end of the long file name entry. More... | |
| int | file_rename (const char *old, const char *new) |
| Function to rename a file/directory. More... | |
| int | create_dir (const char *path) |
| Function to create a directory. More... | |
| int | chk_file_lock (const char *path) |
| file_stat * | read_dir (int fd) |
| int | open_dir (const char *path) |
| Function to open a directory. More... | |
| int | cal_req_dir_cnt (int file_name_len) |
| int | file_truncate (const char *tr_pf, int tr_lgh) |
| file_truncate - function cause the regular file named by path to be truncated to a size of precisely length bytes More... | |
| int | file_remove (const char *fl_name) |
| file_remove - Deletes the file whose name is specified in filename More... | |
| int | file_unlink (const char *ul_name) |
| file_remove - Deletes the file whose name is specified in filename More... | |
| int | list_dir (const char *path) |
| Function to list the directory contents. More... | |
Variables | |
| boot_sector | |
| dir_entry | |
| #define ASCII_DIFF 32 |
| #define ATTR_ARCHIVE 0x20 |
| #define ATTR_DIR 0x10 |
| #define ATTR_HIDDEN 0x02 |
| #define ATTR_LONG_FNAME 0x0F |
| #define ATTR_OFF 11 |
| #define ATTR_READ 0x01 |
| #define ATTR_SYSTEM 0x04 |
| #define ATTR_VOL_LABEL 0x08 |
| #define BACKUP_BOOT_SEC_OFF 50 |
| #define BYTES_PER_CLUSTER_ENTRY 4 |
| #define BYTES_PER_SEC_OFF 11 |
| #define CHECK_SUM_OFF 13 |
| #define DEL_DIR_ENTRY 0xE5 |
| #define DELIMITER '/' |
| #define DIR_ENTRY_LEN 32 |
| #define DOT_DIR_ENTRY 0x2E |
| #define END_OF_CLUSTER 0x0FFFFFFF |
| #define END_OF_ROOT_CLUSTER 0X0FFFFFF8 |
| #define EXTN_DELIMITER '.' |
| #define FAT_CNT_OFF 16 |
| #define FILE_APPEND 0x10 |
| #define FILE_CREATE_ALWAYS 0x08 |
| #define FILE_CREATE_NEW 0x04 |
| #define FILE_NAME_EXTN_LEN 3 |
| #define FILE_NAME_SHRT_LEN 8 |
| #define FILE_READ 0x01 |
| #define FILE_SEEK_CUR 1 |
| #define FILE_SEEK_END 2 |
| #define FILE_SEEK_SET 0 |
| #define FILE_SIZE_OFF 28 |
| #define FILE_STAT_LEN 21 |
| #define FILE_SYS_TYPE_LENGTH 8 |
| #define FILE_SYS_TYPE_OFF 82 |
| #define FILE_WRITE 0X02 |
| #define FNAME_EXTN_SEP_OFF 6 |
| #define FNAME_SEQ_NUM_OFF 7 |
| #define FREE_DIR_ENTRY 0x00 |
| #define FS_INFOSECTOR_OFF 48 |
| #define FS_VER_LEN 2 |
| #define FULL_SHRT_NAME_LEN 13 |
| #define HIGH_CLUSWORD_MASK 0xFFFF0000 |
| #define JUMP_INS_LEN 3 |
| #define LAST_ORD_FIELD_SEQ 0x40 |
| #define LFN_EMPTY_LEN 2 |
| #define LFN_END_MARK 0xFFFF |
| #define LFN_FIRST_OFF 0x01 |
| #define LFN_FIRST_SET_CNT 5 |
| #define LFN_FIRST_SET_LEN 10 |
| #define LFN_LEN_PER_ENTRY 13 |
| #define LFN_SEC_SET_CNT 6 |
| #define LFN_SEC_SET_LEN 12 |
| #define LFN_SIXTH_OFF 0x0E |
| #define LFN_TERM_MARK 0x0000 |
| #define LFN_THIRD_SET_CNT 2 |
| #define LFN_THIRD_SET_LEN 4 |
| #define LFN_TWELVETH_OFF 0x1C |
| #define LONG_FILE_NAME_LEN 255 |
| #define LONG_FNAME_MASK 0x0F |
| #define LOW_CLUSWORD_MASK 0x0000FFFF |
| #define MAX_DIR_ENTRY_CNT 16 |
| #define MAX_FAT_CNT 2 |
| #define NXT_FREE_CLUS_OFF 492 |
| #define OEM_NAME_LEN 8 |
| #define RES_SEC_CNT_OFF 14 |
| #define RESERV_LEN 12 |
| #define ROOT_DIR_STRT_CLUS_OFF 44 |
| #define SEC_PER_CLUS_OFF 13 |
| #define SEC_PER_FAT 36 |
| #define SHRT_FILE_NAME_LEN 11 |
| #define SPACE_VAL 32 |
| #define STRT_CLUS_HIGH_OFF 20 |
| #define STRT_CLUS_LOW_OFF 26 |
| #define TILDE '~' |
| #define TOT_SEC_CNT_OFF 32 |
| #define VOL_ID_LEN 4 |
| #define VOL_LABEL_LEN 11 |
| struct __attribute__ | ( | (__packed__) | ) |
Structure of the boot sector.
Structure of the 32 byte directory entry.
| u32 allocate_cluster | ( | ) |
Function to find an unused cluster from the FAT table.
| void cal_region_offsets | ( | boot_sector * | bs, |
| u8 * | dev | ||
| ) |
Function to calculate all the region offsets.
| bs | Pointer to the boot sector structure which holds the information of the boot sector of the file system |
| dev | Pointer to the start of the file system |
| int cal_req_dir_cnt | ( | int | file_name_len | ) |
| file_name_len |
| u8 calc_check_sum | ( | u8 * | dir_entry | ) |
Function to calculate the checksum for the long file name based on its short name entry.
| dir_entry | Pointer to the start of the short file name corresponding to a long file name |
| bool chk_fat32_file_system | ( | u8 * | file_sys_type | ) |
Verify the type of FAT file system.
| file_sys_type | Pointer to the location where the type of file system is stored |
| int chk_file_lock | ( | const char * | path | ) |
| path |
| u8* cluster_to_memory_addr | ( | u32 | cluster | ) |
Function to get the corresponding physical address from the given cluster.
| cluster | Cluster value for which the address is to be obtained |
| void convert_to_uppercase | ( | char * | file_name | ) |
Function to convert the incoming short file name to its corresponding upper case letters.
| file_name | File name whose values are to be converted |
| int create_dir | ( | const char * | path | ) |
Function to create a directory.
| path | Pointer to the start of the path which represents the directory hierarchy |
| int create_file | ( | char * | lfname, |
| char * | shrt_name, | ||
| u32 | clus, | ||
| dir_entry ** | entry | ||
| ) |
Function to create a file if the file doesnt exists and the create flag is set.
| lfname | Pointer to the start of the long file. NULL in case of short file name creation |
| shrt_name | Pointer to the start of the short file name. In case of long file names the corresponding short file name is found out. |
| clus | Starting cluster of the directory in which the file is going to be created |
| entry | Pointer to a pointer of the directory entry structure in which the short file name directory entry content is to be stored |
| int file_close | ( | int | fd | ) |
Close the opened file based on the file descriptor and free the file structure pointer.
| fd | File descriptor of the file which needs to be closed |
| int file_open | ( | const char * | file_path, |
| int | flags | ||
| ) |
Function to open a specific file mentioned in the path based on the incoming modes.
| file_path | Pointer to the location of the file path string |
| flags | Flags indicating the modes in which the file is to be opened |
| int file_read | ( | int | fd, |
| char * | buffer, | ||
| int | bytes_to_read | ||
| ) |
Function to read the contents of a file.
| fd | File descriptor of the file in which read operation needs to be performed |
| buffer | Pointer to the start of the buffer where the contents read are stored |
| bytes_to_read | Number of bytes to be read from the file |
| int file_remove | ( | const char * | fl_name | ) |
file_remove - Deletes the file whose name is specified in filename
| fl_name | - string containing the name of the file to be deleted |
| int file_rename | ( | const char * | old, |
| const char * | new | ||
| ) |
Function to rename a file/directory.
| old | Constant pointer to the start of the path where the file which needs to be renamed is located |
| new | Constant pointer to the start of the path where the new name of the file/directory is situated |
| int file_seek | ( | int | fd, |
| int | offset, | ||
| int | whence | ||
| ) |
Function to seek the opened file pointer to the desired location so that subsequent read and write operations are performed from the new value.
| fd | File descriptor of the file in which the seek operation needs to be performed |
| offset | Offset bytes indicating the number of bytes which needs to be moved |
| whence | Flag denoting the position from which the seek operation needs to be performed |
| int file_truncate | ( | const char * | tr_pf, |
| int | tr_lgh | ||
| ) |
file_truncate - function cause the regular file named by path to be truncated to a size of precisely length bytes
| tr_pf | - truncates the file whose name is specified in filename |
| tr_lgh | - The desired truncate size of the file in bytes |
| int file_unlink | ( | const char * | ul_name | ) |
file_remove - Deletes the file whose name is specified in filename
| ul_name | - string containing the name of the file to be deleted |
file_remove - Deletes the file whose name is specified in filename
| ul_name | - string containing the name of the file to be deleted |
| int file_write | ( | int | fd, |
| const char * | buffer, | ||
| int | bytes_to_write | ||
| ) |
Function to write into the given file with the contents given.
| fd | File descriptor of the file |
| buffer | Pointer to the start of the contents which needs to be written into the file |
| bytes_to_write | Indicates the number of bytes which needs to be written into the file |
| void fill_lng_fname_entries | ( | char * | fname, |
| u8 * | entry, | ||
| u8 | chk_sum, | ||
| int | count | ||
| ) |
Function to put the long file name entries into the respective allocated region.
| fname | Pointer to the start of the long file name |
| entry | Starting memory location to the short file name directory entry |
| chk_sum | Calculated check sum of the short file name corresponding to the long file name |
| count | Counter indicating the number of 32 byte entries needed for the whole file name to get accommodated |
| int find_depth | ( | const char * | file_path | ) |
Function to calculate the number of iterations needed to reach the file from the given starting path.
| file_path | Pointer to the starting of the file path |
| bool get_dir_entry | ( | char * | fname, |
| dir_entry ** | entry, | ||
| u8 * | strt, | ||
| u32 | strt_clus, | ||
| bool | is_lfn | ||
| ) |
Function to check whether a given file name exists in the file system and if so retrieve the corresponding short file name directory entry.
| fname | Pointer to the start of the file name which needs to be searched |
| entry | Pointer to a pointer of the directory entry structure in which the short file name directory entry content is to be stored |
| strt | Pointer to the start of the region where the file/directory needs to be searched |
| strt_clus | Starting cluster of the directory in which the file is assumed to be present |
| is_lfn | Boolean value which indicates whether the file is short or long file |
| u32 get_fat_table_entry | ( | u32 | cluster | ) |
Function to retrieve the next cluster value in a cluster chain from the FAT table.
| cluster | Cluster whose next cluster value is to be obtained |
| int get_long_file_name | ( | char * | fname, |
| u8 ** | dir_strt, | ||
| int * | count | ||
| ) |
Function to retrieve the long file name given its end of the long file name entry.
| fname | Pointer to a location where the retrieved long file name starts |
| dir_strt | Pointer to the memory location where the last component of the long file name resides |
| count | Count representing the number of directory entries needed for the long file name |
| int get_seek_off | ( | file_info * | file_ptr, |
| u32 | strt_cluster, | ||
| int | offset | ||
| ) |
Function to move the current cluster and its offset value to the value specified in the offset from the starting cluster provided.
| file_ptr | File structure pointer pointing to the opened file |
| strt_cluster | Starting cluster value from which the seek operation has to be performed |
| offset | Offset bytes for the seek operation |
| void get_short_file_name | ( | char * | lfname, |
| char * | sfname, | ||
| char | seq_num | ||
| ) |
Function to extract the short file name given its long file name.
| lfname | : Pointer to the start of the long file name string |
| sfname | : Pointer to the start of the short file name in which this function extracts and stored the short file name value |
| seq_num | : sequence number |
| int lfn_entry_to_name | ( | lfn_entry * | entry, |
| char * | lfname, | ||
| int * | index | ||
| ) |
Function to get the long file name correspoding to a directory slot.
| entry | Pointer to the slot where a long file component resides |
| lfname | Pointer to the start of the long file name |
| index | Pointer to the offset of the long file name where the retrieved name from the given slot is going to be stored |
| int list_dir | ( | const char * | path | ) |
Function to list the directory contents.
| path | Pointer to the start of the path representing the directory hierarchy |
| int mount_file_system | ( | u8 * | dev | ) |
Mount the FAT file system and retrieve its basic information.
| dev | Pointer to the start of the file system image |
| int open_dir | ( | const char * | path | ) |
Function to open a directory.
| path | Pointer to the start of the path representing the directory hierarchy |
| file_stat* read_dir | ( | int | fd | ) |
| fd |
| int retrieve_file_info | ( | file_info * | finfo, |
| dir_entry * | entry, | ||
| u8 | mode, | ||
| u8 * | dir_offset, | ||
| const char * | path | ||
| ) |
Function to assign a file descriptor and necessary information to a file structure inorder to pursue subsequent operations.
| finfo | : Pointer to a file structure where the file information is stored |
| entry | : Pointer to the directory entry of the file/directory |
| mode | : Mode in which the file is requested to be opened |
| dir_offset | : directory offset |
| path | : path |
| void write_fat_table | ( | u32 | cluster, |
| u32 | value | ||
| ) |
Function to write into the FAT table after assigning an empty cluster to a file.
| cluster | Cluster number for which the entry has to be made |
| value | Next cluster value of the cluster number provided |
| boot_sector |
| dir_entry |
1.8.6