Skip to content

Commit 67064c4

Browse files
committed
mid modifying
1 parent 54cbbb3 commit 67064c4

File tree

9 files changed

+120
-8
lines changed

9 files changed

+120
-8
lines changed

ext2.c

+103-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,103 @@ typedef struct
88
#define MAX( a, b ) ( ( a ) > ( b ) ? ( a ) : ( b ) )
99
int* get_data_block_at_inode(EXT2_FILESYSTEM *fs, INODE *inode);
1010
int ext2_write(EXT2_NODE* file, unsigned long offset, unsigned long length, const char* buffer)
11-
{
11+
{
12+
int writeEnd ;
13+
int currentOffset ,currentBlock , blockSeq,copyLength ;
14+
int fileSize ,i=0 ;
15+
INODE * inodeBuffer ;
16+
char sector[MAX_SECTOR_SIZE];
17+
ZeroMemory(sector,sizeof(sector));
18+
inodeBuffer = (INODE *)sector ;
19+
int * dataBlocks;
20+
get_inode(file->fs,file->entry.inode,&inodeBuffer);
21+
// 새로만든 파일이라서 쓸 블럭이 없으면 추가시켜준다
22+
printf("hello \n");
23+
if(inodeBuffer->blocks==0)
24+
{
25+
expand_block(file->fs,file->entry.inode);
26+
printf("블럭이 없어서 추가시켜줬어영\n");
27+
}
28+
get_inode(file->fs,file->entry.inode,inodeBuffer);
29+
currentOffset = offset ; // 어디부터 쓸건지
30+
fileSize =inodeBuffer->blocks; // 파일 사이즈를 기록한다
31+
32+
printf("%d \n",fileSize) ;
33+
while((offset) >(inodeBuffer->blocks*MAX_BLOCK_SIZE-1)) // offset이 가지고 있는 블록보다 클경우
34+
{
35+
36+
expand_block(file->fs,file->entry.inode);
37+
}
38+
39+
40+
dataBlocks =get_data_block_at_inode(file->fs,&inodeBuffer); // 블럭 받는다
41+
printf(" aaa %d\n" ,dataBlocks[0]);
42+
writeEnd = MIN(offset +length , fileSize *MAX_BLOCK_SIZE); // 어디까지 쓸건지
43+
int blockOffset = currentOffset % MAX_BLOCK_SIZE ; // 해당 블록 내에서의 위치
44+
printf("hello \n");
45+
while((offset) >(inodeBuffer->blocks*MAX_BLOCK_SIZE-1))
46+
{
47+
dataBlocks[++i];
48+
} // 해당 블럭을 찾는 일
49+
50+
currentBlock = dataBlocks[i]; // 몇번째 블록 부터 읽을지 정한다
51+
52+
ZeroMemory(sector,sizeof(sector));
53+
printf("hello \n");
54+
while(currentOffset<writeEnd) // 어디까지 읽을지 정하는 것
55+
{ printf("여기까진함 \n");
56+
data_read(file->fs ,file->location.group ,currentBlock,sector); // 일단 해당 그룹의 블록을 읽어온다
57+
printf("여기까진함 \n");
58+
copyLength =MIN(MAX_BLOCK_SIZE-blockOffset , writeEnd - currentOffset );
59+
memcpy(&sector[blockOffset],buffer,copyLength);
60+
data_write(file->fs,file->location.group,currentBlock,sector);
61+
buffer += copyLength ; // 읽은만큼 더해준다
62+
currentOffset += offset ;
63+
}
64+
65+
return currentOffset - offset ; // 얼마나 읽었는지 알려준다
66+
}
67+
int ext2_read(EXT2_NODE * file, unsigned long offset , unsigned long length , const char * buffer)
68+
{
69+
70+
printf("hello \n");
71+
int readEnd ;
72+
int currentOffset ,currentBlock , blockSeq,copyLength ;
73+
int fileSize ,i=0 ;
74+
INODE * inodeBuffer ;
75+
char sector[MAX_SECTOR_SIZE];
76+
ZeroMemory(sector,sizeof(sector));
77+
inodeBuffer = (INODE *)sector ;
78+
int * dataBlocks;
79+
get_inode(file->fs,file->entry.inode,inodeBuffer);
80+
if(inodeBuffer->blocks==0) // 파일에 해당되는 블록이 아예없을경우
81+
{
82+
return EXT2_ERROR ;
83+
}
84+
dataBlocks =get_data_block_at_inode(file->fs,inodeBuffer);
85+
currentOffset = offset ;
86+
fileSize =inodeBuffer->blocks;
87+
readEnd = MIN(offset +length , fileSize *MAX_BLOCK_SIZE);
88+
int blockOffset = currentOffset % MAX_BLOCK_SIZE ; // 해당 블록 내에서 몇번째 섹터인지
89+
printf("hello 2\n");
90+
printf(" %d",dataBlocks[i]);
91+
while((offset/MAX_BLOCK_SIZE) > i )
92+
{
93+
dataBlocks[++i];
94+
} // 해당 블럭을 찾는 일
95+
currentBlock = dataBlocks[i]; // 몇번째 블록 부터 읽을지 정한다
96+
ZeroMemory(sector,sizeof(sector));
97+
printf("hello 3\n");
98+
while(currentOffset<readEnd) // 어디까지 읽을지 정하는 것
99+
{
100+
data_read(file->fs ,file->location.group ,currentBlock,sector); // 일단 해당 그룹의 블록을 읽어온다
101+
copyLength =MIN(MAX_BLOCK_SIZE-blockOffset , readEnd - currentOffset );
102+
memcpy(buffer,&sector[blockOffset],copyLength);
103+
buffer += copyLength ; // 읽은만큼 더해준다
104+
currentOffset += offset ;
105+
}
106+
return currentOffset - offset ; // 얼마나 읽었는지 알려준다
107+
12108
}
13109

14110
UINT32 get_free_inode_number(EXT2_FILESYSTEM* fs, int group);
@@ -630,7 +726,12 @@ UINT32 expand_block(EXT2_FILESYSTEM * fs, UINT32 inode_num)
630726
blocks++;
631727

632728
}
633-
729+
inodeBuffer->blocks = blocks;
730+
printf("used blocks %d \n",used_blocks);
731+
write_bitmap( used_blocks,1,sector);
732+
fs->disk->write_sector(fs->disk, 1+groupNum*fs->sb.block_per_group+2, sector); // 블록 비트맵 수정
733+
printf("ddd %d", inodeBuffer->blocks);
734+
set_inode_onto_inode_table(fs,inode_num,inodeBuffer);
634735
return EXT2_SUCCESS ;
635736

