X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?p=pintos-anon;a=blobdiff_plain;f=src%2Ffilesys%2Ffilesys.c;h=f8348ed2a2eaf4f17182507a9aebce1c47564966;hp=6b7710aa493b77c2df62e42adfdc7b7829ef0d87;hb=3fc16f6e9abc98a3bd5427eb210669860609a224;hpb=540641a18c65c05df757ced2f225ade578da15aa diff --git a/src/filesys/filesys.c b/src/filesys/filesys.c index 6b7710a..f8348ed 100644 --- a/src/filesys/filesys.c +++ b/src/filesys/filesys.c @@ -1,37 +1,90 @@ #include "filesys.h" + #ifdef FILESYS_STUB +#include +#include "debug.h" +#include "filesys-stub.h" +#include "lib.h" + void filesys_init (bool reformat) { if (reformat) printk ("filesystem stubs don't support formatting\n"); + filesys_stub_init (); } bool filesys_create (const char *name) { - bool success = false; - filesys_stub_send ("s'create' s", name); - filesys_stub_receive ("s'create' b", &success); + bool success; + + filesys_stub_lock (); + filesys_stub_put_string ("create"); + filesys_stub_put_string (name); + filesys_stub_match_string ("create"); + success = filesys_stub_get_bool (); + filesys_stub_unlock (); + return success; } struct file * filesys_open (const char *name) { - int32_t handle = -1; - filesys_stub_stub ("s'open' i", name); - filesys_stub_receive ("s'open' i", &handle); - return handle == -1 ? NULL : (struct file *) handle; + struct file *file; + + filesys_stub_lock (); + filesys_stub_put_string ("open"); + filesys_stub_put_string (name); + filesys_stub_match_string ("open"); + file = filesys_stub_get_file (); + filesys_stub_unlock (); + + return file; } bool filesys_remove (const char *name) { - bool success = false; - filesys_stub_send ("s'create' s", name); - filesys_stub_receive ("s'create' b", &success); + bool success; + + filesys_stub_lock (); + filesys_stub_put_string ("remove"); + filesys_stub_put_string (name); + filesys_stub_match_string ("remove"); + success = filesys_stub_get_bool (); + filesys_stub_unlock (); + return success; } #endif /* FILESYS_STUB */ + +#undef NDEBUG +#include "debug.h" +#include "file.h" + +void +filesys_self_test (void) +{ + static const char s[] = "This is a test string."; + struct file *file; + char s2[sizeof s]; + + ASSERT (filesys_create ("foo")); + ASSERT ((file = filesys_open ("foo")) != NULL); + ASSERT (file_write (file, s, sizeof s) == sizeof s); + ASSERT (file_tell (file) == sizeof s); + ASSERT (file_length (file) == sizeof s); + file_close (file); + + ASSERT ((file = filesys_open ("foo")) != NULL); + ASSERT (file_read (file, s2, sizeof s2) == sizeof s2); + ASSERT (memcmp (s, s2, sizeof s) == 0); + ASSERT (file_tell (file) == sizeof s2); + ASSERT (file_length (file) == sizeof s2); + file_close (file); + + ASSERT (filesys_remove ("foo")); +}