32 #define END_OF_CLUSTER 0x0FFFFFFF
33 #define END_OF_ROOT_CLUSTER 0X0FFFFFF8
34 #define MAX_DIR_ENTRY_CNT 16
35 #define FILE_SYS_TYPE_OFF 82
36 #define BYTES_PER_SEC_OFF 11
37 #define SEC_PER_CLUS_OFF 13
38 #define RES_SEC_CNT_OFF 14
39 #define FAT_CNT_OFF 16
40 #define TOT_SEC_CNT_OFF 32
41 #define SEC_PER_FAT 36
42 #define ROOT_DIR_STRT_CLUS_OFF 44
43 #define FS_INFOSECTOR_OFF 48
44 #define BACKUP_BOOT_SEC_OFF 50
45 #define NXT_FREE_CLUS_OFF 492
46 #define FILE_SYS_TYPE_LENGTH 8
47 #define SHRT_FILE_NAME_LEN 11
48 #define STRT_CLUS_LOW_OFF 26
49 #define STRT_CLUS_HIGH_OFF 20
50 #define FILE_SIZE_OFF 28
52 #define FILE_STAT_LEN 21
53 #define CHECK_SUM_OFF 13
54 #define FILE_NAME_SHRT_LEN 8
55 #define FILE_NAME_EXTN_LEN 3
56 #define LONG_FILE_NAME_LEN 255
57 #define LOW_CLUSWORD_MASK 0x0000FFFF
58 #define HIGH_CLUSWORD_MASK 0xFFFF0000
59 #define LONG_FNAME_MASK 0x0F
60 #define LAST_ORD_FIELD_SEQ 0x40
61 #define LFN_END_MARK 0xFFFF
62 #define LFN_TERM_MARK 0x0000
63 #define LFN_FIRST_OFF 0x01
64 #define LFN_SIXTH_OFF 0x0E
65 #define LFN_TWELVETH_OFF 0x1C
66 #define LFN_FIRST_SET_CNT 5
67 #define LFN_SEC_SET_CNT 6
68 #define LFN_THIRD_SET_CNT 2
69 #define LFN_FIRST_SET_LEN 10
70 #define LFN_SEC_SET_LEN 12
71 #define LFN_THIRD_SET_LEN 4
72 #define LFN_EMPTY_LEN 2
73 #define LFN_LEN_PER_ENTRY 13
74 #define FNAME_EXTN_SEP_OFF 6
75 #define FNAME_SEQ_NUM_OFF 7
76 #define BYTES_PER_CLUSTER_ENTRY 4
77 #define DIR_ENTRY_LEN 32
79 #define VOL_LABEL_LEN 11
82 #define OEM_NAME_LEN 8
83 #define JUMP_INS_LEN 3
86 #define FILE_READ 0x01
87 #define FILE_WRITE 0X02
88 #define FILE_CREATE_NEW 0x04
89 #define FILE_CREATE_ALWAYS 0x08
90 #define FILE_APPEND 0x10
91 #define ATTR_READ 0x01
92 #define ATTR_HIDDEN 0x02
93 #define ATTR_SYSTEM 0x04
94 #define ATTR_VOL_LABEL 0x08
96 #define ATTR_ARCHIVE 0x20
97 #define ATTR_LONG_FNAME 0x0F
98 #define FREE_DIR_ENTRY 0x00
99 #define DEL_DIR_ENTRY 0xE5
100 #define DOT_DIR_ENTRY 0x2E
101 #define ASCII_DIFF 32
102 #define FILE_SEEK_SET 0
103 #define FILE_SEEK_CUR 1
104 #define FILE_SEEK_END 2
105 #define DELIMITER '/'
106 #define EXTN_DELIMITER '.'
108 #define FULL_SHRT_NAME_LEN 13
120 u16 reserved_sec_cnt;
122 u16 root_dir_max_cnt;
125 u16 sec_per_fat_fat16;
133 u32 root_dir_strt_cluster;
263 int file_open(
const char *file_path,
int flags);
288 u32 strt_clus,
bool is_lfn);
331 u8 *dir_offset,
const char *path);
398 int file_read(
int fd,
char * buffer,
int bytes_to_read);
413 int file_write(
int fd,
const char *buffer,
int bytes_to_write);
501 int file_seek(
int fd,
int offset,
int whence);
#define OEM_NAME_LEN
Definition: fat32.h:82
dir_entry
Definition: fat32.h:165
u8 ord_field
Definition: fat32.h:173
int file_read(int fd, char *buffer, int bytes_to_read)
Function to read the contents of a file.
Definition: fat32.c:508
#define FILE_NAME_EXTN_LEN
Definition: fat32.h:55
u8 * cluster_to_memory_addr(u32 cluster)
Function to get the corresponding physical address from the given cluster.
Definition: fat32.c:1158
int file_unlink(const char *ul_name)
file_remove - Deletes the file whose name is specified in filename
Definition: fat32.c:1534
u32 allocate_cluster()
Function to find an unused cluster from the FAT table.
Definition: fat32.c:1134
#define JUMP_INS_LEN
Definition: fat32.h:83
u32 bytes_traversed
Definition: fat32.h:200
u8 calc_check_sum(u8 *dir_entry)
Function to calculate the checksum for the long file name based on its short name entry...
Definition: fat32.c:1391
u8 * dir_entry_offset
Definition: fat32.h:201
u16 time
Definition: fat32.h:215
int create_dir(const char *path)
Function to create a directory.
Definition: fat32.c:980
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.
Definition: fat32.c:707
u32 size
Definition: fat32.h:214
void get_short_file_name(char *lfname, char *sfname, char seq_num)
Function to extract the short file name given its long file name.
Definition: fat32.c:1322
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 ...
Definition: fat32.c:466
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.
Definition: fat32.c:389
u32 get_fat_table_entry(u32 cluster)
Function to retrieve the next cluster value in a cluster chain from the FAT table.
Definition: fat32.c:1174
u8 reserved
Definition: fat32.h:176
u8 attr
Definition: fat32.h:217
int file_close(int fd)
Close the opened file based on the file descriptor and free the file structure pointer.
Definition: fat32.c:660
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 ...
Definition: fat32.c:1431
u32 cur_cluster
Definition: fat32.h:196
u32 strt_cluster
Definition: fat32.h:195
int mount_file_system(u8 *dev)
Mount the FAT file system and retrieve its basic information.
Definition: fat32.c:61
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 correspo...
Definition: fat32.c:311
void convert_to_uppercase(char *file_name)
Function to convert the incoming short file name to its corresponding upper case letters.
Definition: fat32.c:1205
int file_open(const char *file_path, int flags)
Function to open a specific file mentioned in the path based on the incoming modes.
Definition: fat32.c:150
Structure containing the basic details of a file/directory.
Definition: fat32.h:210
int file_write(int fd, const char *buffer, int bytes_to_write)
Function to write into the given file with the contents given.
Definition: fat32.c:575
#define LFN_EMPTY_LEN
Definition: fat32.h:72
file_info * next
Definition: fat32.h:202
const char * lname
Definition: fat32.h:213
#define VOL_ID_LEN
Definition: fat32.h:78
dir_entry * entry
Definition: fat32.h:193
#define FULL_SHRT_NAME_LEN
Definition: fat32.h:108
int file_rename(const char *old, const char *new)
Function to rename a file/directory.
Definition: fat32.c:940
#define LFN_THIRD_SET_LEN
Definition: fat32.h:71
u32 file_size
Definition: fat32.h:198
void write_fat_table(u32 cluster, u32 value)
Function to write into the FAT table after assigning an empty cluster to a file.
Definition: fat32.c:1191
#define LFN_FIRST_SET_LEN
Definition: fat32.h:69
#define RESERV_LEN
Definition: fat32.h:80
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.
Definition: fat32.c:801
int cal_req_dir_cnt(int file_name_len)
Definition: fat32.c:1408
u16 date
Definition: fat32.h:216
int file_remove(const char *fl_name)
file_remove - Deletes the file whose name is specified in filename
Definition: fat32.c:1515
#define VOL_LABEL_LEN
Definition: fat32.h:79
int fd
Definition: fat32.h:192
bool chk_fat32_file_system(u8 *file_sys_type)
Verify the type of FAT file system.
Definition: fat32.c:86
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 op...
Definition: fat32.c:870
int chk_file_lock(const char *path)
Definition: fat32.c:1365
s32int count
Definition: virtual_keyboard.c:40
u8 chksum
Definition: fat32.h:177
int open_dir(const char *path)
Function to open a directory.
Definition: fat32.c:999
#define FILE_NAME_SHRT_LEN
Definition: fat32.h:54
const char * file_path
Definition: fat32.h:194
Structure of a file containing its basic information required for many operations.
Definition: fat32.h:190
void cal_region_offsets(boot_sector *bs, u8 *dev)
Function to calculate all the region offsets.
Definition: fat32.c:110
u16 cur_offset
Definition: fat32.h:197
u8 * backup_boot_sector
Definition: fat32.c:36
#define FILE_SYS_TYPE_LENGTH
Definition: fat32.h:46
int lfn_entry_to_name(lfn_entry *entry, char *lfname, int *index)
Function to get the long file name correspoding to a directory slot.
Definition: fat32.c:428
file_stat * read_dir(int fd)
Definition: fat32.c:1045
int list_dir(const char *path)
Function to list the directory contents.
Definition: fat32.c:1014
boot_sector
Definition: fat32.h:143
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 t...
Definition: fat32.c:1252
Structure of the long file name slot.
Definition: fat32.h:171
#define LFN_SEC_SET_LEN
Definition: fat32.h:70
int find_depth(const char *file_path)
Function to calculate the number of iterations needed to reach the file from the given starting path...
Definition: fat32.c:1225
Definition: cpu_mmu.h:126
struct __attribute__((__packed__))
Structure of the boot sector.
Definition: fat32.h:114
u8 mode
Definition: fat32.h:199
#define FS_VER_LEN
Definition: fat32.h:81
u8 flag
Definition: fat32.h:175