@@ -25,17 +25,20 @@ int ext2_write(EXT2_NODE* file, unsigned long offset, unsigned long length, cons
25
25
return EXT2_ERROR ;
26
26
}
27
27
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 );
34
35
} // 해당 아이노드를 구하고
36
+
35
37
currentBlock = node .block [0 ]; // 현재 블록 초기화
36
38
readEnd = offset + length ;
37
39
currentOffset = offset ;
38
40
blockSize = node .blocks * MAX_BLOCK_SIZE ; // 현재 해당 아이노드가 가지고 있는 블록 크기 초기화 해줌
41
+
39
42
i = 0 ;
40
43
while (offset > blockSize - 1 ) // 만약 offset이 아이노드가 가지고 있는 블록 크기를 넘어선다면
41
44
{
@@ -45,6 +48,7 @@ int ext2_write(EXT2_NODE* file, unsigned long offset, unsigned long length, cons
45
48
++ blockSeq ;
46
49
i ++ ;
47
50
}
51
+
48
52
file -> fs -> sb .free_block_count -= i ;
49
53
file -> fs -> gd .free_blocks_count -= i ;
50
54
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
53
57
get_inode (file -> fs ,file -> entry .inode ,& node ); // 다시 초기화 시켜준다
54
58
dataBlocks = get_data_block_at_inode (file -> fs ,& node );
55
59
currentBlock = dataBlocks [i ]; // 해당 블록 받아온다
60
+
56
61
while (currentOffset < readEnd ) // 계속 쓰는 작업
57
62
{
58
63
DWORD copyLength ;
59
64
60
-
61
65
blockNumber = currentOffset / MAX_BLOCK_SIZE ; // 해당 아이노드 블록 넘버
62
66
if (blockSeq != blockNumber ) // 다음 블록을 쓸경우
63
67
{
@@ -76,7 +80,7 @@ int ext2_write(EXT2_NODE* file, unsigned long offset, unsigned long length, cons
76
80
nextBlock = dataBlocks [i ];
77
81
}
78
82
else
79
- nextBlock = dataBlocks [i ];
83
+ nextBlock = dataBlocks [i ];
80
84
81
85
82
86
currentBlock = nextBlock ;
@@ -91,9 +95,7 @@ int ext2_write(EXT2_NODE* file, unsigned long offset, unsigned long length, cons
91
95
break ;
92
96
}
93
97
94
- memcpy (& sector [sectorOffset ],
95
- buffer ,
96
- copyLength );
98
+ memcpy (& sector [sectorOffset ], buffer , copyLength );
97
99
if (data_write (file -> fs , file -> location .group , currentBlock , sector ))
98
100
break ;
99
101
@@ -105,7 +107,8 @@ int ext2_write(EXT2_NODE* file, unsigned long offset, unsigned long length, cons
105
107
106
108
node .size = MAX (currentOffset , node .size );
107
109
set_inode_onto_inode_table (file -> fs , file -> entry .inode , & node );
108
- return currentOffset - offset ; // 얼마나 읽었는지 알려준다
110
+
111
+ return currentOffset - offset ; // 얼마나 읽었는지 알려준다
109
112
}
110
113
int ext2_read (EXT2_NODE * file , unsigned long offset , unsigned long length , const char * buffer )
111
114
{
0 commit comments