-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCVFS.cpp
More file actions
1038 lines (841 loc) · 28.7 KB
/
CVFS.cpp
File metadata and controls
1038 lines (841 loc) · 28.7 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
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
///////////////////////////////////////////////////////////////////////
//
// Header files inclusion
//
///////////////////////////////////////////////////////////////////////
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<string.h>
#include<stdbool.h>
#include<iostream>
using namespace std;
///////////////////////////////////////////////////////////////////////
//
// User defined Macros
//
///////////////////////////////////////////////////////////////////////
// Max file size
# define MAXFILESIZE 100
// Maximum number of files that we can open
# define MAXOPENEDFILES 20
// Maximum number of files that we can create
# define MAXINODE 5
# define READ 1
# define WRITE 2
# define EXECUTE 4
# define REGULARFILE 1
# define SPECIALFILE 2
# define START 0
# define CURRENT 1
# define END 2
# define EXECUTE_SUCCESS 0
///////////////////////////////////////////////////////////////////////
//
// User defined Macros for error handling
//
///////////////////////////////////////////////////////////////////////
# define ERR_INVALID_PARAMETER -1
# define ERR_NO_INODES -2
# define ERR_FILE_ALREADY_EXIST -3
# define ERR_FILE_NOT_EXIST -4
# define ERR_PERMISSION_DENIED -5
# define ERR_INSUFFICIENT_SPACE -6
# define ERR_INSUFFICIENT_DATA -7
///////////////////////////////////////////////////////////////////////
//
// Structure Name : BootBlock
// Description : Holds information to boot the operating system
//
///////////////////////////////////////////////////////////////////////
struct BootBlock
{
char Information[100];
};
///////////////////////////////////////////////////////////////////////
//
// Structure Name : SuperBlock
// Description : Holds information about the file system
//
///////////////////////////////////////////////////////////////////////
struct SuperBlock
{
int TotalInodes;
int FreeInodes;
};
///////////////////////////////////////////////////////////////////////
//
// Structure Name : Inode
// Description : Holds information about the file
//
///////////////////////////////////////////////////////////////////////
typedef struct Inode
{
char FileName[50];
int InodeNumber;
int FileSize;
int ActualFileSize;
int FileType;
int ReferenceCount;
int LinkCount;
int Permission;
char *Buffer;
struct Inode *next;
}INODE, *PINODE, **PPINODE;
///////////////////////////////////////////////////////////////////////
//
// Structure Name : FileTable
// Description : Holds information about the opened file
//
///////////////////////////////////////////////////////////////////////
typedef struct FileTable
{
int ReadOffset;
int WriteOffset;
int Count;
int Mode;
PINODE ptrinode;
}FILETABLE, *PFILETABLE;
///////////////////////////////////////////////////////////////////////
//
// Structure Name : UAREA
// Description : Holds information about the process
//
///////////////////////////////////////////////////////////////////////
struct UAREA
{
char ProcessName[50];
PFILETABLE UFDT[MAXOPENEDFILES];
};
///////////////////////////////////////////////////////////////////////
//
// Global variables or objects used in the project
//
///////////////////////////////////////////////////////////////////////
BootBlock bootobj;
SuperBlock superobj;
PINODE head = NULL;
UAREA uareaobj;
///////////////////////////////////////////////////////////////////////
//
// Function Name : InitialiseUAREA
// Description : It is used to intialise the contents UAREA
// Author : Rohan Murlidhar Pawar
// Date : 10/08/2025
//
///////////////////////////////////////////////////////////////////////
void InitialiseUAREA()
{
strcpy(uareaobj.ProcessName,"Myexe");
int i = 0;
while(i < MAXOPENEDFILES)
{
uareaobj.UFDT[i] = NULL;
i++;
}
cout<<"CVFS : UAREA initialised succesfully\n";
}
///////////////////////////////////////////////////////////////////////
//
// Function Name : InitialiseSuperblock
// Description : It is used to intialise the contents of super block
// Author : Rohan Murlidhar Pawar
// Date : 10/08/2025
//
///////////////////////////////////////////////////////////////////////
void InitialiseSuperblock()
{
superobj.TotalInodes = MAXINODE;
superobj.FreeInodes = MAXINODE;
cout<<"CVFS : Superblock initialised succesfully\n";
}
///////////////////////////////////////////////////////////////////////
//
// Function Name : CreateDILB
// Description : It is used to create Linked List of Inodes
// Author : Rohan Murlidhar Pawar
// Date : 10/08/2025
//
///////////////////////////////////////////////////////////////////////
void CreateDILB()
{
int i = 1;
PINODE newn = NULL;
PINODE temp = head;
while(i <= MAXINODE)
{
newn = new INODE;
newn->InodeNumber = i;
newn->FileSize = 0;
newn->ActualFileSize = 0;
newn->LinkCount = 0;
newn->Permission = 0;
newn->FileType = 0;
newn->ReferenceCount = 0;
newn->Buffer = NULL;
newn->next = NULL;
if(temp == NULL)
{
head = newn;
temp = head;
}
else
{
temp->next = newn;
temp = temp->next;
}
i++;
}
cout<<"CVFS : DILB created succesfully\n";
}
///////////////////////////////////////////////////////////////////////
//
// Function Name : StartAuxilaryDataInitialisation
// Description : It is used to intialise the Auxilary data
// Author : Rohan Murlidhar Pawar
// Date : 10/08/2025
//
///////////////////////////////////////////////////////////////////////
void StartAuxilaryDataInitialisation()
{
strcpy(bootobj.Information,"Boot process of Opertaing System done");
cout<<bootobj.Information<<"\n";
InitialiseSuperblock();
CreateDILB();
InitialiseUAREA();
cout<<"CVFS : Auxilary data initalised succesfully\n";
}
///////////////////////////////////////////////////////////////////////
//
// Function Name : DisplayHelp
// Description : It is used to Display the information about commands
// Author : Rohan Murlidhar Pawar
// Date : 11/08/2025
//
///////////////////////////////////////////////////////////////////////
void DisplayHelp()
{
printf("---------------------------------------------------------\n");
printf("----------- Command Manual of CVFS ----------------------\n");
printf("---------------------------------------------------------\n");
printf("man : It is used to display the specific manual page of command\n");
printf("exit : It is used to terminate the shell of CVFS\n");
printf("clear : It is used to clear the console of CVFS\n");
printf("creat : It is used to create new regular file\n");
printf("unlink : It is used to delete existing file\n");
printf("stat : It is used to display statistical information about file\n");
printf("ls : It is used to list out all files from the directory\n");
printf("write : It is used to write the data into the file\n");
printf("read : It is used to read the data from the file\n");
// Add more options here
printf("---------------------------------------------------------\n");
}
///////////////////////////////////////////////////////////////////////
//
// Function Name : ManPage
// Description : It is used to Display the manual page of the command
// Input : It accepts the command name
// Output : Displays the manual details of the command
// Author : Rohan Murlidhar Pawar
// Date : 11/08/2025
//
///////////////////////////////////////////////////////////////////////
void ManPage(
char *name // Name of command
)
{
if(strcmp(name,"creat") == 0)
{
printf("Description : This command is used to create new regular file on our file system\n");
printf("Usage : creat File_name Permissions\n");
printf("File_name : The name of file that you want to create\n");
printf("Permissions : \n1 : Read \n2 : Write \n3 : Read + Write\n");
}
else if(strcmp(name,"exit") == 0)
{
printf("Description : This command is used to terminate the CVFS\n");
printf("Usage : exit\n");
}
else if(strcmp(name,"unlink") == 0)
{
printf("Description : This command is used to delete regular file from our file system\n");
printf("Usage : unlink File_name\n");
printf("File_name : The name of file that you want to delete\n");
}
else if(strcmp(name,"stat") == 0)
{
printf("Description : This command is used to display statistical information about the file\n");
printf("Usage : stat File_name\n");
printf("File_name : The name of file whose information you want to display\n");
}
else if(strcmp(name,"ls") == 0)
{
printf("Description : This command is used to list all file names form directory\n");
printf("Usage : ls\n");
}
else if(strcmp(name,"write") == 0)
{
printf("Description : This command is used to write the data into the file\n");
printf("Usage : write File_Descriptor\n");
}
else if(strcmp(name,"read") == 0)
{
printf("Description : This command is used to read the data from the file\n");
printf("Usage : read File_Descriptor Size\n");
printf("File_Descriptor : Its a value returned by create system call\n");
printf("Size : Number of bytes that you eant to read\n");
}
// Add more options here
else
{
printf("No manual entry for %s\n",name);
}
}
///////////////////////////////////////////////////////////////////////
//
// Function Name : IsFileExists
// Description : It is used to check whether the given file name is exist or not
// Input : It accepts the file name
// Output : It returns boolean value (True : if present False : if not present)
// Author : Rohan Murlidhar Pawar
// Date : 11/08/2025
//
///////////////////////////////////////////////////////////////////////
bool IsFileExists(
char *name // Name of file that we want to check
)
{
PINODE temp = head;
bool bFlag = false;
while(temp != NULL)
{
if((strcmp(name, temp->FileName) == 0) && (temp->FileType == REGULARFILE))
{
bFlag = true;
break;
}
temp = temp->next;
}
return bFlag;
}
///////////////////////////////////////////////////////////////////////
//
// Function Name : CreateFile
// Description : It is used to create a new regular file
// Input : It accepts the file name and permission
// Output : It returns the file descriptor
// Author : Rohan Murlidhar Pawar
// Date : 11/08/2025
//
///////////////////////////////////////////////////////////////////////
int CreateFile(
char *name, // Name of file
int permission // Permission to create file
)
{
PINODE temp = head;
int i = 0;
printf("Current Inodes remaining : %d\n",superobj.FreeInodes);
// Filters
// If file name is missing
if(name == NULL)
{
return ERR_INVALID_PARAMETER;
}
// If entered permission is invalid
if(permission < 1 || permission > 3)
{
return ERR_INVALID_PARAMETER;
}
// Check whether empty inode is there or not
if(superobj.FreeInodes == 0)
{
return ERR_NO_INODES;
}
// Check whether file is already exist or not
if(IsFileExists(name) == true)
{
return ERR_FILE_ALREADY_EXIST;
}
// Loop to search free Inode
while(temp != NULL)
{
if(temp->FileType == 0)
{
break;
}
temp = temp -> next;
}
// Inode not found
if(temp == NULL)
{
printf("Inode not found\n");
return ERR_NO_INODES;
}
// Search first non NULL value from UFDT
for(i = 0; i < MAXINODE; i++)
{
if(uareaobj.UFDT[i] == NULL)
{
break;
}
}
if(i == MAXINODE)
{
printf("Unable to create file as MAX OPENED FILE LIMIT REACHED\n");
return -1;
}
// Allocate ememory for file table
uareaobj.UFDT[i] = (PFILETABLE)malloc(sizeof(FILETABLE));
// Initailise elements of File table
uareaobj.UFDT[i]->ReadOffset = 0;
uareaobj.UFDT[i]->WriteOffset = 0;
uareaobj.UFDT[i]->Count = 1;
uareaobj.UFDT[i]->Mode = permission;
// Connect file table with IIT
uareaobj.UFDT[i]->ptrinode = temp;
strcpy(uareaobj.UFDT[i]->ptrinode->FileName, name);
uareaobj.UFDT[i]->ptrinode->FileSize = MAXFILESIZE;
uareaobj.UFDT[i]->ptrinode->ActualFileSize = 0;
uareaobj.UFDT[i]->ptrinode->FileType = REGULARFILE;
uareaobj.UFDT[i]->ptrinode->ReferenceCount = 1;
uareaobj.UFDT[i]->ptrinode->LinkCount = 1;
uareaobj.UFDT[i]->ptrinode->Permission = permission;
// Allocate memory for Buffer
uareaobj.UFDT[i]->ptrinode->Buffer = (char * )malloc(MAXFILESIZE);
// Decrement the number of free inodes by 1
superobj.FreeInodes--;
return i;
}
///////////////////////////////////////////////////////////////////////
//
// Function Name : UnlinkFile
// Description : It is used to delete a regular file
// Input : It accepts the file name
// Output : It returns nothing
// Author : Rohan Murlidhar Pawar
// Date : 15/08/2025
//
///////////////////////////////////////////////////////////////////////
// CVFS > unlink Demo.txt
int UnlinkFile(
char *name // Name of file
)
{
int i = 0;
if(name == NULL)
{
return ERR_INVALID_PARAMETER;
}
if(IsFileExists(name) == false)
{
return ERR_FILE_NOT_EXIST;
}
for(i = 0; i < MAXINODE; i++)
{
if(uareaobj.UFDT[i] != NULL)
{
if(strcmp(uareaobj.UFDT[i]->ptrinode->FileName, name) == 0)
{
// Deallocate the memory of buffer
free(uareaobj.UFDT[i]->ptrinode->Buffer);
// Reset all values of Inode
uareaobj.UFDT[i]->ptrinode->FileSize = 0;
uareaobj.UFDT[i]->ptrinode->ActualFileSize = 0;
uareaobj.UFDT[i]->ptrinode->LinkCount = 0;
uareaobj.UFDT[i]->ptrinode->Permission = 0;
uareaobj.UFDT[i]->ptrinode->FileType = 0;
uareaobj.UFDT[i]->ptrinode->ReferenceCount = 0;
// Deallocate memory of file table
free(uareaobj.UFDT[i]);
// Set NULL to the UFDT member
uareaobj.UFDT[i] = NULL;
// Increament the value of free inodes count
superobj.FreeInodes++;
break;
} // End of if
} // End of if
} // End of for
return EXECUTE_SUCCESS;
}
///////////////////////////////////////////////////////////////////////
//
// Function Name : ls_file
// Description : It is used to diplsy the information about all files in the directory
// Input : Nothing
// Output : Nothing
// Author : Rohan Murlidhar Pawar
// Date : 15/08/2025
//
///////////////////////////////////////////////////////////////////////
// CVFS > ls
void ls_file()
{
PINODE temp = head;
while(temp != NULL)
{
if(temp->FileType != 0)
{
printf("%s\n",temp->FileName);
}
temp = temp->next;
}
}
///////////////////////////////////////////////////////////////////////
//
// Function Name : stat_file
// Description : It is used to diplsy the information about the given files
// Input : file name
// Output : Nothing
// Author : Rohan Murlidhar Pawar
// Date : 15/08/2025
//
///////////////////////////////////////////////////////////////////////
// CVFS > stat Demo.txt
int stat_file(
char *name // Name of file
)
{
PINODE temp = head;
if(name == NULL)
{
return ERR_INVALID_PARAMETER;
}
if(IsFileExists(name) == false)
{
return ERR_FILE_NOT_EXIST;
}
while(temp != NULL)
{
if((strcmp(name,temp->FileName) == 0) && (temp->FileType != 0))
{
printf("------------ Statistical Information of file -----------\n");
printf("File name : %s\n",temp->FileName);
printf("File size on Disk : %d\n",temp->FileSize);
printf("Actual File size : %d\n",temp->ActualFileSize);
printf("Link count : %d\n",temp->LinkCount);
printf("File permission : ");
if(temp->Permission == READ)
{
printf("Read\n");
}
else if(temp->Permission == WRITE)
{
printf("Write\n");
}
else if(temp->Permission == READ + WRITE)
{
printf("Read + Write\n");
}
printf("File type : ");
if(temp->FileType == REGULARFILE)
{
printf("Regular file\n");
}
else if(temp->FileType == SPECIALFILE)
{
printf("Special file\n");
}
printf("--------------------------------------------------------\n");
}
temp = temp -> next;
}
return EXECUTE_SUCCESS;
}
///////////////////////////////////////////////////////////////////////
//
// Function Name : write_file
// Description : It is used to write the contents into the file
// Input : File descriptor
// Address of buffer which contains data
// Size of data that we want to write
// Output : Number of bytes succesfully written into the file
// Author : Rohan Murlidhar Pawar
// Date : 15/08/2025
//
///////////////////////////////////////////////////////////////////////
// CVFS > write 3
int write_file(
int fd, // File descriptor of file
char *data, // Data that we want to write
int size // Size of data that we want to write
)
{
unsigned long int offset = 0;
printf("File descriptor is : %d\n",fd);
printf("Data that we want to write : %s\n",data);
printf("Number of bytes that we want to write : %d\n",size);
/// Invalid value of fd
if(fd < 0 || fd > MAXOPENEDFILES)
{
return ERR_INVALID_PARAMETER;
}
// File is not opened or created with the given fd
if(uareaobj.UFDT[fd] == NULL)
{
return ERR_FILE_NOT_EXIST;
}
// If there is no permission to wite the data into the file
if(uareaobj.UFDT[fd]->ptrinode->Permission < WRITE)
{
return ERR_PERMISSION_DENIED;
}
// Unable to write as there is no sufficient space
if((MAXFILESIZE - uareaobj.UFDT[fd]->WriteOffset) < size)
{
return ERR_INSUFFICIENT_SPACE;
}
// Write the actual data
strncpy(uareaobj.UFDT[fd]->ptrinode->Buffer + uareaobj.UFDT[fd]->WriteOffset,data,size);
// Update the write offset
uareaobj.UFDT[fd]->WriteOffset = uareaobj.UFDT[fd]->WriteOffset + size;
// Update the actual size of file after writting the new data
uareaobj.UFDT[fd]->ptrinode->ActualFileSize = uareaobj.UFDT[fd]->ptrinode->ActualFileSize + size;
return size;
}
///////////////////////////////////////////////////////////////////////
//
// Function Name : read_file
// Description : It is used to read the contents from the file
// Input : File descriptor
// Address of empty buffer
// Size of data that we want to read
// Output : Number of bytes succesfully read from the file
// Author : Rohan Murlidhar Pawar
// Date : 15/08/2025
//
///////////////////////////////////////////////////////////////////////
// CVFS > read 3 10
int read_file(
int fd, // File descriptor
char *data, // Address of empty buffer
int size // Number of bytes that we want to read
)
{
/// Invalid value of fd
if(fd < 0 || fd > MAXOPENEDFILES)
{
return ERR_INVALID_PARAMETER;
}
if(data == NULL || size <= 0)
{
return ERR_INVALID_PARAMETER;
}
// File is not opened or created with the given fd
if(uareaobj.UFDT[fd] == NULL)
{
return ERR_FILE_NOT_EXIST;
}
// If there is no permission to wite the data into the file
if(uareaobj.UFDT[fd]->ptrinode->Permission < READ)
{
return ERR_PERMISSION_DENIED;
}
// Unable to read as there is no sufficient data
if((MAXFILESIZE - uareaobj.UFDT[fd]->ReadOffset) < size)
{
return ERR_INSUFFICIENT_DATA;
}
strncpy(data, uareaobj.UFDT[fd]->ptrinode->Buffer + uareaobj.UFDT[fd]->ReadOffset, size);
uareaobj.UFDT[fd]->ReadOffset = uareaobj.UFDT[fd]->ReadOffset + size;
return size;
}
///////////////////////////////////////////////////////////////////////
//
// Entry point function of project (main)
//
///////////////////////////////////////////////////////////////////////
int main()
{
char str[80] = {'\0'};
int iCount = 0;
int iRet = 0;
char Command[5][80];
char InputBuffer[MAXFILESIZE] = {'\0'};
char * EmptyBuffer = NULL;
StartAuxilaryDataInitialisation();
cout<<"---------------------------------------------------------\n";
cout<<"----------------CVFS Started Succesfully ----------------\n";
cout<<"---------------------------------------------------------\n";
while(1)
{
fflush(stdin);
strcpy(str,"");
printf("\n CVFS > ");
fgets(str,sizeof(str),stdin);
iCount = sscanf(str,"%s %s %s %s",Command[0],Command[1], Command[2], Command[3]);
fflush(stdin);
if(iCount == 1)
{
// CVFS > exit
if(strcmp(Command[0], "exit") == 0)
{
printf("Thank you for using CVFS\n");
printf("Deallocating all resources...\n");
break;
}
// CVFS > help
else if(strcmp(Command[0], "help") == 0)
{
DisplayHelp();
}
// CVFS > clear
else if(strcmp(Command[0], "clear") == 0)
{
system("clear");
}
// CVFS > ls
else if(strcmp(Command[0], "ls") == 0)
{
ls_file();
}
else
{
printf("Coomand not found...\n");
printf("Please refer Help option or use man command\n");
}
} // End of if iCount == 1
else if(iCount == 2)
{
// CVFS > man creat
if(strcmp(Command[0], "man") == 0)
{
ManPage(Command[1]);
}
// CVFS > unlink Demo.txt
else if(strcmp(Command[0], "unlink") == 0)
{
iRet = UnlinkFile(Command[1]);
if(iRet == EXECUTE_SUCCESS)
{
printf("Unlink Opertaion is succesfully performed\n");
}
else if(iRet == ERR_FILE_NOT_EXIST)
{
printf("Error : Unable to do unlink activity as file is not present\n");
}
else if(iRet == ERR_INVALID_PARAMETER)
{
printf("Error : Invalid parameters for the function\n");
printf("Please check Man page for more details\n");
}
}
// CVFS > stat Demo.txt
else if(strcmp(Command[0], "stat") == 0)
{
iRet = stat_file(Command[1]);
if(iRet == ERR_FILE_NOT_EXIST)
{
printf("Error : Unable to display statistics as file is not present\n");
}
else if(iRet == ERR_INVALID_PARAMETER)
{
printf("Error : Invalid parameters for the function\n");
printf("Please check Man page for more details\n");
}
}
// CVFS > write 3
else if(strcmp(Command[0], "write") == 0)
{
printf("Please enter the data that you want to write into the file : \n");
fgets(InputBuffer,MAXFILESIZE,stdin);
iRet = write_file(atoi(Command[1]), InputBuffer, strlen(InputBuffer)-1);
if(iRet == ERR_INSUFFICIENT_SPACE)
{
printf("Error : Insufficient space in tha data block for the file\n");
}
else if(iRet == ERR_PERMISSION_DENIED)
{
printf("Error : Unable to write as there is no write permission\n");
}
else if(iRet == ERR_INVALID_PARAMETER)
{
printf("Error : Invalid parameters for the function\n");
printf("Please check Man page for more details\n");
}
else if(iRet == ERR_FILE_NOT_EXIST)
{
printf("Error : FD is invalid\n");
}
else
{
printf("%d bytes gets succesfully written into the file\n",iRet);
printf("Data from file is : %s\n",uareaobj.UFDT[0]->ptrinode->Buffer);
}
}
else
{
printf("Coomand not found...\n");
printf("Please refer Help option or use man command\n");
}
} // End of if iCount == 2
else if(iCount == 3)
{
// CVFS > creat Ganesh.txt 3
if(strcmp(Command[0], "creat") == 0)
{
iRet = CreateFile(Command[1], atoi(Command[2]));
if(iRet == ERR_INVALID_PARAMETER)
{
printf("Error : Invalid parameters for the function\n");
printf("Please check Man page for more details\n");
}
else if(iRet == ERR_NO_INODES)
{
printf("Error : Unable to create file as there is no Inodes\n");
}
else if(iRet == ERR_FILE_ALREADY_EXIST)
{
printf("Error : Unable to create file as file is already existing\n");
}
else
{
printf("File is succesfully created with FD : %d\n",iRet);
}
}
// CVFS > read 3 10
else if(strcmp(Command[0], "read") == 0)
{
EmptyBuffer = (char *)malloc(sizeof(atoi(Command[2])));
iRet = read_file(atoi(Command[1]), EmptyBuffer, atoi(Command[2]));
if(iRet == ERR_INSUFFICIENT_DATA)
{
printf("Error : Insufficient data in tha data block of the file\n");
}
else if(iRet == ERR_PERMISSION_DENIED)
{
printf("Error : Unable to redad as there is no read permission\n");
}
else if(iRet == ERR_INVALID_PARAMETER)
{
printf("Error : Invalid parameters for the function\n");
printf("Please check Man page for more details\n");