@@ -17,30 +17,6 @@ string user_input()
17
17
return s;
18
18
}
19
19
20
- int _block_write (int block, char *buf, int size, int start_position)
21
- {
22
-
23
- if ((block < 0 ) || (block >= DISK_BLOCKS))
24
- {
25
- fprintf (stderr, " block_write: block index out of bounds\n " );
26
- return -1 ;
27
- }
28
-
29
- if (fseek (diskptr, (block * BLOCK_SIZE) + start_position, SEEK_SET) < 0 )
30
- {
31
- perror (" block_write: failed to lseek" );
32
- return -1 ;
33
- }
34
-
35
- if (fwrite (buf, sizeof (char ), size, diskptr) < 0 )
36
- {
37
- perror (" block_write: failed to write" );
38
- return -1 ;
39
- }
40
-
41
- return 0 ;
42
- }
43
-
44
20
int _write_into_file (int fd, char *buff, int len, int *bytes_written)
45
21
{
46
22
@@ -55,7 +31,7 @@ int _write_into_file(int fd, char *buff, int len, int *bytes_written)
55
31
if (filled_data_block < 10 )
56
32
{
57
33
int data_block_to_write = inode_arr[file_inode].pointer [filled_data_block];
58
- _block_write (data_block_to_write, buff, len, cur_pos % BLOCK_SIZE);
34
+ block_write (data_block_to_write, buff, len, cur_pos % BLOCK_SIZE);
59
35
inode_arr[file_inode].filesize += len;
60
36
file_descriptor_map[fd].second += len; // updating the cur pos in the file
61
37
*bytes_written += len;
@@ -70,7 +46,7 @@ int _write_into_file(int fd, char *buff, int len, int *bytes_written)
70
46
memcpy (block_pointers, read_buf, sizeof (read_buf));
71
47
72
48
int data_block_to_write = block_pointers[filled_data_block - 10 ];
73
- _block_write (data_block_to_write, buff, len, cur_pos % BLOCK_SIZE);
49
+ block_write (data_block_to_write, buff, len, cur_pos % BLOCK_SIZE);
74
50
inode_arr[file_inode].filesize += len;
75
51
file_descriptor_map[fd].second += len; // updating the cur pos in the file
76
52
*bytes_written += len;
@@ -90,7 +66,7 @@ int _write_into_file(int fd, char *buff, int len, int *bytes_written)
90
66
memcpy (block_pointers2, read_buf, sizeof (read_buf));
91
67
92
68
int data_block_to_write = block_pointers[(filled_data_block - 1034 ) / 1024 ];
93
- _block_write (data_block_to_write, buff, len, cur_pos % BLOCK_SIZE);
69
+ block_write (data_block_to_write, buff, len, cur_pos % BLOCK_SIZE);
94
70
inode_arr[file_inode].filesize += len;
95
71
file_descriptor_map[fd].second += len; // updating the cur pos in the file
96
72
*bytes_written += len;
@@ -102,7 +78,7 @@ int _write_into_file(int fd, char *buff, int len, int *bytes_written)
102
78
/* if filesize = 0 means file is empty then start writting into file from first direct block. */
103
79
if (inode_arr[file_descriptor_map[fd].first ].filesize == 0 )
104
80
{
105
- _block_write (inode_arr[file_inode].pointer [0 ], buff, len, 0 );
81
+ block_write (inode_arr[file_inode].pointer [0 ], buff, len, 0 );
106
82
inode_arr[file_inode].filesize += len;
107
83
file_descriptor_map[fd].second += len;
108
84
*bytes_written += len;
@@ -126,7 +102,7 @@ int _write_into_file(int fd, char *buff, int len, int *bytes_written)
126
102
free_data_block_vector.pop_back ();
127
103
inode_arr[file_inode].pointer [0 ] = next_avl_datablock;
128
104
}
129
- _block_write (inode_arr[file_inode].pointer [0 ], buff, len, 0 );
105
+ block_write (inode_arr[file_inode].pointer [0 ], buff, len, 0 );
130
106
inode_arr[file_inode].filesize += len;
131
107
file_descriptor_map[fd].second += len;
132
108
*bytes_written += len;
@@ -145,7 +121,7 @@ int _write_into_file(int fd, char *buff, int len, int *bytes_written)
145
121
free_data_block_vector.pop_back ();
146
122
inode_arr[file_inode].pointer [filled_data_block] = data_block_to_write;
147
123
148
- _block_write (data_block_to_write, buff, len, cur_pos % BLOCK_SIZE);
124
+ block_write (data_block_to_write, buff, len, cur_pos % BLOCK_SIZE);
149
125
inode_arr[file_inode].filesize += len;
150
126
file_descriptor_map[fd].second += len; // updating the cur pos in the file
151
127
*bytes_written += len;
@@ -172,7 +148,7 @@ int _write_into_file(int fd, char *buff, int len, int *bytes_written)
172
148
char temp_buf[BLOCK_SIZE];
173
149
memcpy (temp_buf, block_pointers, BLOCK_SIZE);
174
150
175
- _block_write (data_block_single_indirect, temp_buf, BLOCK_SIZE, 0 );
151
+ block_write (data_block_single_indirect, temp_buf, BLOCK_SIZE, 0 );
176
152
}
177
153
178
154
int block = inode_arr[file_inode].pointer [10 ];
@@ -194,10 +170,10 @@ int _write_into_file(int fd, char *buff, int len, int *bytes_written)
194
170
block_pointers[filled_data_block - 10 ] = data_block_to_write;
195
171
char temp_buf[BLOCK_SIZE];
196
172
memcpy (temp_buf, block_pointers, BLOCK_SIZE);
197
- _block_write (block, temp_buf, BLOCK_SIZE, 0 );
173
+ block_write (block, temp_buf, BLOCK_SIZE, 0 );
198
174
199
175
// write data into DB
200
- _block_write (data_block_to_write, buff, len, 0 );
176
+ block_write (data_block_to_write, buff, len, 0 );
201
177
inode_arr[file_inode].filesize += len;
202
178
file_descriptor_map[fd].second += len; // updating the cur pos in the file
203
179
*bytes_written += len;
@@ -223,7 +199,7 @@ int _write_into_file(int fd, char *buff, int len, int *bytes_written)
223
199
char temp_buf[BLOCK_SIZE];
224
200
memcpy (temp_buf, block_pointers, BLOCK_SIZE);
225
201
226
- _block_write (data_block_double_indirect, temp_buf, BLOCK_SIZE, 0 );
202
+ block_write (data_block_double_indirect, temp_buf, BLOCK_SIZE, 0 );
227
203
}
228
204
if ((filled_data_block - 1034 ) % 1024 == 0 ) // i.e if filled_data_block is multiple of 1024 means need new DB to be assigned
229
205
{
@@ -248,10 +224,10 @@ int _write_into_file(int fd, char *buff, int len, int *bytes_written)
248
224
block_pointers[(filled_data_block - 1034 ) / 1024 ] = data_block_double_indirect2;
249
225
char temp_buf[BLOCK_SIZE];
250
226
memcpy (temp_buf, block_pointers2, BLOCK_SIZE);
251
- _block_write (data_block_double_indirect2, temp_buf, BLOCK_SIZE, 0 );
227
+ block_write (data_block_double_indirect2, temp_buf, BLOCK_SIZE, 0 );
252
228
253
229
memcpy (temp_buf, block_pointers, BLOCK_SIZE);
254
- _block_write (block, temp_buf, BLOCK_SIZE, 0 );
230
+ block_write (block, temp_buf, BLOCK_SIZE, 0 );
255
231
}
256
232
257
233
int block = inode_arr[file_inode].pointer [11 ];
@@ -275,12 +251,12 @@ int _write_into_file(int fd, char *buff, int len, int *bytes_written)
275
251
int data_block_to_write = free_data_block_vector.back (); // to store block_pointers[1024] into db_for_double_indirect
276
252
free_data_block_vector.pop_back ();
277
253
block_pointers2[(filled_data_block - 1034 ) % 1024 ] = data_block_to_write;
278
- _block_write (data_block_to_write, buff, len, 0 ); // writing data into db_to_write DB
254
+ block_write (data_block_to_write, buff, len, 0 ); // writing data into db_to_write DB
279
255
280
256
// now restore block_pointers2 back to the block2
281
257
char temp_buf[BLOCK_SIZE];
282
258
memcpy (temp_buf, block_pointers2, BLOCK_SIZE);
283
- _block_write (block2, temp_buf, BLOCK_SIZE, 0 );
259
+ block_write (block2, temp_buf, BLOCK_SIZE, 0 );
284
260
285
261
// updating the filesize
286
262
inode_arr[file_inode].filesize += len;
0 commit comments