Skip to content

Commit dfcec4d

Browse files
committed
need to solve df error
1 parent ca688a3 commit dfcec4d

File tree

8 files changed

+12
-71
lines changed

8 files changed

+12
-71
lines changed

disksim.o

2.45 KB
Binary file not shown.

entrylist.o

1.98 KB
Binary file not shown.

ext2.c

+12-69
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ int ext2_write(EXT2_NODE* file, unsigned long offset, unsigned long length, cons
1919
int *dataBlocks ;
2020
get_inode(file->fs, file->entry.inode, &node); // 해당 아이노드를 구하고
2121
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+
}
2227
if(node.blocks ==0)
2328
{expand_block(file->fs,file->entry.inode); // 블록 하나 늘려주고
2429
file->fs->sb.free_block_count --;
@@ -40,7 +45,7 @@ int ext2_write(EXT2_NODE* file, unsigned long offset, unsigned long length, cons
4045
++ blockSeq ;
4146
i++ ;
4247
}
43-
file->fs->sb.free_block_count -= i;
48+
file->fs->sb.free_block_count -= i;
4449
file->fs->gd.free_blocks_count -= i;
4550
write_super_block(&file->fs->sb, file->fs->disk);
4651
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
413418
// root directory 생성
414419
int create_root(DISK_OPERATIONS* disk, EXT2_SUPER_BLOCK * sb)
415420
{
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+
476422

477-
return EXT2_SUCCESS ;*/
478423
BYTE sector[MAX_SECTOR_SIZE];
479424
SECTOR rootSector = 0;
480425
EXT2_DIR_ENTRY * entry;
@@ -771,10 +716,7 @@ UINT32 expand_block(EXT2_FILESYSTEM * fs, UINT32 inode_num)
771716
for(int i = 0; i < MAX_SECTOR_SIZE; i++)
772717
{
773718

774-
for(int j=7; j>=0; --j)
775-
{
776-
printf("%d", (sector[i]>>j)&1);
777-
}
719+
778720
for(int j = 0; j < 8; j++)
779721
{
780722

@@ -785,10 +727,10 @@ UINT32 expand_block(EXT2_FILESYSTEM * fs, UINT32 inode_num)
785727

786728
}
787729
used_blocks ++;
788-
printf("the blocks %d\n",used_blocks);
730+
789731
}
790732
if(f==1) break;
791-
printf("%d\n", i);
733+
792734

793735
}
794736

@@ -803,7 +745,7 @@ UINT32 expand_block(EXT2_FILESYSTEM * fs, UINT32 inode_num)
803745
else if(blocks < 12+256)
804746
{
805747
int blocknumber = inodeBuffer.block[12];
806-
printf("%d \n",used_blocks);
748+
807749
data_read(fs,groupNum,blocknumber,sector2);
808750
int *a = (int *)sector2 ;
809751
a[blocks-12]=used_blocks ;
@@ -1776,6 +1718,7 @@ int ext2_df( EXT2_FILESYSTEM* fs, UINT32* totalSectors, UINT32* usedSectors )
17761718
EXT2_SUPER_BLOCK* sb = (EXT2_SUPER_BLOCK*)sector;
17771719
data_read(fs, 0, 0, sector);
17781720

1721+
printf("sb->free : %d\n", sb->free_block_count);
17791722
*usedSectors = *totalSectors - (sb->free_block_count * (MAX_BLOCK_SIZE/MAX_SECTOR_SIZE));
17801723
return EXT2_SUCCESS;
17811724
}

ext2.o

31.6 KB
Binary file not shown.

ext2_shell.c

-2
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,6 @@ static SHELL_FS_OPERATIONS g_fsOprs =
147147

148148
int fs_stat( DISK_OPERATIONS* disk, SHELL_FS_OPERATIONS* fsOprs, unsigned int* totalSectors, unsigned int* usedSectors )
149149
{
150-
EXT2_NODE entry;
151-
152150
return ext2_df( (EXT2_FILESYSTEM*)fsOprs->pdata, totalSectors, usedSectors );
153151
}
154152
int fs_remove (DISK_OPERATIONS* disk, SHELL_FS_OPERATIONS* fsOprs, const SHELL_ENTRY* current, const char* name)

ext2_shell.o

13.7 KB
Binary file not shown.

shell

54 KB
Binary file not shown.

shell.o

19.4 KB
Binary file not shown.

0 commit comments

Comments
 (0)