Rev 2433 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2433 | Rev 2435 | ||
---|---|---|---|
1 | /* |
1 | /* |
- | 2 | * Copyright (c) 2007 Konopa-Jelen-Majer |
|
- | 3 | * All rights reserved. |
|
- | 4 | * |
|
- | 5 | * Redistribution and use in source and binary forms, with or without |
|
- | 6 | * modification, are permitted provided that the following conditions |
|
- | 7 | * are met: |
|
2 | * Cat |
8 | * |
- | 9 | * - Redistributions of source code must retain the above copyright |
|
- | 10 | * notice, this list of conditions and the following disclaimer. |
|
- | 11 | * - Redistributions in binary form must reproduce the above copyright |
|
- | 12 | * notice, this list of conditions and the following disclaimer in the |
|
- | 13 | * documentation and/or other materials provided with the distribution. |
|
- | 14 | * - The name of the author may not be used to endorse or promote products |
|
- | 15 | * derived from this software without specific prior written permission. |
|
- | 16 | * |
|
- | 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
|
- | 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
|
- | 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
|
- | 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
|
- | 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
|
- | 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
- | 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
- | 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
- | 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
|
- | 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
3 | */ |
27 | */ |
4 | 28 | ||
- | 29 | /** @addtogroup FSDemo |
|
- | 30 | * @{ |
|
- | 31 | */ |
|
- | 32 | ||
- | 33 | /** |
|
- | 34 | * @file cat.c |
|
- | 35 | * @brief A file system demonstration task - raw IPC version |
|
- | 36 | */ |
|
- | 37 | ||
- | 38 | ||
5 | #include <err.h> |
39 | #include <err.h> |
6 | #include <stdio.h> |
40 | #include <stdio.h> |
7 | #include <stdlib.h> |
41 | #include <stdlib.h> |
8 | #include <string.h> |
42 | #include <string.h> |
9 | #include <unistd.h> |
43 | #include <unistd.h> |
10 | #include <async.h> |
44 | #include <async.h> |
11 | #include <align.h> |
45 | #include <align.h> |
12 | #include <as.h> |
46 | #include <as.h> |
13 | #include <ipc/ipc.h> |
47 | #include <ipc/ipc.h> |
14 | #include <ipc/services.h> |
48 | #include <ipc/services.h> |
15 | #include <sys/mman.h> |
49 | #include <sys/mman.h> |
16 | #include "../fs/fs.h" |
50 | #include "../fs/fs.h" |
17 | #include "../share/shared_proto.h" |
51 | #include "../share/shared_proto.h" |
18 | #include "../console/console.h" |
52 | #include "../console/console.h" |
19 | #include "../fs/stat.h" |
53 | #include "../fs/stat.h" |
20 | 54 | ||
21 | #define CON_FS_ATTEMPTS 1000 |
55 | #define CON_FS_ATTEMPTS 1000 |
22 | #define LINE_LENGTH 30 |
56 | #define LINE_LENGTH 30 |
23 | #define EOL 10 |
57 | #define EOL 10 |
24 | #define SPACE_BAR 32 |
58 | #define SPACE_BAR 32 |
25 | #define CONSOLE_WIDTH 60 |
59 | #define CONSOLE_WIDTH 60 |
26 | #define CONSOLE_HEIGHT 20 |
60 | #define CONSOLE_HEIGHT 20 |
27 | 61 | ||
28 | static int fs_phone; |
62 | static int fs_phone; |
29 | 63 | ||
30 | 64 | ||
31 | /** |
65 | /** |
32 | * Reads one line from input (returns after receiving line feed or after reading max_line_length characters) |
66 | * Reads one line from input (returns after receiving line feed or after reading max_line_length characters) |
33 | * @param max_line_length Maximum line length allowed |
67 | * @param max_line_length Maximum line length allowed |
34 | * @return Pointer to read string (null when max_line_length < 0). |
68 | * @return Pointer to read string (null when max_line_length < 0). |
35 | */ |
69 | */ |
36 | static char* input_read(int max_line_length) |
70 | static char* input_read(int max_line_length) |
37 | { |
71 | { |
38 | if (max_line_length < 0) return NULL; |
72 | if (max_line_length < 0) return NULL; |
39 | 73 | ||
40 | char * input = malloc(max_line_length+1); |
74 | char * input = malloc(max_line_length+1); |
41 | int c,i; |
75 | int c,i; |
42 | 76 | ||
43 | char * cpy = input; |
77 | char * cpy = input; |
44 | i = 0; |
78 | i = 0; |
45 | while ((c = getchar()) != EOL) |
79 | while ((c = getchar()) != EOL) |
46 | { |
80 | { |
47 | if (++i>max_line_length) break; |
81 | if (++i>max_line_length) break; |
48 | putchar(c); |
82 | putchar(c); |
49 | memcpy(cpy++,&c,1); |
83 | memcpy(cpy++,&c,1); |
50 | } |
84 | } |
51 | putchar(EOL); |
85 | putchar(EOL); |
52 | 86 | ||
53 | //adds terminating zero |
87 | //adds terminating zero |
54 | memset(cpy,'\0',1); |
88 | memset(cpy,'\0',1); |
55 | return input; |
89 | return input; |
56 | } |
90 | } |
57 | 91 | ||
58 | /** |
92 | /** |
59 | * Reads input and returns after receiving continue_string |
93 | * Reads input and returns after receiving continue_string |
60 | * @param continue_sign Returns after receiving this character. |
94 | * @param continue_sign Returns after receiving this character. |
61 | */ |
95 | */ |
62 | static void wait_for_char(char continue_sign) |
96 | static void wait_for_char(char continue_sign) |
63 | { |
97 | { |
64 | printf("- More -\n"); |
98 | printf("- More -\n"); |
65 | while (getchar() != continue_sign) {} |
99 | while (getchar() != continue_sign) {} |
66 | } |
100 | } |
67 | 101 | ||
68 | 102 | ||
69 | /** |
103 | /** |
70 | * Writes input string into the console. |
104 | * Writes input string into the console. |
71 | * @param align_size Max width of the output line. |
105 | * @param align_size Max width of the output line. |
72 | * @param line_count After printing line_count lines, wait_for_char is called |
106 | * @param line_count After printing line_count lines, wait_for_char is called |
73 | * @param reset 1 - resets procedure counters |
107 | * @param reset 1 - resets procedure counters |
74 | */ |
108 | */ |
75 | static void little_more4(char * input, int align_size, int line_count, int reset) |
109 | static void little_more4(char * input, int align_size, int line_count, int reset) |
76 | { |
110 | { |
77 | static int lines = 0; |
111 | static int lines = 0; |
78 | static int chars = 0; |
112 | static int chars = 0; |
79 | 113 | ||
80 | if (reset) |
114 | if (reset) |
81 | lines = chars = 0; |
115 | lines = chars = 0; |
82 | 116 | ||
83 | if ((align_size <= 0) || (line_count <=0)) return; |
117 | if ((align_size <= 0) || (line_count <=0)) return; |
84 | 118 | ||
85 | while(*input != '\0') |
119 | while(*input != '\0') |
86 | { |
120 | { |
87 | putchar(*input); |
121 | putchar(*input); |
88 | 122 | ||
89 | if (*(input++) == EOL) |
123 | if (*(input++) == EOL) |
90 | { |
124 | { |
91 | chars = 0; |
125 | chars = 0; |
92 | ++lines; |
126 | ++lines; |
93 | } |
127 | } |
94 | else |
128 | else |
95 | { |
129 | { |
96 | ++chars; |
130 | ++chars; |
97 | if (chars >= align_size) |
131 | if (chars >= align_size) |
98 | { |
132 | { |
99 | chars = 0; |
133 | chars = 0; |
100 | printf("\n"); |
134 | printf("\n"); |
101 | ++lines; |
135 | ++lines; |
102 | } |
136 | } |
103 | } |
137 | } |
104 | 138 | ||
105 | if (lines >= line_count) |
139 | if (lines >= line_count) |
106 | { |
140 | { |
107 | lines = chars = 0; |
141 | lines = chars = 0; |
108 | wait_for_char(SPACE_BAR); |
142 | wait_for_char(SPACE_BAR); |
109 | } |
143 | } |
110 | } |
144 | } |
111 | } |
145 | } |
112 | 146 | ||
113 | /** |
147 | /** |
114 | * Calls little_more(char * input, int align_size, int line_count, int reset) with default values and no reset. |
148 | * Calls little_more(char * input, int align_size, int line_count, int reset) with default values and no reset. |
115 | */ |
149 | */ |
116 | static void little_more(char * input) |
150 | static void little_more(char * input) |
117 | { |
151 | { |
118 | little_more4(input, CONSOLE_WIDTH, CONSOLE_HEIGHT, 0); |
152 | little_more4(input, CONSOLE_WIDTH, CONSOLE_HEIGHT, 0); |
119 | } |
153 | } |
120 | 154 | ||
121 | /** |
155 | /** |
122 | * Calls little_more(char * input, int align_size, int line_count, int reset) with default values. |
156 | * Calls little_more(char * input, int align_size, int line_count, int reset) with default values. |
123 | */ |
157 | */ |
124 | static void little_more2(char * input, int reset) |
158 | static void little_more2(char * input, int reset) |
125 | { |
159 | { |
126 | little_more4(input, CONSOLE_WIDTH, CONSOLE_HEIGHT, reset); |
160 | little_more4(input, CONSOLE_WIDTH, CONSOLE_HEIGHT, reset); |
127 | } |
161 | } |
128 | 162 | ||
129 | static int fopen(char * filename) |
163 | static int fopen(char * filename) |
130 | { |
164 | { |
131 | return -1; |
165 | return -1; |
132 | } |
166 | } |
133 | 167 | ||
134 | static int fclose(int fd) |
168 | static int fclose(int fd) |
135 | { |
169 | { |
136 | return -1; |
170 | return -1; |
137 | } |
171 | } |
138 | 172 | ||
139 | static int fread(void* ptr, int size, int nbmem, int fd) |
173 | static int fread(void* ptr, int size, int nbmem, int fd) |
140 | { |
174 | { |
141 | return 0; |
175 | return 0; |
142 | } |
176 | } |
143 | 177 | ||
144 | /** |
178 | /** |
145 | * Simple atoi function (converts the string into an integer) |
179 | * Simple atoi function (converts the string into an integer) |
146 | * @param str string to convert |
180 | * @param str string to convert |
147 | * @return 0 - if error, else converted number |
181 | * @return 0 - if error, else converted number |
148 | */ |
182 | */ |
149 | static int my_atoi(char * str) |
183 | static int my_atoi(char * str) |
150 | { |
184 | { |
151 | if (str == NULL) return 0; |
185 | if (str == NULL) return 0; |
152 | int minus = 0; |
186 | int minus = 0; |
153 | if (str[0] == '-') |
187 | if (str[0] == '-') |
154 | { |
188 | { |
155 | minus = 1; |
189 | minus = 1; |
156 | ++str; |
190 | ++str; |
157 | }; |
191 | }; |
158 | int res = 0; |
192 | int res = 0; |
159 | while (*(str) != '\0') |
193 | while (*(str) != '\0') |
160 | { |
194 | { |
161 | res = res*10; |
195 | res = res*10; |
162 | switch (*(str++)) |
196 | switch (*(str++)) |
163 | { |
197 | { |
164 | case '0': |
198 | case '0': |
165 | break; |
199 | break; |
166 | case '1': |
200 | case '1': |
167 | ++res; |
201 | ++res; |
168 | break; |
202 | break; |
169 | case '2': |
203 | case '2': |
170 | res = res + 2; |
204 | res = res + 2; |
171 | break; |
205 | break; |
172 | case '3': |
206 | case '3': |
173 | res = res + 3; |
207 | res = res + 3; |
174 | break; |
208 | break; |
175 | case '4': |
209 | case '4': |
176 | res = res + 4; |
210 | res = res + 4; |
177 | break; |
211 | break; |
178 | case '5': |
212 | case '5': |
179 | res = res + 5; |
213 | res = res + 5; |
180 | break; |
214 | break; |
181 | case '6': |
215 | case '6': |
182 | res = res + 6; |
216 | res = res + 6; |
183 | break; |
217 | break; |
184 | case '7': |
218 | case '7': |
185 | res = res + 7; |
219 | res = res + 7; |
186 | break; |
220 | break; |
187 | case '8': |
221 | case '8': |
188 | res = res + 8; |
222 | res = res + 8; |
189 | break; |
223 | break; |
190 | case '9': |
224 | case '9': |
191 | res = res + 9; |
225 | res = res + 9; |
192 | break; |
226 | break; |
193 | default: return 0; |
227 | default: return 0; |
194 | } |
228 | } |
195 | } |
229 | } |
196 | if (minus) |
230 | if (minus) |
197 | { |
231 | { |
198 | return -res; |
232 | return -res; |
199 | } |
233 | } |
200 | else |
234 | else |
201 | { |
235 | { |
202 | return res; |
236 | return res; |
203 | }; |
237 | }; |
204 | } |
238 | } |
205 | 239 | ||
206 | 240 | ||
207 | /** |
241 | /** |
208 | * Simple use of fopen function with some I/O |
242 | * Simple use of fopen function with some I/O |
209 | */ |
243 | */ |
210 | static void open_file() |
244 | static void open_file() |
211 | { |
245 | { |
212 | 246 | ||
213 | printf("\n\nEnter the file name:\n? "); |
247 | printf("\n\nEnter the file name:\n? "); |
214 | char * filename = input_read(LINE_LENGTH); |
248 | char * filename = input_read(LINE_LENGTH); |
215 | int fd = fopen(filename); |
249 | int fd = fopen(filename); |
216 | if (fd < 0) |
250 | if (fd < 0) |
217 | { |
251 | { |
218 | printf("\nfopen failed!\n"); |
252 | printf("\nfopen failed!\n"); |
219 | } |
253 | } |
220 | else |
254 | else |
221 | { |
255 | { |
222 | printf("\nReturned file descriptor: %d\n", fd); |
256 | printf("\nReturned file descriptor: %d\n", fd); |
223 | } |
257 | } |
224 | } |
258 | } |
225 | 259 | ||
226 | /** |
260 | /** |
227 | * Simple use of fclose function with some I/O |
261 | * Simple use of fclose function with some I/O |
228 | */ |
262 | */ |
229 | static void close_file() |
263 | static void close_file() |
230 | { |
264 | { |
231 | printf("\n\nEnter the file descriptor:\n? "); |
265 | printf("\n\nEnter the file descriptor:\n? "); |
232 | char * fd_str = input_read(2); |
266 | char * fd_str = input_read(2); |
233 | int fd = my_atoi(fd_str); |
267 | int fd = my_atoi(fd_str); |
234 | free(fd_str); |
268 | free(fd_str); |
235 | 269 | ||
236 | if (fclose(fd) < 0) |
270 | if (fclose(fd) < 0) |
237 | { |
271 | { |
238 | printf("\nfclose failed!\n"); |
272 | printf("\nfclose failed!\n"); |
239 | } |
273 | } |
240 | else |
274 | else |
241 | { |
275 | { |
242 | printf("\nFile successfully closed.\n"); |
276 | printf("\nFile successfully closed.\n"); |
243 | } |
277 | } |
244 | } |
278 | } |
245 | 279 | ||
246 | /** |
280 | /** |
247 | * Simple use of fread function with some I/O |
281 | * Simple use of fread function with some I/O |
248 | */ |
282 | */ |
249 | static void read_file() |
283 | static void read_file() |
250 | { |
284 | { |
251 | printf("\n\nEnter the file descriptor:\n? "); |
285 | printf("\n\nEnter the file descriptor:\n? "); |
252 | char * buf = input_read(2); |
286 | char * buf = input_read(2); |
253 | int fd = my_atoi(buf); |
287 | int fd = my_atoi(buf); |
254 | free(buf); |
288 | free(buf); |
255 | printf("Enter the no. of elements you want to read:\n? "); |
289 | printf("Enter the no. of elements you want to read:\n? "); |
256 | buf = input_read(5); |
290 | buf = input_read(5); |
257 | int e_no = my_atoi(buf); |
291 | int e_no = my_atoi(buf); |
258 | free(buf); |
292 | free(buf); |
259 | printf("Enter the element size (bytes):\n? "); |
293 | printf("Enter the element size (bytes):\n? "); |
260 | buf = input_read(5); |
294 | buf = input_read(5); |
261 | int e_size = my_atoi(buf); |
295 | int e_size = my_atoi(buf); |
262 | free(buf); |
296 | free(buf); |
263 | //printf("\nEntered values:\n - fd: %d\n- ec: %d\n- es: %d\n",fd,e_no,e_size); |
297 | //printf("\nEntered values:\n - fd: %d\n- ec: %d\n- es: %d\n",fd,e_no,e_size); |
264 | void * ptr = malloc(e_no*e_size+1); |
298 | void * ptr = malloc(e_no*e_size+1); |
265 | memset(ptr,'\0',e_no*e_size+1); |
299 | memset(ptr,'\0',e_no*e_size+1); |
266 | int res = fread(ptr, e_no, e_size, fd); |
300 | int res = fread(ptr, e_no, e_size, fd); |
267 | 301 | ||
268 | printf ("\nNo. of elements read: %d\n",res); |
302 | printf ("\nNo. of elements read: %d\n",res); |
269 | printf("Returned data:\n------------\n"); |
303 | printf("Returned data:\n------------\n"); |
270 | little_more2(ptr,1); |
304 | little_more2(ptr,1); |
271 | printf("\n----EOF-----\n"); |
305 | printf("\n----EOF-----\n"); |
272 | free(ptr); |
306 | free(ptr); |
273 | } |
307 | } |
274 | 308 | ||
275 | 309 | ||
276 | 310 | ||
277 | 311 | ||
278 | int main(int argc, char *argv[]) |
312 | int main(int argc, char *argv[]) |
279 | { |
313 | { |
280 | char fname[30]; |
314 | char fname[30]; |
281 | unsigned int file_handle; |
315 | unsigned int file_handle; |
282 | int retval, flags, entry; |
316 | int retval, flags, entry; |
283 | unsigned short entries_num, inode_num; |
317 | unsigned short entries_num, inode_num; |
284 | size_t size; |
318 | size_t size; |
285 | void *share = NULL; |
319 | void *share = NULL; |
286 | 320 | ||
287 | 321 | ||
288 | little_more2("Cat task\n",1); |
322 | little_more2("Cat task\n",1); |
289 | 323 | ||
290 | little_more("Connecting to the SERVICE_FS..."); |
324 | little_more("Connecting to the SERVICE_FS..."); |
291 | if (!connect_to_fs(&fs_phone, CON_FS_ATTEMPTS)) { |
325 | if (!connect_to_fs(&fs_phone, CON_FS_ATTEMPTS)) { |
292 | little_more("Connection to SERVICE_FS was refused\n"); |
326 | little_more("Connection to SERVICE_FS was refused\n"); |
293 | return -1; |
327 | return -1; |
294 | } |
328 | } |
295 | little_more("OK\n"); |
329 | little_more("OK\n"); |
296 | 330 | ||
297 | little_more("Creating address space area..."); |
331 | little_more("Creating address space area..."); |
298 | size = ALIGN_UP(BLOCK_SIZE * sizeof(char), PAGE_SIZE); |
332 | size = ALIGN_UP(BLOCK_SIZE * sizeof(char), PAGE_SIZE); |
299 | share = mmap(share, size, AS_AREA_READ | AS_AREA_WRITE, MAP_SHARED | MAP_ANONYMOUS, 0, 0); |
333 | share = mmap(share, size, AS_AREA_READ | AS_AREA_WRITE, MAP_SHARED | MAP_ANONYMOUS, 0, 0); |
300 | if ((int)share < 0){ |
334 | if ((int)share < 0){ |
301 | little_more("As_area_create error: "); |
335 | little_more("As_area_create error: "); |
302 | printf("%d", (int)share); |
336 | printf("%d", (int)share); |
303 | little_more("\n"); |
337 | little_more("\n"); |
304 | return -1; |
338 | return -1; |
305 | } |
339 | } |
306 | printf("OK\n"); |
340 | printf("OK\n"); |
307 | 341 | ||
308 | little_more("Connecting the task to FS..."); |
342 | little_more("Connecting the task to FS..."); |
309 | retval = async_req_2(fs_phone, FS_NEW_CONSUMER, task_get_id(), 0, NULL, NULL); |
343 | retval = async_req_2(fs_phone, FS_NEW_CONSUMER, task_get_id(), 0, NULL, NULL); |
310 | if (retval < 0) { |
344 | if (retval < 0) { |
311 | printf("%d", retval); |
345 | printf("%d", retval); |
312 | little_more("\n"); |
346 | little_more("\n"); |
313 | return -1; |
347 | return -1; |
314 | } |
348 | } |
315 | little_more("OK\n"); |
349 | little_more("OK\n"); |
316 | 350 | ||
317 | little_more("Sending memory to FS_SERVICE..."); |
351 | little_more("Sending memory to FS_SERVICE..."); |
318 | flags = 0; |
352 | flags = 0; |
319 | flags = AS_AREA_READ | AS_AREA_WRITE; |
353 | flags = AS_AREA_READ | AS_AREA_WRITE; |
320 | retval = async_req_3(fs_phone, IPC_M_AS_AREA_SEND, (uintptr_t)share, size, flags, NULL, NULL, NULL); |
354 | retval = async_req_3(fs_phone, IPC_M_AS_AREA_SEND, (uintptr_t)share, size, flags, NULL, NULL, NULL); |
321 | if (retval < 0) { |
355 | if (retval < 0) { |
322 | printf("%d", retval); |
356 | printf("%d", retval); |
323 | little_more("\n"); |
357 | little_more("\n"); |
324 | return -1; |
358 | return -1; |
325 | } |
359 | } |
326 | little_more("OK\n"); |
360 | little_more("OK\n"); |
327 | 361 | ||
328 | /* Allocating structure for extended message. */ |
362 | /* Allocating structure for extended message. */ |
329 | message_params_t *params; |
363 | message_params_t *params; |
330 | params = malloc(sizeof(message_params_t)); |
364 | params = malloc(sizeof(message_params_t)); |
331 | memset((void*)params, 0, sizeof(message_params_t)); |
365 | memset((void*)params, 0, sizeof(message_params_t)); |
332 | 366 | ||
333 | /* We want lookup our work directory. */ |
367 | /* We want lookup our work directory. */ |
334 | little_more("Request for get number of entries..."); |
368 | little_more("Request for get number of entries..."); |
335 | retval = send_request(fs_phone, FS_DSUM, params, share); |
369 | retval = send_request(fs_phone, FS_DSUM, params, share); |
336 | if (retval < 0) { |
370 | if (retval < 0) { |
337 | printf("%d", retval); |
371 | printf("%d", retval); |
338 | little_more("\n"); |
372 | little_more("\n"); |
339 | return -1; |
373 | return -1; |
340 | } |
374 | } |
341 | little_more("OK\n"); |
375 | little_more("OK\n"); |
342 | little_more("Total number of entries: "); |
376 | little_more("Total number of entries: "); |
343 | printf("%d", retval); |
377 | printf("%d", retval); |
344 | little_more("\n"); |
378 | little_more("\n"); |
345 | 379 | ||
346 | 380 | ||
347 | entries_num = retval; |
381 | entries_num = retval; |
348 | 382 | ||
349 | 383 | ||
350 | /* File list in working directory. */ |
384 | /* File list in working directory. */ |
351 | little_more("File list:\n"); |
385 | little_more("File list:\n"); |
352 | 386 | ||
353 | for (entry = 0; entry < entries_num; entry++) { |
387 | for (entry = 0; entry < entries_num; entry++) { |
354 | 388 | ||
355 | params->entry_number = entry; |
389 | params->entry_number = entry; |
356 | retval = send_request(fs_phone, FS_READENTRY, params, share); |
390 | retval = send_request(fs_phone, FS_READENTRY, params, share); |
357 | if (retval < 0) { |
391 | if (retval < 0) { |
358 | printf("%d", retval); |
392 | printf("%d", retval); |
359 | little_more("\n"); |
393 | little_more("\n"); |
360 | return -1; |
394 | return -1; |
361 | } |
395 | } |
362 | /* |
396 | /* |
363 | if (retval < sizeof(unsigned short)) |
397 | if (retval < sizeof(unsigned short)) |
364 | continue; |
398 | continue; |
365 | */ |
399 | */ |
366 | memcpy(&inode_num, share, sizeof(unsigned short)); |
400 | memcpy(&inode_num, share, sizeof(unsigned short)); |
367 | memcpy(fname, (void *)(share+sizeof(unsigned short)), retval-sizeof(unsigned short)); |
401 | memcpy(fname, (void *)(share+sizeof(unsigned short)), retval-sizeof(unsigned short)); |
368 | 402 | ||
369 | /* Do not show empty entries. */ |
403 | /* Do not show empty entries. */ |
370 | if (!inode_num) |
404 | if (!inode_num) |
371 | continue; |
405 | continue; |
372 | 406 | ||
373 | little_more("Inode number: "); |
407 | little_more("Inode number: "); |
374 | printf("%u", inode_num); |
408 | printf("%u", inode_num); |
375 | little_more("\t\t"); |
409 | little_more("\t\t"); |
376 | little_more("File name: "); |
410 | little_more("File name: "); |
377 | little_more(fname); |
411 | little_more(fname); |
378 | little_more("\n"); |
412 | little_more("\n"); |
379 | 413 | ||
380 | } |
414 | } |
381 | little_more("OK\n"); |
415 | little_more("OK\n"); |
382 | 416 | ||
383 | /* We want to change working directory */ |
417 | /* We want to change working directory */ |
384 | memcpy(fname, "uspace/fs", 10); |
418 | memcpy(fname, "uspace/fs", 10); |
385 | memcpy(params->fname, fname, 10); |
419 | memcpy(params->fname, fname, 10); |
386 | 420 | ||
387 | little_more("Request for changing actual directory to "); |
421 | little_more("Request for changing actual directory to "); |
388 | little_more(fname); |
422 | little_more(fname); |
389 | little_more("..."); |
423 | little_more("..."); |
390 | retval = send_request(fs_phone, FS_CHDIR, params, share); |
424 | retval = send_request(fs_phone, FS_CHDIR, params, share); |
391 | if (retval < 0) { |
425 | if (retval < 0) { |
392 | printf("%d", retval); |
426 | printf("%d", retval); |
393 | little_more("\n"); |
427 | little_more("\n"); |
394 | return -1; |
428 | return -1; |
395 | } |
429 | } |
396 | little_more("OK\n"); |
430 | little_more("OK\n"); |
397 | 431 | ||
398 | /* We want to work with specified file. */ |
432 | /* We want to work with specified file. */ |
399 | memcpy(fname, "fs.c", 10); |
433 | memcpy(fname, "fs.c", 10); |
400 | memcpy(params->fname, fname, 10); |
434 | memcpy(params->fname, fname, 10); |
401 | 435 | ||
402 | little_more("Request for opening file "); |
436 | little_more("Request for opening file "); |
403 | little_more(fname); |
437 | little_more(fname); |
404 | little_more("..."); |
438 | little_more("..."); |
405 | retval = send_request(fs_phone, FS_OPEN, params, share); |
439 | retval = send_request(fs_phone, FS_OPEN, params, share); |
406 | if (retval < 0) { |
440 | if (retval < 0) { |
407 | printf("%d", retval); |
441 | printf("%d", retval); |
408 | little_more("\n"); |
442 | little_more("\n"); |
409 | return -1; |
443 | return -1; |
410 | } |
444 | } |
411 | little_more("OK\n"); |
445 | little_more("OK\n"); |
412 | 446 | ||
413 | file_handle = retval; |
447 | file_handle = retval; |
414 | little_more("Returned file handle..."); |
448 | little_more("Returned file handle..."); |
415 | printf("%d", file_handle); |
449 | printf("%d", file_handle); |
416 | little_more("\n"); |
450 | little_more("\n"); |
417 | 451 | ||
418 | memcpy(params->fname, fname, 10); |
452 | memcpy(params->fname, fname, 10); |
419 | params->fd = file_handle; |
453 | params->fd = file_handle; |
420 | 454 | ||
421 | little_more("Request for getting info about file "); |
455 | little_more("Request for getting info about file "); |
422 | little_more(fname); |
456 | little_more(fname); |
423 | little_more("[FSTAT called]..."); |
457 | little_more("[FSTAT called]..."); |
424 | retval = send_request(fs_phone, FS_FSTAT, params, share); |
458 | retval = send_request(fs_phone, FS_FSTAT, params, share); |
425 | if (retval < 0) { |
459 | if (retval < 0) { |
426 | printf("%d", retval); |
460 | printf("%d", retval); |
427 | little_more("\n"); |
461 | little_more("\n"); |
428 | return -1; |
462 | return -1; |
429 | } |
463 | } |
430 | little_more("OK\n"); |
464 | little_more("OK\n"); |
431 | 465 | ||
432 | params->fd = file_handle; |
466 | params->fd = file_handle; |
433 | params->offset = 100; |
467 | params->offset = 100; |
434 | params->whence = 1; /* from actual position in the file */ |
468 | params->whence = 1; /* from actual position in the file */ |
435 | 469 | ||
436 | little_more("Request for seeking after "); |
470 | little_more("Request for seeking after "); |
437 | printf("%d", params->offset); |
471 | printf("%d", params->offset); |
438 | little_more(" bytes inside file "); |
472 | little_more(" bytes inside file "); |
439 | little_more(fname); |
473 | little_more(fname); |
440 | little_more("..."); |
474 | little_more("..."); |
441 | retval = send_request(fs_phone, FS_SEEK, params, share); |
475 | retval = send_request(fs_phone, FS_SEEK, params, share); |
442 | if (retval < 0) { |
476 | if (retval < 0) { |
443 | printf("%d", retval); |
477 | printf("%d", retval); |
444 | little_more("\n"); |
478 | little_more("\n"); |
445 | return -1; |
479 | return -1; |
446 | } |
480 | } |
447 | little_more("OK\n"); |
481 | little_more("OK\n"); |
448 | 482 | ||
449 | little_more("New file position is: "); |
483 | little_more("New file position is: "); |
450 | printf("%d", retval); |
484 | printf("%d", retval); |
451 | little_more("\n"); |
485 | little_more("\n"); |
452 | 486 | ||
453 | params->nbytes = 100; |
487 | params->nbytes = 100; |
454 | 488 | ||
455 | little_more("Request for reading "); |
489 | little_more("Request for reading "); |
456 | printf("%d", params->nbytes); |
490 | printf("%d", params->nbytes); |
457 | little_more(" bytes from file "); |
491 | little_more(" bytes from file "); |
458 | little_more(fname); |
492 | little_more(fname); |
459 | little_more("..."); |
493 | little_more("..."); |
460 | 494 | ||
461 | retval = send_request(fs_phone, FS_READ, params, share); |
495 | retval = send_request(fs_phone, FS_READ, params, share); |
462 | if (retval < 0) { |
496 | if (retval < 0) { |
463 | printf("%d", retval); |
497 | printf("%d", retval); |
464 | little_more("\n"); |
498 | little_more("\n"); |
465 | return -1; |
499 | return -1; |
466 | } |
500 | } |
467 | little_more("OK\n"); |
501 | little_more("OK\n"); |
468 | 502 | ||
469 | printf("%d", retval); |
503 | printf("%d", retval); |
470 | little_more(" bytes was read into buffer\n"); |
504 | little_more(" bytes was read into buffer\n"); |
471 | little_more("\nContent of the buffer:\n"); |
505 | little_more("\nContent of the buffer:\n"); |
472 | little_more(share); |
506 | little_more(share); |
473 | little_more("\n\n"); |
507 | little_more("\n\n"); |
474 | 508 | ||
475 | 509 | ||
476 | params->offset = 0; |
510 | params->offset = 0; |
477 | params->whence = 0; /* from beginning of the file */ |
511 | params->whence = 0; /* from beginning of the file */ |
478 | 512 | ||
479 | little_more("Request for seeking after "); |
513 | little_more("Request for seeking after "); |
480 | printf("%d", params->offset); |
514 | printf("%d", params->offset); |
481 | little_more(" bytes inside file "); |
515 | little_more(" bytes inside file "); |
482 | little_more(fname); |
516 | little_more(fname); |
483 | little_more("..."); |
517 | little_more("..."); |
484 | retval = send_request(fs_phone, FS_SEEK, params, share); |
518 | retval = send_request(fs_phone, FS_SEEK, params, share); |
485 | if (retval < 0) { |
519 | if (retval < 0) { |
486 | printf("%d", retval); |
520 | printf("%d", retval); |
487 | little_more("\n"); |
521 | little_more("\n"); |
488 | return -1; |
522 | return -1; |
489 | } |
523 | } |
490 | little_more("OK\n"); |
524 | little_more("OK\n"); |
491 | 525 | ||
492 | little_more("New file position is: "); |
526 | little_more("New file position is: "); |
493 | printf("%d", retval); |
527 | printf("%d", retval); |
494 | little_more("\n"); |
528 | little_more("\n"); |
495 | params->fd = file_handle; |
529 | params->fd = file_handle; |
496 | 530 | ||
497 | params->nbytes = 50; |
531 | params->nbytes = 50; |
498 | 532 | ||
499 | little_more("Another request for reading "); |
533 | little_more("Another request for reading "); |
500 | printf("%d", params->nbytes); |
534 | printf("%d", params->nbytes); |
501 | little_more(" bytes from file "); |
535 | little_more(" bytes from file "); |
502 | little_more(fname); |
536 | little_more(fname); |
503 | little_more("..."); |
537 | little_more("..."); |
504 | retval = send_request(fs_phone, FS_READ, params, share); |
538 | retval = send_request(fs_phone, FS_READ, params, share); |
505 | if (retval < 0) { |
539 | if (retval < 0) { |
506 | printf("%d", retval); |
540 | printf("%d", retval); |
507 | little_more("\n"); |
541 | little_more("\n"); |
508 | return -1; |
542 | return -1; |
509 | } |
543 | } |
510 | little_more("OK\n"); |
544 | little_more("OK\n"); |
511 | 545 | ||
512 | printf("%d", retval); |
546 | printf("%d", retval); |
513 | little_more(" bytes was read into buffer\n"); |
547 | little_more(" bytes was read into buffer\n"); |
514 | little_more("\nContent of the buffer:\n"); |
548 | little_more("\nContent of the buffer:\n"); |
515 | little_more(share); |
549 | little_more(share); |
516 | little_more("\n\n"); |
550 | little_more("\n\n"); |
517 | 551 | ||
518 | little_more("Request for closing file "); |
552 | little_more("Request for closing file "); |
519 | little_more(fname); |
553 | little_more(fname); |
520 | little_more("..."); |
554 | little_more("..."); |
521 | retval = send_request(fs_phone, FS_CLOSE, params, share); |
555 | retval = send_request(fs_phone, FS_CLOSE, params, share); |
522 | if (retval < 0) { |
556 | if (retval < 0) { |
523 | printf("%d", retval); |
557 | printf("%d", retval); |
524 | little_more("\n"); |
558 | little_more("\n"); |
525 | return -1; |
559 | return -1; |
526 | } |
560 | } |
527 | little_more("OK\n"); |
561 | little_more("OK\n"); |
528 | 562 | ||
529 | 563 | ||
530 | /* |
564 | /* |
531 | printf("Request for closing file %s once more...", fname); |
565 | printf("Request for closing file %s once more...", fname); |
532 | retval = send_request(fs_phone, FS_CLOSE, params, share); |
566 | retval = send_request(fs_phone, FS_CLOSE, params, share); |
533 | if (retval < 0) { |
567 | if (retval < 0) { |
534 | printf("%d\n", retval); |
568 | printf("%d\n", retval); |
535 | return -1; |
569 | return -1; |
536 | } |
570 | } |
537 | printf("OK\n"); |
571 | printf("OK\n"); |
538 | */ |
572 | */ |
539 | 573 | ||
540 | little_more("Request for dropping the connection to the FS..."); |
574 | little_more("Request for dropping the connection to the FS..."); |
541 | retval = send_request(fs_phone, FS_DROP_CONSUMER, params, share); |
575 | retval = send_request(fs_phone, FS_DROP_CONSUMER, params, share); |
542 | if (retval < 0) { |
576 | if (retval < 0) { |
543 | printf("%d", retval); |
577 | printf("%d", retval); |
544 | little_more("\n"); |
578 | little_more("\n"); |
545 | return -1; |
579 | return -1; |
546 | } |
580 | } |
547 | little_more("OK\n"); |
581 | little_more("OK\n"); |
548 | 582 | ||
549 | 583 | ||
550 | 584 | ||
551 | /* Unmapping share area. */ |
585 | /* Unmapping share area. */ |
552 | little_more("Unmapping share area..."); |
586 | little_more("Unmapping share area..."); |
553 | retval = munmap(share, size); |
587 | retval = munmap(share, size); |
554 | if (retval < 0) { |
588 | if (retval < 0) { |
555 | printf("%d", retval); |
589 | printf("%d", retval); |
556 | little_more("\n"); |
590 | little_more("\n"); |
557 | return -1; |
591 | return -1; |
558 | } |
592 | } |
559 | little_more("OK\n"); |
593 | little_more("OK\n"); |
560 | 594 | ||
561 | little_more("Creating address space area..."); |
595 | little_more("Creating address space area..."); |
562 | size = ALIGN_UP(BLOCK_SIZE * sizeof(char), PAGE_SIZE); |
596 | size = ALIGN_UP(BLOCK_SIZE * sizeof(char), PAGE_SIZE); |
563 | share = mmap(share, size, AS_AREA_READ | AS_AREA_WRITE, MAP_SHARED | MAP_ANONYMOUS, 0, 0); |
597 | share = mmap(share, size, AS_AREA_READ | AS_AREA_WRITE, MAP_SHARED | MAP_ANONYMOUS, 0, 0); |
564 | if ((int)share < 0){ |
598 | if ((int)share < 0){ |
565 | little_more("As_area_create error: "); |
599 | little_more("As_area_create error: "); |
566 | printf("%d"); |
600 | printf("%d"); |
567 | little_more("\n"); |
601 | little_more("\n"); |
568 | return -1; |
602 | return -1; |
569 | } |
603 | } |
570 | little_more("OK\n"); |
604 | little_more("OK\n"); |
571 | 605 | ||
572 | /* Next connection to the FS. */ |
606 | /* Next connection to the FS. */ |
573 | little_more("Connecting the task to FS..."); |
607 | little_more("Connecting the task to FS..."); |
574 | retval = async_req_2(fs_phone, FS_NEW_CONSUMER, task_get_id(), 0, NULL, NULL); |
608 | retval = async_req_2(fs_phone, FS_NEW_CONSUMER, task_get_id(), 0, NULL, NULL); |
575 | if (retval < 0) { |
609 | if (retval < 0) { |
576 | little_more("FS_NEW_CONSUMER error: "); |
610 | little_more("FS_NEW_CONSUMER error: "); |
577 | printf("%d", retval); |
611 | printf("%d", retval); |
578 | little_more("\n"); |
612 | little_more("\n"); |
579 | return -1; |
613 | return -1; |
580 | } |
614 | } |
581 | little_more("OK\n"); |
615 | little_more("OK\n"); |
582 | 616 | ||
583 | little_more("Sending memory to FS_SERVICE..."); |
617 | little_more("Sending memory to FS_SERVICE..."); |
584 | flags = 0; |
618 | flags = 0; |
585 | flags = AS_AREA_READ | AS_AREA_WRITE; |
619 | flags = AS_AREA_READ | AS_AREA_WRITE; |
586 | retval = async_req_3(fs_phone, IPC_M_AS_AREA_SEND, (uintptr_t)share, size, flags, NULL, NULL, NULL); |
620 | retval = async_req_3(fs_phone, IPC_M_AS_AREA_SEND, (uintptr_t)share, size, flags, NULL, NULL, NULL); |
587 | if (retval < 0) { |
621 | if (retval < 0) { |
588 | printf("%d", retval); |
622 | printf("%d", retval); |
589 | little_more("\n"); |
623 | little_more("\n"); |
590 | return -1; |
624 | return -1; |
591 | } |
625 | } |
592 | little_more("OK\n"); |
626 | little_more("OK\n"); |
593 | 627 | ||
594 | /* We want to work with specified file. */ |
628 | /* We want to work with specified file. */ |
595 | memcpy(fname, "/kernel/arch", 20); |
629 | memcpy(fname, "/kernel/arch", 20); |
596 | memcpy(params->fname, fname, 20); |
630 | memcpy(params->fname, fname, 20); |
597 | 631 | ||
598 | little_more("Request for getting info about file "); |
632 | little_more("Request for getting info about file "); |
599 | little_more(fname); |
633 | little_more(fname); |
600 | little_more("[STAT called]..."); |
634 | little_more("[STAT called]..."); |
601 | retval = send_request(fs_phone, FS_STAT, params, share); |
635 | retval = send_request(fs_phone, FS_STAT, params, share); |
602 | if (retval < 0) { |
636 | if (retval < 0) { |
603 | printf("%d", retval); |
637 | printf("%d", retval); |
604 | little_more("\n"); |
638 | little_more("\n"); |
605 | return -1; |
639 | return -1; |
606 | } |
640 | } |
607 | little_more("OK\n"); |
641 | little_more("OK\n"); |
608 | 642 | ||
609 | stat_t file_info; |
643 | stat_t file_info; |
610 | memcpy((void *)(&file_info), share, sizeof(stat_t)); |
644 | memcpy((void *)(&file_info), share, sizeof(stat_t)); |
611 | 645 | ||
612 | little_more("Info about file: "); |
646 | little_more("Info about file: "); |
613 | little_more(fname); |
647 | little_more(fname); |
614 | little_more("\nInode number: "); |
648 | little_more("\nInode number: "); |
615 | printf("%d", file_info.st_ino); |
649 | printf("%d", file_info.st_ino); |
616 | little_more("\nMode: "); |
650 | little_more("\nMode: "); |
617 | printf("%d", file_info.st_mode); |
651 | printf("%d", file_info.st_mode); |
618 | little_more("\nLinks: "); |
652 | little_more("\nLinks: "); |
619 | printf("%d", file_info.st_nlink); |
653 | printf("%d", file_info.st_nlink); |
620 | little_more("\nSize: "); |
654 | little_more("\nSize: "); |
621 | printf("%d", file_info.st_size); |
655 | printf("%d", file_info.st_size); |
622 | little_more("\n"); |
656 | little_more("\n"); |
623 | 657 | ||
624 | 658 | ||
625 | //================================================================================== |
659 | //================================================================================== |
626 | while(1) |
660 | while(1) |
627 | { |
661 | { |
628 | printf("\n\n\n- <stdio.h> calls -\n\n"); |
662 | printf("\n\n\n- <stdio.h> calls -\n\n"); |
629 | printf("What do you want to do?\n"); |
663 | printf("What do you want to do?\n"); |
630 | printf("o - open some file\n"); |
664 | printf("o - open some file\n"); |
631 | printf("c - close some file\n"); |
665 | printf("c - close some file\n"); |
632 | printf("r - read some file\n"); |
666 | printf("r - read some file\n"); |
633 | printf("? "); |
667 | printf("? "); |
634 | char * choice = input_read(1); |
668 | char * choice = input_read(1); |
635 | 669 | ||
636 | switch (choice[0]) |
670 | switch (choice[0]) |
637 | { |
671 | { |
638 | case 'o': |
672 | case 'o': |
639 | open_file(); |
673 | open_file(); |
640 | break; |
674 | break; |
641 | case 'c': |
675 | case 'c': |
642 | close_file(); |
676 | close_file(); |
643 | break; |
677 | break; |
644 | case 'r': |
678 | case 'r': |
645 | read_file(); |
679 | read_file(); |
646 | break; |
680 | break; |
647 | } |
681 | } |
648 | free(choice); |
682 | free(choice); |
649 | wait_for_char(SPACE_BAR); |
683 | wait_for_char(SPACE_BAR); |
650 | printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); |
684 | printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); |
651 | } |
685 | } |
652 | return 0; |
686 | return 0; |
653 | } |
687 | } |
654 | 688 | ||
655 | 689 | ||
656 | 690 |