+ thread. */
+struct exec_info
+ {
-+ const char *filename; /* Program to load. */
++ const char *file_name; /* Program to load. */
+ struct semaphore load_done; /* "Up"ed when loading complete. */
+ struct wait_status *wait_status; /* Child process. */
+ bool success; /* Program successfully loaded? */
+ };
/* Starts a new thread running a user program loaded from
- FILENAME. The new thread may be scheduled (and may even exit)
+ FILE_NAME. The new thread may be scheduled (and may even exit)
@@ -27,29 +39,37 @@ static bool load (const char *cmdline, v
tid_t
- process_execute (const char *filename)
+ process_execute (const char *file_name)
{
- char *fn_copy;
+ struct exec_info exec;
+ char *save_ptr;
tid_t tid;
-- /* Make a copy of FILENAME.
+- /* Make a copy of FILE_NAME.
- Otherwise there's a race between the caller and load(). */
- fn_copy = palloc_get_page (0);
- if (fn_copy == NULL)
- return TID_ERROR;
-- strlcpy (fn_copy, filename, PGSIZE);
+- strlcpy (fn_copy, file_name, PGSIZE);
+ /* Initialize exec_info. */
-+ exec.filename = filename;
++ exec.file_name = file_name;
+ sema_init (&exec.load_done, 0);
- /* Create a new thread to execute FILENAME. */
-- tid = thread_create (filename, PRI_DEFAULT, execute_thread, fn_copy);
+ /* Create a new thread to execute FILE_NAME. */
+- tid = thread_create (file_name, PRI_DEFAULT, execute_thread, fn_copy);
- if (tid == TID_ERROR)
- palloc_free_page (fn_copy);
-+ strlcpy (thread_name, filename, sizeof thread_name);
++ strlcpy (thread_name, file_name, sizeof thread_name);
+ strtok_r (thread_name, " ", &save_ptr);
+ tid = thread_create (thread_name, PRI_DEFAULT, execute_thread, &exec);
+ if (tid != TID_ERROR)
/* A thread function that loads a user process and starts it
running. */
static void
--execute_thread (void *filename_)
+-execute_thread (void *file_name_)
+execute_thread (void *exec_)
{
-- char *filename = filename_;
+- char *file_name = file_name_;
+ struct exec_info *exec = exec_;
struct intr_frame if_;
bool success;
-@@ -58,10 +78,28 @@ execute_thread (void *filename_)
+@@ -58,10 +78,28 @@ execute_thread (void *file_name_)
if_.gs = if_.fs = if_.es = if_.ds = if_.ss = SEL_UDSEG;
if_.cs = SEL_UCSEG;
if_.eflags = FLAG_IF | FLAG_MBS;
-- success = load (filename, &if_.eip, &if_.esp);
-+ success = load (exec->filename, &if_.eip, &if_.esp);
+- success = load (file_name, &if_.eip, &if_.esp);
++ success = load (exec->file_name, &if_.eip, &if_.esp);
+
+ /* Allocate wait_status. */
+ if (success)
+ }
- /* If load failed, quit. */
-- palloc_free_page (filename);
+- palloc_free_page (file_name);
+ /* Initialize wait_status. */
+ if (success)
+ {
if (!success)
thread_exit ();
-@@ -75,18 +113,47 @@ execute_thread (void *filename_)
+@@ -75,18 +113,47 @@ execute_thread (void *file_name_)
NOT_REACHED ();
}
and its initial stack pointer into *ESP.
Returns true if successful, false otherwise. */
bool
--load (const char *filename, void (**eip) (void), void **esp)
+-load (const char *file_name, void (**eip) (void), void **esp)
+load (const char *cmd_line, void (**eip) (void), void **esp)
{
struct thread *t = thread_current ();
-+ char filename[NAME_MAX + 2];
++ char file_name[NAME_MAX + 2];
struct Elf32_Ehdr ehdr;
struct file *file = NULL;
off_t file_ofs;
int i;
/* Allocate and activate page directory. */
-@@ -224,13 +317,22 @@ load (const char *filename, void (**eip)
+@@ -224,13 +317,22 @@ load (const char *file_name, void (**eip)
goto done;
process_activate ();
-+ /* Extract filename from command line. */
++ /* Extract file_name from command line. */
+ while (*cmd_line == ' ')
+ cmd_line++;
-+ strlcpy (filename, cmd_line, sizeof filename);
-+ cp = strchr (filename, ' ');
++ strlcpy (file_name, cmd_line, sizeof file_name);
++ cp = strchr (file_name, ' ');
+ if (cp != NULL)
+ *cp = '\0';
+
/* Open executable file. */
-- file = filesys_open (filename);
-+ t->bin_file = file = filesys_open (filename);
+- file = filesys_open (file_name);
++ t->bin_file = file = filesys_open (file_name);
if (file == NULL)
{
- printf ("load: %s: open failed\n", filename);
+ printf ("load: %s: open failed\n", file_name);
goto done;
}
+ file_deny_write (file);
/* Read and verify executable header. */
if (file_read (file, &ehdr, sizeof ehdr) != sizeof ehdr
-@@ -284,7 +386,7 @@ load (const char *filename, void (**eip)
+@@ -284,7 +386,7 @@ load (const char *file_name, void (**eip)
}
/* Set up stack. */
goto done;
/* Start address. */
-@@ -294,7 +396,6 @@ load (const char *filename, void (**eip)
+@@ -294,7 +396,6 @@ load (const char *file_name, void (**eip)
done:
/* We arrive here whether the load is successful or not. */
userprog_SRC += userprog/tss.c # TSS management.
# No virtual memory code yet.
--#vm_SRC = vm/filename.c # Some file.
+-#vm_SRC = vm/file.c # Some file.
+vm_SRC = vm/page.c
+vm_SRC += vm/frame.c
+vm_SRC += vm/swap.c
+ thread. */
+struct exec_info
+ {
-+ const char *filename; /* Program to load. */
++ const char *file_name; /* Program to load. */
+ struct semaphore load_done; /* "Up"ed when loading complete. */
+ struct wait_status *wait_status; /* Child process. */
+ bool success; /* Program successfully loaded? */
+ };
/* Starts a new thread running a user program loaded from
- FILENAME. The new thread may be scheduled (and may even exit)
+ FILE_NAME. The new thread may be scheduled (and may even exit)
@@ -28,29 +42,37 @@ static bool load (const char *cmdline, v
tid_t
- process_execute (const char *filename)
+ process_execute (const char *file_name)
{
- char *fn_copy;
+ struct exec_info exec;
+ char *save_ptr;
tid_t tid;
-- /* Make a copy of FILENAME.
+- /* Make a copy of FILE_NAME.
- Otherwise there's a race between the caller and load(). */
- fn_copy = palloc_get_page (0);
- if (fn_copy == NULL)
- return TID_ERROR;
-- strlcpy (fn_copy, filename, PGSIZE);
+- strlcpy (fn_copy, file_name, PGSIZE);
+ /* Initialize exec_info. */
-+ exec.filename = filename;
++ exec.file_name = file_name;
+ sema_init (&exec.load_done, 0);
- /* Create a new thread to execute FILENAME. */
-- tid = thread_create (filename, PRI_DEFAULT, execute_thread, fn_copy);
+ /* Create a new thread to execute FILE_NAME. */
+- tid = thread_create (file_name, PRI_DEFAULT, execute_thread, fn_copy);
- if (tid == TID_ERROR)
- palloc_free_page (fn_copy);
-+ strlcpy (thread_name, filename, sizeof thread_name);
++ strlcpy (thread_name, file_name, sizeof thread_name);
+ strtok_r (thread_name, " ", &save_ptr);
+ tid = thread_create (thread_name, PRI_DEFAULT, execute_thread, &exec);
+ if (tid != TID_ERROR)
/* A thread function that loads a user process and starts it
running. */
static void
--execute_thread (void *filename_)
+-execute_thread (void *file_name_)
+execute_thread (void *exec_)
{
-- char *filename = filename_;
+- char *file_name = file_name_;
+ struct exec_info *exec = exec_;
struct intr_frame if_;
bool success;
-@@ -59,10 +81,28 @@ execute_thread (void *filename_)
+@@ -59,10 +81,28 @@ execute_thread (void *file_name_)
if_.gs = if_.fs = if_.es = if_.ds = if_.ss = SEL_UDSEG;
if_.cs = SEL_UCSEG;
if_.eflags = FLAG_IF | FLAG_MBS;
-- success = load (filename, &if_.eip, &if_.esp);
-+ success = load (exec->filename, &if_.eip, &if_.esp);
+- success = load (file_name, &if_.eip, &if_.esp);
++ success = load (exec->file_name, &if_.eip, &if_.esp);
+
+ /* Allocate wait_status. */
+ if (success)
+ }
- /* If load failed, quit. */
-- palloc_free_page (filename);
+- palloc_free_page (file_name);
+ /* Initialize wait_status. */
+ if (success)
+ {
if (!success)
thread_exit ();
-@@ -76,18 +116,47 @@ execute_thread (void *filename_)
+@@ -76,18 +116,47 @@ execute_thread (void *file_name_)
NOT_REACHED ();
}
and its initial stack pointer into *ESP.
Returns true if successful, false otherwise. */
bool
--load (const char *filename, void (**eip) (void), void **esp)
+-load (const char *file_name, void (**eip) (void), void **esp)
+load (const char *cmd_line, void (**eip) (void), void **esp)
{
struct thread *t = thread_current ();
-+ char filename[NAME_MAX + 2];
++ char file_name[NAME_MAX + 2];
struct Elf32_Ehdr ehdr;
struct file *file = NULL;
off_t file_ofs;
int i;
/* Allocate and activate page directory. */
-@@ -220,13 +318,28 @@ load (const char *filename, void (**eip)
+@@ -220,13 +318,28 @@ load (const char *file_name, void (**eip)
goto done;
process_activate ();
+ goto done;
+ hash_init (t->pages, page_hash, page_less, NULL);
+
-+ /* Extract filename from command line. */
++ /* Extract file_name from command line. */
+ while (*cmd_line == ' ')
+ cmd_line++;
-+ strlcpy (filename, cmd_line, sizeof filename);
-+ cp = strchr (filename, ' ');
++ strlcpy (file_name, cmd_line, sizeof file_name);
++ cp = strchr (file_name, ' ');
+ if (cp != NULL)
+ *cp = '\0';
+
/* Open executable file. */
-- file = filesys_open (filename);
-+ t->bin_file = file = filesys_open (filename);
+- file = filesys_open (file_name);
++ t->bin_file = file = filesys_open (file_name);
if (file == NULL)
{
- printf ("load: %s: open failed\n", filename);
+ printf ("load: %s: open failed\n", file_name);
goto done;
}
+ file_deny_write (t->bin_file);
/* Read and verify executable header. */
if (file_read (file, &ehdr, sizeof ehdr) != sizeof ehdr
-@@ -301,7 +414,7 @@ load (const char *filename, void (**eip)
+@@ -301,7 +414,7 @@ load (const char *file_name, void (**eip)
}
/* Set up stack. */
goto done;
/* Start address. */
-@@ -311,14 +424,11 @@ load (const char *filename, void (**eip)
+@@ -311,14 +424,11 @@ load (const char *file_name, void (**eip)
done:
/* We arrive here whether the load is successful or not. */
userprog_SRC += userprog/tss.c # TSS management.
# No virtual memory code yet.
--#vm_SRC = vm/filename.c # Some file.
+-#vm_SRC = vm/file.c # Some file.
+vm_SRC = vm/page.c
+vm_SRC += vm/frame.c
+vm_SRC += vm/swap.c
#include "devices/disk.h"
+#include "threads/thread.h"
- /* The disk that contains the filesystem. */
+ /* The disk that contains the file system. */
struct disk *filesys_disk;
@@ -23,6 +25,7 @@ filesys_init (bool format)
- PANIC ("hd0:1 (hdb) not present, filesystem initialization failed");
+ PANIC ("hd0:1 (hdb) not present, file system initialization failed");
inode_init ();
+ cache_init ();
+/* Resolves relative or absolute file NAME.
+ Returns true if successful, false on failure.
+ Stores the directory corresponding to the name into *DIRP,
-+ and the file name part into BASENAME. */
++ and the file name part into BASE_NAME. */
+static bool
+resolve_name (const char *name,
-+ struct dir **dirp, char basename[NAME_MAX + 1])
++ struct dir **dirp, char base_name[NAME_MAX + 1])
+{
+ struct dir *dir = NULL;
+ struct inode *inode;
+
+ /* Return our results. */
+ *dirp = dir;
-+ strlcpy (basename, part, NAME_MAX + 1);
++ strlcpy (base_name, part, NAME_MAX + 1);
+ return true;
+
+ error:
+ /* Return failure. */
+ dir_close (dir);
+ *dirp = NULL;
-+ basename[0] = '\0';
++ base_name[0] = '\0';
+ return false;
}
\f
+filesys_create (const char *name, off_t initial_size, enum inode_type type)
{
+ struct dir *dir;
-+ char basename[NAME_MAX + 1];
++ char base_name[NAME_MAX + 1];
disk_sector_t inode_sector = 0;
- struct dir *dir = dir_open_root ();
- bool success = (dir != NULL
- && free_map_allocate (1, &inode_sector)
- && inode_create (inode_sector, initial_size)
- && dir_add (dir, name, inode_sector));
-+ bool success = (resolve_name (name, &dir, basename)
++ bool success = (resolve_name (name, &dir, base_name)
+ && free_map_allocate (&inode_sector)
+ && inode_create (inode_sector, initial_size, type)
-+ && dir_add (dir, basename, inode_sector));
++ && dir_add (dir, base_name, inode_sector));
if (!success && inode_sector != 0)
- free_map_release (inode_sector, 1);
+ free_map_release (inode_sector);
{
- struct dir *dir = dir_open_root ();
+ struct dir *dir = NULL;
-+ char basename[NAME_MAX + 1];
++ char base_name[NAME_MAX + 1];
struct inode *inode = NULL;
- if (dir != NULL)
+ inode = inode_open (ROOT_DIR_SECTOR);
+ else if (!strcmp (name, "."))
+ inode = inode_reopen (dir_get_inode (thread_current ()->wd));
-+ else if (resolve_name (name, &dir, basename))
-+ dir_lookup (dir, basename, &inode);
++ else if (resolve_name (name, &dir, base_name))
++ dir_lookup (dir, base_name, &inode);
dir_close (dir);
- return file_open (inode);
- struct dir *dir = dir_open_root ();
- bool success = dir != NULL && dir_remove (dir, name);
+ struct dir *dir = NULL;
-+ char basename[NAME_MAX + 1];
++ char base_name[NAME_MAX + 1];
+ bool success = false;
+
-+ if (resolve_name (name, &dir, basename))
-+ success = dir_remove (dir, basename);
++ if (resolve_name (name, &dir, base_name))
++ success = dir_remove (dir, base_name);
dir_close (dir);
@@ -91,5 +193,44 @@
+ }
+ else
+ {
-+ char basename[NAME_MAX + 1];
++ char base_name[NAME_MAX + 1];
+ struct inode *base_inode;
+ struct dir *base_dir;
-+ if (!resolve_name (name, &dir, basename)
-+ || !dir_lookup (dir, basename, &base_inode)
++ if (!resolve_name (name, &dir, base_name)
++ || !dir_lookup (dir, base_name, &base_inode)
+ || (base_dir = dir_open (base_inode)) == NULL)
+ {
+ dir_close (dir);
@@ -173,9 +308,13 @@ static void
do_format (void)
{
- printf ("Formatting filesystem...");
+ printf ("Formatting file system...");
+
+ /* Set up free map. */
free_map_create ();
@@ -30,7 +30,7 @@ fsutil_cat (char **argv)
char *buffer;
- printf ("Printing '%s' to the console...\n", filename);
-- file = filesys_open (filename);
-+ file = file_open (filesys_open (filename));
+ printf ("Printing '%s' to the console...\n", file_name);
+- file = filesys_open (file_name);
++ file = file_open (filesys_open (file_name));
if (file == NULL)
- PANIC ("%s: open failed", filename);
+ PANIC ("%s: open failed", file_name);
buffer = palloc_get_page (PAL_ASSERT);
@@ -102,9 +102,9 @@ fsutil_put (char **argv)
- PANIC ("%s: invalid file size %d", filename, size);
+ PANIC ("%s: invalid file size %d", file_name, size);
/* Create destination file. */
-- if (!filesys_create (filename, size))
-+ if (!filesys_create (filename, size, FILE_INODE))
- PANIC ("%s: create failed", filename);
-- dst = filesys_open (filename);
-+ dst = file_open (filesys_open (filename));
+- if (!filesys_create (file_name, size))
++ if (!filesys_create (file_name, size, FILE_INODE))
+ PANIC ("%s: create failed", file_name);
+- dst = filesys_open (file_name);
++ dst = file_open (filesys_open (file_name));
if (dst == NULL)
- PANIC ("%s: open failed", filename);
+ PANIC ("%s: open failed", file_name);
@@ -154,7 +154,7 @@ fsutil_get (char **argv)
PANIC ("couldn't allocate buffer");
/* Open source file. */
-- src = filesys_open (filename);
-+ src = file_open (filesys_open (filename));
+- src = filesys_open (file_name);
++ src = file_open (filesys_open (file_name));
if (src == NULL)
- PANIC ("%s: open failed", filename);
+ PANIC ("%s: open failed", file_name);
size = file_length (src);
Index: src/filesys/inode.c
diff -u src/filesys/inode.c~ src/filesys/inode.c
+ thread. */
+struct exec_info
+ {
-+ const char *filename; /* Program to load. */
++ const char *file_name; /* Program to load. */
+ struct semaphore load_done; /* "Up"ed when loading complete. */
+ struct wait_status *wait_status; /* Child process. */
+ struct dir *wd; /* Working directory. */
+ };
/* Starts a new thread running a user program loaded from
- FILENAME. The new thread may be scheduled (and may even exit)
+ FILE_NAME. The new thread may be scheduled (and may even exit)
@@ -28,41 +43,78 @@ static bool load (const char *cmdline, v
tid_t
- process_execute (const char *filename)
+ process_execute (const char *file_name)
{
- char *fn_copy;
+ struct dir *wd = thread_current ()->wd;
+ char *save_ptr;
tid_t tid;
-- /* Make a copy of FILENAME.
+- /* Make a copy of FILE_NAME.
- Otherwise there's a race between the caller and load(). */
- fn_copy = palloc_get_page (0);
- if (fn_copy == NULL)
+ /* Initialize exec_info. */
-+ exec.filename = filename;
++ exec.file_name = file_name;
+ exec.wd = wd != NULL ? dir_reopen (wd) : dir_open_root ();
+ if (exec.wd == NULL)
return TID_ERROR;
-- strlcpy (fn_copy, filename, PGSIZE);
+- strlcpy (fn_copy, file_name, PGSIZE);
+ sema_init (&exec.load_done, 0);
- /* Create a new thread to execute FILENAME. */
-- tid = thread_create (filename, PRI_DEFAULT, execute_thread, fn_copy);
+ /* Create a new thread to execute FILE_NAME. */
+- tid = thread_create (file_name, PRI_DEFAULT, execute_thread, fn_copy);
- if (tid == TID_ERROR)
- palloc_free_page (fn_copy);
-+ strlcpy (thread_name, filename, sizeof thread_name);
++ strlcpy (thread_name, file_name, sizeof thread_name);
+ strtok_r (thread_name, " ", &save_ptr);
+ tid = thread_create (thread_name, PRI_DEFAULT, execute_thread, &exec);
+ if (tid != TID_ERROR)
/* A thread function that loads a user process and starts it
running. */
static void
--execute_thread (void *filename_)
+-execute_thread (void *file_name_)
+execute_thread (void *exec_)
{
-- char *filename = filename_;
+- char *file_name = file_name_;
+ struct exec_info *exec = exec_;
struct intr_frame if_;
bool success;
if_.gs = if_.fs = if_.es = if_.ds = if_.ss = SEL_UDSEG;
if_.cs = SEL_UCSEG;
if_.eflags = FLAG_IF | FLAG_MBS;
-- success = load (filename, &if_.eip, &if_.esp);
-+ success = load (exec->filename, &if_.eip, &if_.esp);
+- success = load (file_name, &if_.eip, &if_.esp);
++ success = load (exec->file_name, &if_.eip, &if_.esp);
- /* If load failed, quit. */
-- palloc_free_page (filename);
+- palloc_free_page (file_name);
+ /* Allocate wait_status. */
+ if (success)
+ {
if (!success)
thread_exit ();
-@@ -76,18 +128,47 @@ execute_thread (void *filename_)
+@@ -76,18 +128,47 @@ execute_thread (void *file_name_)
NOT_REACHED ();
}
and its initial stack pointer into *ESP.
Returns true if successful, false otherwise. */
bool
--load (const char *filename, void (**eip) (void), void **esp)
+-load (const char *file_name, void (**eip) (void), void **esp)
+load (const char *cmd_line, void (**eip) (void), void **esp)
{
struct thread *t = thread_current ();
-+ char filename[NAME_MAX + 2];
++ char file_name[NAME_MAX + 2];
struct Elf32_Ehdr ehdr;
struct file *file = NULL;
off_t file_ofs;
int i;
/* Allocate and activate page directory. */
-@@ -220,13 +330,28 @@ load (const char *filename, void (**eip)
+@@ -220,13 +330,28 @@ load (const char *file_name, void (**eip)
goto done;
process_activate ();
+ goto done;
+ hash_init (t->pages, page_hash, page_less, NULL);
+
-+ /* Extract filename from command line. */
++ /* Extract file_name from command line. */
+ while (*cmd_line == ' ')
+ cmd_line++;
-+ strlcpy (filename, cmd_line, sizeof filename);
-+ cp = strchr (filename, ' ');
++ strlcpy (file_name, cmd_line, sizeof file_name);
++ cp = strchr (file_name, ' ');
+ if (cp != NULL)
+ *cp = '\0';
+
/* Open executable file. */
-- file = filesys_open (filename);
-+ t->bin_file = file = file_open (filesys_open (filename));
+- file = filesys_open (file_name);
++ t->bin_file = file = file_open (filesys_open (file_name));
if (file == NULL)
{
- printf ("load: %s: open failed\n", filename);
+ printf ("load: %s: open failed\n", file_name);
goto done;
}
+ file_deny_write (file);
/* Read and verify executable header. */
if (file_read (file, &ehdr, sizeof ehdr) != sizeof ehdr
-@@ -301,7 +426,7 @@ load (const char *filename, void (**eip)
+@@ -301,7 +426,7 @@ load (const char *file_name, void (**eip)
}
/* Set up stack. */
goto done;
/* Start address. */
-@@ -311,14 +436,11 @@ load (const char *filename, void (**eip)
+@@ -311,14 +436,11 @@ load (const char *file_name, void (**eip)
done:
/* We arrive here whether the load is successful or not. */
userprog_SRC += userprog/tss.c # TSS management.
# No virtual memory code yet.
-#vm_SRC = vm/filename.c # Some file.
+#vm_SRC = vm/file.c # Some file.
# Filesystem code.
filesys_SRC = filesys/filesys.c # Filesystem core.
" -h: this help message\n"
" -s <integer>: set the random seed (default 4951)\n"
" -n <integer>: choose number of insults (default 4)\n"
- " -f <filename>: redirect output to a File.\n");
+ " -f <file>: redirect output to <file>\n");
exit (ret_code);
}
#include "filesys/directory.h"
#include "devices/disk.h"
-/* The disk that contains the filesystem. */
+/* The disk that contains the file system. */
struct disk *filesys_disk;
static void do_format (void);
-/* Initializes the filesystem module.
- If FORMAT is true, reformats the filesystem. */
+/* Initializes the file system module.
+ If FORMAT is true, reformats the file system. */
void
filesys_init (bool format)
{
filesys_disk = disk_get (0, 1);
if (filesys_disk == NULL)
- PANIC ("hd0:1 (hdb) not present, filesystem initialization failed");
+ PANIC ("hd0:1 (hdb) not present, file system initialization failed");
inode_init ();
free_map_init ();
free_map_open ();
}
-/* Shuts down the filesystem module, writing any unwritten data
+/* Shuts down the file system module, writing any unwritten data
to disk. */
void
filesys_done (void)
static void must_succeed_function (int, bool) NO_INLINE;
#define MUST_SUCCEED(EXPR) must_succeed_function (__LINE__, EXPR)
-/* Performs basic sanity checks on the filesystem.
- The filesystem should not contain a file named `foo' when
+/* Performs basic sanity checks on the file system.
+ The file system should not contain a file named `foo' when
called. */
void
filesys_self_test (void)
PANIC ("filesys_self_test: operation failed on line %d", line_no);
}
\f
-/* Formats the filesystem. */
+/* Formats the file system. */
static void
do_format (void)
{
- printf ("Formatting filesystem...");
+ printf ("Formatting file system...");
free_map_create ();
if (!dir_create (ROOT_DIR_SECTOR, 16))
PANIC ("root directory creation failed");
#define FREE_MAP_SECTOR 0 /* Free map file inode sector. */
#define ROOT_DIR_SECTOR 1 /* Root directory file inode sector. */
-/* Disk used for filesystem. */
+/* Disk used for file system. */
extern struct disk *filesys_disk;
void filesys_init (bool format);
void
fsutil_cat (char **argv)
{
- const char *filename = argv[1];
+ const char *file_name = argv[1];
struct file *file;
char *buffer;
- printf ("Printing '%s' to the console...\n", filename);
- file = filesys_open (filename);
+ printf ("Printing '%s' to the console...\n", file_name);
+ file = filesys_open (file_name);
if (file == NULL)
- PANIC ("%s: open failed", filename);
+ PANIC ("%s: open failed", file_name);
buffer = palloc_get_page (PAL_ASSERT);
for (;;)
{
void
fsutil_rm (char **argv)
{
- const char *filename = argv[1];
+ const char *file_name = argv[1];
- printf ("Deleting '%s'...\n", filename);
- if (!filesys_remove (filename))
- PANIC ("%s: delete failed\n", filename);
+ printf ("Deleting '%s'...\n", file_name);
+ if (!filesys_remove (file_name))
+ PANIC ("%s: delete failed\n", file_name);
}
/* Copies from the "scratch" disk, hdc or hd1:0 to file ARGV[1]
- in the filesystem.
+ in the file system.
The current sector on the scratch disk must begin with the
string "PUT\0" followed by a 32-bit little-endian integer
{
static disk_sector_t sector = 0;
- const char *filename = argv[1];
+ const char *file_name = argv[1];
struct disk *src;
struct file *dst;
off_t size;
void *buffer;
- printf ("Putting '%s' into the file system...\n", filename);
+ printf ("Putting '%s' into the file system...\n", file_name);
/* Allocate buffer. */
buffer = malloc (DISK_SECTOR_SIZE);
/* Read file size. */
disk_read (src, sector++, buffer);
if (memcmp (buffer, "PUT", 4))
- PANIC ("%s: missing PUT signature on scratch disk", filename);
+ PANIC ("%s: missing PUT signature on scratch disk", file_name);
size = ((int32_t *) buffer)[1];
if (size < 0)
- PANIC ("%s: invalid file size %d", filename, size);
+ PANIC ("%s: invalid file size %d", file_name, size);
/* Create destination file. */
- if (!filesys_create (filename, size))
- PANIC ("%s: create failed", filename);
- dst = filesys_open (filename);
+ if (!filesys_create (file_name, size))
+ PANIC ("%s: create failed", file_name);
+ dst = filesys_open (file_name);
if (dst == NULL)
- PANIC ("%s: open failed", filename);
+ PANIC ("%s: open failed", file_name);
/* Do copy. */
while (size > 0)
disk_read (src, sector++, buffer);
if (file_write (dst, buffer, chunk_size) != chunk_size)
PANIC ("%s: write failed with %"PROTd" bytes unwritten",
- filename, size);
+ file_name, size);
size -= chunk_size;
}
free (buffer);
}
-/* Copies file FILENAME from the file system to the scratch disk.
+/* Copies file FILE_NAME from the file system to the scratch disk.
The current sector on the scratch disk will receive "GET\0"
followed by the file's size in bytes as a 32-bit,
{
static disk_sector_t sector = 0;
- const char *filename = argv[1];
+ const char *file_name = argv[1];
void *buffer;
struct file *src;
struct disk *dst;
off_t size;
- printf ("Getting '%s' from the file system...\n", filename);
+ printf ("Getting '%s' from the file system...\n", file_name);
/* Allocate buffer. */
buffer = malloc (DISK_SECTOR_SIZE);
PANIC ("couldn't allocate buffer");
/* Open source file. */
- src = filesys_open (filename);
+ src = filesys_open (file_name);
if (src == NULL)
- PANIC ("%s: open failed", filename);
+ PANIC ("%s: open failed", file_name);
size = file_length (src);
/* Open target disk. */
{
int chunk_size = size > DISK_SECTOR_SIZE ? DISK_SECTOR_SIZE : size;
if (sector >= disk_size (dst))
- PANIC ("%s: out of space on scratch disk", filename);
+ PANIC ("%s: out of space on scratch disk", file_name);
if (file_read (src, buffer, chunk_size) != chunk_size)
- PANIC ("%s: read failed with %"PROTd" bytes unread", filename, size);
+ PANIC ("%s: read failed with %"PROTd" bytes unread", file_name, size);
memset (buffer + chunk_size, 0, DISK_SECTOR_SIZE - chunk_size);
disk_write (dst, sector++, buffer);
size -= chunk_size;
/* Child process for syn-read test.
Reads the contents of a test file a byte at a time, in the
hope that this will take long enough that we can get a
- significant amount of contention in the kernel filesystem
+ significant amount of contention in the kernel file system
code. */
#include <random.h>
random_init (0);
random_bytes (buf, sizeof buf);
- CHECK ((fd = open (filename)) > 1, "open \"%s\"", filename);
+ CHECK ((fd = open (file_name)) > 1, "open \"%s\"", file_name);
for (i = 0; i < sizeof buf; i++)
{
char c;
- CHECK (read (fd, &c, 1) > 0, "read \"%s\"", filename);
- compare_bytes (&c, buf + i, 1, i, filename);
+ CHECK (read (fd, &c, 1) > 0, "read \"%s\"", file_name);
+ compare_bytes (&c, buf + i, 1, i, file_name);
}
close (fd);
random_init (0);
random_bytes (buf, sizeof buf);
- CHECK ((fd = open (filename)) > 1, "open \"%s\"", filename);
+ CHECK ((fd = open (file_name)) > 1, "open \"%s\"", file_name);
seek (fd, CHUNK_SIZE * child_idx);
CHECK (write (fd, buf + CHUNK_SIZE * child_idx, CHUNK_SIZE) > 0,
- "write \"%s\"", filename);
- msg ("close \"%s\"", filename);
+ "write \"%s\"", file_name);
+ msg ("close \"%s\"", file_name);
close (fd);
return child_idx;
void
test_main (void)
{
- const char *filename = "bazzle";
+ const char *file_name = "bazzle";
int fd;
size_t i;
for (i = 0; i < BLOCK_CNT; i++)
order[i] = i;
- CHECK (create (filename, TEST_SIZE), "create \"%s\"", filename);
- CHECK ((fd = open (filename)) > 1, "open \"%s\"", filename);
+ CHECK (create (file_name, TEST_SIZE), "create \"%s\"", file_name);
+ CHECK ((fd = open (file_name)) > 1, "open \"%s\"", file_name);
- msg ("write \"%s\" in random order", filename);
+ msg ("write \"%s\" in random order", file_name);
shuffle (order, BLOCK_CNT, sizeof *order);
for (i = 0; i < BLOCK_CNT; i++)
{
fail ("write %d bytes at offset %zu failed", (int) BLOCK_SIZE, ofs);
}
- msg ("read \"%s\" in random order", filename);
+ msg ("read \"%s\" in random order", file_name);
shuffle (order, BLOCK_CNT, sizeof *order);
for (i = 0; i < BLOCK_CNT; i++)
{
seek (fd, ofs);
if (read (fd, block, BLOCK_SIZE) != BLOCK_SIZE)
fail ("read %d bytes at offset %zu failed", (int) BLOCK_SIZE, ofs);
- compare_bytes (block, buf + ofs, BLOCK_SIZE, ofs, filename);
+ compare_bytes (block, buf + ofs, BLOCK_SIZE, ofs, file_name);
}
- msg ("close \"%s\"", filename);
+ msg ("close \"%s\"", file_name);
close (fd);
}
pid_t children[CHILD_CNT];
int fd;
- CHECK (create (filename, sizeof buf), "create \"%s\"", filename);
- CHECK ((fd = open (filename)) > 1, "open \"%s\"", filename);
+ CHECK (create (file_name, sizeof buf), "create \"%s\"", file_name);
+ CHECK ((fd = open (file_name)) > 1, "open \"%s\"", file_name);
random_bytes (buf, sizeof buf);
- CHECK (write (fd, buf, sizeof buf) > 0, "write \"%s\"", filename);
- msg ("close \"%s\"", filename);
+ CHECK (write (fd, buf, sizeof buf) > 0, "write \"%s\"", file_name);
+ msg ("close \"%s\"", file_name);
close (fd);
exec_children ("child-syn-read", children, CHILD_CNT);
#define TESTS_FILESYS_BASE_SYN_READ_H
#define BUF_SIZE 1024
-static const char filename[] = "data";
+static const char file_name[] = "data";
#endif /* tests/filesys/base/syn-read.h */
void
test_main (void)
{
- const char *filename = "deleteme";
+ const char *file_name = "deleteme";
int fd;
- CHECK (create (filename, sizeof buf1), "create \"%s\"", filename);
- CHECK ((fd = open (filename)) > 1, "open \"%s\"", filename);
- CHECK (remove (filename), "remove \"%s\"", filename);
+ CHECK (create (file_name, sizeof buf1), "create \"%s\"", file_name);
+ CHECK ((fd = open (file_name)) > 1, "open \"%s\"", file_name);
+ CHECK (remove (file_name), "remove \"%s\"", file_name);
random_bytes (buf1, sizeof buf1);
- CHECK (write (fd, buf1, sizeof buf1) > 0, "write \"%s\"", filename);
- msg ("seek \"%s\" to 0", filename);
+ CHECK (write (fd, buf1, sizeof buf1) > 0, "write \"%s\"", file_name);
+ msg ("seek \"%s\" to 0", file_name);
seek (fd, 0);
- CHECK (read (fd, buf2, sizeof buf2) > 0, "read \"%s\"", filename);
- compare_bytes (buf2, buf1, sizeof buf1, 0, filename);
- msg ("close \"%s\"", filename);
+ CHECK (read (fd, buf2, sizeof buf2) > 0, "read \"%s\"", file_name);
+ compare_bytes (buf2, buf1, sizeof buf1, 0, file_name);
+ msg ("close \"%s\"", file_name);
close (fd);
}
pid_t children[CHILD_CNT];
int fd;
- CHECK (create (filename, sizeof buf1), "create \"%s\"", filename);
+ CHECK (create (file_name, sizeof buf1), "create \"%s\"", file_name);
exec_children ("child-syn-wrt", children, CHILD_CNT);
wait_children (children, CHILD_CNT);
- CHECK ((fd = open (filename)) > 1, "open \"%s\"", filename);
- CHECK (read (fd, buf1, sizeof buf1) > 0, "read \"%s\"", filename);
+ CHECK ((fd = open (file_name)) > 1, "open \"%s\"", file_name);
+ CHECK (read (fd, buf1, sizeof buf1) > 0, "read \"%s\"", file_name);
random_bytes (buf2, sizeof buf2);
- compare_bytes (buf1, buf2, sizeof buf1, 0, filename);
+ compare_bytes (buf1, buf2, sizeof buf1, 0, file_name);
}
#define CHILD_CNT 10
#define CHUNK_SIZE 512
#define BUF_SIZE (CHILD_CNT * CHUNK_SIZE)
-static const char filename[] = "stuff";
+static const char file_name[] = "stuff";
#endif /* tests/filesys/base/syn-write.h */
void
test_main (void)
{
- const char *filename = "blargle";
- CHECK (create (filename, TEST_SIZE), "create \"%s\"", filename);
- check_file (filename, buf, TEST_SIZE);
+ const char *file_name = "blargle";
+ CHECK (create (file_name, TEST_SIZE), "create \"%s\"", file_name);
+ check_file (file_name, buf, TEST_SIZE);
}
random_init (0);
random_bytes (buf1, sizeof buf1);
- CHECK ((fd = open (filename)) > 1, "open \"%s\"", filename);
+ CHECK ((fd = open (file_name)) > 1, "open \"%s\"", file_name);
ofs = 0;
while (ofs < sizeof buf2)
{
int bytes_read = read (fd, buf2 + ofs, sizeof buf2 - ofs);
CHECK (bytes_read >= -1 && bytes_read <= (int) (sizeof buf2 - ofs),
"%zu-byte read on \"%s\" returned invalid value of %d",
- sizeof buf2 - ofs, filename, bytes_read);
+ sizeof buf2 - ofs, file_name, bytes_read);
if (bytes_read > 0)
{
- compare_bytes (buf2 + ofs, buf1 + ofs, bytes_read, ofs, filename);
+ compare_bytes (buf2 + ofs, buf1 + ofs, bytes_read, ofs, file_name);
ofs += bytes_read;
}
}
void
test_main (void)
{
- const char *filename = "/0/1/2/3/4/5/6/7/8/9/test";
+ const char *file_name = "/0/1/2/3/4/5/6/7/8/9/test";
char dir[2];
dir[1] = '\0';
}
CHECK (create ("test", 512), "create \"test\"");
CHECK (chdir ("/"), "chdir \"/\"");
- CHECK (open (filename) > 1, "open \"%s\"", filename);
+ CHECK (open (file_name) > 1, "open \"%s\"", file_name);
}
void
test_main (void)
{
- const char *filename = "/0/1/2/3/4/5/6/7/8/9/test";
+ const char *file_name = "/0/1/2/3/4/5/6/7/8/9/test";
int fd;
char tmp[128];
CHECK (create ("test", 512), "create \"test\"");
CHECK (chdir ("/"), "chdir \"/\"");
- CHECK ((fd = open (filename)) > 1, "open \"%s\"", filename);
- msg ("close \"%s\"", filename);
+ CHECK ((fd = open (file_name)) > 1, "open \"%s\"", file_name);
+ msg ("close \"%s\"", file_name);
close (fd);
- strlcpy (tmp, filename, sizeof tmp);
+ strlcpy (tmp, file_name, sizeof tmp);
while (strlen (tmp) > 0)
{
CHECK (remove (tmp), "remove \"%s\"", tmp);
*strrchr (tmp, '/') = 0;
}
- CHECK (open (filename) == -1, "open \"%s\" (must return -1)", filename);
+ CHECK (open (file_name) == -1, "open \"%s\" (must return -1)", file_name);
}
#endif
for (i = 0; i < FILE_CNT; i++)
{
- char filename[128];
- snprintf (filename, sizeof filename, "%sfile%zu", DIR_PREFIX, i);
+ char file_name[128];
+ snprintf (file_name, sizeof file_name, "%sfile%zu", DIR_PREFIX, i);
- msg ("creating and checking \"%s\"", filename);
+ msg ("creating and checking \"%s\"", file_name);
quiet = true;
- seq_test (filename,
+ seq_test (file_name,
buf, sizeof buf, sizeof buf,
return_block_size, NULL);
quiet = false;
void
test_main (void)
{
- const char *filename = "testfile";
+ const char *file_name = "testfile";
char zero = 0;
int fd;
- CHECK (create (filename, 0), "create \"%s\"", filename);
- CHECK ((fd = open (filename)) > 1, "open \"%s\"", filename);
- msg ("seek \"%s\"", filename);
+ CHECK (create (file_name, 0), "create \"%s\"", file_name);
+ CHECK ((fd = open (file_name)) > 1, "open \"%s\"", file_name);
+ msg ("seek \"%s\"", file_name);
seek (fd, sizeof buf - 1);
- CHECK (write (fd, &zero, 1) > 0, "write \"%s\"", filename);
- msg ("close \"%s\"", filename);
+ CHECK (write (fd, &zero, 1) > 0, "write \"%s\"", file_name);
+ msg ("close \"%s\"", file_name);
close (fd);
- check_file (filename, buf, sizeof buf);
+ check_file (file_name, buf, sizeof buf);
}
void
test_main (void)
{
- const char *filename = "fumble";
+ const char *file_name = "fumble";
char zero = 0;
int fd;
- CHECK (create (filename, 0), "create \"%s\"", filename);
- CHECK ((fd = open (filename)) > 1, "open \"%s\"", filename);
- msg ("seek \"%s\"", filename);
+ CHECK (create (file_name, 0), "create \"%s\"", file_name);
+ CHECK ((fd = open (file_name)) > 1, "open \"%s\"", file_name);
+ msg ("seek \"%s\"", file_name);
seek (fd, UINT_MAX);
- msg ("write \"%s\"", filename);
+ msg ("write \"%s\"", file_name);
write (fd, &zero, 1);
- msg ("close \"%s\"", filename);
+ msg ("close \"%s\"", file_name);
close (fd);
}
static char buf_b[FILE_SIZE];
static void
-write_some_bytes (const char *filename, int fd, const char *buf, size_t *ofs)
+write_some_bytes (const char *file_name, int fd, const char *buf, size_t *ofs)
{
if (*ofs < FILE_SIZE)
{
ret_val = write (fd, buf + *ofs, block_size);
if (ret_val != block_size)
fail ("write %zu bytes at offset %zu in \"%s\" returned %zu",
- block_size, *ofs, filename, ret_val);
+ block_size, *ofs, file_name, ret_val);
*ofs += block_size;
}
}
size_t ofs;
int fd;
- CHECK (create (filename, 0), "create \"%s\"", filename);
- CHECK ((fd = open (filename)) > 1, "open \"%s\"", filename);
+ CHECK (create (file_name, 0), "create \"%s\"", file_name);
+ CHECK ((fd = open (file_name)) > 1, "open \"%s\"", file_name);
exec_children ("child-syn-rw", children, CHILD_CNT);
for (ofs = 0; ofs < BUF_SIZE; ofs += CHUNK_SIZE)
CHECK (write (fd, buf + ofs, CHUNK_SIZE) > 0,
"write %d bytes at offset %zu in \"%s\"",
- (int) CHUNK_SIZE, ofs, filename);
+ (int) CHUNK_SIZE, ofs, file_name);
quiet = false;
wait_children (children, CHILD_CNT);
#define CHUNK_SIZE 8
#define CHUNK_CNT 512
#define BUF_SIZE (CHUNK_SIZE * CHUNK_CNT)
-static const char filename[] = "logfile";
+static const char file_name[] = "logfile";
#endif /* tests/filesys/extended/syn-rw.h */
#include "tests/lib.h"
void
-seq_test (const char *filename, void *buf, size_t size, size_t initial_size,
+seq_test (const char *file_name, void *buf, size_t size, size_t initial_size,
size_t (*block_size_func) (void),
void (*check_func) (int fd, long ofs))
{
int fd;
random_bytes (buf, size);
- CHECK (create (filename, initial_size), "create \"%s\"", filename);
- CHECK ((fd = open (filename)) > 1, "open \"%s\"", filename);
+ CHECK (create (file_name, initial_size), "create \"%s\"", file_name);
+ CHECK ((fd = open (file_name)) > 1, "open \"%s\"", file_name);
ofs = 0;
- msg ("writing \"%s\"", filename);
+ msg ("writing \"%s\"", file_name);
while (ofs < size)
{
size_t block_size = block_size_func ();
if (write (fd, buf + ofs, block_size) != (int) block_size)
fail ("write %zu bytes at offset %zu in \"%s\" failed",
- block_size, ofs, filename);
+ block_size, ofs, file_name);
ofs += block_size;
if (check_func != NULL)
check_func (fd, ofs);
}
- msg ("close \"%s\"", filename);
+ msg ("close \"%s\"", file_name);
close (fd);
- check_file (filename, buf, size);
+ check_file (file_name, buf, size);
}
#include <stddef.h>
-void seq_test (const char *filename,
+void seq_test (const char *file_name,
void *buf, size_t size, size_t initial_size,
size_t (*block_size_func) (void),
void (*check_func) (int fd, long ofs));
void
check_file_handle (int fd,
- const char *filename, const void *buf_, size_t size)
+ const char *file_name, const void *buf_, size_t size)
{
const char *buf = buf_;
size_t ofs = 0;
file_size = filesize (fd);
if (file_size != size)
msg ("size of %s (%zu) differs from expected (%zu)",
- filename, file_size, size);
+ file_name, file_size, size);
/* Read the file block-by-block, comparing data as we go. */
while (ofs < size)
ret_val = read (fd, block, block_size);
if (ret_val != block_size)
fail ("read of %zu bytes at offset %zu in \"%s\" returned %zu",
- block_size, ofs, filename, ret_val);
+ block_size, ofs, file_name, ret_val);
- compare_bytes (block, buf + ofs, block_size, ofs, filename);
+ compare_bytes (block, buf + ofs, block_size, ofs, file_name);
ofs += block_size;
}
/* Now fail due to wrong file size. */
if (file_size != size)
fail ("size of %s (%zu) differs from expected (%zu)",
- filename, file_size, size);
+ file_name, file_size, size);
- msg ("verified contents of \"%s\"", filename);
+ msg ("verified contents of \"%s\"", file_name);
}
void
-check_file (const char *filename, const void *buf, size_t size)
+check_file (const char *file_name, const void *buf, size_t size)
{
int fd;
- CHECK ((fd = open (filename)) > 1, "open \"%s\" for verification", filename);
- check_file_handle (fd, filename, buf, size);
- msg ("close \"%s\"", filename);
+ CHECK ((fd = open (file_name)) > 1, "open \"%s\" for verification",
+ file_name);
+ check_file_handle (fd, file_name, buf, size);
+ msg ("close \"%s\"", file_name);
close (fd);
}
void
compare_bytes (const void *read_data_, const void *expected_data_, size_t size,
- size_t ofs, const char *filename)
+ size_t ofs, const char *file_name)
{
const uint8_t *read_data = read_data_;
const uint8_t *expected_data = expected_data_;
quiet = false;
msg ("%zu bytes read starting at offset %zu in \"%s\" differ "
- "from expected.", j - i, ofs + i, filename);
+ "from expected.", j - i, ofs + i, file_name);
show_cnt = j - i;
if (j - i > 64)
{
msg ("Expected data:");
hex_dump (ofs + i, expected_data + i, show_cnt, true);
fail ("%zu bytes read starting at offset %zu in \"%s\" differ "
- "from expected", j - i, ofs, filename);
+ "from expected", j - i, ofs, file_name);
}
void exec_children (const char *child_name, pid_t pids[], size_t child_cnt);
void wait_children (pid_t pids[], size_t child_cnt);
-void check_file_handle (int fd, const char *filename,
+void check_file_handle (int fd, const char *file_name,
const void *buf_, size_t filesize);
-void check_file (const char *filename, const void *buf, size_t filesize);
+void check_file (const char *file_name, const void *buf, size_t filesize);
void compare_bytes (const void *read_data, const void *expected_data,
- size_t size, size_t ofs, const char *filename);
+ size_t size, size_t ofs, const char *file_name);
#endif /* test/lib.h */
bool enable_mlfqs;
#ifdef FILESYS
-/* -f: Format the filesystem? */
+/* -f: Format the file system? */
static bool format_filesys;
#endif
timer_calibrate ();
#ifdef FILESYS
- /* Initialize filesystem. */
+ /* Initialize file system. */
disk_init ();
filesys_init (format_filesys);
#endif
before process_execute() returns. Returns the new process's
thread id, or TID_ERROR if the thread cannot be created. */
tid_t
-process_execute (const char *filename)
+process_execute (const char *file_name)
{
char *fn_copy;
tid_t tid;
- /* Make a copy of FILENAME.
+ /* Make a copy of FILE_NAME.
Otherwise there's a race between the caller and load(). */
fn_copy = palloc_get_page (0);
if (fn_copy == NULL)
return TID_ERROR;
- strlcpy (fn_copy, filename, PGSIZE);
+ strlcpy (fn_copy, file_name, PGSIZE);
- /* Create a new thread to execute FILENAME. */
- tid = thread_create (filename, PRI_DEFAULT, execute_thread, fn_copy);
+ /* Create a new thread to execute FILE_NAME. */
+ tid = thread_create (file_name, PRI_DEFAULT, execute_thread, fn_copy);
if (tid == TID_ERROR)
palloc_free_page (fn_copy);
return tid;
/* A thread function that loads a user process and starts it
running. */
static void
-execute_thread (void *filename_)
+execute_thread (void *file_name_)
{
- char *filename = filename_;
+ char *file_name = file_name_;
struct intr_frame if_;
bool success;
if_.gs = if_.fs = if_.es = if_.ds = if_.ss = SEL_UDSEG;
if_.cs = SEL_UCSEG;
if_.eflags = FLAG_IF | FLAG_MBS;
- success = load (filename, &if_.eip, &if_.esp);
+ success = load (file_name, &if_.eip, &if_.esp);
/* If load failed, quit. */
- palloc_free_page (filename);
+ palloc_free_page (file_name);
if (!success)
thread_exit ();
uint32_t read_bytes, uint32_t zero_bytes,
bool writable);
-/* Loads an ELF executable from FILENAME into the current thread.
+/* Loads an ELF executable from FILE_NAME into the current thread.
Stores the executable's entry point into *EIP
and its initial stack pointer into *ESP.
Returns true if successful, false otherwise. */
bool
-load (const char *filename, void (**eip) (void), void **esp)
+load (const char *file_name, void (**eip) (void), void **esp)
{
struct thread *t = thread_current ();
struct Elf32_Ehdr ehdr;
process_activate ();
/* Open executable file. */
- file = filesys_open (filename);
+ file = filesys_open (file_name);
if (file == NULL)
{
- printf ("load: %s: open failed\n", filename);
+ printf ("load: %s: open failed\n", file_name);
goto done;
}
|| ehdr.e_phentsize != sizeof (struct Elf32_Phdr)
|| ehdr.e_phnum > 1024)
{
- printf ("load: %s: error loading executable\n", filename);
+ printf ("load: %s: error loading executable\n", file_name);
goto done;
}
#include "threads/thread.h"
-tid_t process_execute (const char *filename);
+tid_t process_execute (const char *file_name);
int process_wait (tid_t);
void process_exit (void);
void process_activate (void);
"h|help" => sub { usage (0); },
- "os-disk=s" => \$disks{OS}{FILENAME},
- "fs-disk=s" => \$disks{FS}{FILENAME},
- "scratch-disk=s" => \$disks{SCRATCH}{FILENAME},
- "swap-disk=s" => \$disks{SWAP}{FILENAME},
-
- "0|disk-0|hda=s" => \$disks_by_iface[0]{FILENAME},
- "1|disk-1|hdb=s" => \$disks_by_iface[1]{FILENAME},
- "2|disk-2|hdc=s" => \$disks_by_iface[2]{FILENAME},
- "3|disk-3|hdd=s" => \$disks_by_iface[3]{FILENAME})
+ "os-disk=s" => \$disks{OS}{FILE_NAME},
+ "fs-disk=s" => \$disks{FS}{FILE_NAME},
+ "scratch-disk=s" => \$disks{SCRATCH}{FILE_NAME},
+ "swap-disk=s" => \$disks{SWAP}{FILE_NAME},
+
+ "0|disk-0|hda=s" => \$disks_by_iface[0]{FILE_NAME},
+ "1|disk-1|hdb=s" => \$disks_by_iface[1]{FILE_NAME},
+ "2|disk-2|hdc=s" => \$disks_by_iface[2]{FILE_NAME},
+ "3|disk-3|hdd=s" => \$disks_by_iface[3]{FILE_NAME})
or exit 1;
}
for my $disk (values %disks) {
# If there's no assigned file name but the default file exists,
# try to assign a default file name.
- if (!defined ($disk->{FILENAME})) {
+ if (!defined ($disk->{FILE_NAME})) {
for my $try_fn ($disk->{DEF_FN}, "build/" . $disk->{DEF_FN}) {
- $disk->{FILENAME} = $try_fn, last
+ $disk->{FILE_NAME} = $try_fn, last
if -e $try_fn;
}
}
# If there's no file name, we're done.
- next if !defined ($disk->{FILENAME});
+ next if !defined ($disk->{FILE_NAME});
- if ($disk->{FILENAME} =~ /^\d+(\.\d+)?|\.\d+$/) {
+ if ($disk->{FILE_NAME} =~ /^\d+(\.\d+)?|\.\d+$/) {
# Create a temporary disk of approximately the specified
# size in megabytes.
die "OS disk can't be temporary\n" if $disk == $disks{OS};
- my ($mb) = $disk->{FILENAME};
- undef $disk->{FILENAME};
+ my ($mb) = $disk->{FILE_NAME};
+ undef $disk->{FILE_NAME};
my ($cyl_size) = 512 * 16 * 63;
extend_disk ($disk, ceil ($mb * 2) * $cyl_size);
} else {
# The file must exist and have nonzero size.
- -e $disk->{FILENAME} or die "$disk->{FILENAME}: stat: $!\n";
- -s _ or die "$disk->{FILENAME}: disk has zero size\n";
+ -e $disk->{FILE_NAME} or die "$disk->{FILE_NAME}: stat: $!\n";
+ -s _ or die "$disk->{FILE_NAME}: disk has zero size\n";
}
}
# Warn about (potentially) missing disks.
- die "Cannot find OS disk\n" if !defined $disks{OS}{FILENAME};
+ die "Cannot find OS disk\n" if !defined $disks{OS}{FILE_NAME};
if (my ($project) = `pwd` =~ /\b(threads|userprog|vm|filesys)\b/) {
if ((grep ($project eq $_, qw (userprog vm filesys)))
- && !defined ($disks{FS}{FILENAME})) {
+ && !defined ($disks{FS}{FILE_NAME})) {
print STDERR "warning: it looks like you're running the $project ";
print STDERR "project, but no file system disk is present\n";
}
- if ($project eq 'vm' && !defined $disks{SWAP}{FILENAME}) {
+ if ($project eq 'vm' && !defined $disks{SWAP}{FILE_NAME}) {
print STDERR "warning: it looks like you're running the $project ";
print STDERR "project, but no swap disk is present\n";
}
#
# Copies $file into the scratch disk.
sub put_scratch_file {
- my ($put_filename) = @_;
- my ($disk_handle, $disk_filename) = open_disk ($disks{SCRATCH});
+ my ($put_file_name) = @_;
+ my ($disk_handle, $disk_file_name) = open_disk ($disks{SCRATCH});
- print "Copying $put_filename into $disk_filename...\n";
+ print "Copying $put_file_name into $disk_file_name...\n";
# Write metadata sector, which consists of a 4-byte signature
# followed by the file size.
- stat $put_filename or die "$put_filename: stat: $!\n";
+ stat $put_file_name or die "$put_file_name: stat: $!\n";
my ($size) = -s _;
my ($metadata) = pack ("a4 V x504", "PUT\0", $size);
- write_fully ($disk_handle, $disk_filename, $metadata);
+ write_fully ($disk_handle, $disk_file_name, $metadata);
# Copy file data.
my ($put_handle);
- sysopen ($put_handle, $put_filename, O_RDONLY)
- or die "$put_filename: open: $!\n";
- copy_file ($put_handle, $put_filename, $disk_handle, $disk_filename,
+ sysopen ($put_handle, $put_file_name, O_RDONLY)
+ or die "$put_file_name: open: $!\n";
+ copy_file ($put_handle, $put_file_name, $disk_handle, $disk_file_name,
$size);
close ($put_handle);
# Round up disk data to beginning of next sector.
- write_fully ($disk_handle, $disk_filename, "\0" x (512 - $size % 512))
+ write_fully ($disk_handle, $disk_file_name, "\0" x (512 - $size % 512))
if $size % 512;
}
#
# Copies from the scratch disk to $file.
sub get_scratch_file {
- my ($get_filename) = @_;
- my ($disk_handle, $disk_filename) = open_disk ($disks{SCRATCH});
+ my ($get_file_name) = @_;
+ my ($disk_handle, $disk_file_name) = open_disk ($disks{SCRATCH});
- print "Copying $get_filename out of $disk_filename...\n";
+ print "Copying $get_file_name out of $disk_file_name...\n";
# Read metadata sector, which has a 4-byte signature followed by
# the file size.
- my ($metadata) = read_fully ($disk_handle, $disk_filename, 512);
+ my ($metadata) = read_fully ($disk_handle, $disk_file_name, 512);
my ($signature, $size) = unpack ("a4 V", $metadata);
die "bad signature reading scratch disk--did Pintos run correctly?\n"
if $signature ne "GET\0";
# Copy file data.
my ($get_handle);
- sysopen ($get_handle, $get_filename, O_WRONLY | O_CREAT | O_EXCL, 0666)
- or die "$get_filename: create: $!\n";
- copy_file ($disk_handle, $disk_filename, $get_handle, $get_filename,
+ sysopen ($get_handle, $get_file_name, O_WRONLY | O_CREAT | O_EXCL, 0666)
+ or die "$get_file_name: create: $!\n";
+ copy_file ($disk_handle, $disk_file_name, $get_handle, $get_file_name,
$size);
close ($get_handle);
# Skip forward in disk up to beginning of next sector.
- read_fully ($disk_handle, $disk_filename, 512 - $size % 512)
+ read_fully ($disk_handle, $disk_file_name, 512 - $size % 512)
if $size % 512;
}
\f
$args .= "\0" x (128 - length ($args));
# Write command line.
- my ($handle, $filename) = open_disk_copy ($disk);
- print "Writing command line to $filename...\n";
- sysseek ($handle, 0x17a, 0) == 0x17a or die "$filename: seek: $!\n";
- syswrite ($handle, "$arg_cnt$args") or die "$filename: write: $!\n";
+ my ($handle, $file_name) = open_disk_copy ($disk);
+ print "Writing command line to $file_name...\n";
+ sysseek ($handle, 0x17a, 0) == 0x17a or die "$file_name: seek: $!\n";
+ syswrite ($handle, "$arg_cnt$args") or die "$file_name: write: $!\n";
}
\f
# Running simulators.
" time0=0\n";
print_bochs_disk_line ("ata0-master", 0);
print_bochs_disk_line ("ata0-slave", 1);
- if (defined ($disks_by_iface[2]{FILENAME})
- || defined ($disks_by_iface[3]{FILENAME})) {
+ if (defined ($disks_by_iface[2]{FILE_NAME})
+ || defined ($disks_by_iface[3]{FILE_NAME})) {
print BOCHSRC "ata1: enabled=1, ioaddr1=0x170, ",
"ioaddr2=0x370, irq=15\n";
print_bochs_disk_line ("ata1-master", 2);
sub print_bochs_disk_line {
my ($device, $iface) = @_;
my ($disk) = $disks_by_iface[$iface];
- my ($file) = $disk->{FILENAME};
+ my ($file) = $disk->{FILE_NAME};
if (defined $file) {
my (%geom) = disk_geometry ($disk);
print BOCHSRC "$device: type=disk, path=$file, mode=flat, ";
my (@cmd) = ('qemu');
for my $iface (0...3) {
my ($option) = ('-hda', '-hdb', '-hdc', '-hdd')[$iface];
- push (@cmd, $option, $disks_by_iface[$iface]{FILENAME})
- if defined $disks_by_iface[$iface]{FILENAME};
+ push (@cmd, $option, $disks_by_iface[$iface]{FILE_NAME})
+ if defined $disks_by_iface[$iface]{FILE_NAME};
}
push (@cmd, '-m', $mem);
push (@cmd, '-nographic') if $vga eq 'none';
for (my ($i) = 0; $i < 4; $i++) {
my ($disk) = $disks_by_iface[$i];
- my ($dsk) = $disk->{FILENAME};
+ my ($dsk) = $disk->{FILE_NAME};
next if !defined $dsk;
my ($pln) = $dsk;
sub open_disk {
my ($disk) = @_;
if (!defined ($disk->{HANDLE})) {
- if ($disk->{FILENAME}) {
- sysopen ($disk->{HANDLE}, $disk->{FILENAME}, O_RDWR)
- or die "$disk->{FILENAME}: open: $!\n";
+ if ($disk->{FILE_NAME}) {
+ sysopen ($disk->{HANDLE}, $disk->{FILE_NAME}, O_RDWR)
+ or die "$disk->{FILE_NAME}: open: $!\n";
} else {
- ($disk->{HANDLE}, $disk->{FILENAME}) = tempfile (UNLINK => 1,
+ ($disk->{HANDLE}, $disk->{FILE_NAME}) = tempfile (UNLINK => 1,
SUFFIX => '.dsk');
}
}
- return ($disk->{HANDLE}, $disk->{FILENAME});
+ return ($disk->{HANDLE}, $disk->{FILE_NAME});
}
# open_disk_copy($disk)
# Makes a temporary copy of $disk and returns its file handle and file name.
sub open_disk_copy {
my ($disk) = @_;
- die if !$disk->{FILENAME};
+ die if !$disk->{FILE_NAME};
- my ($orig_handle, $orig_filename) = open_disk ($disk);
- my ($cp_handle, $cp_filename) = tempfile (UNLINK => 1, SUFFIX => '.dsk');
- copy_file ($orig_handle, $orig_filename, $cp_handle, $cp_filename,
+ my ($orig_handle, $orig_file_name) = open_disk ($disk);
+ my ($cp_handle, $cp_file_name) = tempfile (UNLINK => 1, SUFFIX => '.dsk');
+ copy_file ($orig_handle, $orig_file_name, $cp_handle, $cp_file_name,
-s $orig_handle);
- return ($disk->{HANDLE}, $disk->{FILENAME}) = ($cp_handle, $cp_filename);
+ return ($disk->{HANDLE}, $disk->{FILE_NAME}) = ($cp_handle, $cp_file_name);
}
# extend_disk($disk, $size)
# long.
sub extend_disk {
my ($disk, $size) = @_;
- my ($handle, $filename) = open_disk ($disk);
+ my ($handle, $file_name) = open_disk ($disk);
if (-s ($handle) < $size) {
sysseek ($handle, $size - 1, 0) == $size - 1
- or die "$filename: seek: $!\n";
+ or die "$file_name: seek: $!\n";
syswrite ($handle, "\0") == 1
- or die "$filename: write: $!\n";
+ or die "$file_name: write: $!\n";
}
}
# hash.
sub disk_geometry {
my ($disk) = @_;
- my ($file) = $disk->{FILENAME};
+ my ($file) = $disk->{FILE_NAME};
my ($size) = -s $file;
die "$file: stat: $!\n" if !defined $size;
die "$file: size not a multiple of 512 bytes\n" if $size % 512;
S => 63);
}
-# copy_file($from_handle, $from_filename, $to_handle, $to_filename, $size)
+# copy_file($from_handle, $from_file_name, $to_handle, $to_file_name, $size)
#
# Copies $size bytes from $from_handle to $to_handle.
-# $from_filename and $to_filename are used in error messages.
+# $from_file_name and $to_file_name are used in error messages.
sub copy_file {
- my ($from_handle, $from_filename, $to_handle, $to_filename, $size) = @_;
+ my ($from_handle, $from_file_name, $to_handle, $to_file_name, $size) = @_;
while ($size > 0) {
my ($chunk_size) = 4096;
$chunk_size = $size if $chunk_size > $size;
$size -= $chunk_size;
- my ($data) = read_fully ($from_handle, $from_filename, $chunk_size);
- write_fully ($to_handle, $to_filename, $data);
+ my ($data) = read_fully ($from_handle, $from_file_name, $chunk_size);
+ write_fully ($to_handle, $to_file_name, $data);
}
}
-# read_fully($handle, $filename, $bytes)
+# read_fully($handle, $file_name, $bytes)
#
# Reads exactly $bytes bytes from $handle and returns the data read.
-# $filename is used in error messages.
+# $file_name is used in error messages.
sub read_fully {
- my ($handle, $filename, $bytes) = @_;
+ my ($handle, $file_name, $bytes) = @_;
my ($data);
my ($read_bytes) = sysread ($handle, $data, $bytes);
- die "$filename: read: $!\n" if !defined $read_bytes;
- die "$filename: unexpected end of file\n" if $read_bytes != $bytes;
+ die "$file_name: read: $!\n" if !defined $read_bytes;
+ die "$file_name: unexpected end of file\n" if $read_bytes != $bytes;
return $data;
}
-# write_fully($handle, $filename, $data)
+# write_fully($handle, $file_name, $data)
#
# Write $data to $handle.
-# $filename is used in error messages.
+# $file_name is used in error messages.
sub write_fully {
- my ($handle, $filename, $data) = @_;
+ my ($handle, $file_name, $data) = @_;
my ($written_bytes) = syswrite ($handle, $data);
- die "$filename: write: $!\n" if !defined $written_bytes;
- die "$filename: short write\n" if $written_bytes != length $data;
+ die "$file_name: write: $!\n" if !defined $written_bytes;
+ die "$file_name: short write\n" if $written_bytes != length $data;
}
\f
# Subprocess utilities.