projects
/
pintos-anon
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Revert the bitmap randomization change, which had the side effect of
[pintos-anon]
/
src
/
filesys
/
directory.c
diff --git
a/src/filesys/directory.c
b/src/filesys/directory.c
index 45bbdaed320b3ff801e72588c8518fa670db0bb2..0d265d5da78b7be2ca705a5a9b7eeacfbcd5dfd2 100644
(file)
--- a/
src/filesys/directory.c
+++ b/
src/filesys/directory.c
@@
-10,6
+10,7
@@
struct dir
{
struct inode *inode; /* Backing store. */
struct dir
{
struct inode *inode; /* Backing store. */
+ off_t pos; /* Current position. */
};
/* A single directory entry. */
};
/* A single directory entry. */
@@
-37,6
+38,7
@@
dir_open (struct inode *inode)
if (inode != NULL && dir != NULL)
{
dir->inode = inode;
if (inode != NULL && dir != NULL)
{
dir->inode = inode;
+ dir->pos = 0;
return dir;
}
else
return dir;
}
else
@@
-74,6
+76,13
@@
dir_close (struct dir *dir)
}
}
}
}
+/* Returns the inode encapsulated by DIR. */
+struct inode *
+dir_get_inode (struct dir *dir)
+{
+ return dir->inode;
+}
+
/* Searches DIR for a file with the given NAME.
If successful, returns true, sets *EP to the directory entry
if EP is non-null, and sets *OFSP to the byte offset of the
/* Searches DIR for a file with the given NAME.
If successful, returns true, sets *EP to the directory entry
if EP is non-null, and sets *OFSP to the byte offset of the
@@
-206,15
+215,22
@@
dir_remove (struct dir *dir, const char *name)
return success;
}
return success;
}
-/* Prints the names of the files in DIR to the system console. */
-void
-dir_list (const struct dir *dir)
+/* Reads the next directory entry in DIR and stores the name in
+ NAME. Returns true if successful, false if the directory
+ contains no more entries. */
+bool
+dir_readdir (struct dir *dir, char name[NAME_MAX + 1])
{
struct dir_entry e;
{
struct dir_entry e;
- size_t ofs;
-
- for (ofs = 0; inode_read_at (dir->inode, &e, sizeof e, ofs) == sizeof e;
- ofs += sizeof e)
- if (e.in_use)
- printf ("%s\n", e.name);
+
+ while (inode_read_at (dir->inode, &e, sizeof e, dir->pos) == sizeof e)
+ {
+ dir->pos += sizeof e;
+ if (e.in_use)
+ {
+ strlcpy (name, e.name, NAME_MAX + 1);
+ return true;
+ }
+ }
+ return false;
}
}