Skip to content

Commit 8cda326

Browse files
committed
modify code
1 parent 7edf44e commit 8cda326

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

ext2.c

+15-12
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,20 @@ int ext2_write(EXT2_NODE* file, unsigned long offset, unsigned long length, cons
2525
return EXT2_ERROR;
2626
}
2727
if(node.blocks ==0)
28-
{expand_block(file->fs,file->entry.inode); // 블록 하나 늘려주고
29-
file->fs->sb.free_block_count --;
30-
file->fs->gd.free_blocks_count --;
31-
write_super_block(&file->fs->sb, file->fs->disk);
32-
write_group_descriptor(file->fs->disk, &file->fs->gd, file->entry.inode/file->fs->sb.inode_per_group);
33-
get_inode(file->fs, file->entry.inode, &node);
28+
{
29+
expand_block(file->fs,file->entry.inode); // 블록 하나 늘려주고
30+
file->fs->sb.free_block_count --;
31+
file->fs->gd.free_blocks_count --;
32+
write_super_block(&file->fs->sb, file->fs->disk);
33+
write_group_descriptor(file->fs->disk, &file->fs->gd, file->entry.inode/file->fs->sb.inode_per_group);
34+
get_inode(file->fs, file->entry.inode, &node);
3435
} // 해당 아이노드를 구하고
36+
3537
currentBlock = node.block[0]; // 현재 블록 초기화
3638
readEnd = offset + length;
3739
currentOffset = offset;
3840
blockSize = node.blocks * MAX_BLOCK_SIZE ; // 현재 해당 아이노드가 가지고 있는 블록 크기 초기화 해줌
41+
3942
i =0;
4043
while(offset>blockSize-1) // 만약 offset이 아이노드가 가지고 있는 블록 크기를 넘어선다면
4144
{
@@ -45,6 +48,7 @@ int ext2_write(EXT2_NODE* file, unsigned long offset, unsigned long length, cons
4548
++ blockSeq ;
4649
i++ ;
4750
}
51+
4852
file->fs->sb.free_block_count -= i;
4953
file->fs->gd.free_blocks_count -= i;
5054
write_super_block(&file->fs->sb, file->fs->disk);
@@ -53,11 +57,11 @@ int ext2_write(EXT2_NODE* file, unsigned long offset, unsigned long length, cons
5357
get_inode(file->fs,file->entry.inode,&node); // 다시 초기화 시켜준다
5458
dataBlocks = get_data_block_at_inode(file->fs,&node);
5559
currentBlock= dataBlocks[i]; // 해당 블록 받아온다
60+
5661
while (currentOffset < readEnd) // 계속 쓰는 작업
5762
{
5863
DWORD copyLength;
5964

60-
6165
blockNumber = currentOffset / MAX_BLOCK_SIZE; // 해당 아이노드 블록 넘버
6266
if (blockSeq != blockNumber) // 다음 블록을 쓸경우
6367
{
@@ -76,7 +80,7 @@ int ext2_write(EXT2_NODE* file, unsigned long offset, unsigned long length, cons
7680
nextBlock =dataBlocks[i];
7781
}
7882
else
79-
nextBlock = dataBlocks[i];
83+
nextBlock = dataBlocks[i];
8084

8185

8286
currentBlock = nextBlock;
@@ -91,9 +95,7 @@ int ext2_write(EXT2_NODE* file, unsigned long offset, unsigned long length, cons
9195
break;
9296
}
9397

94-
memcpy(&sector[sectorOffset],
95-
buffer,
96-
copyLength);
98+
memcpy(&sector[sectorOffset], buffer, copyLength);
9799
if (data_write(file->fs, file->location.group, currentBlock, sector))
98100
break;
99101

@@ -105,7 +107,8 @@ int ext2_write(EXT2_NODE* file, unsigned long offset, unsigned long length, cons
105107

106108
node.size = MAX(currentOffset, node.size);
107109
set_inode_onto_inode_table(file->fs, file->entry.inode, &node);
108-
return currentOffset - offset ; // 얼마나 읽었는지 알려준다
110+
111+
return currentOffset - offset ; // 얼마나 읽었는지 알려준다
109112
}
110113
int ext2_read(EXT2_NODE * file, unsigned long offset , unsigned long length , const char * buffer)
111114
{

0 commit comments

Comments
 (0)