Skip to content

Commit

Permalink
added iupdate to list of file system functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jeriksson committed Apr 16, 2015
1 parent d78a7f4 commit 8a36a64
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 17 deletions.
7 changes: 5 additions & 2 deletions defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,17 @@ void iput(struct inode*);
void ilock(struct inode*);
void iunlock(struct inode*);
void iunlockput(struct inode*);
void iupdate(struct inode*);
int namecmp(const char*, const char*);
struct inode* namei(char*);
struct inode* nameiparent(char*, char*);
void stati(struct inode*, struct stat*);
// fs-specific functions that are accessed through inode->i_func

// fs-specific functions that should only be accessed through inode->i_func
int fs_readi(struct inode*, char*, uint, uint);
int fs_writei(struct inode*, char*, uint, uint);
void fs_ipopulate(struct inode* ip);
void fs_iupdate(struct inode*);



// ide.c
Expand Down
18 changes: 15 additions & 3 deletions file.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,22 @@ struct file {
uint off;
};

/* file-system specific functions that are maintained for each
inode. When a new in-memory inode is allocated using iget(),
the parent inode is now passed in, and the functions are inherited.
If no parent is passed in, the standard file-system functions are assigned.
WARNING: this list of functions is likely incomplete, meaning that some operation
may not be supported in new file systems introduced. To improve
generality, add new file system function pointers here as needed.
*/

struct inode_functions {
void (*ipopulate)(struct inode*);
int (*readi)(struct inode*, char*, uint, uint);
int (*writei)(struct inode*, char*, uint, uint);
void (*ipopulate)(struct inode*); // fill in inode details
void (*iupdate)(struct inode*); // write inode details back to disk
int (*readi)(struct inode*, char*, uint, uint); // read from file contents
int (*writei)(struct inode*, char*, uint, uint); // write to file contents
};

#define NDIRECT 12
Expand Down
11 changes: 5 additions & 6 deletions fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ static void itrunc(struct inode*);

// fs inode functions

void fs_ipopulate(struct inode* ip);
struct inode_functions fs_i_func = { fs_ipopulate, fs_readi, fs_writei };
struct inode_functions fs_i_func = { fs_ipopulate, fs_iupdate, fs_readi, fs_writei };

// Read the super block.
void
Expand Down Expand Up @@ -204,7 +203,7 @@ ialloc(uint dev, short type, struct inode* parent)

// Copy a modified in-memory inode to disk.
void
iupdate(struct inode *ip)
fs_iupdate(struct inode *ip)
{
struct buf *bp;
struct dinode *dip;
Expand Down Expand Up @@ -346,7 +345,7 @@ iput(struct inode *ip)
release(&icache.lock);
itrunc(ip);
ip->type = 0;
iupdate(ip);
ip->i_func->iupdate(ip);
acquire(&icache.lock);
ip->flags = 0;
wakeup(ip);
Expand Down Expand Up @@ -435,7 +434,7 @@ itrunc(struct inode *ip)
}

ip->size = 0;
iupdate(ip);
ip->i_func->iupdate(ip);
}

// Copy stat information from inode.
Expand Down Expand Up @@ -506,7 +505,7 @@ fs_writei(struct inode *ip, char *src, uint off, uint n)

if(n > 0 && off > ip->size){
ip->size = off;
iupdate(ip);
ip->i_func->iupdate(ip);
}
return n;
}
Expand Down
12 changes: 6 additions & 6 deletions sysfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ sys_link(void)
}

ip->nlink++;
iupdate(ip);
ip->i_func->iupdate(ip);
iunlock(ip);

if((dp = nameiparent(new, name)) == 0)
Expand All @@ -155,7 +155,7 @@ sys_link(void)
bad:
ilock(ip);
ip->nlink--;
iupdate(ip);
ip->i_func->iupdate(ip);
iunlockput(ip);
end_op();
return -1;
Expand Down Expand Up @@ -217,12 +217,12 @@ sys_unlink(void)
panic("unlink: writei");
if(ip->type == T_DIR){
dp->nlink--;
iupdate(dp);
dp->i_func->iupdate(dp);
}
iunlockput(dp);

ip->nlink--;
iupdate(ip);
ip->i_func->iupdate(ip);
iunlockput(ip);

end_op();
Expand Down Expand Up @@ -262,11 +262,11 @@ create(char *path, short type, short major, short minor)
ip->major = major;
ip->minor = minor;
ip->nlink = 1;
iupdate(ip);
ip->i_func->iupdate(ip);

if(type == T_DIR){ // Create . and .. entries.
dp->nlink++; // for ".."
iupdate(dp);
dp->i_func->iupdate(dp);
// No ip->nlink++ for ".": avoid cyclic ref count.
if(dirlink(ip, ".", ip->inum) < 0 || dirlink(ip, "..", dp->inum) < 0)
panic("create dots");
Expand Down

0 comments on commit 8a36a64

Please sign in to comment.