636737

ext2.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ int data_write(EXT2_FILESYSTEM * fs, SECTOR group, SECTOR block, BYTE* sector);
161161
int ext2_format(DISK_OPERATIONS* disk);
162162
int ext2_create(EXT2_NODE* parent, char* entryName, EXT2_NODE* retEntry);
163163
int ext2_lookup(EXT2_NODE* parent, const char* entryName, EXT2_NODE* retEntry);
164-
164+
int ext2_read(EXT2_NODE * file, unsigned long offset , unsigned long length , const char * buffer);
165165
UINT32 expand_block(EXT2_FILESYSTEM * , UINT32 );
166166
int fill_super_block(EXT2_SUPER_BLOCK * sb, SECTOR numberOfSectors, UINT32 bytesPerSector);
167167
int fill_descriptor_block(EXT2_GROUP_DESCRIPTOR * gd, EXT2_SUPER_BLOCK * sb, SECTOR numberOfSectors, UINT32 bytesPerSector);

ext2.o

3.09 KB
Binary file not shown.

ext2_shell.c

+11-3
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ static SHELL_FILE_OPERATIONS g_file =
130130
{
131131
fs_create,
132132
NULL,
133-
NULL,
133+
fs_read,
134134
fs_write
135135
};
136136

@@ -211,7 +211,7 @@ int fs_write(DISK_OPERATIONS* disk, SHELL_FS_OPERATIONS* fsOprs, const SHELL_ENT
211211
EXT2_NODE EXT2Entry;
212212

213213
shell_entry_to_ext2_entry(entry, &EXT2Entry);
214-
214+
215215
return ext2_write(&EXT2Entry, offset, length, buffer);
216216
}
217217

