@@ -107,21 +107,21 @@ int create_file(char *name)
107
107
// check if file already exist in disk
108
108
if (dir_map.find (filename) != dir_map.end ())
109
109
{
110
- cout << " Create File Error : File already present !!!" << endl;
110
+ cout << string (RED) << " Create File Error : File already present !!!" << string (DEFAULT) << endl;
111
111
return -1 ;
112
112
}
113
113
114
114
// check if inode are available
115
115
if (free_inode_vector.size () == 0 )
116
116
{
117
- cout << " Create File Error : No more Inodes available" << endl;
117
+ cout << string (RED) << " Create File Error : No more Inodes available" << string (DEFAULT) << endl;
118
118
return -1 ;
119
119
}
120
120
121
121
// check if datablock are available
122
122
if (free_data_block_vector.size () == 0 )
123
123
{
124
- cout << " Create File Error : No more DataBlock available" << endl;
124
+ cout << string (RED) << " Create File Error : No more DataBlock available" << string (DEFAULT) << endl;
125
125
return -1 ;
126
126
}
127
127
@@ -141,7 +141,7 @@ int create_file(char *name)
141
141
file_inode_mapping_arr[next_avl_inode].inode_num = next_avl_inode;
142
142
strcpy (file_inode_mapping_arr[next_avl_inode].file_name , name);
143
143
144
- cout << " File Successfully Created :) " << endl;
144
+ cout << string (GREEN) << " File Successfully Created :) " << string (DEFAULT) << endl;
145
145
return 1 ;
146
146
}
147
147
@@ -152,7 +152,7 @@ int delete_file(char *name)
152
152
// check if file exist or not
153
153
if (dir_map.find (filename) == dir_map.end ())
154
154
{
155
- cout << " Delete File Error : File doesn't exist !!!" << endl;
155
+ cout << string (RED) << " Delete File Error : File doesn't exist !!!" << string (DEFAULT) << endl;
156
156
return -1 ;
157
157
}
158
158
@@ -163,7 +163,7 @@ int delete_file(char *name)
163
163
{
164
164
if (file_descriptor_map.find (i) != file_descriptor_map.end () && file_descriptor_map[i].first == cur_inode)
165
165
{
166
- cout << " Delete File Error : File is opened, Can not delete an opened file !!!" << endl;
166
+ cout << string (RED) << " Delete File Error : File is opened, Can not delete an opened file !!!" << string (DEFAULT) << endl;
167
167
return -1 ;
168
168
}
169
169
}
@@ -178,8 +178,7 @@ int delete_file(char *name)
178
178
inode_to_file_map.erase (dir_map[filename]);
179
179
dir_map.erase (filename);
180
180
181
-
182
- cout << " File Deleted successfully :) " << endl;
181
+ cout << string (GREEN) << " File Deleted successfully :) " << string (DEFAULT) << endl;
183
182
184
183
return 0 ;
185
184
}
@@ -189,24 +188,24 @@ int open_file(char *name)
189
188
string filename = string (name);
190
189
if (dir_map.find (filename) == dir_map.end ())
191
190
{
192
- cout << " Open File Error : File not found !!!" << endl;
191
+ cout << string (RED) << " Open File Error : File not found !!!" << string (DEFAULT) << endl;
193
192
return -1 ;
194
193
}
195
194
196
195
if (free_filedescriptor_vector.size () == 0 )
197
196
{
198
- cout << " Open File Error : File descriptor not available !!!" << endl;
197
+ cout << string (RED) << " Open File Error : File descriptor not available !!!" << string (DEFAULT) << endl;
199
198
return -1 ;
200
199
}
201
200
/* asking for mode of file */
202
201
int file_mode = -1 ;
203
202
do
204
203
{
205
- cout << " 0: read mode\n 1: write mode\n 2: append mode\n " ;
204
+ cout << " 0 : read mode\n 1 : write mode\n 2 : append mode\n " ;
206
205
cin >> file_mode;
207
206
if (file_mode < 0 || file_mode > 2 )
208
207
{
209
- cout << " Please make valid choice" << endl;
208
+ cout << string (RED) << " Please make valid choice" << string (DEFAULT) << endl;
210
209
}
211
210
} while (file_mode < 0 || file_mode > 2 );
212
211
@@ -221,7 +220,7 @@ int open_file(char *name)
221
220
file_descriptor_map[i].first == cur_inode &&
222
221
(file_descriptor_mode_map[i] == 1 || file_descriptor_mode_map[i] == 2 ))
223
222
{
224
- cout << " File is already in use with file descriptor : " << i << endl;
223
+ cout << string (RED) << " File is already in use with file descriptor : " << i << string (DEFAULT) << endl;
225
224
return -1 ;
226
225
}
227
226
}
@@ -235,7 +234,7 @@ int open_file(char *name)
235
234
file_descriptor_mode_map[fd] = file_mode;
236
235
openfile_count++;
237
236
238
- cout << " File " << filename << " opened with file descriptor : " << fd << endl;
237
+ cout << string (GREEN) << " File " << filename << " opened with file descriptor : " << fd << string (DEFAULT) << endl;
239
238
240
239
return fd;
241
240
}
@@ -244,35 +243,34 @@ int close_file(int fd)
244
243
{
245
244
if (file_descriptor_map.find (fd) == file_descriptor_map.end ())
246
245
{
247
- cout << " close File Error : file is not opened yet !!!" << endl;
246
+ cout << string (RED) << " close File Error : file is not opened yet !!!" << string (DEFAULT) << endl;
248
247
return -1 ;
249
248
}
250
249
251
250
file_descriptor_map.erase (fd);
252
251
file_descriptor_mode_map.erase (fd);
253
252
openfile_count--;
254
253
free_filedescriptor_vector.push_back (fd);
255
- cout << " File closed successfully :) " << endl;
254
+ cout << string (GREEN) << " File closed successfully :) " << string (DEFAULT) << endl;
256
255
return 1 ;
257
256
}
258
257
259
258
int read_file (int fd)
260
259
{
261
-
262
-
260
+
263
261
if (file_descriptor_map.find (fd) == file_descriptor_map.end ())
264
262
{
265
- cout << " Read File Error : file is not opened yet !!!" << endl;
263
+ cout << string (RED) << " Read File Error : file is not opened yet !!!" << string (DEFAULT) << endl;
266
264
return -1 ;
267
265
}
268
266
269
267
if (file_descriptor_mode_map[fd] != 0 )
270
268
{
271
- cout << " Read File Error : file with descriptor " << fd << " is not opened in read mode !!!" << endl;
269
+ cout << string (RED) << " Read File Error : file with descriptor " << fd << " is not opened in read mode !!!" << string (DEFAULT) << endl;
272
270
return -1 ;
273
271
}
274
272
275
- int bytes_read= 0 ;
273
+ int bytes_read = 0 ;
276
274
bool partial_read = false ;
277
275
int fs = file_descriptor_map[fd].second ;
278
276
@@ -281,7 +279,7 @@ int read_file(int fd)
281
279
int filesize = in.filesize ;
282
280
char *buf;
283
281
buf = new char [filesize];
284
- char *initial_buf_pos= buf;
282
+ char *initial_buf_pos = buf;
285
283
286
284
int noOfBlocks = ceil (((float )inode_arr[cur_inode].filesize ) / BLOCK_SIZE);
287
285
int tot_block = noOfBlocks; // tot_block = numner of blocks to read and noOfBlocks = blocks left to read
@@ -307,9 +305,10 @@ int read_file(int fd)
307
305
partial_read = true ;
308
306
bytes_read += BLOCK_SIZE - fs % BLOCK_SIZE;
309
307
}
310
- else {
311
-
312
- memcpy (buf, read_buf, BLOCK_SIZE );
308
+ else
309
+ {
310
+
311
+ memcpy (buf, read_buf, BLOCK_SIZE);
313
312
buf = buf + BLOCK_SIZE;
314
313
bytes_read += BLOCK_SIZE;
315
314
}
@@ -335,15 +334,16 @@ int read_file(int fd)
335
334
{
336
335
if (partial_read == false )
337
336
{
338
-
337
+
339
338
memcpy (buf, read_buf + (fs % BLOCK_SIZE), (BLOCK_SIZE - fs % BLOCK_SIZE));
340
339
buf = buf + (BLOCK_SIZE - fs % BLOCK_SIZE);
341
340
partial_read = true ;
342
341
bytes_read += BLOCK_SIZE - fs % BLOCK_SIZE;
343
342
}
344
- else {
345
-
346
- memcpy (buf, read_buf, BLOCK_SIZE );
343
+ else
344
+ {
345
+
346
+ memcpy (buf, read_buf, BLOCK_SIZE);
347
347
buf = buf + BLOCK_SIZE;
348
348
bytes_read += BLOCK_SIZE;
349
349
}
@@ -374,19 +374,19 @@ int read_file(int fd)
374
374
{
375
375
if (partial_read == false )
376
376
{
377
-
377
+
378
378
memcpy (buf, read_buf + (fs % BLOCK_SIZE), (BLOCK_SIZE - fs % BLOCK_SIZE));
379
379
buf = buf + (BLOCK_SIZE - fs % BLOCK_SIZE);
380
380
partial_read = true ;
381
381
bytes_read += BLOCK_SIZE - fs % BLOCK_SIZE;
382
382
}
383
- else {
384
-
385
- memcpy (buf, read_buf, BLOCK_SIZE );
386
- buf = buf + BLOCK_SIZE;
383
+ else
384
+ {
385
+
386
+ memcpy (buf, read_buf, BLOCK_SIZE);
387
+ buf = buf + BLOCK_SIZE;
387
388
bytes_read += BLOCK_SIZE;
388
389
}
389
-
390
390
}
391
391
noOfBlocks--;
392
392
}
@@ -402,12 +402,12 @@ int read_file(int fd)
402
402
memcpy (buf, read_buf + (fs % BLOCK_SIZE), (inode_arr[cur_inode].filesize ) % BLOCK_SIZE - fs % BLOCK_SIZE);
403
403
bytes_read += (inode_arr[cur_inode].filesize ) % BLOCK_SIZE - fs % BLOCK_SIZE;
404
404
}
405
-
406
- initial_buf_pos[bytes_read]= ' \0 ' ;
405
+
406
+ initial_buf_pos[bytes_read] = ' \0 ' ;
407
407
cout.flush ();
408
408
cout << initial_buf_pos << endl;
409
409
cout.flush ();
410
- cout << endl<< " File read successfully " << endl;
410
+ cout << string (GREEN) << " File read successfully " << string (DEFAULT) << endl;
411
411
return 1 ;
412
412
}
413
413
0 commit comments