-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVFS.cpp
More file actions
886 lines (767 loc) · 18.6 KB
/
Copy pathVFS.cpp
File metadata and controls
886 lines (767 loc) · 18.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <io.h>
#define MAXINODE 50
#define READ 1
#define WRITE 2
#define MAXFILESIZE 1024
#define REGULAR 1
#define SPECIAL 2
#define START 0
#define CURRENT 1
#define END 2
typedef struct superblock
{
int TotalInodes;
int FreeInode;
} SUPERBLOCK, *PSUPERBLOCK;
typedef struct inode
{
char FileName[50];
int INodeNumber;
int FileSize;
int FileActualSize;
int FileType;
char *Buffer;
int LinkCount;
int ReferenceCount;
int permission;
struct inode *next;
}INODE, *PINODE, **PPINODE;
typedef struct filetable
{
int readoffset;
int writeoffset;
int count;
int mode;
PINODE ptrinode;
} FILETABLE, *PFILETABLE;
typedef struct ufdt
{
PFILETABLE ptrfiletable;
}UFDT;
UFDT UFDTArr[50];
SUPERBLOCK SUPERBLOCKobj;
PINODE head = NULL;
void man (char *name)
{
if(name == NULL) return;
if (strcmp(name, "create") == 0)
{
printf("Description: Used to create new regular file\n");
printf("Usage: create File_name Permission\n");
}
else if (strcmp(name, "read") == 0)
{
printf("Description: Used to read data from regular file\n");
printf("Usage: read file_name No_Of_Bytes_To_Read \n");
}
else if (strcmp(name, "write") == 0)
{
printf("Description Used to write data into regular file\n");
printf("Usage: write File_name\n After this enter the data that we want to write\n");
}
else if (strcmp(name, "ls") == 0)
{
printf("Description: Used to list all information of files \n");
printf("Usage: ls\n");
}
else if (strcmp(name, "stat") == 0)
{
printf("Description: Used to display information of file \n");
printf("Usage: stat File_name\n");
}
else if (strcmp(name, "fstat") == 0)
{
printf("Description: Used to display information of file \n");
printf("Usage: stat File_Discriptor\n");
}
else if (strcmp(name, "truncate") == 0)
{
printf("Description: Used to remove the data from file \n");
printf("Usage: truncate File_name \n");
}
else if (strcmp(name, "open") == 0)
{
printf("Description: Used to open existing file \n");
printf("Usage: open File_name mode");
}
else if (strcmp(name, "close") == 0)
{
printf("Description: Used to close opend file\n");
printf("Usage: Close File_name\n");
}
else if (strcmp(name, "closeall") == 0)
{
printf("Description: Ised to close all opened file\n");
printf("Usage: closeall\n");
}
else if (strcmp(name, "lseek") == 0)
{
printf("Description: Used to change file offset\n");
printf("Usage: lseek File_name ChnageInOffset StartPoint \n");
}
else if (strcmp(name, "rm") == 0)
{
printf("Description: Used to delete the file \n");
printf("Usage: rm File_Name\n");
}
else
{
printf("ERROR: No mannual entry available \n");
}
}
void DisplayHelp()
{
printf("ls: To list out all files \n");
printf("clear: To clear console \n");
printf("open: To open the file \n");
printf("close : To close the file \n");
printf("closeall: To close all opend file \n");
printf("read: To read the contents from file \n");
printf("write: To write contents into the file \n");
printf("exit: To terminate the file system \n");
printf("stat: To display information of file using name\n");
printf("fsat: To display the infomation of file using file descriptor \n");
printf("truncate : To remove all data from file \n");
printf("rm: To delete the file \n");
}
int GetFDFromName(char *name)
{
int i = 0;
while (i < 50)
{
if (UFDTArr[i].ptrfiletable != NULL)
{
if (strcmp( (UFDTArr[i].ptrfiletable -> ptrinode -> FileName), name) == 0)
{
break;
}
}
i++;
}
if (i == 50)
{
return -1;
}
else
{
return i;
}
}
PINODE Get_Inode (char *name)
{
PINODE temp = head;
int i = 0;
if (name == NULL)
{
return NULL;
}
while (temp != NULL)
{
if (strcmp (name, temp -> FileName) == 0)
{
break;
}
temp = temp -> next;
}
return temp;
}
void CreateDILB()
{
int i = 1;
PINODE newn = NULL;
PINODE temp = head;
while (i <= MAXINODE)
{
newn = (PINODE)malloc(sizeof(INODE));
newn -> LinkCount = newn -> ReferenceCount = 0;
newn -> FileType = newn -> FileSize = 0;
newn -> Buffer = NULL;
newn -> next = NULL;
newn -> INodeNumber = i;
if (temp == NULL)
{
head = newn;
temp = head;
}
else
{
temp -> next = newn;
temp = temp -> next;
}
i++;
}
printf("DILB created Successfully \n");
}
void InitialiseSuperBlock()
{
int i = 0;
while (i < 50)
{
UFDTArr[i].ptrfiletable = NULL;
i++;
}
SUPERBLOCKobj.TotalInodes = MAXINODE;
SUPERBLOCKobj.FreeInode = MAXINODE;
}
int CreateFile (char *name, int permission)
{
int i = 0;
PINODE temp = head;
if ( (name == NULL) || (permission == 0) || (permission > 3))
{
return -1;
}
if (SUPERBLOCKobj.FreeInode == 0)
{
return -2;
}
if (Get_Inode(name) != NULL)
{
return -3;
}
(SUPERBLOCKobj.FreeInode)--;
while (temp != NULL)
{
if(temp -> FileType == 0)
break;
temp = temp -> next;
}
while (i < 50)
{
if (UFDTArr[i].ptrfiletable == NULL)
break;
i++;
}
UFDTArr[i].ptrfiletable = (PFILETABLE)malloc(sizeof(FILETABLE));
if (UFDTArr[i].ptrfiletable == NULL)
{
return -4;
}
UFDTArr[i].ptrfiletable -> count = 1;
UFDTArr[i].ptrfiletable -> mode = permission;
UFDTArr[i].ptrfiletable -> readoffset = 0;
UFDTArr[i].ptrfiletable -> writeoffset = 0;
UFDTArr[i].ptrfiletable -> ptrinode = temp;
strcpy(UFDTArr[i].ptrfiletable -> ptrinode-> FileName,name);
UFDTArr[i].ptrfiletable -> ptrinode -> FileType = REGULAR;
UFDTArr[i].ptrfiletable -> ptrinode -> ReferenceCount = 1;
UFDTArr[i].ptrfiletable -> ptrinode -> LinkCount = 1;
UFDTArr[i].ptrfiletable -> ptrinode -> FileSize = MAXFILESIZE;
UFDTArr[i].ptrfiletable -> ptrinode -> FileActualSize = 0;
UFDTArr[i].ptrfiletable -> ptrinode -> permission = permission;
UFDTArr[i].ptrfiletable -> ptrinode -> Buffer = (char *)malloc(sizeof(MAXFILESIZE));
memset(UFDTArr[i].ptrfiletable -> ptrinode ->Buffer, 0, 1024);
return i;
}
int rm_File(char *name)
{
int fd = 0;
fd = GetFDFromName(name);
if (fd == -1)
{
return -1;
}
(UFDTArr[fd].ptrfiletable -> ptrinode -> LinkCount)--;
if (UFDTArr[fd].ptrfiletable -> ptrinode -> LinkCount == 0)
{
UFDTArr[fd].ptrfiletable -> ptrinode -> FileType = 0;
free(UFDTArr[fd].ptrfiletable);
}
UFDTArr[fd].ptrfiletable -= NULL;
(SUPERBLOCKobj.FreeInode)++;
}
int ReadFile (int fd, char *arr, int isize)
{
int read_size = 0;
if (UFDTArr[fd].ptrfiletable == NULL)
{
return -1;
}
if (UFDTArr[fd].ptrfiletable -> mode != READ && UFDTArr[fd].ptrfiletable -> mode != READ+WRITE)
{
return -2;
}
if (UFDTArr[fd].ptrfiletable -> ptrinode -> permission != READ && UFDTArr[fd].ptrfiletable -> ptrinode -> permission != READ+WRITE)
{
return -2;
}
if (UFDTArr[fd].ptrfiletable -> readoffset == UFDTArr[fd].ptrfiletable -> ptrinode -> FileActualSize)
{
return -3;
}
if (UFDTArr[fd].ptrfiletable -> ptrinode -> FileType != REGULAR)
{
return -4;
}
read_size = (UFDTArr[fd].ptrfiletable -> ptrinode -> FileActualSize) - (UFDTArr[fd].ptrfiletable -> readoffset);
if (read_size < isize)
{
strncpy(arr, (UFDTArr[fd].ptrfiletable -> ptrinode -> Buffer) + (UFDTArr[fd].ptrfiletable -> readoffset), read_size);
UFDTArr[fd].ptrfiletable -> readoffset = UFDTArr[fd].ptrfiletable -> readoffset + read_size;
}
else
{
strncpy(arr, (UFDTArr[fd].ptrfiletable -> ptrinode -> Buffer) + (UFDTArr[fd].ptrfiletable -> readoffset), isize);
UFDTArr[fd].ptrfiletable -> readoffset = UFDTArr[fd].ptrfiletable -> readoffset + isize;
}
return isize;
}
int WriteFile(int fd, char *arr, int isize)
{
if (UFDTArr[fd].ptrfiletable -> mode != READ && UFDTArr[fd].ptrfiletable -> mode != READ+WRITE)
{
return -1;
}
if (UFDTArr[fd].ptrfiletable -> ptrinode -> permission != READ && UFDTArr[fd].ptrfiletable -> ptrinode -> permission != READ+WRITE)
{
return -1;
}
if ((UFDTArr[fd].ptrfiletable -> writeoffset) == MAXFILESIZE)
{
return -2;
}
if ( (UFDTArr[fd].ptrfiletable -> ptrinode -> FileType) != REGULAR)
{
return -3;
}
strncpy((UFDTArr[fd].ptrfiletable -> ptrinode -> Buffer) + (UFDTArr[fd].ptrfiletable -> writeoffset), arr, isize);
(UFDTArr[fd].ptrfiletable -> writeoffset) = (UFDTArr[fd].ptrfiletable -> writeoffset) + isize;
(UFDTArr[fd].ptrfiletable -> ptrinode -> FileActualSize) = (UFDTArr[fd].ptrfiletable -> ptrinode -> FileActualSize) + isize;
return isize;
}
int OpenFile (char *name, int mode)
{
int i = 0;
PINODE temp = NULL;
if (name == NULL || mode <= 0)
{
return -1;
}
temp = Get_Inode(name);
if (temp == NULL)
{
return -2;
}
if (temp -> permission < mode)
{
return -3;
}
while(i < 50)
{
if(UFDTArr[i].ptrfiletable == NULL)
break;
i++;
}
UFDTArr[i].ptrfiletable = (PFILETABLE)malloc(sizeof(FILETABLE));
if (UFDTArr[i].ptrfiletable == NULL)
{
return -1;
}
UFDTArr[i].ptrfiletable -> count = 1;
UFDTArr[i].ptrfiletable -> mode = mode;
if (mode == READ + WRITE)
{
UFDTArr[i].ptrfiletable -> readoffset = 0;
UFDTArr[i].ptrfiletable -> writeoffset = 0;
}
else if (mode == READ)
{
UFDTArr[i].ptrfiletable -> readoffset = 0;
}
else if ( mode == WRITE)
{
UFDTArr[i].ptrfiletable -> writeoffset = 0;
}
UFDTArr[i].ptrfiletable -> ptrinode = temp;
(UFDTArr[i].ptrfiletable -> ptrinode -> ReferenceCount)++;
return i;
}
void CloseFileByName(int fd)
{
UFDTArr[fd].ptrfiletable -> readoffset = 0;
UFDTArr[fd].ptrfiletable -> writeoffset = 0;
(UFDTArr[fd].ptrfiletable -> ptrinode -> ReferenceCount)--;
}
int CloseFileByName(char *name)
{
int i = 0;
i = GetFDFromName(name);
if (i == -1)
{
return -1;
}
UFDTArr[i].ptrfiletable -> readoffset = 0;
UFDTArr[i].ptrfiletable -> writeoffset = 0;
(UFDTArr[i].ptrfiletable -> ptrinode -> ReferenceCount)--;
return 0;
}
void CloseAllFile()
{
int i = 0;
while (i < 50)
{
if(UFDTArr[i].ptrfiletable != NULL)
{
UFDTArr[i].ptrfiletable -> readoffset = 0;
UFDTArr[i].ptrfiletable -> writeoffset = 0;
(UFDTArr[i].ptrfiletable -> ptrinode -> ReferenceCount)--;
break;
}
i++;
}
}
/*
int LseekFile(int fd, int size, int from)
{
if((fd < 0) || (from > 2)) return -1;
if (UFDTArr[fd].ptrfiletable == NULL) return -1;
if ((UFDTArr[fd].ptrfiletable -> mode == READ) || (UFDTArr[fd].ptrfiletable -> mode == READ +WRITE))
{
if (from == CURRENT)
{
if(((UFDTArr[fd].ptrfiletable -> readoffset) + size) > UFDTArr[fd].ptrfiletable -> ptrinode -> FileActualSize)
{
return -1;
}
if (((UFDTArr[fd].ptrfiletable -> readoffset) + size) < 0)
{
return -1;
}
(UFDTArr[fd].ptrfiletable -> readoffset) = (UFDTArr[fd].ptrfiletable -> readoffset) + size;
}
else if (from == START)
{
if (size > (UFDTArr[fd].ptrfiletable -> ptrinode -> FileActualSize))
{
return -1;
}
if (size < 0)
{
return -1;
}
(UFDTArr[fd].ptrfiletable-> readoffset) = size;
}
else if (from == END)
{
if ((UFDTArr[fd].ptrfiletable -> ptrinode -> FileActualSize) + size > MAXFILESIZE)
{
return -1;
}
(UFDTArr[fd].ptrfiletable -> readoffset) = (UFDTArr[fd].ptrfiletable -> ptrinode -> FileActualSize) + size;
}
}
else if (UFDTArr[fd].ptrfiletable -> mode == WRITE)
{
if (from == CURRENT)
{
if (((UFDTArr[fd].ptrfiletable -> writeoffset) + size) > MAXFILESIZE)
{
return -1;
}
if (((UFDTArr[fd].ptrfiletable -> writeoffset) + size) > )
}
}
}
*/
void ls_file()
{
int i = 0;
PINODE temp = head;
if (SUPERBLOCKobj.FreeInode == MAXFILESIZE)
{
printf("Error: There are no files\n"); return;
}
printf("\nFile Name\tInode number\tFile size\tLink count\n");
printf("------------------------------------------------------\n");
while(temp != NULL)
{
if (temp -> FileType != 0)
{
printf("%s\t\t%d\t\t%d\n\n", temp -> FileName, temp -> INodeNumber, temp -> FileActualSize, temp -> LinkCount);
}
temp = temp -> next;
}
printf("------------------------------------------------------\n");
}
int fstat_file (int fd)
{
PINODE temp = head;
int i = 0;
if (fd < 0)
{
return -1;
}
if (UFDTArr[fd].ptrfiletable == NULL)
{
return -2;
}
temp = UFDTArr[fd].ptrfiletable -> ptrinode;
printf("\n-----------Statistical information about file---------------\n");
printf("File name : %s\n", temp -> FileName);
printf("Inode Number : %d\n", temp -> INodeNumber);
printf("File Size : %d\n", temp -> FileSize);
printf("Actual File Size : %d\n", temp -> FileActualSize);
printf("Link count : %d\n", temp -> LinkCount);
printf("Reference count : %d\n", temp -> ReferenceCount);
if (temp -> permission == 1)
printf("File Permission : Read Only\n");
else if (temp -> permission == 2)
printf("File Permission : Write\n");
else if (temp -> permission == 3)
printf("File Permission : Read & Write\n");
printf("\n-----------------------------------------------------\n");
return 0;
}
int stat_file (char *name)
{
PINODE temp = head;
int i = 0;
if (name == NULL)
{
return -1;
}
while (temp != NULL)
{
if (strcmp(name, temp -> FileName) == 0)
break;
temp = temp -> next;
}
if (temp == NULL) return -2;
printf("\n-----------Statistical information about file---------------\n");
printf("File name : %s\n", temp -> FileName);
printf("Inode Number : %d\n", temp -> INodeNumber);
printf("File Size : %d\n", temp -> FileSize);
printf("Actual File Size : %d\n", temp -> FileActualSize);
printf("Link count : %d\n", temp -> LinkCount);
printf("Reference count : %d\n", temp -> ReferenceCount);
if (temp -> permission == 1)
printf("File Permission : Read Only\n");
else if (temp -> permission == 2)
printf("File Permission : Write\n");
else if (temp -> permission == 3)
printf("File Permission : Read & Write\n");
printf("\n-----------------------------------------------------\n");
return 0;
}
int truncate_File(char *name)
{
int fd = GetFDFromName(name);
if (fd == -1)
{
return -1;
}
memset(UFDTArr[fd].ptrfiletable -> ptrinode -> Buffer, 0, 1024);
UFDTArr[fd].ptrfiletable -> readoffset = 0;
UFDTArr[fd].ptrfiletable -> writeoffset = 0;
UFDTArr[fd].ptrfiletable -> ptrinode -> FileActualSize = 0;
}
int main()
{
char *ptr = NULL;
int ret = 0, fd = 0, count = 0;
char command[4][80], str[80], arr[1024];
InitialiseSuperBlock();
CreateDILB();
while(1)
{
fflush(stdin);
strcpy(str, "");
printf("Aditya's VFS : > ");
fgets(str, 80, stdin);
count = sscanf(str, "%s %s %s %s", command[0], command[1], command[2], command[3]);
if (count == 1)
{
if (strcmp(command[0], "ls") == 0)
{
ls_file();
}
else if (strcmp(command[0], "closeall") == 0)
{
CloseAllFile();
printf("All files closed Successfully\n"); continue;
}
else if (strcmp(command[0], "clear") == 0)
{
system("cls");
continue;
}
else if (strcmp(command[0], "help") == 0)
{
DisplayHelp(); continue;
}
else if (strcmp(command[0], "exit") == 0)
{
printf("Terminating the Aditya's Virtual File System\n");
break;
}
else
{
printf("\nERROR: command not found !!! \n"); continue;
}
}
else if (count == 2)
{
if(strcmp(command[0], "stat") == 0)
{
ret = stat_file(command[1]);
if (ret == -1)
printf("ERROR: Incorrect parameter\n");
if (ret == -2)
printf("ERROR: There is no usch file\n");
continue;
}
else if (strcmp(command[0], "fstat") == 0)
{
ret = fstat_file(atoi(command[1]));
if (ret == -1)
printf("ERROR: Incorrect parameter\n");
if (ret == -2)
printf("ERROR: There is no usch file\n");
continue;
}
else if (strcmp(command[0], "close") == 0)
{
ret = CloseFileByName(command[1]);
if (ret == -1)
printf("ERROR: There is no such file\n");
continue;
}
else if (strcmp(command[0], "rm") == 0)
{
ret = rm_File(command[1]);
if (ret == -1)
printf("ERROR: There is no such file\n");
continue;
}
else if (strcmp(command[0], "man") == 0)
{
man(command[1]);
}
else if (strcmp(command[0], "write") == 0)
{
fd = GetFDFromName(command[1]);
if (fd == -1)
{
printf("ERROR : Incorrect parameter\n"); continue;
}
printf("Enter the data : \n");
scanf("%[^\n]", arr);
ret = strlen(arr);
if (ret == 0)
{
printf("ERROR : Incorrect parameter\n"); continue;
}
ret = WriteFile(fd, arr, ret);
if (ret == -1)
printf("ERROR : Permission denied\n");
if (ret == -2)
printf("ERROR : There is no suffienct memory to write\n");
if (ret == -3)
printf("ERROR : It is not regular file\n");
}
else if (strcmp(command[0], "truncate") == 0)
{
ret = truncate_File(command[1]);
if (ret == -1)
printf("ERROR : Incorrect parameter\n");
}
else
{
printf("\nERROR : command not found !!!\n"); continue;
}
}
else if (count == 3)
{
if (strcmp(command[0], "create") == 0)
{
ret = CreateFile(command[1], atoi(command[2]));
if (ret >= 0)
printf("File is created Successfully with file descriptor : %d\n", ret);
if (ret == -1)
printf("ERROR : Incorrect parameter\n");
if (ret == -2)
printf("ERROR : There is no inodes\n");
if (ret == -3)
printf("ERROR : File already exits\n");
if (ret == -4)
printf("ERROR : Memory allocation failure\n");
continue;
}
else if (strcmp(command[0], "open") == 0)
{
ret = OpenFile(command[1], atoi(command[2]));
if (ret >= 0)
printf("File is opened Successfully with file descriptor : %d\n", ret);
if (ret == -1)
printf("ERROR : Incorrect parameter\n");
if (ret == -2)
printf("ERROR : File not present\n");
if (ret == -3)
printf("ERROR : Permission denied\n");
continue;
}
else if (strcmp(command[0], "read") == 0)
{
fd = GetFDFromName(command[1]);
if(fd == -1)
{
printf("ERROR : Incorrect parameter\n"); continue;
}
ptr = (char *)malloc(sizeof(atoi(command[2]))+1);
if (ptr == NULL)
{
printf("ERROR : Memory allocation failure \n");
}
ret = ReadFile(fd, ptr, atoi(command[2]));
if (ret == -1)
printf("ERROR : File not existing\n");
if (ret == -2)
printf("ERROR : Permission denied\n");
if (ret == -3)
printf("ERROR : Reached at end of file\n");
if (ret == -4)
printf("ERROR : It is not regular file\n");
if (ret == 0)
printf("ERROR : File empty\n");
if (ret > 0)
{
_write(2, ptr, ret);
}
continue;
}
else
{
printf("\nERROR : Command not found !!! \n"); continue;
}
}
else if (count == 4)
{
if (strcmp(command[0], "lseek") == 0)
{
fd = GetFDFromName(command[1]);
if (fd == -1)
{
printf("ERROR : Incorrect parameter\n"); continue;
}
//ret = LseekFile(fd, atoi(command[2], atoi(command[3])));
if(ret == -1)
{
printf("ERROR : Unable to perfrom lseek\n");
}
}
else
{
printf("\nERROR : Command not found !!!\n"); continue;
}
}
else
{
printf("\nERROR : Command not found !!!\n"); continue;
}
}
return 0;
}