From 3f1ab89acd506bccd47bf9a3a764f0a9985bdaa7 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Fri, 19 May 2006 23:41:59 +0000 Subject: [PATCH] Consistently spell "file name" and "file system" as two words. --- solutions/p2.patch | 54 +++---- solutions/p3.patch | 56 ++++---- solutions/p4.patch | 120 ++++++++-------- src/Makefile.build | 2 +- src/examples/insult.c | 2 +- src/filesys/filesys.c | 18 +-- src/filesys/filesys.h | 2 +- src/filesys/fsutil.c | 50 +++---- src/tests/filesys/base/child-syn-read.c | 8 +- src/tests/filesys/base/child-syn-wrt.c | 6 +- src/tests/filesys/base/random.inc | 14 +- src/tests/filesys/base/syn-read.c | 8 +- src/tests/filesys/base/syn-read.h | 2 +- src/tests/filesys/base/syn-remove.c | 18 +-- src/tests/filesys/base/syn-write.c | 8 +- src/tests/filesys/base/syn-write.h | 2 +- src/tests/filesys/create.inc | 6 +- src/tests/filesys/extended/child-syn-rw.c | 6 +- src/tests/filesys/extended/dir-mk-vine.c | 4 +- src/tests/filesys/extended/dir-rm-vine.c | 10 +- src/tests/filesys/extended/grow-dir.inc | 8 +- src/tests/filesys/extended/grow-sparse.c | 14 +- src/tests/filesys/extended/grow-too-big.c | 12 +- src/tests/filesys/extended/grow-two-files.c | 4 +- src/tests/filesys/extended/syn-rw.c | 6 +- src/tests/filesys/extended/syn-rw.h | 2 +- src/tests/filesys/seq-test.c | 14 +- src/tests/filesys/seq-test.h | 2 +- src/tests/lib.c | 27 ++-- src/tests/lib.h | 6 +- src/threads/init.c | 4 +- src/userprog/process.c | 28 ++-- src/userprog/process.h | 2 +- src/utils/pintos | 152 ++++++++++---------- 34 files changed, 339 insertions(+), 338 deletions(-) diff --git a/solutions/p2.patch b/solutions/p2.patch index 83d91fe..10723eb 100644 --- a/solutions/p2.patch +++ b/solutions/p2.patch @@ -136,17 +136,17 @@ diff -u src/userprog/process.c~ src/userprog/process.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) @@ -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; @@ -154,21 +154,21 @@ diff -u src/userprog/process.c~ src/userprog/process.c + 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) @@ -186,20 +186,20 @@ diff -u src/userprog/process.c~ src/userprog/process.c /* 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) @@ -210,7 +210,7 @@ diff -u src/userprog/process.c~ src/userprog/process.c + } - /* If load failed, quit. */ -- palloc_free_page (filename); +- palloc_free_page (file_name); + /* Initialize wait_status. */ + if (success) + { @@ -226,7 +226,7 @@ diff -u src/userprog/process.c~ src/userprog/process.c if (!success) thread_exit (); -@@ -75,18 +113,47 @@ execute_thread (void *filename_) +@@ -75,18 +113,47 @@ execute_thread (void *file_name_) NOT_REACHED (); } @@ -325,11 +325,11 @@ diff -u src/userprog/process.c~ src/userprog/process.c 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; @@ -338,31 +338,31 @@ diff -u src/userprog/process.c~ src/userprog/process.c 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. */ @@ -371,7 +371,7 @@ diff -u src/userprog/process.c~ src/userprog/process.c 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. */ diff --git a/solutions/p3.patch b/solutions/p3.patch index c452931..773a712 100644 --- a/solutions/p3.patch +++ b/solutions/p3.patch @@ -6,7 +6,7 @@ diff -u src/Makefile.build~ src/Makefile.build 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 @@ -367,17 +367,17 @@ diff -u src/userprog/process.c~ src/userprog/process.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; @@ -385,21 +385,21 @@ diff -u src/userprog/process.c~ src/userprog/process.c + 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) @@ -417,20 +417,20 @@ diff -u src/userprog/process.c~ src/userprog/process.c /* 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) @@ -441,7 +441,7 @@ diff -u src/userprog/process.c~ src/userprog/process.c + } - /* If load failed, quit. */ -- palloc_free_page (filename); +- palloc_free_page (file_name); + /* Initialize wait_status. */ + if (success) + { @@ -457,7 +457,7 @@ diff -u src/userprog/process.c~ src/userprog/process.c if (!success) thread_exit (); -@@ -76,18 +116,47 @@ execute_thread (void *filename_) +@@ -76,18 +116,47 @@ execute_thread (void *file_name_) NOT_REACHED (); } @@ -559,11 +559,11 @@ diff -u src/userprog/process.c~ src/userprog/process.c 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; @@ -572,7 +572,7 @@ diff -u src/userprog/process.c~ src/userprog/process.c 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 (); @@ -582,27 +582,27 @@ diff -u src/userprog/process.c~ src/userprog/process.c + 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. */ @@ -611,7 +611,7 @@ diff -u src/userprog/process.c~ src/userprog/process.c 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. */ diff --git a/solutions/p4.patch b/solutions/p4.patch index 4d8d44a..61ef9e8 100644 --- a/solutions/p4.patch +++ b/solutions/p4.patch @@ -6,7 +6,7 @@ diff -u src/Makefile.build~ src/Makefile.build 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 @@ -780,10 +780,10 @@ diff -u src/filesys/filesys.c~ src/filesys/filesys.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 (); @@ -835,10 +835,10 @@ diff -u src/filesys/filesys.c~ src/filesys/filesys.c +/* 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; @@ -878,14 +878,14 @@ diff -u src/filesys/filesys.c~ src/filesys/filesys.c + + /* 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; } @@ -898,17 +898,17 @@ diff -u src/filesys/filesys.c~ src/filesys/filesys.c +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); @@ -925,7 +925,7 @@ diff -u src/filesys/filesys.c~ src/filesys/filesys.c { - 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) @@ -934,8 +934,8 @@ diff -u src/filesys/filesys.c~ src/filesys/filesys.c + 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); @@ -950,11 +950,11 @@ diff -u src/filesys/filesys.c~ src/filesys/filesys.c - 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 @@ @@ -978,11 +978,11 @@ diff -u src/filesys/filesys.c~ src/filesys/filesys.c + } + 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); @@ -1034,7 +1034,7 @@ diff -u src/filesys/filesys.c~ src/filesys/filesys.c @@ -173,9 +308,13 @@ static void do_format (void) { - printf ("Formatting filesystem..."); + printf ("Formatting file system..."); + + /* Set up free map. */ free_map_create (); @@ -1192,32 +1192,32 @@ diff -u src/filesys/fsutil.c~ src/filesys/fsutil.c @@ -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 @@ -2200,7 +2200,7 @@ diff -u src/userprog/process.c~ src/userprog/process.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. */ @@ -2208,10 +2208,10 @@ diff -u src/userprog/process.c~ src/userprog/process.c + }; /* 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; @@ -2220,23 +2220,23 @@ diff -u src/userprog/process.c~ src/userprog/process.c + 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) @@ -2259,10 +2259,10 @@ diff -u src/userprog/process.c~ src/userprog/process.c /* 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; @@ -2274,11 +2274,11 @@ diff -u src/userprog/process.c~ src/userprog/process.c 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) + { @@ -2302,7 +2302,7 @@ diff -u src/userprog/process.c~ src/userprog/process.c if (!success) thread_exit (); -@@ -76,18 +128,47 @@ execute_thread (void *filename_) +@@ -76,18 +128,47 @@ execute_thread (void *file_name_) NOT_REACHED (); } @@ -2404,11 +2404,11 @@ diff -u src/userprog/process.c~ src/userprog/process.c 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; @@ -2417,7 +2417,7 @@ diff -u src/userprog/process.c~ src/userprog/process.c 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 (); @@ -2427,27 +2427,27 @@ diff -u src/userprog/process.c~ src/userprog/process.c + 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. */ @@ -2456,7 +2456,7 @@ diff -u src/userprog/process.c~ src/userprog/process.c 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. */ diff --git a/src/Makefile.build b/src/Makefile.build index cf0f9b6..8fa804b 100644 --- a/src/Makefile.build +++ b/src/Makefile.build @@ -53,7 +53,7 @@ userprog_SRC += userprog/gdt.c # GDT initialization. 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. diff --git a/src/examples/insult.c b/src/examples/insult.c index 442a3ec..80acc6e 100644 --- a/src/examples/insult.c +++ b/src/examples/insult.c @@ -263,7 +263,7 @@ usage (int ret_code, const char *message, ...) " -h: this help message\n" " -s : set the random seed (default 4951)\n" " -n : choose number of insults (default 4)\n" - " -f : redirect output to a File.\n"); + " -f : redirect output to \n"); exit (ret_code); } diff --git a/src/filesys/filesys.c b/src/filesys/filesys.c index 5cf1d97..5df0d9d 100644 --- a/src/filesys/filesys.c +++ b/src/filesys/filesys.c @@ -8,19 +8,19 @@ #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 (); @@ -31,7 +31,7 @@ filesys_init (bool format) 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) @@ -94,8 +94,8 @@ filesys_remove (const char *name) 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) @@ -150,11 +150,11 @@ must_succeed_function (int line_no, bool success) PANIC ("filesys_self_test: operation failed on line %d", line_no); } -/* 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"); diff --git a/src/filesys/filesys.h b/src/filesys/filesys.h index 9c30c25..5a03f81 100644 --- a/src/filesys/filesys.h +++ b/src/filesys/filesys.h @@ -8,7 +8,7 @@ #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); diff --git a/src/filesys/fsutil.c b/src/filesys/fsutil.c index 14e615f..14a4507 100644 --- a/src/filesys/fsutil.c +++ b/src/filesys/fsutil.c @@ -32,15 +32,15 @@ fsutil_ls (char **argv UNUSED) 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 (;;) { @@ -59,15 +59,15 @@ fsutil_cat (char **argv) 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 @@ -83,13 +83,13 @@ fsutil_put (char **argv) { 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); @@ -104,17 +104,17 @@ fsutil_put (char **argv) /* 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) @@ -123,7 +123,7 @@ fsutil_put (char **argv) 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; } @@ -132,7 +132,7 @@ fsutil_put (char **argv) 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, @@ -148,13 +148,13 @@ fsutil_get (char **argv) { 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); @@ -162,9 +162,9 @@ fsutil_get (char **argv) 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. */ @@ -183,9 +183,9 @@ fsutil_get (char **argv) { 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; diff --git a/src/tests/filesys/base/child-syn-read.c b/src/tests/filesys/base/child-syn-read.c index a7801d4..e426fad 100644 --- a/src/tests/filesys/base/child-syn-read.c +++ b/src/tests/filesys/base/child-syn-read.c @@ -1,7 +1,7 @@ /* 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 @@ -28,12 +28,12 @@ main (int argc, const char *argv[]) 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); diff --git a/src/tests/filesys/base/child-syn-wrt.c b/src/tests/filesys/base/child-syn-wrt.c index 48f1640..1b52584 100644 --- a/src/tests/filesys/base/child-syn-wrt.c +++ b/src/tests/filesys/base/child-syn-wrt.c @@ -24,11 +24,11 @@ main (int argc, char *argv[]) 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; diff --git a/src/tests/filesys/base/random.inc b/src/tests/filesys/base/random.inc index e297854..eeeea68 100644 --- a/src/tests/filesys/base/random.inc +++ b/src/tests/filesys/base/random.inc @@ -19,7 +19,7 @@ int order[BLOCK_CNT]; void test_main (void) { - const char *filename = "bazzle"; + const char *file_name = "bazzle"; int fd; size_t i; @@ -29,10 +29,10 @@ test_main (void) 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++) { @@ -42,7 +42,7 @@ test_main (void) 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++) { @@ -51,9 +51,9 @@ test_main (void) 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); } diff --git a/src/tests/filesys/base/syn-read.c b/src/tests/filesys/base/syn-read.c index 27db471..7c36a42 100644 --- a/src/tests/filesys/base/syn-read.c +++ b/src/tests/filesys/base/syn-read.c @@ -19,11 +19,11 @@ test_main (void) 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); diff --git a/src/tests/filesys/base/syn-read.h b/src/tests/filesys/base/syn-read.h index e8dad42..bff8082 100644 --- a/src/tests/filesys/base/syn-read.h +++ b/src/tests/filesys/base/syn-read.h @@ -2,6 +2,6 @@ #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 */ diff --git a/src/tests/filesys/base/syn-remove.c b/src/tests/filesys/base/syn-remove.c index 7f6cd9f..c9ba110 100644 --- a/src/tests/filesys/base/syn-remove.c +++ b/src/tests/filesys/base/syn-remove.c @@ -13,18 +13,18 @@ char buf2[1234]; 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); } diff --git a/src/tests/filesys/base/syn-write.c b/src/tests/filesys/base/syn-write.c index 19e9d59..1439862 100644 --- a/src/tests/filesys/base/syn-write.c +++ b/src/tests/filesys/base/syn-write.c @@ -19,13 +19,13 @@ test_main (void) 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); } diff --git a/src/tests/filesys/base/syn-write.h b/src/tests/filesys/base/syn-write.h index 2f16765..07a6d5a 100644 --- a/src/tests/filesys/base/syn-write.h +++ b/src/tests/filesys/base/syn-write.h @@ -4,6 +4,6 @@ #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 */ diff --git a/src/tests/filesys/create.inc b/src/tests/filesys/create.inc index 57858cb..4baf771 100644 --- a/src/tests/filesys/create.inc +++ b/src/tests/filesys/create.inc @@ -9,7 +9,7 @@ static char buf[TEST_SIZE]; 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); } diff --git a/src/tests/filesys/extended/child-syn-rw.c b/src/tests/filesys/extended/child-syn-rw.c index 434a542..0e2217d 100644 --- a/src/tests/filesys/extended/child-syn-rw.c +++ b/src/tests/filesys/extended/child-syn-rw.c @@ -33,17 +33,17 @@ main (int argc, const char *argv[]) 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; } } diff --git a/src/tests/filesys/extended/dir-mk-vine.c b/src/tests/filesys/extended/dir-mk-vine.c index 7ac18a1..444727a 100644 --- a/src/tests/filesys/extended/dir-mk-vine.c +++ b/src/tests/filesys/extended/dir-mk-vine.c @@ -10,7 +10,7 @@ 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'; @@ -21,6 +21,6 @@ test_main (void) } 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); } diff --git a/src/tests/filesys/extended/dir-rm-vine.c b/src/tests/filesys/extended/dir-rm-vine.c index c424c04..e01ff49 100644 --- a/src/tests/filesys/extended/dir-rm-vine.c +++ b/src/tests/filesys/extended/dir-rm-vine.c @@ -10,7 +10,7 @@ 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]; @@ -23,16 +23,16 @@ test_main (void) 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); } diff --git a/src/tests/filesys/extended/grow-dir.inc b/src/tests/filesys/extended/grow-dir.inc index ffc32d3..bee0ba0 100644 --- a/src/tests/filesys/extended/grow-dir.inc +++ b/src/tests/filesys/extended/grow-dir.inc @@ -27,13 +27,13 @@ test_main (void) #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; diff --git a/src/tests/filesys/extended/grow-sparse.c b/src/tests/filesys/extended/grow-sparse.c index 135a918..6eab210 100644 --- a/src/tests/filesys/extended/grow-sparse.c +++ b/src/tests/filesys/extended/grow-sparse.c @@ -10,16 +10,16 @@ static char buf[76543]; 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); } diff --git a/src/tests/filesys/extended/grow-too-big.c b/src/tests/filesys/extended/grow-too-big.c index d49fcb2..a908e45 100644 --- a/src/tests/filesys/extended/grow-too-big.c +++ b/src/tests/filesys/extended/grow-too-big.c @@ -9,16 +9,16 @@ 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); } diff --git a/src/tests/filesys/extended/grow-two-files.c b/src/tests/filesys/extended/grow-two-files.c index cc0f5fa..6a8fb1c 100644 --- a/src/tests/filesys/extended/grow-two-files.c +++ b/src/tests/filesys/extended/grow-two-files.c @@ -11,7 +11,7 @@ static char buf_a[FILE_SIZE]; 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) { @@ -23,7 +23,7 @@ write_some_bytes (const char *filename, int fd, const char *buf, size_t *ofs) 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; } } diff --git a/src/tests/filesys/extended/syn-rw.c b/src/tests/filesys/extended/syn-rw.c index f2900d0..657dfb5 100644 --- a/src/tests/filesys/extended/syn-rw.c +++ b/src/tests/filesys/extended/syn-rw.c @@ -18,8 +18,8 @@ test_main (void) 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); @@ -28,7 +28,7 @@ test_main (void) 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); diff --git a/src/tests/filesys/extended/syn-rw.h b/src/tests/filesys/extended/syn-rw.h index 50ad2bb..170aeb4 100644 --- a/src/tests/filesys/extended/syn-rw.h +++ b/src/tests/filesys/extended/syn-rw.h @@ -4,6 +4,6 @@ #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 */ diff --git a/src/tests/filesys/seq-test.c b/src/tests/filesys/seq-test.c index 5494921..8ce222c 100644 --- a/src/tests/filesys/seq-test.c +++ b/src/tests/filesys/seq-test.c @@ -4,7 +4,7 @@ #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)) { @@ -12,11 +12,11 @@ seq_test (const char *filename, void *buf, size_t size, size_t initial_size, 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 (); @@ -25,13 +25,13 @@ seq_test (const char *filename, void *buf, size_t size, size_t initial_size, 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); } diff --git a/src/tests/filesys/seq-test.h b/src/tests/filesys/seq-test.h index e85ff74..0697381 100644 --- a/src/tests/filesys/seq-test.h +++ b/src/tests/filesys/seq-test.h @@ -3,7 +3,7 @@ #include -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)); diff --git a/src/tests/lib.c b/src/tests/lib.c index b1a1cbb..e3b30b8 100644 --- a/src/tests/lib.c +++ b/src/tests/lib.c @@ -106,7 +106,7 @@ wait_children (pid_t pids[], size_t child_cnt) 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; @@ -118,7 +118,7 @@ check_file_handle (int fd, 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) @@ -133,34 +133,35 @@ check_file_handle (int fd, 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_; @@ -179,7 +180,7 @@ compare_bytes (const void *read_data_, const void *expected_data_, size_t size, 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) { @@ -191,5 +192,5 @@ compare_bytes (const void *read_data_, const void *expected_data_, size_t size, 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); } diff --git a/src/tests/lib.h b/src/tests/lib.h index c13e08b..648327b 100644 --- a/src/tests/lib.h +++ b/src/tests/lib.h @@ -40,11 +40,11 @@ void shuffle (void *, size_t cnt, size_t size); 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 */ diff --git a/src/threads/init.c b/src/threads/init.c index ef82cb1..a624ef5 100644 --- a/src/threads/init.c +++ b/src/threads/init.c @@ -46,7 +46,7 @@ uint32_t *base_page_dir; bool enable_mlfqs; #ifdef FILESYS -/* -f: Format the filesystem? */ +/* -f: Format the file system? */ static bool format_filesys; #endif @@ -119,7 +119,7 @@ main (void) timer_calibrate (); #ifdef FILESYS - /* Initialize filesystem. */ + /* Initialize file system. */ disk_init (); filesys_init (format_filesys); #endif diff --git a/src/userprog/process.c b/src/userprog/process.c index 8f5aa59..bece1fe 100644 --- a/src/userprog/process.c +++ b/src/userprog/process.c @@ -26,20 +26,20 @@ static bool load (const char *cmdline, void (**eip) (void), void **esp); 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; @@ -48,9 +48,9 @@ process_execute (const char *filename) /* 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; @@ -59,10 +59,10 @@ execute_thread (void *filename_) 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 (); @@ -200,12 +200,12 @@ static bool load_segment (struct file *file, off_t ofs, uint8_t *upage, 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; @@ -221,10 +221,10 @@ load (const char *filename, void (**eip) (void), void **esp) 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; } @@ -237,7 +237,7 @@ load (const char *filename, void (**eip) (void), void **esp) || 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; } diff --git a/src/userprog/process.h b/src/userprog/process.h index 228c324..688cd2a 100644 --- a/src/userprog/process.h +++ b/src/userprog/process.h @@ -3,7 +3,7 @@ #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); diff --git a/src/utils/pintos b/src/utils/pintos index 214e051..19ef70f 100755 --- a/src/utils/pintos +++ b/src/utils/pintos @@ -70,15 +70,15 @@ sub parse_command_line { "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; } @@ -201,42 +201,42 @@ sub find_disks { 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"; } @@ -268,28 +268,28 @@ sub finish_scratch_disk { # # 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; } @@ -297,28 +297,28 @@ sub put_scratch_file { # # 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; } @@ -345,10 +345,10 @@ sub write_cmd_line { $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"; } # Running simulators. @@ -387,8 +387,8 @@ EOF " 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); @@ -428,7 +428,7 @@ EOF 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, "; @@ -446,8 +446,8 @@ sub run_qemu { 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'; @@ -491,7 +491,7 @@ EOF 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; @@ -539,15 +539,15 @@ EOF 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) @@ -555,13 +555,13 @@ sub open_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) @@ -570,12 +570,12 @@ sub open_disk_copy { # 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"; } } @@ -585,7 +585,7 @@ sub extend_disk { # 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; @@ -599,45 +599,45 @@ sub disk_geometry { 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; } # Subprocess utilities. -- 2.30.2