Skip to content

Commit c7bf1ff

Browse files
committed
modify
1 parent 7ee628d commit c7bf1ff

File tree

8 files changed

+104
-23
lines changed

8 files changed

+104
-23
lines changed

disksim.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include "ext2.h"
44
#include "disk.h"
55
#include "disksim.h"
6-
//work
6+
77
typedef struct
88
{
99
char* address;

ext2.c

+102-13
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ int fill_descriptor_block(EXT2_GROUP_DESCRIPTOR * gd, EXT2_SUPER_BLOCK * sb, SEC
239239
// root directory 생성
240240
int create_root(DISK_OPERATIONS* disk, EXT2_SUPER_BLOCK * sb)
241241
{
242-
EXT2_NODE dotNode, dotdotNode ;
242+
/* EXT2_NODE dotNode, dotdotNode ;
243243
EXT2_DIR_ENTRY * entry ;
244244
BYTE sector[MAX_SECTOR_SIZE];
245245
BYTE sector2[MAX_SECTOR_SIZE];
@@ -300,7 +300,63 @@ int create_root(DISK_OPERATIONS* disk, EXT2_SUPER_BLOCK * sb)
300300
301301
302302
303-
return EXT2_SUCCESS ;
303+
return EXT2_SUCCESS ;*/
304+
305+
BYTE sector[MAX_SECTOR_SIZE];
306+
SECTOR rootSector = 0;
307+
EXT2_DIR_ENTRY * entry;
308+
EXT2_GROUP_DESCRIPTOR * gd;
309+
EXT2_SUPER_BLOCK * sb_read;
310+
QWORD sector_num_per_group = (disk->numberOfSectors - 1) / NUMBER_OF_GROUPS;
311+
INODE * ip;
312+
const int BOOT_SECTOR_BASE = 1;
313+
int gi;
314+
315+
ZeroMemory(sector, MAX_SECTOR_SIZE);
316+
entry = (EXT2_DIR_ENTRY*)sector;
317+
318+
memcpy(entry->name, VOLUME_LABLE, 11);
319+
entry->name_len = strlen(VOLUME_LABLE);
320+
entry->inode = 2;
321+
entry++;
322+
entry->name[0] = DIR_ENTRY_NO_MORE;
323+
rootSector = 1 + sb->first_data_block_each_group;
324+
disk->write_sector(disk, rootSector, sector);
325+
326+
sb_read = (EXT2_SUPER_BLOCK *)sector;
327+
for (gi = 0; gi < NUMBER_OF_GROUPS; gi++)
328+
{
329+
disk->read_sector(disk, sector_num_per_group * gi + BOOT_SECTOR_BASE, sector);
330+
sb_read->free_block_count--;
331+
332+
disk->write_sector(disk, sector_num_per_group * gi + BOOT_SECTOR_BASE, sector);
333+
}
334+
sb->free_block_count--;
335+
336+
gd = (EXT2_GROUP_DESCRIPTOR *)sector;
337+
disk->read_sector(disk, BOOT_SECTOR_BASE + 1, sector);
338+
339+
340+
gd->free_blocks_count--;
341+
gd->directories_count = 1;
342+
343+
for (gi = 0; gi < NUMBER_OF_GROUPS; gi++)
344+
disk->write_sector(disk, sector_num_per_group * gi + BOOT_SECTOR_BASE + 1, sector);
345+
346+
disk->read_sector(disk, BOOT_SECTOR_BASE + 2, sector);
347+
sector[2] |= 0x02;
348+
disk->write_sector(disk, BOOT_SECTOR_BASE + 2, sector);
349+
350+
ZeroMemory(sector, MAX_SECTOR_SIZE);
351+
ip = (INODE *)sector;
352+
ip++;
353+
ip->mode = 0x1FF | 0x4000;
354+
ip->size = 0;
355+
ip->blocks = 1;
356+
ip->block[0] = sb->first_data_block_each_group;
357+
disk->write_sector(disk, BOOT_SECTOR_BASE + 4, sector);
358+
359+
return EXT2_SUCCESS;
304360
}
305361

306362
// inode 변경사항이 있을 때 meta data수정
@@ -679,26 +735,59 @@ int* get_data_block_at_inode(EXT2_FILESYSTEM *fs, INODE inode )
679735
// 슈퍼블록하고 그룹디스크립터의 섹터들을 읽어와서 연결된 구조체에 연결한다
680736

681737
int ext2_read_superblock(EXT2_FILESYSTEM* fs, EXT2_NODE* root)
682-
{ BYTE sector[MAX_SECTOR_SIZE];
738+
{
739+
740+
/*BYTE sector[MAX_SECTOR_SIZE];
683741
EXT2_SUPER_BLOCK * sb2;
684742
EXT2_GROUP_DESCRIPTOR * gd2;
685-
ZeroMemory(sector,sizeof(sector));
686-
if(fs==NULL || fs->disk==NULL)
687-
return EXT2_ERROR;
688-
sb2= (EXT2_SUPER_BLOCK *)sector ;
689-
fs->disk->read_sector(fs,1,sector);
690-
fs->sb=sb2;
743+
ZeroMemory(sector,sizeof(sector));
744+
745+
if(fs==NULL || fs->disk==NULL)
746+
return EXT2_ERROR;
747+
748+
sb2= (EXT2_SUPER_BLOCK *)sector ;
749+
fs->disk->read_sector(fs,1,sector);
750+
fs->sb = *sb2;
751+
691752
ZeroMemory(sector,sizeof(sector));
692753
gd2= (EXT2_GROUP_DESCRIPTOR *)sector ;
693-
fs->disk(fs,2,sector);
694-
fs->gd= gd2;
754+
fs->disk->read_sector(fs,2,sector);
755+
fs->gd= *gd2;
695756
ZeroMemory(sector,sizeof(sector));
757+
696758
if(read_root_sector(fs,sector))
697759
return EXT2_ERROR;
698-
ZeromMemory(root,sizeof(EXT2_NODE));
760+
ZeroMemory(root,sizeof(EXT2_NODE));
699761
memcpy(&root->entry,sector,sizeof(EXT2_DIR_ENTRY));
700762
root->fs= fs;
701-
return EXT2_SUCCESS ;
763+
return EXT2_SUCCESS ;*/
764+
765+
INT result;
766+
BYTE sector[MAX_SECTOR_SIZE];
767+
768+
if (fs == NULL || fs->disk == NULL)
769+
{
770+
WARNING("DISK OPERATIONS : %p\nEXT2_FILESYSTEM : %p\n", fs, fs->disk);
771+
return EXT2_ERROR;
772+
}
773+
774+
meta_read(fs, 0, SUPER_BLOCK, sector);
775+
memcpy(&fs->sb, sector, sizeof(EXT2_SUPER_BLOCK));
776+
meta_read(fs, 0, GROUP_DES, sector);
777+
memcpy(&fs->gd, sector, sizeof(EXT2_GROUP_DESCRIPTOR));
778+
779+
if (fs->sb.magic_signature != 0xEF53)
780+
return EXT2_ERROR;
781+
782+
ZeroMemory(sector, sizeof(MAX_SECTOR_SIZE));
783+
if (read_root_sector(fs, sector))
784+
return EXT2_ERROR;
785+
786+
ZeroMemory(root, sizeof(EXT2_NODE));
787+
memcpy(&root->entry, sector, sizeof(EXT2_DIR_ENTRY));
788+
root->fs = fs;
789+
790+
return EXT2_SUCCESS;
702791

703792

704793

ext2.o

128 Bytes
Binary file not shown.

ext2_shell.c

-5
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,6 @@ int fs_mount(DISK_OPERATIONS* disk, SHELL_FS_OPERATIONS* fsOprs, SHELL_ENTRY* ro
180180
}
181181
void fs_umount(DISK_OPERATIONS* disk, SHELL_FS_OPERATIONS* fsOprs)
182182
{
183-
if(fsOprs && fsOprs->pdata)
184-
{ free(fsOprs->pdata);
185-
fsOprs->pdata=0;
186-
}
187-
188183
return;
189184
}
190185

ext2_shell.o

-88 Bytes
Binary file not shown.

shell

0 Bytes
Binary file not shown.

shell.c

+1-4
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
#include "shell.h"
77
#include "disksim.h"
88

9-
// block과 sector모두 1024byte
10-
// boot block은 1block, block group은 2048block, 2개의 그룹
11-
// --> 전체 크기 : 1024(4096+1) byte
129
#define SECTOR DWORD
1310
#define BLOCK_SIZE 1024
1411
#define SECTOR_SIZE 1024
@@ -122,7 +119,7 @@ void do_shell(void)
122119

123120
while (-1)
124121
{
125-
printf("�й� : [/%s]# ", g_currentDir.name);
122+
printf("Çйø : [/%s]# ", g_currentDir.name);
126123

127124
fgets(buf, 1000, stdin);
128125
argc = seperate_string(buf, argv);

shell.o

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)