65 u8 *type = file_sys_type;
67 if(*type != fs_type[i] ){
98 + (bs->fat_cnt * bs->sectors_per_fat)
99 + (bs->root_dir_strt_cluster-2))*
sec_size) ;
100 next_clus = bs->root_dir_strt_cluster;
126 const char *path = file_path;
127 const char *temp_path,*delim_strt;
130 int len = 0,fl_des = 0,crt_flag,i;
133 int extn_len_cnt = 0;
140 bool is_long_file_name =
false;
146 for(i=0;i<delim_cnt;i++){
153 long_file_name[len] = *path;
160 while(*temp_path !=
DELIMITER && *temp_path !=
'\0'){
166 is_long_file_name =
true;
168 if(is_long_file_name){
175 long_file_name[len] = *path;
179 long_file_name[len] =
'\0';
185 pwd,strt_cluster,
true);
193 long_file_name[len] = *path;
203 pwd,strt_cluster,
false);
205 if((is_file_found) & (i != delim_cnt - 1)){
206 strt_cluster = (entry->strt_clus_hword)<<16 |
207 (entry->strt_clus_lword);
213 is_long_file_name =
false;
221 sw_printf(
"Cannot open the file in write mode\n");
232 if(is_long_file_name){
236 pwd,strt_cluster,
false) ==
true){
238 pwd,strt_cluster,
false)){
241 shrt_file_name,
'seq_num');
246 shrt_file_name,strt_cluster,&entry);
284 u32 strt_clus,
bool is_lfn)
289 bool file_found =
false;
295 u32 next_clus = strt_clus;
313 if(
sw_memcmp(temp_lfn,fname,lfn_len) == 0)
404 for(i = 0; i <= 8; i += 2){
407 lfname[*index] = entry->
fname0_4[i];
410 for(i = 0; i <= 10; i += 2){
416 for(i = 0 ; i <= 2; i += 2){
440 u8 *dir_offset,
const char *path)
455 finfo->
entry = entry;
457 (entry->strt_clus_lword);
488 int tmp_bytes_cnt = 0;
498 tmp_bytes_cnt = tmp_offset;
501 tmp_offset = tmp_bytes_cnt = bytes_to_read;
503 while(tmp_offset > 0){
509 bytes_to_copy =
cluster_size - (tmp_bytes_cnt - bytes_read);
510 bytes_to_copy = bytes_to_copy > 0 ?
511 tmp_bytes_cnt - bytes_read:
516 sw_memcpy(buffer + bytes_read,file_cont,bytes_to_copy);
517 tmp_offset -= bytes_to_copy;
519 bytes_read += bytes_to_copy;
548 int file_write(
int fd,
const char *buffer,
int bytes_to_write)
552 int tmp_offset = bytes_to_write;
553 int alloc_cluster_cnt = 0;
555 int bytes_written = 0;
565 sw_printf(
"File opened in read only mode\n");
568 while(tmp_offset > 0){
574 bytes_to_copy =
cluster_size - (bytes_to_write - bytes_written);
575 bytes_to_copy = bytes_to_copy > 0 ?
576 bytes_to_write - bytes_written:
580 sw_memcpy(file_cont,buffer + bytes_written,bytes_to_copy);
581 bytes_written += bytes_to_copy;
583 tmp_offset -= bytes_to_copy;
594 if(alloc_cluster_cnt == 0 && temp->
cur_cluster == 0
615 if(alloc_cluster_cnt > 0)
618 return bytes_written;
649 prev->next = temp->
next;
680 u32 next_clus = clus;
683 int new_clus_cnt = 0;
684 int i = 0,j = 0,k = 0;
687 char *lfptr = lfname;
688 bool is_gap_found =
false;
693 while(!is_gap_found){
695 prev_clus = next_clus;
707 while(*lfptr !=
'\0'){
712 temp_cnt = req_ent_cnt;
713 while(req_ent_cnt--){
715 req_ent_cnt = temp_cnt;
731 req_ent_cnt = temp_cnt;
774 char *file_name = fname;
776 bool end_of_name =
false;
782 lf_entry = (
u8 *)lfn_ent;
787 for(j = 0;j < 3;j++){
802 for(i = 0; i < max_ord_cnt; i++){
803 if(*file_name ==
'\0'){
812 *(lf_entry) = *file_name;
842 int seek_mode = whence;
845 int tmp_off = offset;
848 int bytes_traversed = 0;
852 while (temp !=
NULL){
925 while(temp_old->
fd != fd_old)
926 temp_old = temp_old->
next;
927 while(temp_new->
fd != fd_new)
928 temp_new = temp_new->
next;
999 while(finfo !=
NULL){
1034 bool set_extn_lim =
false;
1037 while(temp !=
NULL){
1060 lfn[lfn_len + 1] =
'\0';
1067 set_extn_lim =
false;
1074 set_extn_lim =
true;
1080 sfn[index] = *(
u8 *)(entry + index1);
1084 *(sfn + (index + 1)) =
'\0';
1095 stat->
size = entry->size;
1096 stat->
attr = entry->attr;
1169 *(
u32*)(offset) = value;
1181 char *name = file_name;
1184 *name = (*name >=
'a' && *name <=
'z') ? *name -
ASCII_DIFF : *name;
1201 char *path = file_path;
1203 while(*path !=
'\0'){
1229 u32 cur_cluster = strt_cluster;
1230 int tmp_off = offset;
1234 int alloc_clus_cnt = 0;
1235 int bytes_traversed = 0;
1248 prev_cluster = cur_cluster;
1250 (offset - bytes_traversed);
1251 bytes_to_copy = bytes_to_copy > 0 ?
1252 offset - bytes_traversed :
1255 bytes_to_copy ? bytes_to_copy :
1257 bytes_traversed += bytes_to_copy;
1258 tmp_off -= bytes_to_copy;
1273 if(alloc_clus_cnt != 0)
1280 if(alloc_clus_cnt > 0)
1298 char *start = lfname;
1307 while(*start !=
'\0' && len != 6){
1314 sfname[len] = *start;
1343 while(temp !=
NULL){
1346 sw_printf(
"File already opened in write mode\n");
1370 sum = ((sum & 1) << 7) + (sum >> 1) + dir_entry[i];
1385 int len = file_name_len;
1390 req_cnt = len != 0 ? req_cnt++ : req_cnt;
1407 u32 new_clstr,prev_clstr,*tr_addr;
1409 int sk_ted,end_size,tmp_tsize,wt_zo=0,zo_cnt=0,i=1;
1410 char buff[1024]={
'\0'};
1419 tinfo = tinfo->
next;
1425 *tr_addr=(
u32)tr_lgh;
1434 end_size=tr_lgh-(
int)(tinfo->
file_size);
1437 wt_zo+=
file_write(tinfo->
fd,(
const char*)&buff,end_size);
1441 if(zo_cnt!=tmp_tsize && wt_zo==0) {
1442 sw_printf(
"null bytes is not appended \n");
1466 prev_clstr=new_clstr;
1520 rinfo = rinfo->
next;
1526 sw_printf(
"the file is not removed from the filesystem \n");