From d039b59b7c09e18285d69469dcd24a6e56f31c3d Mon Sep 17 00:00:00 2001 From: sBubshait Date: Fri, 6 Dec 2024 18:14:47 +0000 Subject: [PATCH] Refactor mmap system call code to follow pintos style in indentation --- src/vm/mmap.c | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/src/vm/mmap.c b/src/vm/mmap.c index 64ad28f..4e5a620 100644 --- a/src/vm/mmap.c +++ b/src/vm/mmap.c @@ -67,26 +67,27 @@ mmap_unmap (struct mmap_entry *mmap) if necessary. */ off_t length = file_length (mmap->file); for (off_t ofs = 0; ofs < length; ofs += PGSIZE) - { - void *upage = mmap->upage + ofs; - - /* Get the SPT page entry for this page. */ - struct page_entry *page = page_get(thread_current (), upage); - if (page == NULL) - continue; - - /* Write the page back to the file if it is dirty. */ - if (pagedir_is_dirty (thread_current ()->pagedir, upage)) { - lock_acquire (&filesys_lock); - file_write_at (mmap->file, upage, page->read_bytes, ofs); - lock_release (&filesys_lock); + void *upage = mmap->upage + ofs; + + /* Get the SPT page entry for this page. */ + struct page_entry *page = page_get(thread_current (), upage); + if (page == NULL) + continue; + + /* Write the page back to the file if it is dirty. */ + if (pagedir_is_dirty (thread_current ()->pagedir, upage)) + { + lock_acquire (&filesys_lock); + file_write_at (mmap->file, upage, page->read_bytes, ofs); + lock_release (&filesys_lock); + } + + /* Remove the page from the supplemental page table. */ + hash_delete (&thread_current ()->pages, &page->elem); } - /* Remove the page from the supplemental page table. */ - hash_delete (&thread_current ()->pages, &page->elem); - } - + /* Close the file and free the mmap entry. */ file_close (mmap->file); free (mmap); } -- 2.49.1