@@ -323,7 +323,15 @@ int fs_read_dir(DISK_OPERATIONS* disk, SHELL_FS_OPERATIONS* fsOprs, const SHELL_
323323

324324
return EXT2_SUCCESS;
325325
}
326+
int fs_read( DISK_OPERATIONS* disk, SHELL_FS_OPERATIONS* fsOprs, const SHELL_ENTRY* parent, SHELL_ENTRY* entry, unsigned long offset, unsigned long length, char* buffer )
327+
{
328+
EXT2_NODE EXTEntry;
326329

330+
shell_entry_to_ext2_entry( entry, &EXTEntry );
331+
printf("thissis me\n");
332+
return ext2_read( &EXTEntry, offset, length, buffer );
333+
334+
}
327335
int my_strnicmp(const char* str1, const char* str2, int length)
328336
{
329337
char c1, c2;
@@ -354,7 +362,7 @@ int is_exist(DISK_OPERATIONS* disk, SHELL_FS_OPERATIONS* fsOprs, const SHELL_ENT
354362

355363
fs_read_dir(disk, fsOprs, parent, &list);
356364
current = list.first;
357-
365+
printf("%s ffffff \n",list.first->entry.name);
358366
while (current)
359367
{
360368
if (my_strnicmp((char*)current->entry.name, name, 12) == 0)

ext2_shell.h

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
void shell_register_filesystem( SHELL_FILESYSTEM* );
88
int fs_write( DISK_OPERATIONS* disk, SHELL_FS_OPERATIONS* fsOprs, const SHELL_ENTRY* parent, SHELL_ENTRY* entry, unsigned long offset, unsigned long length, const char* buffer );
99
int fs_create(DISK_OPERATIONS* disk, SHELL_FS_OPERATIONS* fsOprs, const SHELL_ENTRY* parent, const char* name, SHELL_ENTRY* retEntry);
10+
int fs_read( DISK_OPERATIONS* disk, SHELL_FS_OPERATIONS* fsOprs, const SHELL_ENTRY* parent, SHELL_ENTRY* entry, unsigned long offset, unsigned long length, char* buffer );
1011
int fs_lookup(DISK_OPERATIONS* disk, SHELL_FS_OPERATIONS* fsOprs, const SHELL_ENTRY* parent, SHELL_ENTRY* entry, const char* name);
1112
int fs_read_dir(DISK_OPERATIONS* disk, SHELL_FS_OPERATIONS* fsOprs, const SHELL_ENTRY* parent, SHELL_ENTRY_LIST* list);
1213
int fs_mkdir(DISK_OPERATIONS* disk, SHELL_FS_OPERATIONS* fsOprs, const SHELL_ENTRY* parent, const char* name, SHELL_ENTRY* retEntry);

ext2_shell.o

424 Bytes
Binary file not shown.

shell

4.07 KB
Binary file not shown.

shell.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,11 @@ int shell_cmd_dumpdatablockbyname(int argc, char * agrv[]);
4343
int shell_cmd_dumpfileinode(int argc, char * argv[]);
4444
int shell_cmd_fill(int argc, char* argv[]);
4545
int shell_cmd_dumpdatablockbynum(int argc, char * argv[]);
46-
46+
int shell_cmd_cat(int argc, char * argv[]);
4747
static COMMAND g_commands[] =
4848
{
4949
{ "cd", shell_cmd_cd, COND_MOUNT },
50+
{ "cat", shell_cmd_cat, COND_MOUNT },
5051
{ "mount", shell_cmd_mount, COND_UMOUNT },
5152
{ "touch", shell_cmd_touch, COND_MOUNT },
5253
{ "fill", shell_cmd_fill, COND_MOUNT },
@@ -384,6 +385,7 @@ int shell_cmd_fill(int argc, char* argv[])
384385
memcpy(tmp, "Can you see? ", 13);
385386
tmp += 13;
386387
}
388+
387389
g_fsOprs.fileOprs->write(&g_disk, &g_fsOprs, &g_currentDir, &entry, offset, size, buffer);
388390
free(buffer);
389391

@@ -546,7 +548,7 @@ int shell_cmd_cat(int argc, char* argv[])
546548
printf("%s lookup failed\n", argv[1]);
547549
return -1;
548550
}
549-
551+
printf("1\n");
550552
while (g_fsOprs.fileOprs->read(&g_disk, &g_fsOprs, &g_currentDir, &entry, offset, 1024, buf) > 0)
551553
{
552554
printf("%s", buf);

shell.o

152 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)