diff --git a/src/fs.c b/src/fs.c index 6492a31..b3a514e 100644 --- a/src/fs.c +++ b/src/fs.c @@ -50,7 +50,7 @@ static bool name_ch_is_valid(word ch) return true; if (ch >= '0' && ch <= '9') return true; - return ch == '_' || ch == '-'; + return ch == '_' || ch == '-' || ch == '.'; } static bool name_is_valid(const word *name) @@ -486,7 +486,7 @@ word fs_opendir(Fs *fs, DirCursor *out_cursor, INode *inode) (void)fs; if (inode->mode != INode_Dir) - return -1; // Not a directory. + return 1; // Not a directory. *out_cursor = (DirCursor) { .inode = inode, @@ -539,10 +539,10 @@ DirEntry *fs_readdir(Fs *fs, DirCursor *cursor) word fs_mkdir(Fs *fs, INode *out_inode, INode *parent, const word *name) { if (!name_is_valid(name)) - return -1; // Invalid name. + return 1; // Invalid name. if (dirinode_entry_exists(fs, parent, name)) - return -2; // Entry exists. + return 2; // Entry exists. word inode_id = allocate_inode(fs); make_dir_inode(fs, out_inode, inode_id, parent->id); @@ -554,10 +554,10 @@ word fs_mkdir(Fs *fs, INode *out_inode, INode *parent, const word *name) word fs_rmdir(Fs *fs, INode *inode) { if (inode->mode != INode_Dir) - return -1; // Not a directory. + return 1; // Not a directory. if (inode->blocks_count != 1) - return -2; // Not empty. + return 2; // Not empty. DirCursor cursor; fs_opendir(fs, &cursor, inode); @@ -573,13 +573,13 @@ word fs_rmdir(Fs *fs, INode *inode) fs_closedir(fs, &cursor); if (!is_empty) - return -2; // Not empty; + return 2; // Not empty; // We have cleaned up correctly. assert(inode->blocks_count == 1); if (parent_id == inode->id) - return -3; // Root. + return 3; // Root. INode parent; fs_inode(fs, &parent, parent_id); @@ -593,10 +593,10 @@ word fs_rmdir(Fs *fs, INode *inode) word fs_mkfile(Fs *fs, INode *out_inode, INode *parent, const word *name) { if (!name_is_valid(name)) - return -1; // Invalid name. + return 1; // Invalid name. if (dirinode_entry_exists(fs, parent, name)) - return -2; // Entry exists. + return 2; // Entry exists. word inode_id = allocate_inode(fs); @@ -617,7 +617,7 @@ word fs_mkfile(Fs *fs, INode *out_inode, INode *parent, const word *name) word fs_unlink(Fs *fs, INode *inode, INode *dirinode) { if (inode->mode != INode_File) - return -1; // Not a file. + return 1; // Not a file. remove_inode_from_dir(fs, dirinode, inode->id); write_inode(fs, dirinode); @@ -632,10 +632,10 @@ word fs_unlink(Fs *fs, INode *inode, INode *dirinode) word fs_open(Fs *fs, FileCursor *out_cursor, INode *inode, FileMode mode) { if (inode->mode != INode_File) - return -1; // Not a file. + return 1; // Not a file. if ((mode & File_Trunc) && !(mode & File_Write)) - return -2; // Invalid mode. + return 2; // Invalid mode. if (mode & File_Trunc) inode_deallocate_blocks(fs, inode); @@ -991,11 +991,11 @@ static int do_mkdir(Shell *s) INode inode = { }; word result = fs_mkdir(s->fs, &inode, &parent, name); - if (result == (word)-2) { + if (result == 2) { printf("already exists\n"); return 0; } else if (result != 0) { - printf("error occured\n"); + printf("error occured (status %d)\n", result); return 1; } return 0; @@ -1117,7 +1117,6 @@ static int do_cat(Shell *s) int read; while ((read = fs_read(s->fs, &cursor, buffer, buffer_cap)) > 0) { - printf("read = %d\n", read); for (int i = 0; i < read; ++i) fputc(buffer[i], stdout); words_read += read;