Skip to content

Commit 6a4b62f

Browse files
committedNov 29, 2019
fixed path resolvement in ls and added javadoc
1 parent ae13eb7 commit 6a4b62f

29 files changed

+6451
-53
lines changed
 

‎FileSystemException.java

+19
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/**
2+
* Errors that occurs in the filesystem.
3+
*/
14
public class FileSystemException extends Exception {
25
private static final String[] err_msgs = {
36
"Operation not permitted",
@@ -133,16 +136,32 @@ public class FileSystemException extends Exception {
133136
public int errno;
134137
public String name;
135138

139+
/**
140+
* Creates the exception.
141+
*
142+
* @param errno Error number
143+
* @param name Prefix of the error message
144+
*/
136145
public FileSystemException(int errno, String name) {
137146
super(Integer.toString(errno));
138147
this.errno = errno;
139148
this.name = name;
140149
}
141150

151+
/**
152+
* Creates the exception, for no prefix errors.
153+
*
154+
* @param errno Error number
155+
*/
142156
public FileSystemException(int errno) {
143157
this(errno, null);
144158
}
145159

160+
/**
161+
* Prints the error message.
162+
*
163+
* @param prefix Prefix to add before the error message
164+
*/
146165
public void print_err_msg(String prefix) {
147166
if (name != null) {
148167
System.err.println(prefix + ": " + name + ": " + err_msgs[errno - 1]);

‎Helper.java

+4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import java.util.*;
22

3+
/**
4+
* A helper class.
5+
*/
36
public class Helper {
47
public static final String GREY_COL = "\u001b[38;5;245m";
58
public static final String RESET_COL = "\u001b[0m";
9+
610
/**
711
* Outputs an array of bytes as returned by read( ) in a readable
812
* hexadecimal format, perhaps with printable ASCII codes by the side. Need

‎Inode.java

+28-14
Original file line numberDiff line numberDiff line change
@@ -84,20 +84,6 @@ public Inode lookup(String filename) throws FileSystemException { // TODO not ju
8484
throw new FileSystemException(2);
8585
}
8686

87-
// TODO check if needed
88-
public int datablock_pointer() {
89-
return vol.bb.getInt(offset + 40) * 1024;
90-
}
91-
92-
// TODO check if needed
93-
public String filename_color() {
94-
String color_string = new String();
95-
if (is_directory()) {
96-
color_string += Main.BOLD_FONT + Main.BLUE_COL;
97-
}
98-
return color_string;
99-
}
100-
10187
/**
10288
* Gets the owner user id.
10389
*
@@ -206,29 +192,51 @@ public int[] stat() {
206192
return stat;
207193
}
208194

195+
/**
196+
* Creates and returns a DirEntryIterable.
197+
*/
209198
public Iterable<Integer> iter_direntries() {
210199
return new DirEntryIterable();
211200
}
212201

202+
/**
203+
* Iterable for directory entries.
204+
*/
213205
public class DirEntryIterable implements Iterable<Integer> {
214206
public Iterator<Integer> iterator() {
215207
return new DirEntryIterator();
216208
}
217209
}
218210

211+
/**
212+
* Iterator for directory entries.
213+
*/
219214
public class DirEntryIterator implements Iterator<Integer> {
220215
private int direntry_offset;
221216

217+
/**
218+
* Creates the directory entry iterator with the pointer at the first valid directory entry.
219+
*/
222220
public DirEntryIterator() {
223221
direntry_offset = 0;
224222

225223
valid_direntry();
226224
}
227225

226+
/**
227+
* Checks if there's a next directory entry.
228+
*
229+
* @return If there's a next directory entry
230+
*/
228231
public boolean hasNext() {
229232
return direntry_offset < file_size();
230233
}
231234

235+
/**
236+
* Gets the next directory entry position.
237+
*
238+
* @return Position of the next directory
239+
*/
232240
public Integer next() {
233241
if (!hasNext()) {
234242
throw new NoSuchElementException("There are no more directory elements.");
@@ -242,6 +250,9 @@ public Integer next() {
242250
}
243251
}
244252

253+
/**
254+
* Moves to the next valid directory entry.
255+
*/
245256
private void valid_direntry() {
246257
while (hasNext()) {
247258
int datablock_pt = get_datablock_pt(direntry_offset / Volume.BLOCK_LEN);
@@ -252,6 +263,9 @@ private void valid_direntry() {
252263
}
253264
}
254265

266+
/**
267+
* Gets the next directory entry.
268+
*/
255269
private void next_direntry() {
256270
int datablock_pt = get_datablock_pt(direntry_offset / Volume.BLOCK_LEN);
257271
direntry_offset += vol.bb.getShort(datablock_pt + direntry_offset % Volume.BLOCK_LEN + 4);

0 commit comments

Comments
 (0)