projects
/
pintos-anon
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fsutil_ls must close the directory after reading it
[pintos-anon]
/
src
/
filesys
/
fsutil.c
diff --git
a/src/filesys/fsutil.c
b/src/filesys/fsutil.c
index bf2c15466af77514211de9ca9e79b54f677ed905..5f045d64a5ad076f02d686007687d0a93a082f90 100644
(file)
--- a/
src/filesys/fsutil.c
+++ b/
src/filesys/fsutil.c
@@
-7,7
+7,6
@@
#include "filesys/directory.h"
#include "filesys/file.h"
#include "filesys/filesys.h"
#include "filesys/directory.h"
#include "filesys/file.h"
#include "filesys/filesys.h"
-#include "devices/disk.h"
#include "threads/malloc.h"
#include "threads/palloc.h"
#include "threads/vaddr.h"
#include "threads/malloc.h"
#include "threads/palloc.h"
#include "threads/vaddr.h"
@@
-25,6
+24,7
@@
fsutil_ls (char **argv UNUSED)
PANIC ("root dir open failed");
while (dir_readdir (dir, name))
printf ("%s\n", name);
PANIC ("root dir open failed");
while (dir_readdir (dir, name))
printf ("%s\n", name);
+ dir_close (dir);
printf ("End of listing.\n");
}
printf ("End of listing.\n");
}
@@
-67,28
+67,29
@@
fsutil_rm (char **argv)
PANIC ("%s: delete failed\n", file_name);
}
PANIC ("%s: delete failed\n", file_name);
}
-/* Extracts a ustar-format tar archive from the scratch
disk, hdc
-
or hd1:0,
into the Pintos file system. */
+/* Extracts a ustar-format tar archive from the scratch
block
+
device
into the Pintos file system. */
void
fsutil_extract (char **argv UNUSED)
{
void
fsutil_extract (char **argv UNUSED)
{
- static
dis
k_sector_t sector = 0;
+ static
bloc
k_sector_t sector = 0;
- struct
dis
k *src;
+ struct
bloc
k *src;
void *header, *data;
/* Allocate buffers. */
void *header, *data;
/* Allocate buffers. */
- header = malloc (
DIS
K_SECTOR_SIZE);
- data = malloc (
DIS
K_SECTOR_SIZE);
+ header = malloc (
BLOC
K_SECTOR_SIZE);
+ data = malloc (
BLOC
K_SECTOR_SIZE);
if (header == NULL || data == NULL)
PANIC ("couldn't allocate buffers");
if (header == NULL || data == NULL)
PANIC ("couldn't allocate buffers");
- /* Open source
disk
. */
- src =
disk_get (1, 0
);
+ /* Open source
block device
. */
+ src =
block_get_role (BLOCK_SCRATCH
);
if (src == NULL)
if (src == NULL)
- PANIC ("couldn't open scratch d
isk (hdc or hd1:0)
");
+ PANIC ("couldn't open scratch d
evice
");
- printf ("Extracting ustar archive from scratch disk into file system...\n");
+ printf ("Extracting ustar archive from scratch device "
+ "into file system...\n");
for (;;)
{
for (;;)
{
@@
-98,7
+99,7
@@
fsutil_extract (char **argv UNUSED)
int size;
/* Read and parse ustar header. */
int size;
/* Read and parse ustar header. */
-
dis
k_read (src, sector++, header);
+
bloc
k_read (src, sector++, header);
error = ustar_parse_header (header, &file_name, &type, &size);
if (error != NULL)
PANIC ("bad ustar header in sector %"PRDSNu" (%s)", sector - 1, error);
error = ustar_parse_header (header, &file_name, &type, &size);
if (error != NULL)
PANIC ("bad ustar header in sector %"PRDSNu" (%s)", sector - 1, error);
@@
-126,10
+127,10
@@
fsutil_extract (char **argv UNUSED)
/* Do copy. */
while (size > 0)
{
/* Do copy. */
while (size > 0)
{
- int chunk_size = (size >
DIS
K_SECTOR_SIZE
- ?
DIS
K_SECTOR_SIZE
+ int chunk_size = (size >
BLOC
K_SECTOR_SIZE
+ ?
BLOC
K_SECTOR_SIZE
: size);
: size);
-
dis
k_read (src, sector++, data);
+
bloc
k_read (src, sector++, data);
if (file_write (dst, data, chunk_size) != chunk_size)
PANIC ("%s: write failed with %d bytes unwritten",
file_name, size);
if (file_write (dst, data, chunk_size) != chunk_size)
PANIC ("%s: write failed with %d bytes unwritten",
file_name, size);
@@
-141,42
+142,42
@@
fsutil_extract (char **argv UNUSED)
}
}
}
}
- /* Erase the ustar header from the start of the
disk, so that
- the extraction operation is idempotent. We erase two blocks
- because two blocks of zeros are the ustar end-of-archive
- marker. */
+ /* Erase the ustar header from the start of the
block device,
+ so that the extraction operation is idempotent. We erase
+ two blocks because two blocks of zeros are the ustar
+
end-of-archive
marker. */
printf ("Erasing ustar archive...\n");
printf ("Erasing ustar archive...\n");
- memset (header, 0,
DIS
K_SECTOR_SIZE);
-
dis
k_write (src, 0, header);
-
dis
k_write (src, 1, header);
+ memset (header, 0,
BLOC
K_SECTOR_SIZE);
+
bloc
k_write (src, 0, header);
+
bloc
k_write (src, 1, header);
free (data);
free (header);
}
/* Copies file FILE_NAME from the file system to the scratch
free (data);
free (header);
}
/* Copies file FILE_NAME from the file system to the scratch
- d
isk
, in ustar format.
+ d
evice
, in ustar format.
The first call to this function will write starting at the
The first call to this function will write starting at the
- beginning of the scratch d
isk. Later calls advance across the
-
disk
. This position is independent of that used for
+ beginning of the scratch d
evice. Later calls advance across
+
the device
. This position is independent of that used for
fsutil_extract(), so `extract' should precede all
`append's. */
void
fsutil_append (char **argv)
{
fsutil_extract(), so `extract' should precede all
`append's. */
void
fsutil_append (char **argv)
{
- static
dis
k_sector_t sector = 0;
+ static
bloc
k_sector_t sector = 0;
const char *file_name = argv[1];
void *buffer;
struct file *src;
const char *file_name = argv[1];
void *buffer;
struct file *src;
- struct
dis
k *dst;
+ struct
bloc
k *dst;
off_t size;
off_t size;
- printf ("Appending '%s' to ustar archive on scratch d
isk
...\n", file_name);
+ printf ("Appending '%s' to ustar archive on scratch d
evice
...\n", file_name);
/* Allocate buffer. */
/* Allocate buffer. */
- buffer = malloc (
DIS
K_SECTOR_SIZE);
+ buffer = malloc (
BLOC
K_SECTOR_SIZE);
if (buffer == NULL)
PANIC ("couldn't allocate buffer");
if (buffer == NULL)
PANIC ("couldn't allocate buffer");
@@
-186,35
+187,35
@@
fsutil_append (char **argv)
PANIC ("%s: open failed", file_name);
size = file_length (src);
PANIC ("%s: open failed", file_name);
size = file_length (src);
- /* Open target
disk
. */
- dst =
disk_get (1, 0
);
+ /* Open target
block device
. */
+ dst =
block_get_role (BLOCK_SCRATCH
);
if (dst == NULL)
if (dst == NULL)
- PANIC ("couldn't open
target disk (hdc or hd1:0)
");
+ PANIC ("couldn't open
scratch device
");
/* Write ustar header to first sector. */
if (!ustar_make_header (file_name, USTAR_REGULAR, size, buffer))
PANIC ("%s: name too long for ustar format", file_name);
/* Write ustar header to first sector. */
if (!ustar_make_header (file_name, USTAR_REGULAR, size, buffer))
PANIC ("%s: name too long for ustar format", file_name);
-
dis
k_write (dst, sector++, buffer);
+
bloc
k_write (dst, sector++, buffer);
/* Do copy. */
while (size > 0)
{
/* Do copy. */
while (size > 0)
{
- int chunk_size = size >
DISK_SECTOR_SIZE ? DIS
K_SECTOR_SIZE : size;
- if (sector >=
dis
k_size (dst))
- PANIC ("%s: out of space on scratch d
isk
", file_name);
+ int chunk_size = size >
BLOCK_SECTOR_SIZE ? BLOC
K_SECTOR_SIZE : size;
+ if (sector >=
bloc
k_size (dst))
+ PANIC ("%s: out of space on scratch d
evice
", file_name);
if (file_read (src, buffer, chunk_size) != chunk_size)
PANIC ("%s: read failed with %"PROTd" bytes unread", file_name, size);
if (file_read (src, buffer, chunk_size) != chunk_size)
PANIC ("%s: read failed with %"PROTd" bytes unread", file_name, size);
- memset (buffer + chunk_size, 0,
DIS
K_SECTOR_SIZE - chunk_size);
-
dis
k_write (dst, sector++, buffer);
+ memset (buffer + chunk_size, 0,
BLOC
K_SECTOR_SIZE - chunk_size);
+
bloc
k_write (dst, sector++, buffer);
size -= chunk_size;
}
/* Write ustar end-of-archive marker, which is two consecutive
sectors full of zeros. Don't advance our position past
them, though, in case we have more files to append. */
size -= chunk_size;
}
/* Write ustar end-of-archive marker, which is two consecutive
sectors full of zeros. Don't advance our position past
them, though, in case we have more files to append. */
- memset (buffer, 0,
DIS
K_SECTOR_SIZE);
-
dis
k_write (dst, sector, buffer);
-
dis
k_write (dst, sector, buffer + 1);
+ memset (buffer, 0,
BLOC
K_SECTOR_SIZE);
+
bloc
k_write (dst, sector, buffer);
+
bloc
k_write (dst, sector, buffer + 1);
/* Finish up. */
file_close (src);
/* Finish up. */
file_close (src);