@@ -19,6 +19,11 @@ int ext2_write(EXT2_NODE* file, unsigned long offset, unsigned long length, cons
19
19
int * dataBlocks ;
20
20
get_inode (file -> fs , file -> entry .inode , & node ); // 해당 아이노드를 구하고
21
21
printf ("%d \n" ,file -> entry .inode );
22
+ if (file -> fs -> gd .free_blocks_count < (length /MAX_SECTOR_SIZE )+ 1 )
23
+ {
24
+ printf ("not enough blocks\n" );
25
+ return EXT2_ERROR ;
26
+ }
22
27
if (node .blocks == 0 )
23
28
{expand_block (file -> fs ,file -> entry .inode ); // 블록 하나 늘려주고
24
29
file -> fs -> sb .free_block_count -- ;
@@ -40,7 +45,7 @@ int ext2_write(EXT2_NODE* file, unsigned long offset, unsigned long length, cons
40
45
++ blockSeq ;
41
46
i ++ ;
42
47
}
43
- file -> fs -> sb .free_block_count -= i ;
48
+ file -> fs -> sb .free_block_count -= i ;
44
49
file -> fs -> gd .free_blocks_count -= i ;
45
50
write_super_block (& file -> fs -> sb , file -> fs -> disk );
46
51
write_group_descriptor (file -> fs -> disk , & file -> fs -> gd , file -> entry .inode /file -> fs -> sb .inode_per_group );
@@ -413,68 +418,8 @@ int fill_descriptor_block(EXT2_GROUP_DESCRIPTOR * gd, EXT2_SUPER_BLOCK * sb, SEC
413
418
// root directory 생성
414
419
int create_root (DISK_OPERATIONS * disk , EXT2_SUPER_BLOCK * sb )
415
420
{
416
- /* EXT2_NODE dotNode, dotdotNode ;
417
- EXT2_DIR_ENTRY * entry ;
418
- BYTE sector[MAX_SECTOR_SIZE];
419
- BYTE sector2[MAX_SECTOR_SIZE];
420
- INODE *id;
421
- INODE *id2;
422
- EXT2_GROUP_DESCRIPTOR * gd;
423
- SECTOR rootsector =0;
424
- EXT2_SUPER_BLOCK * sb2;
425
- ZeroMemory(sector,MAX_SECTOR_SIZE);
426
- entry= (EXT2_DIR_ENTRY *)sector;
427
- memcpy(entry->name,VOLUME_LABLE,13);
428
- entry->name_len=sizeof(VOLUME_LABLE);
429
- entry->inode=2;
430
- ZeroMemory(&dotNode, sizeof(EXT2_NODE));
431
- memset(dotNode.entry.name,0x20,11);
432
- dotNode.entry.name[0]=".";
433
- dotNode.entry.inode=2;
434
- insert_entry(2,dotNode,0x4000);
435
- ZeroMemory(&dotNode, sizeof(EXT2_NODE));
436
- memset(dotNode.entry.name,0x20,11);
437
- dotdotNode.entry.name[0]=".";
438
- dotdotNode.entry.name[1]=".";
439
- dotdotNode.entry.inode=2;
440
- insert_entry(2,dotdotNode,0x4000);
441
- entry++;
442
- entry->name[0]= DIR_ENTRY_NO_MORE;
443
- rootsector= 1+sb->first_data_block_each_group; // 부트 코드 땜에 1 더해줌
444
- disk->write_sector(disk,rootsector,sector);
445
- // 지금까지 해당 엔트리를 만들어서 넣었고 이제 inode 테이블하고 superblock하고 groupdescriptor 내용 바꾸는 일 해야함
446
- ZeroMemory(sector,MAX_SECTOR_SIZE);
447
- sb2= (EXT2_SUPER_BLOCK *)sector ;
448
- disk->read_sector(disk,1,sector);
449
- sb2->free_block_count --;
450
- sb2->free_inode_count --;
451
- write_super_block(sb,disk);
452
- gd= (EXT2_GROUP_DESCRIPTOR *)sector ;
453
- ZeroMemory(sector,MAX_SECTOR_SIZE);
454
- disk->read_sector(disk,2,gd);
455
- gd-> free_blocks_count --;
456
- gd-> free_inodes_count --;
457
- gd-> directories_count ++;
458
- for(int i=0; i<NUMBER_OF_GROUPS; i++)
459
- write_group_descriptor(disk,gd,i);
460
- ZeroMemory(sector, sizeof(sector));
461
- disk->read_sector(disk, 3,sector);
462
- sector[2] |= 0x02;
463
- disk->write_sector(disk,3,sector); // 블록 비트맵 할당
464
- ZeroMemory(sector, MAX_SECTOR_SIZE);
465
- id= (INODE *)sector;
466
- disk->read_sector(disk,5,sector); // 아이노드 테이블
467
- id ++;
468
- id->mode = 0x4000 ;
469
- id->size =0 ;
470
- id->uid = 0;
471
- id->block[0]= 1+sb->first_data_block_each_group ;
472
- disk->write_sector(disk,5,sector);
473
-
474
-
475
-
421
+
476
422
477
- return EXT2_SUCCESS ;*/
478
423
BYTE sector [MAX_SECTOR_SIZE ];
479
424
SECTOR rootSector = 0 ;
480
425
EXT2_DIR_ENTRY * entry ;
@@ -771,10 +716,7 @@ UINT32 expand_block(EXT2_FILESYSTEM * fs, UINT32 inode_num)
771
716
for (int i = 0 ; i < MAX_SECTOR_SIZE ; i ++ )
772
717
{
773
718
774
- for (int j = 7 ; j >=0 ; -- j )
775
- {
776
- printf ("%d" , (sector [i ]>>j )& 1 );
777
- }
719
+
778
720
for (int j = 0 ; j < 8 ; j ++ )
779
721
{
780
722
@@ -785,10 +727,10 @@ UINT32 expand_block(EXT2_FILESYSTEM * fs, UINT32 inode_num)
785
727
786
728
}
787
729
used_blocks ++ ;
788
- printf ( "the blocks %d\n" , used_blocks );
730
+
789
731
}
790
732
if (f == 1 ) break ;
791
- printf ( "%d\n" , i );
733
+
792
734
793
735
}
794
736
@@ -803,7 +745,7 @@ UINT32 expand_block(EXT2_FILESYSTEM * fs, UINT32 inode_num)
803
745
else if (blocks < 12 + 256 )
804
746
{
805
747
int blocknumber = inodeBuffer .block [12 ];
806
- printf ( "%d \n" , used_blocks );
748
+
807
749
data_read (fs ,groupNum ,blocknumber ,sector2 );
808
750
int * a = (int * )sector2 ;
809
751
a [blocks - 12 ]= used_blocks ;
@@ -1776,6 +1718,7 @@ int ext2_df( EXT2_FILESYSTEM* fs, UINT32* totalSectors, UINT32* usedSectors )
1776
1718
EXT2_SUPER_BLOCK * sb = (EXT2_SUPER_BLOCK * )sector ;
1777
1719
data_read (fs , 0 , 0 , sector );
1778
1720
1721
+ printf ("sb->free : %d\n" , sb -> free_block_count );
1779
1722
* usedSectors = * totalSectors - (sb -> free_block_count * (MAX_BLOCK_SIZE /MAX_SECTOR_SIZE ));
1780
1723
return EXT2_SUCCESS ;
1781
1724
}
0 commit comments