Working backdoor filesystem implementation.
[pintos-anon] / src / filesys / file.c
1 #include "file.h"
2
3 #ifdef FILESYS_STUB
4 #include "debug.h"
5 #include "filesys-stub.h"
6 #include "lib.h"
7 #include "malloc.h"
8
9 void
10 file_close (struct file *file) 
11 {
12   filesys_stub_lock ();
13   filesys_stub_put_string ("close");
14   filesys_stub_put_file (file);
15   filesys_stub_match_string ("close");
16   filesys_stub_unlock ();
17 }
18
19 off_t
20 file_read (struct file *file, void *buffer, off_t size) 
21 {
22   int32_t retval;
23
24   filesys_stub_lock ();
25   filesys_stub_put_string ("read");
26   filesys_stub_put_file (file);
27   filesys_stub_put_uint32 (size);
28   filesys_stub_match_string ("read");
29   retval = filesys_stub_get_int32 ();
30   if (retval > 0) 
31     {
32       ASSERT (retval <= size);
33       filesys_stub_get_bytes (buffer, retval);
34     }
35   filesys_stub_unlock ();
36   
37   return retval;
38 }
39
40 off_t
41 file_write (struct file *file, const void *buffer, off_t size) 
42 {
43   int32_t retval;
44
45   filesys_stub_lock ();
46   filesys_stub_put_string ("write");
47   filesys_stub_put_file (file);
48   filesys_stub_put_uint32 (size);
49   filesys_stub_put_bytes (buffer, size);
50   filesys_stub_match_string ("write");
51   retval = filesys_stub_get_int32 ();
52   ASSERT (retval <= size);
53   filesys_stub_unlock ();
54
55   return retval;
56 }
57
58 off_t
59 file_length (struct file *file) 
60 {
61   int32_t length;
62
63   filesys_stub_lock ();
64   filesys_stub_put_string ("length");
65   filesys_stub_put_file (file);
66   filesys_stub_match_string ("length");
67   length = filesys_stub_get_int32 ();
68   filesys_stub_unlock ();
69
70   return length;
71 }
72
73 void
74 file_seek (struct file *file, off_t pos) 
75 {
76   filesys_stub_lock ();
77   filesys_stub_put_string ("seek");
78   filesys_stub_put_file (file);
79   filesys_stub_put_uint32 (pos);
80   filesys_stub_match_string ("seek");
81   filesys_stub_unlock ();
82 }
83
84 off_t
85 file_tell (struct file *file) 
86 {
87   int32_t pos;
88
89   filesys_stub_lock ();
90   filesys_stub_put_string ("tell");
91   filesys_stub_put_file (file);
92   filesys_stub_match_string ("tell");
93   pos = filesys_stub_get_int32 ();
94   filesys_stub_unlock ();
95
96   return pos;
97 }
98 #endif /* FILESYS_STUB */