File system project updates:
[pintos-anon] / src / filesys / inode.c
index 98dd36a1a9e5c62a537b2316d3b67bcd753f796d..d890ed8d3c7f0375dc9f3a6a1178254d2c2db011 100644 (file)
@@ -76,6 +76,9 @@ inode_create (disk_sector_t sector, off_t length)
   bool success = false;
 
   ASSERT (length >= 0);
+
+  /* If this assertion fails, the inode structure is not exactly
+     one sector in size, and you should fix that. */
   ASSERT (sizeof *disk_inode == DISK_SECTOR_SIZE);
 
   disk_inode = calloc (1, sizeof *disk_inode);
@@ -140,13 +143,20 @@ inode_open (disk_sector_t sector)
 
 /* Reopens and returns INODE. */
 struct inode *
-inode_reopen (struct inode *inode) 
+inode_reopen (struct inode *inode)
 {
-  if (inode != NULL) 
+  if (inode != NULL)
     inode->open_cnt++;
   return inode;
 }
 
+/* Returns INODE's inode number. */
+disk_sector_t
+inode_get_inumber (const struct inode *inode)
+{
+  return inode->sector;
+}
+
 /* Closes INODE and writes it to disk.
    If this was the last reference to INODE, frees its memory.
    If INODE was also a removed inode, frees its blocks. */
@@ -162,7 +172,7 @@ inode_close (struct inode *inode)
     {
       /* Remove from inode list and release lock. */
       list_remove (&inode->elem);
-
       /* Deallocate blocks if removed. */
       if (inode->removed) 
         {
@@ -258,7 +268,7 @@ inode_write_at (struct inode *inode, const void *buffer_, off_t size,
   while (size > 0) 
     {
       /* Sector to write, starting byte offset within sector. */
-      off_t sector_idx = byte_to_sector (inode, offset);
+      disk_sector_t sector_idx = byte_to_sector (inode, offset);
       int sector_ofs = offset % DISK_SECTOR_SIZE;
 
       /* Bytes left in inode, bytes left in sector, lesser of the two. */