1 | /* |
---|
2 | * Header file for the In-Memory File System |
---|
3 | * |
---|
4 | * COPYRIGHT (c) 1989-2007. |
---|
5 | * On-Line Applications Research Corporation (OAR). |
---|
6 | * |
---|
7 | * The license and distribution terms for this file may be |
---|
8 | * found in the file LICENSE in this distribution or at |
---|
9 | * http://www.rtems.com/license/LICENSE. |
---|
10 | * |
---|
11 | * $Id$ |
---|
12 | */ |
---|
13 | |
---|
14 | #ifndef _RTEMS_IMFS_H |
---|
15 | #define _RTEMS_IMFS_H |
---|
16 | |
---|
17 | #ifdef __cplusplus |
---|
18 | extern "C" { |
---|
19 | #endif |
---|
20 | |
---|
21 | #include <rtems.h> |
---|
22 | #include <rtems/chain.h> |
---|
23 | |
---|
24 | #include <sys/types.h> |
---|
25 | #include <limits.h> |
---|
26 | #include <rtems/libio.h> |
---|
27 | |
---|
28 | /* |
---|
29 | * File name macros |
---|
30 | */ |
---|
31 | |
---|
32 | #define IMFS_is_valid_name_char( _ch ) ( 1 ) |
---|
33 | |
---|
34 | #define IMFS_is_separator( _ch ) \ |
---|
35 | rtems_filesystem_is_separator( _ch ) |
---|
36 | |
---|
37 | /* |
---|
38 | * Data types |
---|
39 | */ |
---|
40 | |
---|
41 | struct IMFS_jnode_tt; |
---|
42 | typedef struct IMFS_jnode_tt IMFS_jnode_t; |
---|
43 | |
---|
44 | typedef struct { |
---|
45 | rtems_chain_control Entries; |
---|
46 | rtems_filesystem_mount_table_entry_t *mt_fs; |
---|
47 | } IMFS_directory_t; |
---|
48 | |
---|
49 | typedef struct { |
---|
50 | rtems_device_major_number major; |
---|
51 | rtems_device_minor_number minor; |
---|
52 | } IMFS_device_t; |
---|
53 | |
---|
54 | typedef struct { |
---|
55 | IMFS_jnode_t *link_node; |
---|
56 | } IMFS_link_t; |
---|
57 | |
---|
58 | typedef struct { |
---|
59 | char *name; |
---|
60 | } IMFS_sym_link_t; |
---|
61 | |
---|
62 | /* |
---|
63 | * IMFS "memfile" information |
---|
64 | * |
---|
65 | * The data structure for the in-memory "memfiles" is based on classic UNIX. |
---|
66 | * |
---|
67 | * block_ptr is a pointer to a block of IMFS_MEMFILE_BYTES_PER_BLOCK in |
---|
68 | * length which could be data or a table of pointers to blocks. |
---|
69 | * |
---|
70 | * Setting IMFS_MEMFILE_BYTES_PER_BLOCK to different values has a significant |
---|
71 | * impact on the maximum file size supported as well as the amount of |
---|
72 | * memory wasted due to internal file fragmentation. The following |
---|
73 | * is a list of maximum file sizes based on various settings |
---|
74 | * |
---|
75 | * max_filesize with blocks of 16 is 1,328 |
---|
76 | * max_filesize with blocks of 32 is 18,656 |
---|
77 | * max_filesize with blocks of 64 is 279,488 |
---|
78 | * max_filesize with blocks of 128 is 4,329,344 |
---|
79 | * max_filesize with blocks of 256 is 68,173,568 |
---|
80 | * max_filesize with blocks of 512 is 1,082,195,456 |
---|
81 | */ |
---|
82 | |
---|
83 | #define IMFS_MEMFILE_DEFAULT_BYTES_PER_BLOCK 128 |
---|
84 | extern int imfs_rq_memfile_bytes_per_block; |
---|
85 | extern int imfs_memfile_bytes_per_block; |
---|
86 | |
---|
87 | #define IMFS_MEMFILE_BYTES_PER_BLOCK imfs_memfile_bytes_per_block |
---|
88 | #define IMFS_MEMFILE_BLOCK_SLOTS \ |
---|
89 | (IMFS_MEMFILE_BYTES_PER_BLOCK / sizeof(void *)) |
---|
90 | |
---|
91 | typedef uint8_t *block_p; |
---|
92 | typedef block_p *block_ptr; |
---|
93 | |
---|
94 | typedef struct { |
---|
95 | off_t size; /* size of file in bytes */ |
---|
96 | block_ptr indirect; /* array of 128 data blocks pointers */ |
---|
97 | block_ptr doubly_indirect; /* 128 indirect blocks */ |
---|
98 | block_ptr triply_indirect; /* 128 doubly indirect blocks */ |
---|
99 | } IMFS_memfile_t; |
---|
100 | |
---|
101 | typedef struct { |
---|
102 | off_t size; /* size of file in bytes */ |
---|
103 | block_p direct; /* pointer to file image */ |
---|
104 | } IMFS_linearfile_t; |
---|
105 | |
---|
106 | /* |
---|
107 | * Important block numbers for "memfiles" |
---|
108 | */ |
---|
109 | |
---|
110 | #define FIRST_INDIRECT (0) |
---|
111 | #define LAST_INDIRECT (IMFS_MEMFILE_BLOCK_SLOTS - 1) |
---|
112 | |
---|
113 | #define FIRST_DOUBLY_INDIRECT (LAST_INDIRECT + 1) |
---|
114 | #define LAST_DOUBLY_INDIRECT \ |
---|
115 | (LAST_INDIRECT + \ |
---|
116 | (IMFS_MEMFILE_BLOCK_SLOTS * IMFS_MEMFILE_BLOCK_SLOTS)) |
---|
117 | |
---|
118 | #define FIRST_TRIPLY_INDIRECT (LAST_DOUBLY_INDIRECT + 1) |
---|
119 | #define LAST_TRIPLY_INDIRECT \ |
---|
120 | (LAST_DOUBLY_INDIRECT +\ |
---|
121 | (IMFS_MEMFILE_BLOCK_SLOTS * \ |
---|
122 | IMFS_MEMFILE_BLOCK_SLOTS * IMFS_MEMFILE_BLOCK_SLOTS)) |
---|
123 | |
---|
124 | #define IMFS_MEMFILE_MAXIMUM_SIZE \ |
---|
125 | (LAST_TRIPLY_INDIRECT * IMFS_MEMFILE_BYTES_PER_BLOCK) |
---|
126 | |
---|
127 | /* |
---|
128 | * What types of IMFS file systems entities there can be. |
---|
129 | */ |
---|
130 | |
---|
131 | #define IMFS_jnode_types_t rtems_filesystem_node_types_t |
---|
132 | #define IMFS_DIRECTORY RTEMS_FILESYSTEM_DIRECTORY |
---|
133 | #define IMFS_DEVICE RTEMS_FILESYSTEM_DEVICE |
---|
134 | #define IMFS_HARD_LINK RTEMS_FILESYSTEM_HARD_LINK |
---|
135 | #define IMFS_SYM_LINK RTEMS_FILESYSTEM_SYM_LINK |
---|
136 | #define IMFS_MEMORY_FILE RTEMS_FILESYSTEM_MEMORY_FILE |
---|
137 | #define IMFS_LINEAR_FILE (IMFS_MEMORY_FILE + 1) |
---|
138 | |
---|
139 | #define IMFS_NUMBER_OF_TYPES (IMFS_LINEAR_FILE + 1) |
---|
140 | |
---|
141 | typedef union { |
---|
142 | IMFS_directory_t directory; |
---|
143 | IMFS_device_t device; |
---|
144 | IMFS_link_t hard_link; |
---|
145 | IMFS_sym_link_t sym_link; |
---|
146 | IMFS_memfile_t file; |
---|
147 | IMFS_linearfile_t linearfile; |
---|
148 | } IMFS_types_union; |
---|
149 | |
---|
150 | /* |
---|
151 | * Maximum length of a "basename" of an IMFS file/node. |
---|
152 | */ |
---|
153 | |
---|
154 | #define IMFS_NAME_MAX 32 |
---|
155 | |
---|
156 | /* |
---|
157 | * The control structure for an IMFS jnode. |
---|
158 | */ |
---|
159 | |
---|
160 | struct IMFS_jnode_tt { |
---|
161 | rtems_chain_node Node; /* for chaining them together */ |
---|
162 | IMFS_jnode_t *Parent; /* Parent node */ |
---|
163 | char name[IMFS_NAME_MAX+1]; /* "basename" */ |
---|
164 | mode_t st_mode; /* File mode */ |
---|
165 | nlink_t st_nlink; /* Link count */ |
---|
166 | ino_t st_ino; /* inode */ |
---|
167 | |
---|
168 | uid_t st_uid; /* User ID of owner */ |
---|
169 | gid_t st_gid; /* Group ID of owner */ |
---|
170 | |
---|
171 | time_t stat_atime; /* Time of last access */ |
---|
172 | time_t stat_mtime; /* Time of last modification */ |
---|
173 | time_t stat_ctime; /* Time of last status change */ |
---|
174 | IMFS_jnode_types_t type; /* Type of this entry */ |
---|
175 | IMFS_types_union info; |
---|
176 | }; |
---|
177 | |
---|
178 | #define IMFS_update_atime( _jnode ) \ |
---|
179 | do { \ |
---|
180 | struct timeval tv; \ |
---|
181 | gettimeofday( &tv, 0 ); \ |
---|
182 | _jnode->stat_atime = (time_t) tv.tv_sec; \ |
---|
183 | } while (0) |
---|
184 | |
---|
185 | #define IMFS_update_mtime( _jnode ) \ |
---|
186 | do { \ |
---|
187 | struct timeval tv; \ |
---|
188 | gettimeofday( &tv, 0 ); \ |
---|
189 | _jnode->stat_mtime = (time_t) tv.tv_sec; \ |
---|
190 | } while (0) |
---|
191 | |
---|
192 | #define IMFS_update_ctime( _jnode ) \ |
---|
193 | do { \ |
---|
194 | struct timeval tv; \ |
---|
195 | gettimeofday( &tv, 0 ); \ |
---|
196 | _jnode->stat_ctime = (time_t) tv.tv_sec; \ |
---|
197 | } while (0) |
---|
198 | |
---|
199 | #define IMFS_atime_mtime_update( _jnode ) \ |
---|
200 | do { \ |
---|
201 | struct timeval tv; \ |
---|
202 | gettimeofday( &tv, 0 ); \ |
---|
203 | _jnode->stat_mtime = (time_t) tv.tv_sec; \ |
---|
204 | _jnode->stat_atime = (time_t) tv.tv_sec; \ |
---|
205 | } while (0) |
---|
206 | |
---|
207 | typedef struct { |
---|
208 | ino_t ino_count; |
---|
209 | const rtems_filesystem_file_handlers_r *memfile_handlers; |
---|
210 | const rtems_filesystem_file_handlers_r *directory_handlers; |
---|
211 | } IMFS_fs_info_t; |
---|
212 | |
---|
213 | /* |
---|
214 | * Type defination for tokens returned from IMFS_get_token |
---|
215 | */ |
---|
216 | |
---|
217 | typedef enum { |
---|
218 | IMFS_NO_MORE_PATH, |
---|
219 | IMFS_CURRENT_DIR, |
---|
220 | IMFS_UP_DIR, |
---|
221 | IMFS_NAME, |
---|
222 | IMFS_INVALID_TOKEN |
---|
223 | } IMFS_token_types; |
---|
224 | |
---|
225 | /* |
---|
226 | * Shared Data |
---|
227 | */ |
---|
228 | |
---|
229 | extern const rtems_filesystem_file_handlers_r IMFS_directory_handlers; |
---|
230 | extern const rtems_filesystem_file_handlers_r IMFS_device_handlers; |
---|
231 | extern const rtems_filesystem_file_handlers_r IMFS_link_handlers; |
---|
232 | extern const rtems_filesystem_file_handlers_r IMFS_memfile_handlers; |
---|
233 | extern const rtems_filesystem_operations_table IMFS_ops; |
---|
234 | extern const rtems_filesystem_operations_table miniIMFS_ops; |
---|
235 | extern const rtems_filesystem_limits_and_options_t IMFS_LIMITS_AND_OPTIONS; |
---|
236 | |
---|
237 | /* |
---|
238 | * Routines |
---|
239 | */ |
---|
240 | |
---|
241 | int IMFS_initialize( |
---|
242 | rtems_filesystem_mount_table_entry_t *mt_entry |
---|
243 | ); |
---|
244 | |
---|
245 | int miniIMFS_initialize( |
---|
246 | rtems_filesystem_mount_table_entry_t *mt_entry |
---|
247 | ); |
---|
248 | |
---|
249 | int IMFS_initialize_support( |
---|
250 | rtems_filesystem_mount_table_entry_t *mt_entry, |
---|
251 | const rtems_filesystem_operations_table *op_table, |
---|
252 | const rtems_filesystem_file_handlers_r *memfile_handlers, |
---|
253 | const rtems_filesystem_file_handlers_r *directory_handlers |
---|
254 | ); |
---|
255 | |
---|
256 | int IMFS_fsunmount( |
---|
257 | rtems_filesystem_mount_table_entry_t *mt_entry |
---|
258 | ); |
---|
259 | |
---|
260 | int rtems_tarfs_load( |
---|
261 | char *mountpoint, |
---|
262 | uint8_t *tar_image, |
---|
263 | size_t tar_size |
---|
264 | ); |
---|
265 | |
---|
266 | /* |
---|
267 | * Returns the number of characters copied from path to token. |
---|
268 | */ |
---|
269 | IMFS_token_types IMFS_get_token( |
---|
270 | const char *path, |
---|
271 | char *token, |
---|
272 | int *token_len |
---|
273 | ); |
---|
274 | |
---|
275 | void IMFS_dump( void ); |
---|
276 | |
---|
277 | void IMFS_initialize_jnode( |
---|
278 | IMFS_jnode_t *the_jnode, |
---|
279 | IMFS_jnode_types_t type, |
---|
280 | IMFS_jnode_t *the_parent, |
---|
281 | char *name, |
---|
282 | mode_t mode |
---|
283 | ); |
---|
284 | |
---|
285 | IMFS_jnode_t *IMFS_find_match_in_dir( |
---|
286 | IMFS_jnode_t *directory, /* IN */ |
---|
287 | char *name /* IN */ |
---|
288 | ); |
---|
289 | |
---|
290 | rtems_filesystem_node_types_t IMFS_node_type( |
---|
291 | rtems_filesystem_location_info_t *pathloc /* IN */ |
---|
292 | ); |
---|
293 | |
---|
294 | int IMFS_stat( |
---|
295 | rtems_filesystem_location_info_t *loc, /* IN */ |
---|
296 | struct stat *buf /* OUT */ |
---|
297 | ); |
---|
298 | |
---|
299 | int IMFS_Set_handlers( |
---|
300 | rtems_filesystem_location_info_t *loc |
---|
301 | ); |
---|
302 | |
---|
303 | int IMFS_evaluate_link( |
---|
304 | rtems_filesystem_location_info_t *node, /* IN/OUT */ |
---|
305 | int flags /* IN */ |
---|
306 | ); |
---|
307 | |
---|
308 | int IMFS_eval_path( |
---|
309 | const char *pathname, /* IN */ |
---|
310 | int flags, /* IN */ |
---|
311 | rtems_filesystem_location_info_t *pathloc /* IN/OUT */ |
---|
312 | ); |
---|
313 | |
---|
314 | |
---|
315 | int IMFS_link( |
---|
316 | rtems_filesystem_location_info_t *to_loc, /* IN */ |
---|
317 | rtems_filesystem_location_info_t *parent_loc, /* IN */ |
---|
318 | const char *token /* IN */ |
---|
319 | ); |
---|
320 | |
---|
321 | int IMFS_unlink( |
---|
322 | rtems_filesystem_location_info_t *pathloc /* IN */ |
---|
323 | ); |
---|
324 | |
---|
325 | int IMFS_chown( |
---|
326 | rtems_filesystem_location_info_t *pathloc, /* IN */ |
---|
327 | uid_t owner, /* IN */ |
---|
328 | gid_t group /* IN */ |
---|
329 | ); |
---|
330 | |
---|
331 | int IMFS_freenodinfo( |
---|
332 | rtems_filesystem_location_info_t *pathloc /* IN */ |
---|
333 | ); |
---|
334 | |
---|
335 | int IMFS_mknod( |
---|
336 | const char *path, /* IN */ |
---|
337 | mode_t mode, /* IN */ |
---|
338 | dev_t dev, /* IN */ |
---|
339 | rtems_filesystem_location_info_t *pathloc /* IN/OUT */ |
---|
340 | ); |
---|
341 | |
---|
342 | IMFS_jnode_t *IMFS_create_node( |
---|
343 | rtems_filesystem_location_info_t *parent_loc, /* IN */ |
---|
344 | IMFS_jnode_types_t type, /* IN */ |
---|
345 | const char *name, /* IN */ |
---|
346 | mode_t mode, /* IN */ |
---|
347 | const IMFS_types_union *info /* IN */ |
---|
348 | ); |
---|
349 | |
---|
350 | int IMFS_evaluate_for_make( |
---|
351 | const char *path, /* IN */ |
---|
352 | rtems_filesystem_location_info_t *pathloc, /* IN/OUT */ |
---|
353 | const char **name /* OUT */ |
---|
354 | ); |
---|
355 | |
---|
356 | int IMFS_mount( |
---|
357 | rtems_filesystem_mount_table_entry_t *mt_entry /* IN */ |
---|
358 | ); |
---|
359 | |
---|
360 | int IMFS_unmount( |
---|
361 | rtems_filesystem_mount_table_entry_t *mt_entry /* IN */ |
---|
362 | ); |
---|
363 | |
---|
364 | int IMFS_freenod( |
---|
365 | rtems_filesystem_location_info_t *node /* IN/OUT */ |
---|
366 | ); |
---|
367 | |
---|
368 | int IMFS_memfile_remove( |
---|
369 | IMFS_jnode_t *the_jnode /* IN/OUT */ |
---|
370 | ); |
---|
371 | |
---|
372 | int memfile_ftruncate( |
---|
373 | rtems_libio_t *iop, /* IN */ |
---|
374 | off_t length /* IN */ |
---|
375 | ); |
---|
376 | |
---|
377 | int imfs_dir_open( |
---|
378 | rtems_libio_t *iop, /* IN */ |
---|
379 | const char *pathname, /* IN */ |
---|
380 | uint32_t flag, /* IN */ |
---|
381 | uint32_t mode /* IN */ |
---|
382 | ); |
---|
383 | |
---|
384 | int imfs_dir_close( |
---|
385 | rtems_libio_t *iop /* IN */ |
---|
386 | ); |
---|
387 | |
---|
388 | ssize_t imfs_dir_read( |
---|
389 | rtems_libio_t *iop, /* IN */ |
---|
390 | void *buffer, /* IN */ |
---|
391 | size_t count /* IN */ |
---|
392 | ); |
---|
393 | |
---|
394 | int imfs_dir_lseek( |
---|
395 | rtems_libio_t *iop, /* IN */ |
---|
396 | off_t offset, /* IN */ |
---|
397 | int whence /* IN */ |
---|
398 | ); |
---|
399 | |
---|
400 | int imfs_dir_fstat( |
---|
401 | rtems_filesystem_location_info_t *loc, /* IN */ |
---|
402 | struct stat *buf /* OUT */ |
---|
403 | ); |
---|
404 | |
---|
405 | int imfs_dir_rmnod( |
---|
406 | rtems_filesystem_location_info_t *pathloc /* IN */ |
---|
407 | ); |
---|
408 | |
---|
409 | int memfile_open( |
---|
410 | rtems_libio_t *iop, /* IN */ |
---|
411 | const char *pathname, /* IN */ |
---|
412 | uint32_t flag, /* IN */ |
---|
413 | uint32_t mode /* IN */ |
---|
414 | ); |
---|
415 | |
---|
416 | int memfile_close( |
---|
417 | rtems_libio_t *iop /* IN */ |
---|
418 | ); |
---|
419 | |
---|
420 | ssize_t memfile_read( |
---|
421 | rtems_libio_t *iop, /* IN */ |
---|
422 | void *buffer, /* IN */ |
---|
423 | size_t count /* IN */ |
---|
424 | ); |
---|
425 | |
---|
426 | ssize_t memfile_write( |
---|
427 | rtems_libio_t *iop, /* IN */ |
---|
428 | const void *buffer, /* IN */ |
---|
429 | size_t count /* IN */ |
---|
430 | ); |
---|
431 | |
---|
432 | int memfile_ioctl( |
---|
433 | rtems_libio_t *iop, /* IN */ |
---|
434 | uint32_t command, /* IN */ |
---|
435 | void *buffer /* IN */ |
---|
436 | ); |
---|
437 | |
---|
438 | int memfile_lseek( |
---|
439 | rtems_libio_t *iop, /* IN */ |
---|
440 | off_t offset, /* IN */ |
---|
441 | int whence /* IN */ |
---|
442 | ); |
---|
443 | |
---|
444 | int memfile_rmnod( |
---|
445 | rtems_filesystem_location_info_t *pathloc /* IN */ |
---|
446 | ); |
---|
447 | |
---|
448 | int device_open( |
---|
449 | rtems_libio_t *iop, /* IN */ |
---|
450 | const char *pathname, /* IN */ |
---|
451 | uint32_t flag, /* IN */ |
---|
452 | uint32_t mode /* IN */ |
---|
453 | ); |
---|
454 | |
---|
455 | int device_close( |
---|
456 | rtems_libio_t *iop /* IN */ |
---|
457 | ); |
---|
458 | |
---|
459 | ssize_t device_read( |
---|
460 | rtems_libio_t *iop, /* IN */ |
---|
461 | void *buffer, /* IN */ |
---|
462 | size_t count /* IN */ |
---|
463 | ); |
---|
464 | |
---|
465 | ssize_t device_write( |
---|
466 | rtems_libio_t *iop, /* IN */ |
---|
467 | const void *buffer, /* IN */ |
---|
468 | size_t count /* IN */ |
---|
469 | ); |
---|
470 | |
---|
471 | int device_ioctl( |
---|
472 | rtems_libio_t *iop, /* IN */ |
---|
473 | uint32_t command, /* IN */ |
---|
474 | void *buffer /* IN */ |
---|
475 | ); |
---|
476 | |
---|
477 | int device_lseek( |
---|
478 | rtems_libio_t *iop, /* IN */ |
---|
479 | off_t offset, /* IN */ |
---|
480 | int whence /* IN */ |
---|
481 | ); |
---|
482 | |
---|
483 | int IMFS_utime( |
---|
484 | rtems_filesystem_location_info_t *pathloc, /* IN */ |
---|
485 | time_t actime, /* IN */ |
---|
486 | time_t modtime /* IN */ |
---|
487 | ); |
---|
488 | |
---|
489 | int IMFS_fchmod( |
---|
490 | rtems_filesystem_location_info_t *loc, |
---|
491 | mode_t mode |
---|
492 | ); |
---|
493 | |
---|
494 | int IMFS_symlink( |
---|
495 | rtems_filesystem_location_info_t *parent_loc, /* IN */ |
---|
496 | const char *link_name, |
---|
497 | const char *node_name |
---|
498 | ); |
---|
499 | |
---|
500 | int IMFS_readlink( |
---|
501 | rtems_filesystem_location_info_t *loc, /* IN */ |
---|
502 | char *buf, /* OUT */ |
---|
503 | size_t bufsize |
---|
504 | ); |
---|
505 | |
---|
506 | int IMFS_fdatasync( |
---|
507 | rtems_libio_t *iop |
---|
508 | ); |
---|
509 | |
---|
510 | int IMFS_fcntl( |
---|
511 | int cmd, |
---|
512 | rtems_libio_t *iop |
---|
513 | ); |
---|
514 | |
---|
515 | int IMFS_rmnod( |
---|
516 | rtems_filesystem_location_info_t *pathloc /* IN */ |
---|
517 | ); |
---|
518 | |
---|
519 | #ifdef __cplusplus |
---|
520 | } |
---|
521 | #endif |
---|
522 | |
---|
523 | #endif |
---|
524 | /* end of include file */ |
---|