├── Version 1
├── DataBase
│ ├── ContiguousAllocation.vfs
│ ├── IndexedAllocation.vfs
│ └── LinkedAllocation.vfs
├── out
│ └── production
│ │ └── VFS
│ │ ├── main.class
│ │ ├── AllocationMethods
│ │ ├── Node.class
│ │ ├── indexedNode.class
│ │ ├── FileAllocation.class
│ │ ├── LinkedAllocation.class
│ │ ├── IndexedAllocation.class
│ │ └── ContiguousAllocation.class
│ │ ├── FileSystemStructure
│ │ ├── Directory.class
│ │ └── VirtualFile.class
│ │ └── SystemControl
│ │ ├── DiskDataControl.class
│ │ └── CommandsConverter.class
├── .idea
│ ├── .gitignore
│ ├── modules.xml
│ └── misc.xml
├── VFS.iml
└── src
│ ├── AllocationMethods
│ ├── FileAllocation.java
│ ├── ContiguousAllocation.java
│ ├── IndexedAllocation.java
│ └── LinkedAllocation.java
│ ├── SystemControl
│ ├── CommandsConverter.java
│ └── DiskDataControl.java
│ ├── FileSystemStructure
│ ├── VirtualFile.java
│ └── Directory.java
│ └── main.java
├── Version 2 (With Protection)
├── DataBase
│ ├── capabilities.txt
│ ├── user.txt
│ ├── LinkedAllocation.vfs
│ ├── ContiguousAllocation.vfs
│ └── IndexedAllocation.vfs
├── out
│ └── production
│ │ └── VFS_V2
│ │ ├── main.class
│ │ ├── SystemControl
│ │ ├── User.class
│ │ ├── Protection.class
│ │ ├── CommandsConverter.class
│ │ └── DiskDataControl.class
│ │ ├── AllocationMethods
│ │ ├── Node.class
│ │ ├── indexedNode.class
│ │ ├── FileAllocation.class
│ │ ├── IndexedAllocation.class
│ │ ├── LinkedAllocation.class
│ │ └── ContiguousAllocation.class
│ │ └── FileSystemStructure
│ │ ├── Directory.class
│ │ └── VirtualFile.class
├── ContiguousAllocation.vfs
├── .idea
│ ├── .gitignore
│ ├── misc.xml
│ └── modules.xml
├── VFS_V2.iml
├── IndexedAllocation.vfs
├── src
│ ├── AllocationMethods
│ │ ├── FileAllocation.java
│ │ ├── ContiguousAllocation.java
│ │ ├── IndexedAllocation.java
│ │ └── LinkedAllocation.java
│ ├── SystemControl
│ │ ├── User.java
│ │ ├── CommandsConverter.java
│ │ ├── DiskDataControl.java
│ │ └── Protection.java
│ ├── FileSystemStructure
│ │ ├── VirtualFile.java
│ │ └── Directory.java
│ └── main.java
└── LinkedAllocation.vfs
├── LICENSE.md
└── README.md
/Version 1/DataBase/ContiguousAllocation.vfs:
--------------------------------------------------------------------------------
1 | root/Khaled
2 | root/hegy.pdf 0 26
3 | root/Khaled/Hegy
4 |
--------------------------------------------------------------------------------
/Version 1/DataBase/IndexedAllocation.vfs:
--------------------------------------------------------------------------------
1 | root/khaled
2 | root/khaled/h.pdf 7
3 | 66 27 72 26 95 43 11 32 59 56 90 5 46 3 15 53 45 51 84 29
4 |
--------------------------------------------------------------------------------
/Version 1/out/production/VFS/main.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KhaledAshrafH/Virtual-File-System/HEAD/Version 1/out/production/VFS/main.class
--------------------------------------------------------------------------------
/Version 2 (With Protection)/DataBase/capabilities.txt:
--------------------------------------------------------------------------------
1 | root/khaled,khaled,10,ahmed,01,sss,11
2 | root/khaled/ahmed,khaled,11,ahmed,10
3 | root/khaledddd,omar,01,hegy,10,ali,10
4 |
--------------------------------------------------------------------------------
/Version 2 (With Protection)/DataBase/user.txt:
--------------------------------------------------------------------------------
1 | admin , admin
2 | khaled , 123
3 | ahmed , 123
4 | omar , 123
5 | hegy , 123
6 | ali , 987654
7 | mohamed , 555
8 | sss , 555
9 |
--------------------------------------------------------------------------------
/Version 1/out/production/VFS/AllocationMethods/Node.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KhaledAshrafH/Virtual-File-System/HEAD/Version 1/out/production/VFS/AllocationMethods/Node.class
--------------------------------------------------------------------------------
/Version 2 (With Protection)/out/production/VFS_V2/main.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KhaledAshrafH/Virtual-File-System/HEAD/Version 2 (With Protection)/out/production/VFS_V2/main.class
--------------------------------------------------------------------------------
/Version 1/out/production/VFS/AllocationMethods/indexedNode.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KhaledAshrafH/Virtual-File-System/HEAD/Version 1/out/production/VFS/AllocationMethods/indexedNode.class
--------------------------------------------------------------------------------
/Version 1/out/production/VFS/FileSystemStructure/Directory.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KhaledAshrafH/Virtual-File-System/HEAD/Version 1/out/production/VFS/FileSystemStructure/Directory.class
--------------------------------------------------------------------------------
/Version 1/out/production/VFS/SystemControl/DiskDataControl.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KhaledAshrafH/Virtual-File-System/HEAD/Version 1/out/production/VFS/SystemControl/DiskDataControl.class
--------------------------------------------------------------------------------
/Version 1/out/production/VFS/AllocationMethods/FileAllocation.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KhaledAshrafH/Virtual-File-System/HEAD/Version 1/out/production/VFS/AllocationMethods/FileAllocation.class
--------------------------------------------------------------------------------
/Version 1/out/production/VFS/FileSystemStructure/VirtualFile.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KhaledAshrafH/Virtual-File-System/HEAD/Version 1/out/production/VFS/FileSystemStructure/VirtualFile.class
--------------------------------------------------------------------------------
/Version 1/out/production/VFS/SystemControl/CommandsConverter.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KhaledAshrafH/Virtual-File-System/HEAD/Version 1/out/production/VFS/SystemControl/CommandsConverter.class
--------------------------------------------------------------------------------
/Version 1/out/production/VFS/AllocationMethods/LinkedAllocation.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KhaledAshrafH/Virtual-File-System/HEAD/Version 1/out/production/VFS/AllocationMethods/LinkedAllocation.class
--------------------------------------------------------------------------------
/Version 1/out/production/VFS/AllocationMethods/IndexedAllocation.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KhaledAshrafH/Virtual-File-System/HEAD/Version 1/out/production/VFS/AllocationMethods/IndexedAllocation.class
--------------------------------------------------------------------------------
/Version 1/out/production/VFS/AllocationMethods/ContiguousAllocation.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KhaledAshrafH/Virtual-File-System/HEAD/Version 1/out/production/VFS/AllocationMethods/ContiguousAllocation.class
--------------------------------------------------------------------------------
/Version 2 (With Protection)/out/production/VFS_V2/SystemControl/User.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KhaledAshrafH/Virtual-File-System/HEAD/Version 2 (With Protection)/out/production/VFS_V2/SystemControl/User.class
--------------------------------------------------------------------------------
/Version 2 (With Protection)/out/production/VFS_V2/AllocationMethods/Node.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KhaledAshrafH/Virtual-File-System/HEAD/Version 2 (With Protection)/out/production/VFS_V2/AllocationMethods/Node.class
--------------------------------------------------------------------------------
/Version 2 (With Protection)/out/production/VFS_V2/SystemControl/Protection.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KhaledAshrafH/Virtual-File-System/HEAD/Version 2 (With Protection)/out/production/VFS_V2/SystemControl/Protection.class
--------------------------------------------------------------------------------
/Version 2 (With Protection)/ContiguousAllocation.vfs:
--------------------------------------------------------------------------------
1 | root/hegy.pdf 0 26
2 | root/khaledddd
3 | root/khaled
4 | root/khaled/ahmed
5 | root/khaled/kk.txt 26 20
6 | root/khaled/ahmed/hegy.pdf 46 10
7 | root/khaled/ahmed/ddd.pdf 56 40
8 |
--------------------------------------------------------------------------------
/Version 2 (With Protection)/out/production/VFS_V2/AllocationMethods/indexedNode.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KhaledAshrafH/Virtual-File-System/HEAD/Version 2 (With Protection)/out/production/VFS_V2/AllocationMethods/indexedNode.class
--------------------------------------------------------------------------------
/Version 2 (With Protection)/out/production/VFS_V2/FileSystemStructure/Directory.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KhaledAshrafH/Virtual-File-System/HEAD/Version 2 (With Protection)/out/production/VFS_V2/FileSystemStructure/Directory.class
--------------------------------------------------------------------------------
/Version 2 (With Protection)/out/production/VFS_V2/FileSystemStructure/VirtualFile.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KhaledAshrafH/Virtual-File-System/HEAD/Version 2 (With Protection)/out/production/VFS_V2/FileSystemStructure/VirtualFile.class
--------------------------------------------------------------------------------
/Version 2 (With Protection)/out/production/VFS_V2/SystemControl/CommandsConverter.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KhaledAshrafH/Virtual-File-System/HEAD/Version 2 (With Protection)/out/production/VFS_V2/SystemControl/CommandsConverter.class
--------------------------------------------------------------------------------
/Version 2 (With Protection)/out/production/VFS_V2/SystemControl/DiskDataControl.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KhaledAshrafH/Virtual-File-System/HEAD/Version 2 (With Protection)/out/production/VFS_V2/SystemControl/DiskDataControl.class
--------------------------------------------------------------------------------
/Version 2 (With Protection)/out/production/VFS_V2/AllocationMethods/FileAllocation.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KhaledAshrafH/Virtual-File-System/HEAD/Version 2 (With Protection)/out/production/VFS_V2/AllocationMethods/FileAllocation.class
--------------------------------------------------------------------------------
/Version 2 (With Protection)/out/production/VFS_V2/AllocationMethods/IndexedAllocation.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KhaledAshrafH/Virtual-File-System/HEAD/Version 2 (With Protection)/out/production/VFS_V2/AllocationMethods/IndexedAllocation.class
--------------------------------------------------------------------------------
/Version 2 (With Protection)/out/production/VFS_V2/AllocationMethods/LinkedAllocation.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KhaledAshrafH/Virtual-File-System/HEAD/Version 2 (With Protection)/out/production/VFS_V2/AllocationMethods/LinkedAllocation.class
--------------------------------------------------------------------------------
/Version 2 (With Protection)/out/production/VFS_V2/AllocationMethods/ContiguousAllocation.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KhaledAshrafH/Virtual-File-System/HEAD/Version 2 (With Protection)/out/production/VFS_V2/AllocationMethods/ContiguousAllocation.class
--------------------------------------------------------------------------------
/Version 1/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 | # Datasource local storage ignored files
5 | /../../../../../:\Users\Eng Khaled\VFS\.idea/dataSources/
6 | /dataSources.local.xml
7 | # Editor-based HTTP Client requests
8 | /httpRequests/
9 |
--------------------------------------------------------------------------------
/Version 1/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Version 2 (With Protection)/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 | # Datasource local storage ignored files
5 | /../../../../../:\Users\Eng Khaled\VFS_V2\.idea/dataSources/
6 | /dataSources.local.xml
7 | # Editor-based HTTP Client requests
8 | /httpRequests/
9 |
--------------------------------------------------------------------------------
/Version 2 (With Protection)/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Version 1/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Version 2 (With Protection)/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Version 2 (With Protection)/DataBase/LinkedAllocation.vfs:
--------------------------------------------------------------------------------
1 | root/bb
2 | root/bb/gg.pdf 98 51
3 | 98 52
4 | 52 75
5 | 75 7
6 | 7 12
7 | 12 4
8 | 4 69
9 | 69 56
10 | 56 62
11 | 62 51
12 | 51 nil
13 | root/k.gg 95 63
14 | 95 58
15 | 58 32
16 | 32 55
17 | 55 2
18 | 2 31
19 | 31 48
20 | 48 80
21 | 80 96
22 | 96 63
23 | 63 nil
24 |
--------------------------------------------------------------------------------
/Version 2 (With Protection)/DataBase/ContiguousAllocation.vfs:
--------------------------------------------------------------------------------
1 | root/hegy.pdf 0 26
2 | root/khaledddd
3 | root/khaled
4 | root/khaled/ahmed
5 | root/khaled/ahmed/hegy.pdf 26 10
6 | root/khaled/ahmed/ddd.pdf 36 40
7 | root/khaled/omar
8 | root/khaled/ahmed/ali
9 | root/khaled/ahmed/ali/mohamed
10 | root/khaled/ali
11 | root/khaled/aa
12 |
--------------------------------------------------------------------------------
/Version 1/DataBase/LinkedAllocation.vfs:
--------------------------------------------------------------------------------
1 | root/khaled.pdf 95 86
2 | 95 97
3 | 97 62
4 | 62 5
5 | 5 47
6 | 47 52
7 | 52 92
8 | 92 67
9 | 67 37
10 | 37 66
11 | 66 41
12 | 41 96
13 | 96 61
14 | 61 26
15 | 26 54
16 | 54 27
17 | 27 36
18 | 36 73
19 | 73 93
20 | 93 13
21 | 13 0
22 | 0 3
23 | 3 30
24 | 30 19
25 | 19 25
26 | 25 48
27 | 48 80
28 | 80 72
29 | 72 86
30 | root/hegy.txttt 75 43
31 | 75 33
32 | 33 81
33 | 81 23
34 | 23 49
35 | 49 79
36 | 79 43
37 | 43 nil
38 |
--------------------------------------------------------------------------------
/Version 1/VFS.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/Version 2 (With Protection)/VFS_V2.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/Version 2 (With Protection)/IndexedAllocation.vfs:
--------------------------------------------------------------------------------
1 | root/khaled
2 | root/khaled/ahmed
3 | root/khaled/hh.pdf 74
4 | 89 55 42 67 95 60 1 14 50 16 36 12 19 64 48 51 70 35 56 8
5 | root/khaled/ahmed/hegy.txt 68
6 | 17 83 71 3 62 85 23 47 87 61 96 82 94 24 52 39 88 33 21 78 2 57 40 91 26 25 45 0 22 69 77 37 27 98 34 28 6 30 58 54
7 | root/hhh.pf 18
8 | 79 29 32 9 63 43 97 13 11 20
9 | root/khaled/ahmed/dd.pdf 31
10 | 49 15 90 99 38 92 4 44 81 59 72 80 66 46 93
11 | root/khaled/ahmed/gg
12 | root/khaled/ahmed/gg/rr.pdf 53
13 | 84 86 41 65 73 75 10 76 5
14 |
--------------------------------------------------------------------------------
/Version 2 (With Protection)/DataBase/IndexedAllocation.vfs:
--------------------------------------------------------------------------------
1 | root/khaled
2 | root/khaled/ahmed
3 | root/khaled/hh.pdf 74
4 | 89 55 42 67 95 60 1 14 50 16 36 12 19 64 48 51 70 35 56 8
5 | root/khaled/ahmed/hegy.txt 68
6 | 17 83 71 3 62 85 23 47 87 61 96 82 94 24 52 39 88 33 21 78 2 57 40 91 26 25 45 0 22 69 77 37 27 98 34 28 6 30 58 54
7 | root/hhh.pf 18
8 | 79 29 32 9 63 43 97 13 11 20
9 | root/khaled/ahmed/dd.pdf 31
10 | 49 15 90 99 38 92 4 44 81 59 72 80 66 46 93
11 | root/khaled/ahmed/gg
12 | root/khaled/ahmed/gg/rr.pdf 53
13 | 84 86 41 65 73 75 10 76 5
14 | root/gg
15 | root/khaled/hegy
16 |
--------------------------------------------------------------------------------
/Version 1/src/AllocationMethods/FileAllocation.java:
--------------------------------------------------------------------------------
1 | package AllocationMethods;
2 |
3 | import FileSystemStructure.VirtualFile;
4 |
5 | import java.io.File;
6 | import java.util.ArrayList;
7 |
8 | public interface FileAllocation {
9 | boolean allocateFile(VirtualFile file, File f,String path) throws Exception;
10 | boolean allocateFile(VirtualFile file, File f, String path, ArrayList spaces) throws Exception;
11 | void deAllocateFile(VirtualFile file,File f,String path) throws Exception;
12 | int getNumOfFreeBlocks();
13 | int getNumOfAllocatedBlocks();
14 | String getFreeAndAllocatedBlocks();
15 | }
16 |
--------------------------------------------------------------------------------
/Version 2 (With Protection)/src/AllocationMethods/FileAllocation.java:
--------------------------------------------------------------------------------
1 | package AllocationMethods;
2 |
3 | import FileSystemStructure.VirtualFile;
4 |
5 | import java.io.File;
6 | import java.util.ArrayList;
7 |
8 | public interface FileAllocation {
9 | boolean allocateFile(VirtualFile file, File f,String path) throws Exception;
10 | boolean allocateFile(VirtualFile file, File f, String path, ArrayList spaces) throws Exception;
11 | void deAllocateFile(VirtualFile file,File f,String path) throws Exception;
12 | int getNumOfFreeBlocks();
13 | int getNumOfAllocatedBlocks();
14 | String getFreeAndAllocatedBlocks();
15 | }
16 |
--------------------------------------------------------------------------------
/Version 2 (With Protection)/src/SystemControl/User.java:
--------------------------------------------------------------------------------
1 | package SystemControl;
2 |
3 | import java.util.HashMap;
4 |
5 | public class User {
6 | String username,password;
7 | HashMap capabilities; //path,access
8 |
9 | public User(String username, String password) {
10 | this.username = username;
11 | this.password = password;
12 | capabilities=new HashMap<>();
13 | }
14 |
15 | public User() {
16 | capabilities=new HashMap<>();
17 | }
18 |
19 | public String getUsername() {
20 | return username;
21 | }
22 |
23 | public void setUsername(String username) {
24 | this.username = username;
25 | }
26 |
27 | public String getPassword() {
28 | return password;
29 | }
30 |
31 | public void setPassword(String password) {
32 | this.password = password;
33 | }
34 |
35 | public HashMap getCapabilities() {
36 | return capabilities;
37 | }
38 |
39 | public void setCapabilities(HashMap capabilities) {
40 | this.capabilities = capabilities;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2022 Khaled Ashraf Hanafy
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/Version 2 (With Protection)/LinkedAllocation.vfs:
--------------------------------------------------------------------------------
1 | root/khaled
2 | root/khaled/ahmed.txt 68 54
3 | 68 65
4 | 65 8
5 | 8 78
6 | 78 76
7 | 76 74
8 | 74 5
9 | 5 84
10 | 84 67
11 | 67 3
12 | 3 66
13 | 66 37
14 | 37 6
15 | 6 79
16 | 79 1
17 | 1 15
18 | 15 41
19 | 41 35
20 | 35 17
21 | 17 54
22 | root/khaled/gfg.fff 70 10
23 | 70 57
24 | 57 99
25 | 99 40
26 | 40 94
27 | 94 26
28 | 26 39
29 | 39 60
30 | 60 82
31 | 82 71
32 | 71 42
33 | 42 86
34 | 86 27
35 | 27 0
36 | 0 61
37 | 61 64
38 | 64 81
39 | 81 30
40 | 30 20
41 | 20 72
42 | 72 59
43 | 59 34
44 | 34 28
45 | 28 21
46 | 21 24
47 | 24 53
48 | 53 89
49 | 89 88
50 | 88 92
51 | 92 93
52 | 93 33
53 | 33 49
54 | 49 38
55 | 38 22
56 | 22 29
57 | 29 45
58 | 45 47
59 | 47 19
60 | 19 73
61 | 73 10
62 | 10 nil
63 | root/khaled/aheew
64 | root/khaled/aheew/ll.pdf 18 36
65 | 18 50
66 | 50 85
67 | 85 25
68 | 25 43
69 | 43 44
70 | 44 97
71 | 97 91
72 | 91 13
73 | 13 36
74 | 36 nil
75 | root/bb
76 | root/bb/gg.pdf 98 51
77 | 98 52
78 | 52 75
79 | 75 7
80 | 7 12
81 | 12 4
82 | 4 69
83 | 69 56
84 | 56 62
85 | 62 51
86 | 51 nil
87 | root/k.gg 95 63
88 | 95 58
89 | 58 32
90 | 32 55
91 | 55 2
92 | 2 31
93 | 31 48
94 | 48 80
95 | 80 96
96 | 96 63
97 | 63 nil
98 | root/khaled/aheew/vv
99 | root/khaled/aheew/vv/ll
100 | root/khaled/aheew/vv/ll/oo
101 | root/khaled/aheew/vv/ip.txt 83 9
102 | 83 23
103 | 23 46
104 | 46 9
105 | 9 nil
106 | root/khaled/aheew/vv/ll/hh.pdf 16 90
107 | 16 77
108 | 77 90
109 | 90 nil
110 | root/khaled/aheew/vv/ll/oo/pe.txt 14 11
111 | 14 11
112 | 11 nil
113 |
--------------------------------------------------------------------------------
/Version 1/src/SystemControl/CommandsConverter.java:
--------------------------------------------------------------------------------
1 | package SystemControl;
2 |
3 | import java.util.ArrayList;
4 |
5 | public class CommandsConverter {
6 | String command;
7 | ArrayList commandParts;
8 | int numOfParts;
9 | public CommandsConverter(String command){
10 | this.command=command;
11 | commandParts=new ArrayList<>();
12 |
13 | numOfParts=getNumOfSpaces(command)+1;
14 | String temp="";
15 | char c;
16 | for(int i=0;i=2) return commandParts.get(1);
34 | return "null";
35 | }
36 | public String getName(){
37 | if(numOfParts>=2){
38 | String str=commandParts.get(1);
39 | String result="";
40 | int lastSlash=str.lastIndexOf("/");
41 | for(int i=lastSlash+1;i=3){
50 | return (Integer.parseInt(String.valueOf(Integer.parseInt(commandParts.get(2)))));
51 | }
52 | return -1;
53 | }
54 |
55 | public int getNumOfParts() {
56 | return numOfParts;
57 | }
58 |
59 | private int getNumOfSpaces(String str){
60 | int cnt=0;
61 | for(int i=0;i commandParts;
8 | int numOfParts;
9 | public CommandsConverter(String command){
10 | this.command=command;
11 | commandParts=new ArrayList<>();
12 |
13 | numOfParts=getNumOfSpaces(command)+1;
14 | String temp="";
15 | char c;
16 | for(int i=0;i=2) return commandParts.get(1);
34 | return "null";
35 | }
36 | public String getPathDir(){
37 | String str="";int index=0;
38 | if(commandParts.get(1).contains("/")) index=commandParts.get(1).lastIndexOf("/");
39 | else return commandParts.get(1);
40 | for(int i=0;i=2){
47 | String str=commandParts.get(1);
48 | String result="";
49 | int lastSlash=str.lastIndexOf("/");
50 | for(int i=lastSlash+1;i=3){
59 | return (Integer.parseInt(String.valueOf(Integer.parseInt(commandParts.get(2)))));
60 | }
61 | return -1;
62 | }
63 |
64 | public int getNumOfParts() {
65 | return numOfParts;
66 | }
67 |
68 | private int getNumOfSpaces(String str){
69 | int cnt=0;
70 | for(int i=0;i allocatedBlocks;
10 | private boolean deleted=false;
11 | private int fileSize;
12 | private int startBlock;
13 | private int endBlock;
14 |
15 | public int getEndBlock() {
16 | return endBlock;
17 | }
18 |
19 | public void setEndBlock(int endBlock) {
20 | this.endBlock = endBlock;
21 | }
22 |
23 | public VirtualFile(String name, String path, int size) {
24 | this.fileName = name;
25 | this.filePath =path;
26 | this.fileSize = size;
27 | allocatedBlocks=new ArrayList<>();
28 | }
29 |
30 | public VirtualFile(String fileName) {
31 | this.fileName = fileName;
32 | this.filePath = filePath;
33 | this.type = type;
34 | this.allocatedBlocks = allocatedBlocks;
35 | this.deleted = deleted;
36 | this.fileSize = fileSize;
37 | }
38 |
39 | public void setFileName(String fileName) {
40 | this.fileName = fileName;
41 | }
42 |
43 | public void setFilePath(String filePath) {
44 | this.filePath = filePath;
45 | }
46 |
47 | public void setType(String type) {
48 | this.type = type;
49 | }
50 |
51 | public void setAllocatedBlocks(ArrayList allocatedBlocks) {
52 | this.allocatedBlocks = allocatedBlocks;
53 | }
54 |
55 | public void setDeleted(boolean deleted) {
56 | this.deleted = deleted;
57 | }
58 |
59 | public void setFileSize(int fileSize) {
60 | this.fileSize = fileSize;
61 | }
62 |
63 | public String getFileName() {
64 | return fileName;
65 | }
66 |
67 | public String getFilePath() {
68 | return filePath;
69 | }
70 |
71 | public String getType() {
72 | return type;
73 | }
74 |
75 | public ArrayList getAllocatedBlocks() {
76 | return allocatedBlocks;
77 | }
78 |
79 | public boolean isDeleted() {
80 | return deleted;
81 | }
82 |
83 | public int getFileSize() {
84 | return fileSize;
85 | }
86 |
87 | public int getStartBlock() {
88 | return startBlock;
89 | }
90 |
91 | public void setStartBlock(int startBlock) {
92 | this.startBlock = startBlock;
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/Version 2 (With Protection)/src/FileSystemStructure/VirtualFile.java:
--------------------------------------------------------------------------------
1 | package FileSystemStructure;
2 |
3 | import java.util.ArrayList;
4 |
5 | public class VirtualFile {
6 | private String fileName;
7 | private String filePath;
8 | private String type;
9 | private ArrayList allocatedBlocks;
10 | private boolean deleted=false;
11 | private int fileSize;
12 | private int startBlock;
13 | private int endBlock;
14 |
15 | public int getEndBlock() {
16 | return endBlock;
17 | }
18 |
19 | public void setEndBlock(int endBlock) {
20 | this.endBlock = endBlock;
21 | }
22 |
23 | public VirtualFile(String name, String path, int size) {
24 | this.fileName = name;
25 | this.filePath =path;
26 | this.fileSize = size;
27 | allocatedBlocks=new ArrayList<>();
28 | }
29 |
30 | public VirtualFile(String fileName) {
31 | this.fileName = fileName;
32 | this.filePath = filePath;
33 | this.type = type;
34 | this.allocatedBlocks = allocatedBlocks;
35 | this.deleted = deleted;
36 | this.fileSize = fileSize;
37 | }
38 |
39 | public void setFileName(String fileName) {
40 | this.fileName = fileName;
41 | }
42 |
43 | public void setFilePath(String filePath) {
44 | this.filePath = filePath;
45 | }
46 |
47 | public void setType(String type) {
48 | this.type = type;
49 | }
50 |
51 | public void setAllocatedBlocks(ArrayList allocatedBlocks) {
52 | this.allocatedBlocks = allocatedBlocks;
53 | }
54 |
55 | public void setDeleted(boolean deleted) {
56 | this.deleted = deleted;
57 | }
58 |
59 | public void setFileSize(int fileSize) {
60 | this.fileSize = fileSize;
61 | }
62 |
63 | public String getFileName() {
64 | return fileName;
65 | }
66 |
67 | public String getFilePath() {
68 | return filePath;
69 | }
70 |
71 | public String getType() {
72 | return type;
73 | }
74 |
75 | public ArrayList getAllocatedBlocks() {
76 | return allocatedBlocks;
77 | }
78 |
79 | public boolean isDeleted() {
80 | return deleted;
81 | }
82 |
83 | public int getFileSize() {
84 | return fileSize;
85 | }
86 |
87 | public int getStartBlock() {
88 | return startBlock;
89 | }
90 |
91 | public void setStartBlock(int startBlock) {
92 | this.startBlock = startBlock;
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/Version 1/src/SystemControl/DiskDataControl.java:
--------------------------------------------------------------------------------
1 | package SystemControl;
2 |
3 | import java.io.*;
4 | import java.nio.file.Files;
5 | import java.nio.file.Paths;
6 | import java.nio.file.StandardOpenOption;
7 | import java.util.ArrayList;
8 |
9 | public class DiskDataControl {
10 | public static void FWrite(File file, String r) throws Exception {
11 | r+="\n";
12 | Files.write(Paths.get(String.valueOf(file)), r.getBytes(), StandardOpenOption.APPEND);
13 | }
14 |
15 | public static ArrayList FRead(File file) throws Exception {
16 | BufferedReader bufReader = new BufferedReader(new FileReader(file));
17 | ArrayList listOfLines = new ArrayList<>();
18 | String line = bufReader.readLine(); while (line != null) { listOfLines.add(line);
19 | line = bufReader.readLine();
20 | }
21 | bufReader.close();
22 | return listOfLines;
23 | }
24 | public static void removeLine(File f, String path) throws IOException {
25 | File tempFile = new File("C:\\Users\\Eng Khaled\\VFS\\DataBase\\myTempFile.vfs");
26 | BufferedReader reader = new BufferedReader(new FileReader(f));
27 | BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile));
28 |
29 | String currentLine;
30 | while((currentLine = reader.readLine()) != null) {
31 | String trimmedLine = currentLine.trim();
32 | if(trimmedLine.contains(path)) continue;
33 | writer.write(currentLine + System.getProperty("line.separator"));
34 | }//ContiguousAllocation.vfs
35 | writer.close();
36 | reader.close();
37 | f.delete();
38 | tempFile.renameTo(f);
39 | }
40 | public static void removeLines(String path, int startline, int numOfLines) throws IOException {
41 |
42 | BufferedReader br=new BufferedReader(new FileReader(path));
43 |
44 | //to store contents of the file
45 | StringBuffer sb=new StringBuffer("");
46 |
47 | int linenumber=1;
48 | String line;
49 |
50 | while((line=br.readLine())!=null)
51 | {
52 | if(linenumber=startline+numOfLines)
53 | sb.append(line).append("\n");
54 | linenumber++;
55 | }
56 | br.close();
57 |
58 | FileWriter fw=new FileWriter(new File(path));
59 | fw.write(sb.toString());
60 | fw.close();
61 | }
62 |
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/Version 2 (With Protection)/src/SystemControl/DiskDataControl.java:
--------------------------------------------------------------------------------
1 | package SystemControl;
2 |
3 | import java.io.*;
4 | import java.nio.file.Files;
5 | import java.nio.file.Paths;
6 | import java.nio.file.StandardOpenOption;
7 | import java.util.ArrayList;
8 |
9 | public class DiskDataControl {
10 | public static void FWrite(File file, String r) throws Exception {
11 | r+="\n";
12 | Files.write(Paths.get(String.valueOf(file)), r.getBytes(), StandardOpenOption.APPEND);
13 | }
14 |
15 | public static ArrayList FRead(File file) throws Exception {
16 | BufferedReader bufReader = new BufferedReader(new FileReader(file));
17 | ArrayList listOfLines = new ArrayList<>();
18 | String line = bufReader.readLine(); while (line != null) { listOfLines.add(line);
19 | line = bufReader.readLine();
20 | }
21 | bufReader.close();
22 | return listOfLines;
23 | }
24 | public static void removeLine(File f, String path) throws IOException {
25 | File tempFile = new File("C:\\Users\\Eng Khaled\\VFS_V2\\DataBase\\myTempFile.vfs");
26 | BufferedReader reader = new BufferedReader(new FileReader(f));
27 | BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile));
28 |
29 | String currentLine;
30 | while((currentLine = reader.readLine()) != null) {
31 | String trimmedLine = currentLine.trim();
32 | if(trimmedLine.contains(path)) continue;
33 | writer.write(currentLine + System.getProperty("line.separator"));
34 | }//ContiguousAllocation.vfs
35 | writer.close();
36 | reader.close();
37 | f.delete();
38 | tempFile.renameTo(f);
39 | }
40 | public static void removeLines(String path, int startline, int numOfLines) throws IOException {
41 |
42 | BufferedReader br=new BufferedReader(new FileReader(path));
43 |
44 | //to store contents of the file
45 | StringBuffer sb=new StringBuffer("");
46 |
47 | int linenumber=1;
48 | String line;
49 |
50 | while((line=br.readLine())!=null)
51 | {
52 | if(linenumber=startline+numOfLines)
53 | sb.append(line).append("\n");
54 | linenumber++;
55 | }
56 | br.close();
57 |
58 | FileWriter fw=new FileWriter(new File(path));
59 | fw.write(sb.toString());
60 | fw.close();
61 | }
62 |
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/Version 1/src/AllocationMethods/ContiguousAllocation.java:
--------------------------------------------------------------------------------
1 | package AllocationMethods;
2 |
3 | import FileSystemStructure.VirtualFile;
4 | import SystemControl.DiskDataControl;
5 |
6 | import java.io.File;
7 | import java.io.IOException;
8 | import java.util.ArrayList;
9 |
10 | public class ContiguousAllocation implements FileAllocation{
11 | private static ArrayList blocksOfFiles;
12 | private int totalSize=100;
13 |
14 | public ContiguousAllocation(int totalSize) {
15 | this.totalSize = totalSize;
16 | blocksOfFiles = new ArrayList<>();
17 | for (int i = 0; i < totalSize; i++) {
18 | blocksOfFiles.add(0);
19 | }
20 | }
21 |
22 | public ContiguousAllocation() {
23 | blocksOfFiles = new ArrayList<>();
24 | for (int i = 0; i < 100; i++) {
25 | blocksOfFiles.add(0);
26 | }
27 | }
28 |
29 | @Override
30 | public boolean allocateFile(VirtualFile file, File f,String path) throws Exception {
31 | int sizeOfFile =file.getFileSize();
32 | int freeBlocks=getNumOfFreeBlocks();
33 | String TempFile="";
34 | if(sizeOfFile>freeBlocks) return false;
35 | else{
36 | int checkSize=0;
37 | int start=blocksOfFiles.indexOf(0),end=0;
38 | for(int i=start;i spaces) throws Exception {
72 | return false;
73 | }
74 |
75 | @Override
76 | public void deAllocateFile(VirtualFile file,File f,String path) throws IOException {
77 | int sizeOfFile=file.getFileSize();
78 | for(int i=file.getStartBlock();i blocksOfFiles;
12 | private int totalSize=100;
13 |
14 | public ContiguousAllocation(int totalSize) {
15 | this.totalSize = totalSize;
16 | blocksOfFiles = new ArrayList<>();
17 | for (int i = 0; i < totalSize; i++) {
18 | blocksOfFiles.add(0);
19 | }
20 | }
21 |
22 | public ContiguousAllocation() {
23 | blocksOfFiles = new ArrayList<>();
24 | for (int i = 0; i < 100; i++) {
25 | blocksOfFiles.add(0);
26 | }
27 | }
28 |
29 | @Override
30 | public boolean allocateFile(VirtualFile file, File f,String path) throws Exception {
31 | int sizeOfFile =file.getFileSize();
32 | int freeBlocks=getNumOfFreeBlocks();
33 | String TempFile="";
34 | if(sizeOfFile>freeBlocks) return false;
35 | else{
36 | int checkSize=0;
37 | int start=blocksOfFiles.indexOf(0),end=0;
38 | for(int i=start;i spaces) throws Exception {
73 | return false;
74 | }
75 |
76 | @Override
77 | public void deAllocateFile(VirtualFile file,File f,String path) throws IOException {
78 | for(int i=file.getStartBlock();i<=file.getEndBlock();i++){
79 | blocksOfFiles.set(i,0);
80 | }
81 | DiskDataControl.removeLine(f,path);
82 | }
83 |
84 | public int getNumOfFreeBlocks(){
85 | int cnt=0;
86 | for(int i=0;i users; // to store list of users that admin create it
13 |
14 | public Protection(User admin) {
15 | this.admin = admin;
16 | users=new ArrayList<>();
17 | }
18 |
19 | // create new user by admin only
20 | public void createUser(String username,String password,User currUser) throws Exception {
21 | //check the current user that already login in the system now
22 | // if current user is admin..
23 | if(currUser==admin){
24 | // if username valid and not exist in the system
25 | if(checkUserExist(username)==-1){
26 | String userInfo=username + " , " + password;
27 | File f=new File("C:\\Users\\Eng Khaled\\VFS_V2\\DataBase\\user.txt");
28 | DiskDataControl.FWrite(f,userInfo);
29 | User newUser=new User(username,password);
30 | users.add(newUser);
31 | System.out.println(">User added Successfully");
32 | }
33 | // if username already exist
34 | else {
35 | System.out.println(">Not Valid Username");
36 | }
37 | }
38 | // if current user is user..
39 | else System.out.println(">You don't Allow to use this command");
40 | }
41 |
42 | // login user already exist in the system
43 | public int login(String username,String password){
44 | int index=checkUserExist(username);
45 | // if username found
46 | if(index!=-1){
47 | //check the password of the user
48 | if(users.get(index).getPassword().equals(password)){
49 | System.out.println(">You are successfully logged in.");
50 | return index;
51 | }
52 | else{
53 | System.out.println(">Password not correct");
54 | }
55 | }
56 | // if username not found
57 | else{
58 | System.out.println(">Username not found!");
59 | }
60 | return -1;
61 | }
62 |
63 | public void grantUser(String username, String path, String access, User currUser, Directory root){
64 | //check if current user is admin
65 | if(currUser==admin){
66 | // if path of directory
67 | if(!path.contains(".")){
68 | String Temp=path;
69 | Directory dir=root.checkPathFolder(Temp,root);
70 | // check if path is found
71 | if(dir!=null){
72 | int index =checkUserExist(username);
73 |
74 | // check user exist in the system ot not
75 | if(index!=-1){
76 | users.get(index).capabilities.put(path,access);
77 | System.out.println("User Granted Successfully");
78 | }
79 | else {
80 | System.out.println(">Username Not Found");
81 | }
82 | }
83 | // if path not found
84 | else{
85 | System.out.println(">Path Not Found");
86 | }
87 | }
88 | //if the path of file
89 | else {
90 | System.out.println(">This Command use for Folders only");
91 | }
92 | }
93 | // if current user is not admin
94 | else System.out.println(">You don't Allow to use this command");
95 | }
96 |
97 | // used to store Capabilities of users in the file (as database)
98 | public void setCapabilitiesFile() throws Exception {
99 | File f=new File("C:\\Users\\Eng Khaled\\VFS_V2\\DataBase\\capabilities.txt");
100 | if(f.exists()) {f.delete();
101 | f.createNewFile();}
102 | Set paths=new LinkedHashSet();
103 | String str="";
104 | for(int i=0;i getUsers() {
139 | return users;
140 | }
141 |
142 | public void setUsers(ArrayList users) {
143 | this.users = users;
144 | }
145 | }
146 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Virtual File System With Protection Layer
2 |
3 | Virtual File System is a Java project that simulates the allocation and de-allocation of files and folders in a virtual file system using different allocation techniques. It provides a command-line interface for users to interact with the virtual file system and perform various operations such as creating files and folders, deleting files and folders, displaying disk status, and more. The project also includes a protection layer for user management and access control.
4 |
5 | ## Features
6 |
7 | The Virtual File System project offers the following features:
8 |
9 | - Contiguous Allocation using the Best Fit algorithm.
10 | - Indexed Allocation.
11 | - Linked Allocation.
12 | - Creation and deletion of files and folders.
13 | - Displaying disk status, including empty space, allocated space, empty blocks, and allocated blocks.
14 | - Displaying the disk structure in a tree-like format.
15 | - User management with the ability to create users and assign capabilities.
16 | - Login functionality to switch between users with proper authentication.
17 | - Command validation and error handling.
18 | - File and folder permissions and access control.
19 | - Ability to display file and folder details such as size, creation date, and last modified date.
20 |
21 | ## Commands
22 |
23 | The Virtual File System project supports the following commands:
24 |
25 | - `CreateFile `: Creates a file with the specified path and size in KB.
26 | - `CreateFolder `: Creates a new folder with the specified path.
27 | - `DeleteFile `: Deletes the file at the specified path and deallocates the blocks allocated to it.
28 | - `DeleteFolder `: Deletes the folder at the specified path, along with all its files and subdirectories.
29 | - `DisplayDiskStatus`: Displays the status of the disk, including empty space, allocated space, empty blocks, and allocated blocks.
30 | - `DisplayDiskStructure`: Displays the files and folders in the system in a tree structure.
31 | - `Details `: Displays the details of the file or folder at the specified path.
32 | - `TellUser`: Displays the name of the currently logged-in user.
33 | - `CUser `: Creates a new user with the specified username and password.
34 | - `Grant `: Grants the specified user create and delete capabilities on the specified folder.
35 | - `Login `: Changes the currently logged-in user to the specified user.
36 |
37 |
38 | ## Getting Started
39 |
40 | To run the Virtual File System project, follow these steps:
41 |
42 | 1. Clone the project repository from GitHub: [Virtual File System](https://github.com/KhaledAshrafH/Virtual-File-System).
43 | 2. Open the project in your preferred Java IDE.
44 | 3. Build the project to compile the source code.
45 | 4. Run the project.
46 |
47 | ## Usage
48 |
49 | Once the project is running, you can enter commands to interact with the virtual file system. Below are examples of the available commands:
50 | ```
51 | CreateFile /docs/report.txt 1024
52 | CreateFolder /docs/notes
53 | DeleteFile /docs/report.txt
54 | DeleteFolder /docs/notes
55 | DisplayDiskStatus
56 | DisplayDiskStructure
57 | TellUser
58 | CUser khalouda pass123
59 | Grant khalouda /docs create,delete
60 | Login khalouda pass123
61 | ```
62 |
63 | ## Saving and Loading
64 |
65 | The Virtual File System project supports saving and loading the virtual file system structure. When the application starts, it automatically loads the disk structure from the "c:\DiskStructure.vfs" file. Any changes made during the session are written back to the file before the application terminates.
66 |
67 | The Virtual File System file contains the structure of the files and folders in a tree structure. This allows for printing the tree structure when the user requests the "DisplayDiskStructure" command.
68 |
69 | ## File Storage
70 |
71 | The project uses two allocation techniques to store files in the disk: contiguous allocation (using best fit) and indexed allocation. The user can choose which technique to use by changing the value of the `allocationType` variable in the `Main` class.
72 |
73 | ### Contiguous Allocation
74 |
75 | In contiguous allocation, each file occupies a set of contiguous blocks on the disk. The project uses the best fit strategy to find the smallest free space that can accommodate the file size. The project stores the start block number and the end block number for each file in the `DiskStructure.vfs` file.
76 |
77 | ### Indexed Allocation
78 |
79 | In indexed allocation, each file has an index block that contains pointers to the data blocks of the file. The index block number is stored in the `DiskStructure.vfs` file, along with the data block numbers. The project uses a free space manager component to keep track of the free blocks and allocate them to files when needed.
80 | ## Extensibility
81 |
82 | The Virtual File System project is designed to be extensible. Additional allocation techniques can be implemented by creating new classes that extend the `AllocationStrategy` abstract class and implementing the required methods. Moreover, new commands and functionality can be added by extending the existing classes and implementing the necessary logic.
83 |
84 | ## Contributing
85 |
86 | Contributions to the Virtual File System project are welcome! If you find any issues or have suggestions for improvements, please open an issue on the project's GitHub repository. You can also fork the repository, make your changes, and submit a pull request.
87 |
88 | ## License
89 |
90 | The Virtual File System project is licensed under the [MIT License](LICENSE.md).
91 |
--------------------------------------------------------------------------------
/Version 1/src/AllocationMethods/IndexedAllocation.java:
--------------------------------------------------------------------------------
1 | package AllocationMethods;
2 |
3 | import FileSystemStructure.VirtualFile;
4 | import SystemControl.DiskDataControl;
5 |
6 | import java.io.File;
7 | import java.io.IOException;
8 | import java.util.ArrayList;
9 | import java.util.Collections;
10 |
11 | class indexedNode{
12 | public boolean checkAllocate;
13 | public boolean isRoot;
14 | public ArrayList pointersToBlocks;
15 | indexedNode(){
16 | checkAllocate=false;
17 | isRoot=false;
18 | pointersToBlocks=new ArrayList<>();
19 | }
20 | }
21 | public class IndexedAllocation implements FileAllocation{
22 | private static ArrayList blocksOfFiles;
23 | private int totalSize=100;
24 |
25 | public IndexedAllocation(int totalSize) {
26 | this.totalSize = totalSize;
27 | blocksOfFiles=new ArrayList<>();
28 | for(int i=0;i();
34 | for(int i=0;i 0) {
43 | ArrayList freeSpaces = new ArrayList<>();
44 | for (int i = 0; i < totalSize; i++) {
45 | if (!blocksOfFiles.get(i).checkAllocate) freeSpaces.add(i);
46 | }
47 | Collections.shuffle(freeSpaces);
48 | if (freeSpaces.size() >= file.getFileSize()+1) {
49 | int startIndex=freeSpaces.get(0);
50 | int tempIndex;
51 | file.setStartBlock(startIndex);
52 | blocksOfFiles.get(startIndex).isRoot=true;
53 | blocksOfFiles.get(startIndex).checkAllocate=true;
54 | for(int i=1;i< file.getFileSize()+1;i++){
55 | tempIndex=freeSpaces.get(i);
56 | blocksOfFiles.get(startIndex).pointersToBlocks.add(tempIndex);
57 | blocksOfFiles.get(tempIndex).checkAllocate=true;
58 | }
59 | int num,len=blocksOfFiles.get(startIndex).pointersToBlocks.size();
60 | TempFile+=String.valueOf(startIndex)+"\n";
61 | for(int i=0;i spaces) throws Exception {
78 | String TempFile=(path+" ");
79 | ArrayList freeSpaces = spaces;
80 | int startIndex=freeSpaces.get(0);
81 | int tempIndex;
82 | file.setStartBlock(startIndex);
83 | blocksOfFiles.get(startIndex).isRoot=true;
84 | blocksOfFiles.get(startIndex).checkAllocate=true;
85 | TempFile+=String.valueOf(startIndex)+"\n";
86 | int len=spaces.size();
87 | for(int i=1;i< len;i++){
88 | tempIndex=freeSpaces.get(i);
89 | blocksOfFiles.get(startIndex).pointersToBlocks.add(tempIndex);
90 | blocksOfFiles.get(tempIndex).checkAllocate=true;
91 | if(i!=len-1) TempFile+=(String.valueOf(tempIndex) + " ");
92 | else TempFile+=(String.valueOf(tempIndex));
93 | }
94 | DiskDataControl.FWrite(f,TempFile);
95 | return true;
96 | }
97 |
98 | @Override
99 | public void deAllocateFile(VirtualFile file,File f,String path) throws IOException {
100 | indexedNode rootNode=blocksOfFiles.get(file.getStartBlock());
101 | int secondBlock=rootNode.pointersToBlocks.get(0);
102 | int thirdBlock=rootNode.pointersToBlocks.get(1);
103 | String str="";
104 | str=(String.valueOf(secondBlock) + " " + String.valueOf(thirdBlock));
105 | DiskDataControl.removeLine(f,path);
106 | DiskDataControl.removeLine(f,str);
107 | int lenOfList=rootNode.pointersToBlocks.size();
108 | int indexTemp;
109 | for(int i=0;i pointersToBlocks;
15 | indexedNode(){
16 | checkAllocate=false;
17 | isRoot=false;
18 | pointersToBlocks=new ArrayList<>();
19 | }
20 | }
21 | public class IndexedAllocation implements FileAllocation{
22 | private static ArrayList blocksOfFiles;
23 | private int totalSize=100;
24 |
25 | public IndexedAllocation(int totalSize) {
26 | this.totalSize = totalSize;
27 | blocksOfFiles=new ArrayList<>();
28 | for(int i=0;i();
34 | for(int i=0;i 0) {
43 | ArrayList freeSpaces = new ArrayList<>();
44 | for (int i = 0; i < totalSize; i++) {
45 | if (!blocksOfFiles.get(i).checkAllocate) freeSpaces.add(i);
46 | }
47 | Collections.shuffle(freeSpaces);
48 | if (freeSpaces.size() >= file.getFileSize()+1) {
49 | int startIndex=freeSpaces.get(0);
50 | int tempIndex;
51 | file.setStartBlock(startIndex);
52 | blocksOfFiles.get(startIndex).isRoot=true;
53 | blocksOfFiles.get(startIndex).checkAllocate=true;
54 | for(int i=1;i< file.getFileSize()+1;i++){
55 | tempIndex=freeSpaces.get(i);
56 | blocksOfFiles.get(startIndex).pointersToBlocks.add(tempIndex);
57 | blocksOfFiles.get(tempIndex).checkAllocate=true;
58 | }
59 | int num,len=blocksOfFiles.get(startIndex).pointersToBlocks.size();
60 | TempFile+=String.valueOf(startIndex)+"\n";
61 | for(int i=0;i spaces) throws Exception {
78 | String TempFile=(path+" ");
79 | ArrayList freeSpaces = spaces;
80 | int startIndex=freeSpaces.get(0);
81 | int tempIndex;
82 | file.setStartBlock(startIndex);
83 | blocksOfFiles.get(startIndex).isRoot=true;
84 | blocksOfFiles.get(startIndex).checkAllocate=true;
85 | TempFile+=String.valueOf(startIndex)+"\n";
86 | int len=spaces.size();
87 | for(int i=1;i< len;i++){
88 | tempIndex=freeSpaces.get(i);
89 | blocksOfFiles.get(startIndex).pointersToBlocks.add(tempIndex);
90 | blocksOfFiles.get(tempIndex).checkAllocate=true;
91 | if(i!=len-1) TempFile+=(String.valueOf(tempIndex) + " ");
92 | else TempFile+=(String.valueOf(tempIndex));
93 | }
94 | DiskDataControl.FWrite(f,TempFile);
95 | return true;
96 | }
97 |
98 | @Override
99 | public void deAllocateFile(VirtualFile file,File f,String path) throws IOException {
100 | indexedNode rootNode=blocksOfFiles.get(file.getStartBlock());
101 | int secondBlock=rootNode.pointersToBlocks.get(0);
102 | int thirdBlock=rootNode.pointersToBlocks.get(1);
103 | String str="";
104 | str=(String.valueOf(secondBlock) + " " + String.valueOf(thirdBlock));
105 | DiskDataControl.removeLine(f,path);
106 | DiskDataControl.removeLine(f,str);
107 | int lenOfList=rootNode.pointersToBlocks.size();
108 | int indexTemp;
109 | for(int i=0;i blocksOfFiles;
23 | private int totalSize=100;
24 |
25 | public LinkedAllocation(int totalSize) {
26 | this.totalSize = totalSize;
27 | blocksOfFiles=new ArrayList<>();
28 | for(int i=0;i();
35 | for(int i=0;i0){
43 | ArrayList freeSpaces= new ArrayList<>();
44 | for(int i=0;i= file.getFileSize()){
50 | int i;
51 | file.setStartBlock(freeSpaces.get(0));
52 | blocksOfFiles.get(freeSpaces.get(0)).data=1;
53 | blocksOfFiles.get(freeSpaces.get(0)).index=freeSpaces.get(0);
54 | blocksOfFiles.get(freeSpaces.get(0)).next=blocksOfFiles.get(freeSpaces.get(1));
55 | blocksOfFiles.get(freeSpaces.get(0)).checkAllocate=true;
56 | for(i=1;i< file.getFileSize()-1;i++){
57 | blocksOfFiles.get(freeSpaces.get(i)).data=1;
58 | blocksOfFiles.get(freeSpaces.get(i)).index=freeSpaces.get(i);
59 | blocksOfFiles.get(freeSpaces.get(i)).next=blocksOfFiles.get(freeSpaces.get(i+1));
60 | blocksOfFiles.get(freeSpaces.get(i)).checkAllocate=true;
61 | }
62 | blocksOfFiles.get(freeSpaces.get(i)).data=1;
63 | blocksOfFiles.get(freeSpaces.get(i)).index=freeSpaces.get(i);
64 | blocksOfFiles.get(freeSpaces.get(i)).next=null;
65 | blocksOfFiles.get(freeSpaces.get(i)).checkAllocate=true;
66 | file.setEndBlock(freeSpaces.get(i));
67 | TempFile+=(path + " " + String.valueOf(file.getStartBlock())+" "+(String.valueOf(file.getEndBlock()))+"\n");
68 | Node current=blocksOfFiles.get(file.getStartBlock());
69 | int index;
70 | while(current.next!=null){
71 | Node Temp=current.next;
72 | TempFile+=( String.valueOf(current.index)+" "+String.valueOf(Temp.index))+"\n";
73 | current=current.next;
74 | }
75 | TempFile+=(String.valueOf(file.getEndBlock())) + " nil";
76 | DiskDataControl.FWrite(f,TempFile);
77 | return true;
78 | }
79 | else {
80 | return false;
81 | }
82 | }
83 | return false;
84 | }
85 | public boolean allocateFile(VirtualFile file, File f,String path,ArrayList spaces) throws Exception {
86 | String TempFile="";
87 | if(getNumOfFreeBlocks()>0){
88 | ArrayList freeSpaces= spaces;
89 | for(int i=0;i= file.getFileSize()){
95 | int i;
96 | file.setStartBlock(freeSpaces.get(0));
97 | blocksOfFiles.get(freeSpaces.get(0)).data=1;
98 | blocksOfFiles.get(freeSpaces.get(0)).index=freeSpaces.get(0);
99 | blocksOfFiles.get(freeSpaces.get(0)).next=blocksOfFiles.get(freeSpaces.get(1));
100 | blocksOfFiles.get(freeSpaces.get(0)).checkAllocate=true;
101 | for(i=1;i< file.getFileSize()-1;i++){
102 | blocksOfFiles.get(freeSpaces.get(i)).data=1;
103 | blocksOfFiles.get(freeSpaces.get(i)).index=freeSpaces.get(i);
104 | blocksOfFiles.get(freeSpaces.get(i)).next=blocksOfFiles.get(freeSpaces.get(i+1));
105 | blocksOfFiles.get(freeSpaces.get(i)).checkAllocate=true;
106 | }
107 | blocksOfFiles.get(freeSpaces.get(i)).data=1;
108 | blocksOfFiles.get(freeSpaces.get(i)).index=freeSpaces.get(i);
109 | blocksOfFiles.get(freeSpaces.get(i)).next=null;
110 | blocksOfFiles.get(freeSpaces.get(i)).checkAllocate=true;
111 | file.setEndBlock(freeSpaces.get(i));
112 | TempFile+=(path + " " + String.valueOf(file.getStartBlock())+" "+(String.valueOf(file.getEndBlock()))+"\n");
113 | Node current=blocksOfFiles.get(file.getStartBlock());
114 | int index;
115 | while(current.next!=null){
116 | Node Temp=current.next;
117 | TempFile+=( String.valueOf(current.index)+" "+String.valueOf(Temp.index))+"\n";
118 | current=current.next;
119 | }
120 | TempFile+=(String.valueOf(file.getEndBlock())) + " nil";
121 | DiskDataControl.FWrite(f,TempFile);
122 | return true;
123 | }
124 | else {
125 | return false;
126 | }
127 | }
128 | return false;
129 | }
130 |
131 | @Override
132 | public void deAllocateFile(VirtualFile file,File f,String path) throws Exception {
133 | Node current=blocksOfFiles.get(file.getStartBlock());
134 | Node current2=blocksOfFiles.get(file.getStartBlock());
135 | ArrayList Data=DiskDataControl.FRead(f);
136 | String firstLine=path+" "+String.valueOf(file.getStartBlock())+" "+String.valueOf(file.getEndBlock());
137 | int startIdx=Data.indexOf(firstLine);
138 | int count=0;
139 | while(current2!=null){
140 | current2=current2.next;
141 | count++;
142 | }
143 | DiskDataControl.removeLines(f.getPath(),startIdx,count+2);
144 | int index;
145 | while(current!=null){
146 | Node Temp=current.next;
147 | index=blocksOfFiles.indexOf(current);
148 | blocksOfFiles.get(index).checkAllocate=false;
149 | blocksOfFiles.get(index).data=0;
150 | blocksOfFiles.get(index).next=null;
151 | current=Temp;
152 | }
153 | }
154 |
155 | @Override
156 | public int getNumOfAllocatedBlocks() {
157 | int cnt=0;
158 | for(int i=0;i blocksOfFiles;
23 | private int totalSize=100;
24 |
25 | public LinkedAllocation(int totalSize) {
26 | this.totalSize = totalSize;
27 | blocksOfFiles=new ArrayList<>();
28 | for(int i=0;i();
35 | for(int i=0;i0){
43 | ArrayList freeSpaces= new ArrayList<>();
44 | for(int i=0;i= file.getFileSize()){
50 | int i;
51 | file.setStartBlock(freeSpaces.get(0));
52 | blocksOfFiles.get(freeSpaces.get(0)).data=1;
53 | blocksOfFiles.get(freeSpaces.get(0)).index=freeSpaces.get(0);
54 | blocksOfFiles.get(freeSpaces.get(0)).next=blocksOfFiles.get(freeSpaces.get(1));
55 | blocksOfFiles.get(freeSpaces.get(0)).checkAllocate=true;
56 | for(i=1;i< file.getFileSize()-1;i++){
57 | blocksOfFiles.get(freeSpaces.get(i)).data=1;
58 | blocksOfFiles.get(freeSpaces.get(i)).index=freeSpaces.get(i);
59 | blocksOfFiles.get(freeSpaces.get(i)).next=blocksOfFiles.get(freeSpaces.get(i+1));
60 | blocksOfFiles.get(freeSpaces.get(i)).checkAllocate=true;
61 | }
62 | blocksOfFiles.get(freeSpaces.get(i)).data=1;
63 | blocksOfFiles.get(freeSpaces.get(i)).index=freeSpaces.get(i);
64 | blocksOfFiles.get(freeSpaces.get(i)).next=null;
65 | blocksOfFiles.get(freeSpaces.get(i)).checkAllocate=true;
66 | file.setEndBlock(freeSpaces.get(i));
67 | TempFile+=(path + " " + String.valueOf(file.getStartBlock())+" "+(String.valueOf(file.getEndBlock()))+"\n");
68 | Node current=blocksOfFiles.get(file.getStartBlock());
69 | int index;
70 | while(current.next!=null){
71 | Node Temp=current.next;
72 | TempFile+=( String.valueOf(current.index)+" "+String.valueOf(Temp.index))+"\n";
73 | current=current.next;
74 | }
75 | TempFile+=(String.valueOf(file.getEndBlock())) + " nil";
76 | DiskDataControl.FWrite(f,TempFile);
77 | return true;
78 | }
79 | else {
80 | return false;
81 | }
82 | }
83 | return false;
84 | }
85 | public boolean allocateFile(VirtualFile file, File f,String path,ArrayList spaces) throws Exception {
86 | String TempFile="";
87 | if(getNumOfFreeBlocks()>0){
88 | ArrayList freeSpaces= spaces;
89 | for(int i=0;i= file.getFileSize()){
95 | int i;
96 | file.setStartBlock(freeSpaces.get(0));
97 | blocksOfFiles.get(freeSpaces.get(0)).data=1;
98 | blocksOfFiles.get(freeSpaces.get(0)).index=freeSpaces.get(0);
99 | blocksOfFiles.get(freeSpaces.get(0)).next=blocksOfFiles.get(freeSpaces.get(1));
100 | blocksOfFiles.get(freeSpaces.get(0)).checkAllocate=true;
101 | for(i=1;i< file.getFileSize()-1;i++){
102 | blocksOfFiles.get(freeSpaces.get(i)).data=1;
103 | blocksOfFiles.get(freeSpaces.get(i)).index=freeSpaces.get(i);
104 | blocksOfFiles.get(freeSpaces.get(i)).next=blocksOfFiles.get(freeSpaces.get(i+1));
105 | blocksOfFiles.get(freeSpaces.get(i)).checkAllocate=true;
106 | }
107 | blocksOfFiles.get(freeSpaces.get(i)).data=1;
108 | blocksOfFiles.get(freeSpaces.get(i)).index=freeSpaces.get(i);
109 | blocksOfFiles.get(freeSpaces.get(i)).next=null;
110 | blocksOfFiles.get(freeSpaces.get(i)).checkAllocate=true;
111 | file.setEndBlock(freeSpaces.get(i));
112 | TempFile+=(path + " " + String.valueOf(file.getStartBlock())+" "+(String.valueOf(file.getEndBlock()))+"\n");
113 | Node current=blocksOfFiles.get(file.getStartBlock());
114 | int index;
115 | while(current.next!=null){
116 | Node Temp=current.next;
117 | TempFile+=( String.valueOf(current.index)+" "+String.valueOf(Temp.index))+"\n";
118 | current=current.next;
119 | }
120 | TempFile+=(String.valueOf(file.getEndBlock())) + " nil";
121 | DiskDataControl.FWrite(f,TempFile);
122 | return true;
123 | }
124 | else {
125 | return false;
126 | }
127 | }
128 | return false;
129 | }
130 |
131 | @Override
132 | public void deAllocateFile(VirtualFile file,File f,String path) throws Exception {
133 | Node current=blocksOfFiles.get(file.getStartBlock());
134 | Node current2=blocksOfFiles.get(file.getStartBlock());
135 | ArrayList Data=DiskDataControl.FRead(f);
136 | String firstLine=path+" "+String.valueOf(file.getStartBlock())+" "+String.valueOf(file.getEndBlock());
137 | int startIdx=Data.indexOf(firstLine);
138 | int count=0;
139 | while(current2!=null){
140 | current2=current2.next;
141 | count++;
142 | }
143 | DiskDataControl.removeLines(f.getPath(),startIdx,count+2);
144 | int index;
145 | while(current!=null){
146 | Node Temp=current.next;
147 | index=blocksOfFiles.indexOf(current);
148 | blocksOfFiles.get(index).checkAllocate=false;
149 | blocksOfFiles.get(index).data=0;
150 | blocksOfFiles.get(index).next=null;
151 | current=Temp;
152 | }
153 | }
154 |
155 | @Override
156 | public int getNumOfAllocatedBlocks() {
157 | int cnt=0;
158 | for(int i=0;i lines;
20 |
21 | System.out.println("Enter Number of The Allocation Method:");
22 | System.out.println("1- Contiguous Allocation\n2- Linked Allocation\n3- Indexed Allocation");
23 |
24 | choiceAlloc=input.nextInt();
25 | switch (choiceAlloc){
26 | case 1:{
27 | f=new File("C:\\Users\\Eng Khaled\\VFS\\DataBase\\ContiguousAllocation.vfs");
28 | lines= DiskDataControl.FRead(f);
29 | root=new Directory("","root",new ContiguousAllocation(100));
30 | if(lines.size()>0){
31 | String command,operation;
32 | int sizeOfFile=0,startBlock;
33 | if(f.exists()) f.delete();
34 | f.createNewFile();
35 | for(int i=0;i< lines.size();i++){
36 | String str=lines.get(i);
37 | String [] splittedLine = str.split(" ");
38 | str=splittedLine[0];
39 | if(splittedLine.length>1) sizeOfFile=Integer.parseInt(splittedLine[2]);
40 | if(str.contains(".")){
41 | root.CreateFile(str,root,sizeOfFile,f,false);
42 | }
43 | else{
44 | root.CreateFolder(str,root,f,false);
45 | }
46 |
47 | }
48 | }
49 | System.out.println("File System with Contiguous Allocation Method");
50 | System.out.println("---------------------------------------------");
51 | break;
52 | }
53 | case 2:{
54 | f=new File("C:\\Users\\Eng Khaled\\VFS\\DataBase\\LinkedAllocation.vfs");
55 | lines= DiskDataControl.FRead(f);
56 | root=new Directory("","root",new LinkedAllocation(100));
57 | if(lines.size()>0){
58 | String command,operation;
59 | int sizeOfFile=0,startBlock,endBlock,tempBlock;
60 | // System.out.println(lines);
61 | if(f.exists()) f.delete();
62 | f.createNewFile();
63 |
64 | for(int i=0;i< lines.size();i++){
65 | ArrayList spaces=new ArrayList();
66 | String str=lines.get(i);
67 | String [] splittedLine = str.split(" ");
68 | str=splittedLine[0];
69 | if(str.contains(".") && str.contains("root")){
70 | startBlock=Integer.parseInt(splittedLine[1]);
71 | endBlock=Integer.parseInt(splittedLine[2]);
72 | spaces.add(startBlock);
73 | i++;
74 | sizeOfFile++;
75 | String str2=lines.get(i);
76 | String [] splittedNums= str2.split(" ");
77 | tempBlock=Integer.parseInt(splittedLine[1]);
78 | while(true){
79 | if(i>1){
80 | str2=lines.get(i);
81 | String [] splittedNums2= str2.split(" ");
82 | tempBlock=Integer.parseInt(splittedNums2[1]);
83 | }
84 | if(tempBlock==endBlock) break;
85 | spaces.add(tempBlock);
86 | sizeOfFile++;
87 | i++;
88 | }
89 | spaces.add(endBlock);
90 | sizeOfFile++;
91 | i++;
92 | root.CreateFile(str,root,sizeOfFile,f,false,spaces);
93 | sizeOfFile=0;
94 | }
95 |
96 | else if(str.contains("root") && !str.contains(".")){
97 | root.CreateFolder(str,root,f,false);
98 | }
99 |
100 | }
101 | }
102 | System.out.println("File System with Linked Allocation");
103 | System.out.println("----------------------------------");
104 | break;
105 | }
106 | case 3:{
107 | f=new File("C:\\Users\\Eng Khaled\\VFS\\DataBase\\IndexedAllocation.vfs");
108 | lines= DiskDataControl.FRead(f);
109 | root=new Directory("","root",new IndexedAllocation(100));
110 | if(lines.size()>0){
111 | String command,operation;
112 | int sizeOfFile=0,startBlock,endBlock,tempBlock;
113 | if(f.exists()) f.delete();
114 | f.createNewFile();
115 |
116 | for(int i=0;i< lines.size();i++){
117 | ArrayList spaces=new ArrayList();
118 | String str=lines.get(i);
119 | String [] splittedLine = str.split(" ");
120 | str=splittedLine[0];
121 | if(str.contains(".") && str.contains("root")){
122 | startBlock=Integer.parseInt(splittedLine[1]);
123 | spaces.add(startBlock);
124 | i++;
125 | String str2=lines.get(i);
126 | String [] splittedNums= str2.split(" ");
127 | for (String splittedNum : splittedNums) {
128 | tempBlock = Integer.parseInt(splittedNum);
129 | spaces.add(tempBlock);
130 | }
131 | sizeOfFile=spaces.size();
132 | root.CreateFile(str,root,sizeOfFile,f,false,spaces);
133 | }
134 |
135 | else if(str.contains("root") && !str.contains(".")){
136 | root.CreateFolder(str,root,f,false);
137 | }
138 |
139 | }
140 | }
141 | System.out.println("File System with Indexed Allocation Method");
142 | System.out.println("------------------------------------------");
143 | break;
144 | }
145 | default:{
146 | return;
147 | }
148 | }
149 |
150 | int temp=0;
151 | while(true){
152 | System.out.print(">");
153 | String command,operation;
154 | int numOfParts;
155 | if(temp==0) {
156 | temp++;
157 | input.nextLine();
158 | }
159 | command= input.nextLine();
160 | CommandsConverter commandsConverter=new CommandsConverter(command);
161 | numOfParts=commandsConverter.getNumOfParts();
162 | operation =commandsConverter.getOperation();
163 | if(operation.equalsIgnoreCase("CreateFile") && numOfParts==3){
164 | root.CreateFile(commandsConverter.getPath(),root,commandsConverter.getSize(),f,true);
165 | }
166 | else if(operation.equalsIgnoreCase("CreateFolder") && numOfParts==2){
167 | root.CreateFolder(commandsConverter.getPath(),root,f,true);
168 | }
169 | else if(operation.equalsIgnoreCase("DeleteFile") && numOfParts==2){
170 | root.deleteFile(commandsConverter.getPath(),root,f);
171 | }
172 | else if(operation.equalsIgnoreCase("DeleteFolder") && numOfParts==2){
173 | root.deleteFolder(commandsConverter.getPath(),root,f);
174 | }
175 | else if(operation.equalsIgnoreCase("DisplayDiskStatus") && numOfParts==1){
176 | root.displayDiskStatus();
177 | }
178 | else if(operation.equalsIgnoreCase("DisplayDiskStructure") && numOfParts==1){
179 | root.printDirectoryStructure(root,0);
180 | }
181 | else if(operation.equalsIgnoreCase("exit")){
182 | String exitCheck="no";
183 | System.out.println(">You want to close the program?(yes/no)");
184 | exitCheck=input.next();
185 | if(exitCheck.equalsIgnoreCase("yes")) {
186 | System.out.println("Program Terminated Successfully");
187 | break;
188 | }
189 | }
190 | else if(operation.equalsIgnoreCase("help")){
191 | System.out.println(">CreateFile PathOfFile SizeOfFile");
192 | System.out.println(" CreateFolder PathOfFolder");
193 | System.out.println(" DeleteFile PathOfFile");
194 | System.out.println(" DeleteFolder PathOfFolder");
195 | System.out.println(" DisplayDiskStructure");
196 | System.out.println(" DisplayDiskStatus");
197 | }
198 | else {
199 | if(operation.equalsIgnoreCase("CreateFile") && numOfParts==2){
200 | System.out.println(">Please, Enter Size of the File!");
201 | }
202 | else System.out.println(">You Enter command incorrect, you can use command 'help'");
203 | }
204 |
205 | }
206 |
207 | }
208 | }
209 |
--------------------------------------------------------------------------------
/Version 1/src/FileSystemStructure/Directory.java:
--------------------------------------------------------------------------------
1 | package FileSystemStructure;
2 |
3 | import AllocationMethods.FileAllocation;
4 | import SystemControl.DiskDataControl;
5 |
6 | import java.io.File;
7 | import java.io.IOException;
8 | import java.util.ArrayList;
9 |
10 | public class Directory {
11 | private String directoryPath;
12 | private String directoryName;
13 | private ArrayList files;
14 | private ArrayList subDirectories;
15 | private boolean deleted = false;
16 | private FileAllocation allocationType;
17 |
18 |
19 | public Directory(String directoryPath, String directoryName, FileAllocation allocationType) {
20 | this.directoryPath = directoryPath;
21 | this.directoryName = directoryName;
22 | this.allocationType = allocationType;
23 | files=new ArrayList<>();
24 | subDirectories=new ArrayList<>();
25 | }
26 |
27 | public Directory(String directoryPath, String directoryName, ArrayList files, ArrayList subDirectories, boolean deleted, FileAllocation allocationType) {
28 | this.directoryPath = directoryPath;
29 | this.directoryName = directoryName;
30 | this.files = files;
31 | this.subDirectories = subDirectories;
32 | this.deleted = deleted;
33 | this.allocationType = allocationType;
34 | }
35 |
36 |
37 | public String getDirectoryPath() {
38 | return directoryPath;
39 | }
40 |
41 | public void setDirectoryPath(String directoryPath) {
42 | this.directoryPath = directoryPath;
43 | }
44 |
45 | public String getDirectoryName() {
46 | return directoryName;
47 | }
48 |
49 | public void setDirectoryName(String directoryName) {
50 | this.directoryName = directoryName;
51 | }
52 |
53 | public ArrayList getFiles() {
54 | return files;
55 | }
56 |
57 | public void setFiles(ArrayList files) {
58 | this.files = files;
59 | }
60 |
61 | public ArrayList getSubDirectories() {
62 | return subDirectories;
63 | }
64 |
65 | public void setSubDirectories(ArrayList subDirectories) {
66 | this.subDirectories = subDirectories;
67 | }
68 |
69 | public boolean isDeleted() {
70 | return deleted;
71 | }
72 |
73 | public void setDeleted(boolean deleted) {
74 | this.deleted = deleted;
75 | }
76 |
77 | public FileAllocation getAllocationType() {
78 | return allocationType;
79 | }
80 |
81 | public void setAllocationType(FileAllocation allocationType) {
82 | this.allocationType = allocationType;
83 | }
84 |
85 | public void CreateFolder(String path,Directory rootDir,File f,boolean check) throws Exception { // root/folder1
86 | String directoryName="",directoryPath="";
87 | int temp = 0;
88 | int index=0;
89 | if(path.contains("/")) {index=path.lastIndexOf("/");} // / => 4
90 | if(!path.contains("root")) {
91 | System.out.println(">Please Enter path correctly!");
92 | return;
93 | }
94 | for(int i=index+1;iPlease Enter path correctly!");
105 | return;
106 | }
107 | if(Dir!=null && !Dir.checkFolderExist(directoryName,temp)) {
108 | Directory folder=new Directory(directoryPath,directoryName,Dir.allocationType);
109 | Dir.getSubDirectories().add(folder);
110 | DiskDataControl.FWrite(f,path);
111 | if(check) System.out.println(">Folder Created Successfully");
112 | }
113 | else{
114 | System.out.println(">Failed, Folder Already Exist");
115 | }
116 | }
117 |
118 | public void CreateFile(String path, Directory rootDir, int sizeFile, File f,boolean check) throws Exception {
119 | String fileName="",filePath="";
120 | int temp = 0,index=0;
121 | if(!path.contains(".")) {
122 | System.out.println(">Please Enter the Extension of the file!");
123 | return;
124 | }
125 | if(!path.contains("root")) {
126 | System.out.println(">Please Enter path correctly!");
127 | return;
128 | }
129 | if(path.contains("/")) { index=path.lastIndexOf("/");} // / => 4
130 |
131 | for(int i=index+1;iPlease Enter path correctly!");
142 | return;
143 | }
144 | if(Dir!=null && !Dir.checkFileExist(fileName,temp)) {
145 | VirtualFile file=new VirtualFile(fileName,Temp,sizeFile);
146 | if(Dir.getAllocationType().allocateFile(file,f,path)){
147 | Dir.getFiles().add(file);
148 | if(check) System.out.println(">File Created Successfully");
149 | }
150 | else {
151 | System.out.println(">Not Found Space Enough");
152 | }
153 | }
154 | else{
155 | System.out.println(">Failed, File Already Exist");
156 | }
157 | }
158 |
159 | public void CreateFile(String path, Directory rootDir, int sizeFile, File f,boolean check,ArrayList spaces) throws Exception {
160 | String fileName="",filePath="";
161 | int temp = 0,index=0;
162 | if(!path.contains(".")) {
163 | System.out.println(">Please Enter the Extension of the file!");
164 | return;
165 | }
166 | if(!path.contains("root")) {
167 | System.out.println(">Please Enter path correctly!");
168 | return;
169 | }
170 | if(path.contains("/")) { index=path.lastIndexOf("/");} // / => 4
171 |
172 | for(int i=index+1;iPlease Enter path correctly!");
183 | return;
184 | }
185 | if(Dir!=null && !Dir.checkFileExist(fileName,temp)) {
186 | VirtualFile file=new VirtualFile(fileName,Temp,sizeFile);
187 | if(Dir.getAllocationType().allocateFile(file,f,path,spaces)){
188 | Dir.getFiles().add(file);
189 | if(check) System.out.println(">File Created Successfully");
190 | }
191 | else {
192 | System.out.println(">Not Found Space Enough");
193 | }
194 | }
195 | else{
196 | System.out.println(">Failed, File Already Exist");
197 | }
198 | }
199 |
200 | public void deleteFile(String path,Directory rootDir,File f) throws Exception {
201 | String fileName="",filePath="";
202 | int temp = 0,index=0;
203 |
204 | if(path.contains("/")) { index=path.lastIndexOf("/");} // / => 4
205 |
206 | for(int i=index+1;iFile Deleted Successfully");
220 | }
221 | else System.out.println(">File not Found");
222 | }
223 | public void deleteFolder (String path,Directory rootDir,File f) throws IOException {
224 | String folderName="",folderPath="";
225 | int temp = 0,index=0;
226 | if(path.contains("/")) { index=path.lastIndexOf("/");} // / => 4
227 |
228 | for(int i=index+1;iFolder Deleted Successfully");
242 | }
243 | else System.out.println(">Folder not Found");
244 | }
245 |
246 | public boolean checkFolderExist(String folderName,int index){ //true if exist ...
247 | boolean check=false;
248 | for(int i=0;i-" +rootDir.getDirectoryName());
325 |
326 | for(int i=0;i0 || d.files.size()>0) {
334 | d.printDirectoryStructure(d,level+1);
335 | }
336 | }
337 |
338 | }
339 | public void displayDiskStatus(){
340 | ArrayList freeSpaces=new ArrayList<>();
341 | ArrayList allocatedSpaces=new ArrayList<>();
342 | System.out.print(">Empty space: "+this.getAllocationType().getNumOfFreeBlocks()+"\n");
343 | System.out.print(">Allocated space: "+this.getAllocationType().getNumOfAllocatedBlocks()+"\n");
344 | String AllBlocks=getAllocationType().getFreeAndAllocatedBlocks();
345 | for(int i=0;iEmpty Blocks in the Disk");
351 | System.out.println("-------------------------");
352 | System.out.print("");
353 | for(int i=0;iAllocated Blocks in the Disk");
358 | System.out.println("--------------------------------");
359 | System.out.print("");
360 | for(int i=0;i");
365 |
366 | }
367 |
368 | }
369 |
--------------------------------------------------------------------------------
/Version 2 (With Protection)/src/FileSystemStructure/Directory.java:
--------------------------------------------------------------------------------
1 | package FileSystemStructure;
2 |
3 | import AllocationMethods.FileAllocation;
4 | import SystemControl.DiskDataControl;
5 |
6 | import java.io.File;
7 | import java.io.IOException;
8 | import java.util.ArrayList;
9 |
10 | public class Directory {
11 | private String directoryPath;
12 | private String directoryName;
13 | private ArrayList files;
14 | private ArrayList subDirectories;
15 | private boolean deleted = false;
16 | private FileAllocation allocationType;
17 |
18 |
19 | public Directory(String directoryPath, String directoryName, FileAllocation allocationType) {
20 | this.directoryPath = directoryPath;
21 | this.directoryName = directoryName;
22 | this.allocationType = allocationType;
23 | files=new ArrayList<>();
24 | subDirectories=new ArrayList<>();
25 | }
26 |
27 | public Directory(String directoryPath, String directoryName, ArrayList files, ArrayList subDirectories, boolean deleted, FileAllocation allocationType) {
28 | this.directoryPath = directoryPath;
29 | this.directoryName = directoryName;
30 | this.files = files;
31 | this.subDirectories = subDirectories;
32 | this.deleted = deleted;
33 | this.allocationType = allocationType;
34 | }
35 |
36 |
37 | public String getDirectoryPath() {
38 | return directoryPath;
39 | }
40 |
41 | public void setDirectoryPath(String directoryPath) {
42 | this.directoryPath = directoryPath;
43 | }
44 |
45 | public String getDirectoryName() {
46 | return directoryName;
47 | }
48 |
49 | public void setDirectoryName(String directoryName) {
50 | this.directoryName = directoryName;
51 | }
52 |
53 | public ArrayList getFiles() {
54 | return files;
55 | }
56 |
57 | public void setFiles(ArrayList files) {
58 | this.files = files;
59 | }
60 |
61 | public ArrayList getSubDirectories() {
62 | return subDirectories;
63 | }
64 |
65 | public void setSubDirectories(ArrayList subDirectories) {
66 | this.subDirectories = subDirectories;
67 | }
68 |
69 | public boolean isDeleted() {
70 | return deleted;
71 | }
72 |
73 | public void setDeleted(boolean deleted) {
74 | this.deleted = deleted;
75 | }
76 |
77 | public FileAllocation getAllocationType() {
78 | return allocationType;
79 | }
80 |
81 | public void setAllocationType(FileAllocation allocationType) {
82 | this.allocationType = allocationType;
83 | }
84 |
85 | public void CreateFolder(String path,Directory rootDir,File f,boolean check) throws Exception { // root/folder1
86 | String directoryName="",directoryPath="";
87 | int temp = 0;
88 | int index=0;
89 | if(path.contains("/")) {index=path.lastIndexOf("/");} // / => 4
90 | if(!path.contains("root")) {
91 | System.out.println(">Please Enter path correctly!");
92 | return;
93 | }
94 | for(int i=index+1;iPlease Enter path correctly!");
105 | return;
106 | }
107 | if(Dir!=null && !Dir.checkFolderExist(directoryName,temp)) {
108 | Directory folder=new Directory(directoryPath,directoryName,Dir.allocationType);
109 | Dir.getSubDirectories().add(folder);
110 | DiskDataControl.FWrite(f,path);
111 | if(check) System.out.println(">Folder Created Successfully");
112 | }
113 | else{
114 | System.out.println(">Failed, Folder Already Exist");
115 | }
116 | }
117 |
118 | public void CreateFile(String path, Directory rootDir, int sizeFile, File f,boolean check) throws Exception {
119 | String fileName="",filePath="";
120 | int temp = 0,index=0;
121 | if(!path.contains(".")) {
122 | System.out.println(">Please Enter the Extension of the file!");
123 | return;
124 | }
125 | if(!path.contains("root")) {
126 | System.out.println(">Please Enter path correctly!");
127 | return;
128 | }
129 | if(path.contains("/")) { index=path.lastIndexOf("/");} // / => 4
130 |
131 | for(int i=index+1;iPlease Enter path correctly!");
142 | return;
143 | }
144 | if(Dir!=null && !Dir.checkFileExist(fileName,temp)) {
145 | VirtualFile file=new VirtualFile(fileName,Temp,sizeFile);
146 | if(Dir.getAllocationType().allocateFile(file,f,path)){
147 | Dir.getFiles().add(file);
148 | if(check) System.out.println(">File Created Successfully");
149 | }
150 | else {
151 | System.out.println(">Not Found Space Enough");
152 | }
153 | }
154 | else{
155 | System.out.println(">Failed, File Already Exist");
156 | }
157 | }
158 |
159 | public void CreateFile(String path, Directory rootDir, int sizeFile, File f,boolean check,ArrayList spaces) throws Exception {
160 | String fileName="",filePath="";
161 | int temp = 0,index=0;
162 | if(!path.contains(".")) {
163 | System.out.println(">Please Enter the Extension of the file!");
164 | return;
165 | }
166 | if(!path.contains("root")) {
167 | System.out.println(">Please Enter path correctly!");
168 | return;
169 | }
170 | if(path.contains("/")) { index=path.lastIndexOf("/");} // / => 4
171 |
172 | for(int i=index+1;iPlease Enter path correctly!");
183 | return;
184 | }
185 | if(Dir!=null && !Dir.checkFileExist(fileName,temp)) {
186 | VirtualFile file=new VirtualFile(fileName,Temp,sizeFile);
187 | if(Dir.getAllocationType().allocateFile(file,f,path,spaces)){
188 | Dir.getFiles().add(file);
189 | if(check) System.out.println(">File Created Successfully");
190 | }
191 | else {
192 | System.out.println(">Not Found Space Enough");
193 | }
194 | }
195 | else{
196 | System.out.println(">Failed, File Already Exist");
197 | }
198 | }
199 |
200 | public void deleteFile(String path,Directory rootDir,File f) throws Exception {
201 | String fileName="",filePath="";
202 | int temp = 0,index=0;
203 |
204 | if(path.contains("/")) { index=path.lastIndexOf("/");} // / => 4
205 |
206 | for(int i=index+1;iFile Deleted Successfully");
220 | }
221 | else System.out.println(">File not Found");
222 | }
223 | public void deleteFolder (String path,Directory rootDir,File f) throws Exception {
224 | String folderName="",folderPath="";
225 | int temp = 0,index=0;
226 | if(path.contains("/")) { index=path.lastIndexOf("/");} // / => 4
227 |
228 | for(int i=index+1;iFolder Deleted Successfully");
251 | }
252 | else System.out.println(">Folder not Found");
253 | }
254 |
255 | public boolean checkFolderExist(String folderName,int index){ //true if exist ...
256 | boolean check=false;
257 | for(int i=0;i-" +rootDir.getDirectoryName());
345 |
346 | for(int i=0;i0 || d.files.size()>0) {
354 | d.printDirectoryStructure(d,level+1);
355 | }
356 | }
357 |
358 | }
359 | public void displayDiskStatus(){
360 | ArrayList freeSpaces=new ArrayList<>();
361 | ArrayList allocatedSpaces=new ArrayList<>();
362 | System.out.print(">Empty space: "+this.getAllocationType().getNumOfFreeBlocks()+"\n");
363 | System.out.print(">Allocated space: "+this.getAllocationType().getNumOfAllocatedBlocks()+"\n");
364 | String AllBlocks=getAllocationType().getFreeAndAllocatedBlocks();
365 | for(int i=0;iEmpty Blocks in the Disk");
371 | System.out.println("-------------------------");
372 | System.out.print("");
373 | for(int i=0;iAllocated Blocks in the Disk");
378 | System.out.println("--------------------------------");
379 | System.out.print("");
380 | for(int i=0;i");
385 |
386 | }
387 |
388 | }
389 |
--------------------------------------------------------------------------------
/Version 2 (With Protection)/src/main.java:
--------------------------------------------------------------------------------
1 | import AllocationMethods.ContiguousAllocation;
2 | import AllocationMethods.IndexedAllocation;
3 | import AllocationMethods.LinkedAllocation;
4 | import FileSystemStructure.Directory;
5 | import SystemControl.CommandsConverter;
6 | import SystemControl.DiskDataControl;
7 | import SystemControl.Protection;
8 | import SystemControl.User;
9 |
10 | import java.io.File;
11 | import java.util.ArrayList;
12 | import java.util.Arrays;
13 | import java.util.Scanner;
14 |
15 | public class main {
16 | private static final Scanner input = new Scanner(System.in);
17 |
18 | static Directory root ;
19 | public static void main(String[] args) throws Exception {
20 | int choiceAlloc=0;
21 | File f;
22 | ArrayList lines;
23 | User admin=new User("admin","admin");
24 | Protection protection=new Protection(admin);
25 | protection.getUsers().add(admin);
26 | User currentUser=admin;
27 | //protection get users data from file
28 | f=new File("C:\\Users\\Eng Khaled\\VFS_V2\\DataBase\\user.txt");
29 | lines =DiskDataControl.FRead(f);
30 | if(lines.size()>0){
31 | for(int i=1;i< lines.size();i++){
32 | String []splitStr=lines.get(i).split(" , ");
33 | User user=new User(splitStr[0],splitStr[1]);
34 | protection.getUsers().add(user);
35 | }
36 | }
37 | //protection get capabilities data from file
38 | f=new File("C:\\Users\\Eng Khaled\\VFS_V2\\DataBase\\capabilities.txt");
39 | lines =DiskDataControl.FRead(f);
40 | if(lines.size()>0){
41 | for(int i=0;i< lines.size();i++){
42 | String str=lines.get(i);
43 | String []splitStr=str.split(",");
44 | //System.out.println(lines.get(i));
45 | //System.out.println(Arrays.toString(splitStr));
46 | String path=splitStr[0];
47 | for(int j=1;j0){
80 | String command,operation;
81 | int sizeOfFile=0,startBlock;
82 | if(f.exists()) f.delete();
83 | f.createNewFile();
84 | for(int i=0;i< lines.size();i++){
85 | String str=lines.get(i);
86 | String [] splittedLine = str.split(" ");
87 | str=splittedLine[0];
88 | if(splittedLine.length>1) sizeOfFile=Integer.parseInt(splittedLine[2]);
89 | if(str.contains(".")){
90 | root.CreateFile(str,root,sizeOfFile,f,false);
91 | }
92 | else{
93 | root.CreateFolder(str,root,f,false);
94 | }
95 |
96 | }
97 | }
98 | System.out.println("File System with Contiguous Allocation Method");
99 | System.out.println("---------------------------------------------");
100 | break;
101 | }
102 | case 2:{
103 | f=new File("C:\\Users\\Eng Khaled\\VFS_V2\\DataBase\\LinkedAllocation.vfs");
104 | lines= DiskDataControl.FRead(f);
105 | root=new Directory("","root",new LinkedAllocation(100));
106 | if(lines.size()>0){
107 | String command,operation;
108 | int sizeOfFile=0,startBlock,endBlock,tempBlock;
109 | // System.out.println(lines);
110 | if(f.exists()) f.delete();
111 | f.createNewFile();
112 |
113 | for(int i=0;i< lines.size();i++){
114 | ArrayList spaces=new ArrayList();
115 | String str=lines.get(i);
116 | String [] splittedLine = str.split(" ");
117 | str=splittedLine[0];
118 | if(str.contains(".") && str.contains("root")){
119 | startBlock=Integer.parseInt(splittedLine[1]);
120 | endBlock=Integer.parseInt(splittedLine[2]);
121 | spaces.add(startBlock);
122 | i++;
123 | sizeOfFile++;
124 | String str2=lines.get(i);
125 | String [] splittedNums= str2.split(" ");
126 | tempBlock=Integer.parseInt(splittedLine[1]);
127 | while(true){
128 | if(i>1){
129 | str2=lines.get(i);
130 | String [] splittedNums2= str2.split(" ");
131 | tempBlock=Integer.parseInt(splittedNums2[1]);
132 | }
133 | if(tempBlock==endBlock) break;
134 | spaces.add(tempBlock);
135 | sizeOfFile++;
136 | i++;
137 | }
138 | spaces.add(endBlock);
139 | sizeOfFile++;
140 | i++;
141 | root.CreateFile(str,root,sizeOfFile,f,false,spaces);
142 | sizeOfFile=0;
143 | }
144 |
145 | else if(str.contains("root") && !str.contains(".")){
146 | root.CreateFolder(str,root,f,false);
147 | }
148 |
149 | }
150 | }
151 | System.out.println("File System with Linked Allocation");
152 | System.out.println("----------------------------------");
153 | break;
154 | }
155 | case 3:{
156 | f=new File("C:\\Users\\Eng Khaled\\VFS_V2\\DataBase\\IndexedAllocation.vfs");
157 | lines= DiskDataControl.FRead(f);
158 | root=new Directory("","root",new IndexedAllocation(100));
159 | if(lines.size()>0){
160 | String command,operation;
161 | int sizeOfFile=0,startBlock,endBlock,tempBlock;
162 | if(f.exists()) f.delete();
163 | f.createNewFile();
164 |
165 | for(int i=0;i< lines.size();i++){
166 | ArrayList spaces=new ArrayList();
167 | String str=lines.get(i);
168 | String [] splittedLine = str.split(" ");
169 | str=splittedLine[0];
170 | if(str.contains(".") && str.contains("root")){
171 | startBlock=Integer.parseInt(splittedLine[1]);
172 | spaces.add(startBlock);
173 | i++;
174 | String str2=lines.get(i);
175 | String [] splittedNums= str2.split(" ");
176 | for (String splittedNum : splittedNums) {
177 | tempBlock = Integer.parseInt(splittedNum);
178 | spaces.add(tempBlock);
179 | }
180 | sizeOfFile=spaces.size();
181 | root.CreateFile(str,root,sizeOfFile,f,false,spaces);
182 | }
183 |
184 | else if(str.contains("root") && !str.contains(".")){
185 | root.CreateFolder(str,root,f,false);
186 | }
187 |
188 | }
189 | }
190 | System.out.println("File System with Indexed Allocation Method");
191 | System.out.println("------------------------------------------");
192 | break;
193 | }
194 | default:{
195 | return;
196 | }
197 | }
198 |
199 | int temp=0;
200 | while(true){
201 | System.out.print(">");
202 | String command,operation;
203 | int numOfParts;
204 | if(temp==0) {
205 | temp++;
206 | input.nextLine();
207 | }
208 | command= input.nextLine();
209 | CommandsConverter commandsConverter=new CommandsConverter(command);
210 | numOfParts=commandsConverter.getNumOfParts();
211 | operation =commandsConverter.getOperation();
212 | String []str=command.split(" ");
213 | if(operation.equalsIgnoreCase("CreateFile") && numOfParts==3){
214 | if(currentUser==admin){
215 | root.CreateFile(commandsConverter.getPath(),root,commandsConverter.getSize(),f,true);
216 | }
217 | else if(currentUser.getCapabilities().containsKey(commandsConverter.getPathDir())){
218 | String access=currentUser.getCapabilities().get(commandsConverter.getPathDir());
219 | if(access.equals("10") || access.equals("11")) root.CreateFile(commandsConverter.getPath(),root,commandsConverter.getSize(),f,true);
220 | else System.out.println("You don't allow do this");
221 | }
222 | else System.out.println("You don't allow do this");
223 | }
224 | else if(operation.equalsIgnoreCase("CreateFolder") && numOfParts==2){
225 | if(currentUser==admin){
226 | root.CreateFolder(commandsConverter.getPath(),root,f,true);
227 | }
228 | else if(currentUser.getCapabilities().containsKey(commandsConverter.getPathDir())){
229 | String access=currentUser.getCapabilities().get(commandsConverter.getPathDir());
230 | if(access.equals("10") || access.equals("11")) root.CreateFolder(commandsConverter.getPath(),root,f,true);
231 | else System.out.println("You don't allow do this");
232 | }
233 | else {
234 | // boolean check =false;
235 | // String k="";
236 | // for ( String key : currentUser.getCapabilities().keySet() ) {
237 | // if(commandsConverter.getPathDir().contains(key)) {
238 | // check =true;
239 | // k=key;
240 | // break;
241 | // }
242 | // }
243 | // if(check){
244 | // String access=currentUser.getCapabilities().get(k);
245 | // if(access.equals("10") || access.equals("11")) root.CreateFolder(commandsConverter.getPath(),root,f,true);
246 | // else System.out.println("You don't allow do this");
247 | // }
248 | System.out.println("You don't allow do this");
249 | }
250 | }
251 | else if(operation.equalsIgnoreCase("DeleteFile") && numOfParts==2){
252 | if(currentUser==admin){
253 | root.deleteFile(commandsConverter.getPath(),root,f);
254 | }
255 | else if(currentUser.getCapabilities().containsKey(commandsConverter.getPathDir())){
256 | String access=currentUser.getCapabilities().get(commandsConverter.getPathDir());
257 | if(access.equals("01") || access.equals("11")) root.deleteFile(commandsConverter.getPath(),root,f);
258 | else System.out.println("You don't allow do this");
259 | }
260 | else System.out.println("You don't allow do this");
261 | }
262 | else if(operation.equalsIgnoreCase("DeleteFolder") && numOfParts==2){
263 | if(currentUser==admin){
264 | root.deleteFolder(commandsConverter.getPath(),root,f);
265 | }
266 | else if(currentUser.getCapabilities().containsKey(commandsConverter.getPathDir())){
267 | String access=currentUser.getCapabilities().get(commandsConverter.getPathDir());
268 | if(access.equals("01") || access.equals("11")) root.deleteFolder(commandsConverter.getPath(),root,f);
269 | else System.out.println("You don't allow do this");
270 | }
271 | else System.out.println("You don't allow do this");
272 | }
273 | else if(operation.equalsIgnoreCase("DisplayDiskStatus") && numOfParts==1){
274 | root.displayDiskStatus();
275 | }
276 | else if(operation.equalsIgnoreCase("DisplayDiskStructure") && numOfParts==1){
277 | root.printDirectoryStructure(root,0);
278 | }
279 | else if(operation.equalsIgnoreCase("exit")){
280 | String exitCheck="no";
281 | System.out.println(">You want to close the program?(yes/no)");
282 | exitCheck=input.next();
283 | if(exitCheck.equalsIgnoreCase("yes")) {
284 | System.out.println("Program Terminated Successfully");
285 | //protection.setCapabilitiesFile();
286 | break;
287 | }
288 | }
289 | else if(operation.equalsIgnoreCase("help")){
290 | System.out.println(">CreateFile PathOfFile SizeOfFile");
291 | System.out.println(" CreateFolder PathOfFolder");
292 | System.out.println(" CUser username password 'for admin only'");
293 | System.out.println(" DeleteFile PathOfFile");
294 | System.out.println(" DeleteFolder PathOfFolder");
295 | System.out.println(" DisplayDiskStructure");
296 | System.out.println(" DisplayDiskStatus");
297 | System.out.println(" Grant username pathFolder Access 'for admin only'");
298 | System.out.println(" login username password");
299 | System.out.println(" TellUser");
300 | }
301 | else if(operation.equalsIgnoreCase("TellUser") && numOfParts==1){
302 | System.out.println(">"+currentUser.getUsername());
303 | }
304 | else if(operation.equalsIgnoreCase("CUser") && numOfParts==3){
305 | String [] arr=command.split(" ");
306 | protection.createUser(arr[1],arr[2],currentUser);
307 | }
308 | else if(operation.equalsIgnoreCase("Grant") && numOfParts==4){
309 | String [] arr=command.split(" ");
310 | protection.grantUser(arr[1],arr[2],arr[3],currentUser,root);
311 | protection.setCapabilitiesFile();
312 | }
313 | else if(operation.equalsIgnoreCase("Login") && numOfParts==3){
314 | String [] arr=command.split(" ");
315 | int idx= protection.login(arr[1],arr[2]);
316 | if(idx!=-1) currentUser=protection.getUsers().get(idx);
317 | }
318 | else {
319 | if(operation.equalsIgnoreCase("CreateFile") && numOfParts==2){
320 | System.out.println(">Please, Enter Size of the File!");
321 | }
322 | else System.out.println(">You Enter command incorrect, you can use command 'help'");
323 | }
324 |
325 | }
326 |
327 | }
328 | }
329 |
--------------------------------------------------------------------------------