Data Structures | |
struct | attrib |
struct | bootsect |
struct | date |
struct | FAT12 |
struct | fat_time |
struct | FileEntry |
struct | logical_FAT12 |
struct | sector |
struct | SectorDir |
Defines | |
#define | FAT_PHYS_SIZE 9 |
#define | FAT_BOOT_SECTOR 0 |
#define | FAT_SECTOR_SIZE 512 |
#define | EOF_FAT12 0xFF8 |
#define | EOF_FAT16 0xFFF8 |
#define | EOF_FAT32 0xFFFFFF8 |
Typedefs | |
typedef bootsect | bootsect_t |
typedef FAT12 | FAT12_t |
typedef logical_FAT12 | logical_FAT12_t |
typedef sector | sector_t |
typedef FileEntry | FileEntry_t |
typedef date | date_t |
typedef fat_time | fat_time_t |
typedef attrib | attrib_t |
typedef SectorDir | SectorDir_t |
Functions | |
bool | Read_FAT () |
bool | load_file (char *stringa, byte *buffer) |
int | get_file_size (char *file_name) |
char * | pwd () |
void | ls () |
bool | cd (char *new_path) |
bool | cat (char *stringa) |
bool | rm (char *filename) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Definition at line 388 of file fat12.c.
00389 { 00390 unsigned char Nome[9], Ext[4]; 00391 SectorDir_t *Buf, *Buf2; 00392 word sector; 00393 int counter; 00394 int h, i; 00395 bool a=FALSE; 00396 00397 name_ext(stringa, Nome, Ext); 00398 00399 counter = how_many_cluster(directory); 00400 Buf = kmalloc(FAT_SECTOR_SIZE*counter); 00401 memset(Buf, 0, FAT_SECTOR_SIZE*counter); 00402 read_file((sector_t *)Buf, directory, counter); 00403 00404 for(h=0; h<counter; h++) 00405 { 00406 for(i=0; i<FAT_SECTOR_SIZE/sizeof(FileEntry_t); i++) 00407 { 00408 a = compare_name_ext(Buf[h].Entry[i].Name, Nome, Buf[h].Entry[i].Extension, Ext); 00409 if (a) 00410 { 00411 // The file is empty // 00412 if ( !(Buf[h].Entry[i].StartCluster) ) goto founded; 00413 00414 // Print the file to the standard output // 00415 sector = Buf[h].Entry[i].StartCluster; 00416 Buf2 = kmalloc(sizeof(sector_t)); 00417 memset(Buf2, 0, sizeof(sector_t)); 00418 for (;;) 00419 { 00420 read_file((sector_t *)Buf2, sector, 1); 00421 for (i=0; i<FAT_SECTOR_SIZE; i++) 00422 { 00423 kputchar( ((byte *)Buf2)[i] ); 00424 } 00425 if (!(next_sector(§or, sector))) break; 00426 } 00427 kfree(Buf2); 00428 goto founded; 00429 } 00430 } 00431 } 00432 founded: 00433 kfree(Buf); 00434 if (!a) return(FALSE); 00435 return(TRUE); 00436 } |
|
Definition at line 458 of file fat12.c.
00459 { 00460 int counter=0; 00461 int l, h, i; 00462 bool change=FALSE; 00463 word a=0; 00464 attrib_t FileAttr; 00465 char dir_name[8]; 00466 SectorDir_t *Buf; 00467 00468 // Goto the root // 00469 if (new_path[0]=='/') 00470 if (new_path[1]=='\0') 00471 { 00472 path[0]='\0'; 00473 directory=0; 00474 return(TRUE); 00475 } 00476 00477 00478 counter = how_many_cluster(directory); 00479 Buf = kmalloc(FAT_SECTOR_SIZE*counter); 00480 memset(Buf, 0, FAT_SECTOR_SIZE*counter); 00481 read_file((sector_t *)Buf, directory, counter); 00482 00483 for(h=0; h<counter; h++) 00484 { 00485 for(i=0; i<FAT_SECTOR_SIZE/sizeof(FileEntry_t); i++) 00486 { 00487 read_attrib(&FileAttr, Buf[h].Entry[i].Attribute); 00488 if (FileAttr.Directory) 00489 { 00490 if ((Buf[h].Entry[i].Name[0]!=0)&&(Buf[h].Entry[i].Name[0]!=0xE5)) 00491 { 00492 if (Buf[h].Entry[i].Name[0]==5) Buf[h].Entry[i].Name[0]=0xE5; 00493 l=0; 00494 do 00495 { 00496 dir_name[l]=Buf[h].Entry[i].Name[l]; 00497 } while(dir_name[l++]!=' '); 00498 00499 dir_name[--l]='\0'; 00500 00501 if (strcmp(new_path, dir_name)==0) 00502 { 00503 a = Buf[h].Entry[i].StartCluster; 00504 change=TRUE; 00505 goto founded; 00506 } 00507 if (Buf[h].Entry[i].Name[0]==0xE5) Buf[h].Entry[i].Name[0]=0x05; 00508 } 00509 } 00510 } 00511 } 00512 founded: 00513 kfree(Buf); 00514 if (change) 00515 { 00516 directory = a; 00517 if (!a) 00518 path[0]='\0'; 00519 else 00520 { 00521 if(new_path[0] != '.') add_dir_path(new_path); 00522 else 00523 { 00524 if (new_path[1] == '.') up_dir_path(); 00525 } 00526 } 00527 return TRUE; 00528 } 00529 else 00530 return FALSE; 00531 } |
|
Definition at line 311 of file fat12.c.
00312 { 00313 // Get the size of a file // 00314 unsigned char name[9], ext[4]; 00315 SectorDir_t *Buf; 00316 int counter, count=0, h, i; 00317 bool found=FALSE; 00318 00319 // Get the file name and extension // 00320 name_ext(file_name, name, ext); 00321 00322 // Get the list of file into the current directory // 00323 counter = how_many_cluster(directory); 00324 Buf = kmalloc(FAT_SECTOR_SIZE*counter); 00325 memset(Buf, 0, FAT_SECTOR_SIZE*counter); 00326 // Read the directory // 00327 read_file((sector_t *)Buf, directory, counter); 00328 00329 // Find the file // 00330 for(h=0; h<counter; h++) 00331 { 00332 for(i=0; i<FAT_SECTOR_SIZE/sizeof(FileEntry_t); i++) 00333 { 00334 found = compare_name_ext(Buf[h].Entry[i].Name, name, Buf[h].Entry[i].Extension, ext); 00335 if (found) 00336 { 00337 // The file is empty // 00338 if ( !(Buf[h].Entry[i].StartCluster) ) goto founded; 00339 00340 // Get the size in clusters // 00341 count = how_many_cluster(Buf[h].Entry[i].StartCluster); 00342 goto founded; 00343 } 00344 } 00345 } 00346 founded: 00347 kfree(Buf); 00348 if (!found) return(-1); 00349 return(count*FAT_SECTOR_SIZE); 00350 }; |
|
Definition at line 267 of file fat12.c.
00268 { 00269 unsigned char Nome[9], Ext[4]; 00270 SectorDir_t *Buf; 00271 int counter, count; 00272 int h, i; 00273 bool found=FALSE; 00274 00275 // Get the file name and extension // 00276 name_ext(stringa, Nome, Ext); 00277 00278 // Get the list of file into the current directory // 00279 counter = how_many_cluster(directory); 00280 00281 Buf = kmalloc(FAT_SECTOR_SIZE*counter); 00282 memset(Buf, 0, FAT_SECTOR_SIZE*counter); 00283 00284 // Read the directory // 00285 read_file((sector_t *)Buf, directory, counter); 00286 00287 for(h=0; h<counter; h++) 00288 { 00289 for(i=0; i<FAT_SECTOR_SIZE/sizeof(FileEntry_t); i++) 00290 { 00291 found = compare_name_ext(Buf[h].Entry[i].Name, Nome, Buf[h].Entry[i].Extension, Ext); 00292 if (found) 00293 { 00294 // The file is empty // 00295 if ( !(Buf[h].Entry[i].StartCluster) ) goto founded; 00296 00297 // Copy the file into the buffer // 00298 count = how_many_cluster(Buf[h].Entry[i].StartCluster); 00299 read_file((sector_t *)buffer, Buf[h].Entry[i].StartCluster, count); 00300 goto founded; 00301 } 00302 } 00303 } 00304 founded: 00305 kfree(Buf); 00306 00307 if (!found) return(FALSE); 00308 return(TRUE); 00309 } |
|
Definition at line 352 of file fat12.c.
00353 { 00354 int counter=0; 00355 int h, i, scroll; 00356 SectorDir_t *Buf; 00357 00358 counter = how_many_cluster(directory); 00359 Buf = kmalloc(FAT_SECTOR_SIZE*counter); 00360 memset(Buf, 0, FAT_SECTOR_SIZE*counter); 00361 00362 read_file((sector_t *)Buf, directory, counter); 00363 00364 kprintf("\nList of files into the directory:\n\r\n\r"); 00365 for(h=0, scroll=0; h<counter; h++) 00366 { 00367 for(i=0; i<(bootsector.BytesPerSector/sizeof(FileEntry_t)); i++) 00368 { 00369 if (scroll==20) 00370 { 00371 kprintf("\n\rPress a key to continue...\n\r"); 00372 scroll=0; 00373 if (kgetchar() == CTRL_C) 00374 { 00375 kprintf("\n\r"); 00376 kfree(Buf); 00377 return; 00378 } 00379 } 00380 if ( show_file_entry(&(Buf[h].Entry[i])) ) 00381 scroll++; 00382 } 00383 } 00384 kfree(Buf); 00385 kprintf("\n\r"); 00386 } |
|
Definition at line 452 of file fat12.c.
00453 { 00454 // Return the current path // 00455 return(path); 00456 } |
|
Definition at line 673 of file fat12.c.
00674 { 00675 // Read the FAT from the floppy (mount) // 00676 int i, j; 00677 00678 if (!( init_FAT() )) 00679 { 00680 kprintf("\n\rFloppy I/O error. Unable to read the block!!!\n\r"); 00681 return(FALSE); 00682 } 00683 00684 // FAT initializazion OK! // 00685 for (i=0; i<3; i++) 00686 if (fdc_read(1, (byte *)&fat, bootsector.SectorsPerFat)) 00687 break; 00688 if (i == 3) 00689 { 00690 kprintf("\n\rFloppy I/O error. Unable to read the block!!!\n\r"); 00691 return(FALSE); 00692 } 00693 00694 // Converts the FAT into the logical structures (array of word) // 00695 for(i=0, j=0; i<4608; i+=3) 00696 { 00697 lfat.data[j++] = (fat.data[i] + (fat.data[i+1] << 8)) & 0x0FFF; 00698 lfat.data[j++] = (fat.data[i+1] + (fat.data[i+2] << 8)) >> 4; 00699 } 00700 00701 // Check if the FAT is correct // 00702 if (!( check_FAT() )) 00703 { 00704 kprintf("\n\rNot a valid FAT12 filesystem!!!\n\r"); 00705 return(FALSE); 00706 } 00707 00708 // Initialize the path // 00709 path[0]='\0'; 00710 00711 #ifdef FAT_DEBUG 00712 kprintf("\n\rInitializing FileSystem...\n\r"); 00713 kprintf("\n\r"); 00714 kprintf("Jump:\t\t\t%02x %02x %02x\n\r", bootsector.Jump[0], bootsector.Jump[1], bootsector.Jump[2]); 00715 kprintf("OS Name:\t\t\t%s\n\r", bootsector.Name); 00716 kprintf("BytesPerSector:\t\t\t%u\n\r", bootsector.BytesPerSector); 00717 kprintf("SectorsPerCluster:\t\t\t%u\n\r", bootsector.SectorsPerCluster); 00718 kprintf("ReservedSectors:\t\t\t%u\n\r", bootsector.ReservedSectors); 00719 kprintf("Fats:\t\t\t%u\n\r", bootsector.Fats); 00720 kprintf("RootDirectoryEntries:\t\t\t%u\n\r", bootsector.RootDirectoryEntries); 00721 kprintf("LogicalSectors:\t\t\t%u\n\r", bootsector.LogicalSectors); 00722 kprintf("MediumDescriptorByte:\t\t\t%X\n\r", bootsector.MediumDescriptorByte); 00723 kprintf("SectorsPerFat:\t\t\t%u\n\r", bootsector.SectorsPerFat); 00724 kprintf("SectorsPerTrack:\t\t\t%u\n\r", bootsector.SectorsPerTrack); 00725 kprintf("Heads:\t\t\t%u\n\r", bootsector.Heads); 00726 kprintf("HiddenSectors:\t\t\t%u\n\r", bootsector.HiddenSectors); 00727 kprintf("\n\r"); 00728 #endif 00729 00730 return(TRUE); 00731 } |
|
Definition at line 606 of file fat12.c.
00607 { 00608 // Remove a file from the disk // 00609 unsigned char name[9], ext[4]; 00610 SectorDir_t *Buf; 00611 int counter, h, i; 00612 bool a=FALSE; 00613 00614 if ( (strcmp(filename, ".")==0) || (strcmp(filename, "..")==0) ) 00615 return(FALSE); 00616 00617 name_ext(filename, name, ext); 00618 00619 counter = how_many_cluster(directory); 00620 Buf = kmalloc(FAT_SECTOR_SIZE*counter); 00621 memset(Buf, 0, FAT_SECTOR_SIZE*counter); 00622 read_file((sector_t *)Buf, directory, counter); 00623 00624 for(h=0; h<counter; h++) 00625 { 00626 for(i=0; i<FAT_SECTOR_SIZE/sizeof(FileEntry_t); i++) 00627 { 00628 a = compare_name_ext(Buf[h].Entry[i].Name, name, Buf[h].Entry[i].Extension, ext); 00629 if (a) 00630 { 00631 // Delete the file // 00632 Buf[h].Entry[i].Name[0] = 0xE5; 00633 write_sector_dir(&Buf[h], h); 00634 delete_file(Buf[h].Entry[i].StartCluster); 00635 fat12_write(); 00636 goto founded; 00637 } 00638 } 00639 } 00640 founded: 00641 kfree(Buf); 00642 if (!a) return(FALSE); 00643 return(TRUE); 00644 } |