Changeset 661 for soft/giet_vm/giet_fat32
- Timestamp:
- Jul 24, 2015, 3:21:35 PM (9 years ago)
- Location:
- soft/giet_vm/giet_fat32
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/giet_fat32/fat32.c
r658 r661 4348 4348 4349 4349 4350 /////////////////////////////////////////////////////////////////////////////////4351 // The following function implements the giet_fat_list() system call.4352 // It displays the content of a directory identified by the "pathname" argument.4353 // It returns an error code if the pathname is not a directory.4354 /////////////////////////////////////////////////////////////////////////////////4355 // Returns 0 if success.4356 // Returns a negative value if error:4357 // -1 : "FAT not initialised4358 // -2 : "Directory not found"4359 // -3 : "Name in path too long4360 // -4 : "Not a directory"4361 // -5 : "Cannot access directory"4362 /////////////////////////////////////////////////////////////////////////////////4363 int _fat_list( char* pathname )4364 {4365 fat_inode_t* inode;4366 4367 // checking FAT initialised4368 if( _fat.initialised != FAT_INITIALISED )4369 {4370 _printf("\n[FAT ERROR] in _fat_list() : FAT not initialised\n");4371 return -1;4372 }4373 4374 #if GIET_DEBUG_FAT4375 unsigned int procid = _get_procid();4376 unsigned int x = procid >> (Y_WIDTH + P_WIDTH);4377 unsigned int y = (procid >> P_WIDTH) & ((1<<Y_WIDTH)-1);4378 unsigned int p = procid & ((1<<P_WIDTH)-1);4379 if ( _get_proctime() > GIET_DEBUG_FAT )4380 _printf("\n[DEBUG FAT] _fat_list() : P[%d,%d,%d] enters for path <%s>\n",4381 x, y, p, pathname );4382 #endif4383 4384 // get inode4385 unsigned int code = _get_inode_from_path( pathname , &inode );4386 4387 if ( (code == 1) || (code == 2) )4388 {4389 _printf("\n[FAT ERROR] in _fat_list() : directory <%s> not found\n", pathname );4390 return -2;4391 }4392 if ( code == 3 )4393 {4394 _printf("\n[FAT ERROR] in _fat_list() : name too long in path <%s>\n", pathname );4395 return -3;4396 }4397 4398 // check found inode is a directory4399 if ( inode->is_dir == 0 )4400 {4401 _printf("\n[FAT ERROR] in _fat_list() : <%s> is not a directory\n", pathname );4402 return -4;4403 }4404 4405 #if GIET_DEBUG_FAT4406 if ( _get_proctime() > GIET_DEBUG_FAT )4407 _printf("\n[DEBUG FAT] _fat_list() : P[%d,%d,%d] found inode for path <%s>\n",4408 x, y, p, pathname );4409 #endif4410 4411 // scan directory up to end of directory / two embedded loops :4412 // - loop on the clusters allocated to the directory4413 // - loop on the directory entries in each 4 Kbytes buffer4414 unsigned char* buffer;4415 fat_cache_desc_t* pdesc;4416 unsigned int cluster_id = 0; // cluster index in directory4417 unsigned int offset = 0; // position in scanned buffer4418 unsigned int lfn = 0; // number of lfn entries4419 unsigned int nb_entries = 0; // number of directory entries4420 unsigned int done = 0; // end of directory found4421 unsigned int attr; // ATTR field value4422 unsigned int ord; // ORD field value4423 char lfn1[16]; // temporary buffer for string in LFN14424 char lfn2[16]; // temporary buffer for string in LFN24425 char lfn3[16]; // temporary buffer for string in LFN34426 char name[36]; // directory entry full name4427 unsigned int cluster; // directory entry cluster index4428 unsigned int size; // directory entry size4429 unsigned int is_dir; // directory entry is a directory4430 unsigned int is_vid; // directory entry is volume_id4431 4432 // TODO : define a method to transfer this information to user mode4433 _printf("\n<%s> cluster = %x / lba = %x\n", pathname ,4434 inode->cluster , _cluster_to_lba( inode->cluster) );4435 4436 while ( done == 0 )4437 {4438 // get one 4 Kytes buffer4439 if ( _get_buffer_from_cache( inode,4440 cluster_id,4441 &pdesc ) )4442 {4443 _printf("\n[FAT ERROR] in _fat_list() : cannot access <%s>\n", pathname );4444 return -5;4445 }4446 buffer = pdesc->buffer;4447 4448 // scan this 4 Kbytes buffer4449 while ( (offset < 4096) && (done == 0) )4450 {4451 attr = _read_entry( DIR_ATTR , buffer + offset , 0 );4452 ord = _read_entry( LDIR_ORD , buffer + offset , 0 );4453 4454 if (ord == NO_MORE_ENTRY) // no more entry in directory => break4455 {4456 done = 1;4457 }4458 else if ( ord == FREE_ENTRY ) // free entry => skip4459 {4460 offset = offset + 32;4461 }4462 else if ( attr == ATTR_LONG_NAME_MASK ) // LFN entry => get partial names4463 {4464 unsigned int seq = ord & 0x3;4465 lfn = (seq > lfn) ? seq : lfn;4466 if ( seq == 1 ) _get_name_from_long( buffer + offset, lfn1 );4467 else if ( seq == 2 ) _get_name_from_long( buffer + offset, lfn2 );4468 else if ( seq == 3 ) _get_name_from_long( buffer + offset, lfn3 );4469 offset = offset + 32;4470 }4471 else // NORMAL entry4472 {4473 if ( lfn == 0 )4474 {4475 _get_name_from_short( buffer + offset , name );4476 }4477 else if ( lfn == 1 )4478 {4479 _strcpy( name , lfn1 );4480 }4481 else if ( lfn == 2 )4482 {4483 _strcpy( name , lfn1 );4484 _strcpy( name + 13 , lfn2 );4485 }4486 else if ( lfn == 3 )4487 {4488 _strcpy( name , lfn1 );4489 _strcpy( name + 13 , lfn2 );4490 _strcpy( name + 26 , lfn3 );4491 }4492 4493 is_dir = ((attr & ATTR_DIRECTORY) == ATTR_DIRECTORY);4494 is_vid = ((attr & ATTR_VOLUME_ID) == ATTR_VOLUME_ID);4495 size = (_read_entry( DIR_FILE_SIZE , buffer + offset , 1 ) ) ;4496 cluster = (_read_entry( DIR_FST_CLUS_HI , buffer + offset , 1 ) << 16) |4497 (_read_entry( DIR_FST_CLUS_LO , buffer + offset , 1 ) ) ;4498 4499 if ( is_vid == 0 )4500 {4501 // TODO : define a method to transfer this information to user mode4502 if (is_dir) _printf(" DIR | size = %X | cluster = %X | %s\n",4503 size , cluster, name );4504 else _printf(" FILE | size = %X | cluster = %X | %s\n",4505 size , cluster, name );4506 nb_entries++;4507 }4508 4509 offset = offset + 32;4510 lfn = 0;4511 }4512 } // end loop on directory entries4513 4514 if ( done == 0 )4515 {4516 cluster_id++;4517 offset = 0;4518 }4519 } // end loop on buffers4520 4521 // TODO : define a method to transfer this information to user mode4522 _printf(" total = %d entries\n", nb_entries );4523 4524 return 0;4525 } // end _fat_list()4526 4527 4528 4529 4530 4531 4350 /////////////////////////////////////////////////////////////////////////////// 4532 4351 // This functiond load a file identified by the "pathname" argument into the -
soft/giet_vm/giet_fat32/fat32.h
r658 r661 275 275 fat_dirent_t* entry ); // directory entry 276 276 277 extern int _fat_list( char* pathname ); // path from root278 279 277 extern int _fat_load_no_cache( char* pathname, // path from root 280 278 unsigned int buffer_vbase, // buffer base
Note: See TracChangeset
for help on using the changeset viewer.