Skip to content

Commit

Permalink
Debugging minifile_rmdir
Browse files Browse the repository at this point in the history
  • Loading branch information
mtian committed Dec 8, 2012
1 parent dcfb1d1 commit 9874066
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
36 changes: 26 additions & 10 deletions P6/minifile.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,32 +357,48 @@ int minifile_rmdir(char *dirname)
{
inodenum_t inodenum, parent_inodenum;
mem_inode_t ino, parent_ino;
char* parent, *name;

/* Need further changes to handle parent and name */
if (strcmp(dirname, "/") == 0) {
printf("Forbide you remove root!!!\n");
printf("Remove root: permission denied. \n");
return -1;
}

inodenum = namei(dirname);
if (inodenum == 0) {
return -1;
parent = get_path(dirname);
name = get_filename(dirname);

if (parent == NULL) {
parent_inodenum = minithread_wd();
} else {
parent_inodenum = namei(parent);
}
if (iget(maindisk, inodenum, &ino) != 0) {
if (parent_inodenum == 0) {
free(parent);
free(name);
return -1;
}
iget(maindisk, parent_inodenum, &parent_ino);

parent_inodenum = nameinode("..", ino);
if (iget(maindisk, parent_inodenum, &parent_ino) != 0) {
iput(ino);
return -1;
}
/* Do not create dir if duplicate path and name exists */
inodenum = namei(dirname);
if (0 != inodenum) {
return -1;
} else {
inodenum = ialloc(maindisk);
if (0 == inodenum) {
return -1;
}
}
iget(maindisk, inodenum, &ino);

/* When want to create file in this dirctory by other process
* they first grab lock and check if this directory is deleted
* If delete, should return path not found to user
* If this functions grabs lock later, the directory is not empty then
*/
ilock(ino);
printf("got lock.\n");
if (ino->size > 0) {
iunlock(ino);
iput(parent_ino);
Expand Down
2 changes: 1 addition & 1 deletion P6/minifile_fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ fs_format(mem_sblock_t sbp)
bitmap_set(sbp->block_bitmap, i);
}
/* Set inode 0 to be occupied */
bitmap_set(sbp->inode_bitmap, 1);
bitmap_set(sbp->inode_bitmap, 0);
/* Push updates to disk */
for (i = sbp->inode_bitmap_first; i <= sbp->inode_bitmap_last; ++i) {
bpush(i, (char*) sbp->inode_bitmap + (i - sbp->inode_bitmap_first)
Expand Down

0 comments on commit 9874066

Please sign in to comment.