1 | /** |
---|
2 | * @file rtems/imfs.h |
---|
3 | * |
---|
4 | * Header file for the In-Memory File System |
---|
5 | */ |
---|
6 | |
---|
7 | /* |
---|
8 | * COPYRIGHT (c) 1989-2011. |
---|
9 | * On-Line Applications Research Corporation (OAR). |
---|
10 | * |
---|
11 | * The license and distribution terms for this file may be |
---|
12 | * found in the file LICENSE in this distribution or at |
---|
13 | * http://www.rtems.com/license/LICENSE. |
---|
14 | */ |
---|
15 | |
---|
16 | #ifndef _RTEMS_IMFS_H |
---|
17 | #define _RTEMS_IMFS_H |
---|
18 | |
---|
19 | #include <limits.h> |
---|
20 | |
---|
21 | #include <rtems/libio_.h> |
---|
22 | #include <rtems/pipe.h> |
---|
23 | |
---|
24 | #ifdef __cplusplus |
---|
25 | extern "C" { |
---|
26 | #endif |
---|
27 | |
---|
28 | /* |
---|
29 | * Data types |
---|
30 | */ |
---|
31 | |
---|
32 | struct IMFS_jnode_tt; |
---|
33 | typedef struct IMFS_jnode_tt IMFS_jnode_t; |
---|
34 | |
---|
35 | typedef struct { |
---|
36 | rtems_chain_control Entries; |
---|
37 | rtems_filesystem_mount_table_entry_t *mt_fs; |
---|
38 | } IMFS_directory_t; |
---|
39 | |
---|
40 | typedef struct { |
---|
41 | rtems_device_major_number major; |
---|
42 | rtems_device_minor_number minor; |
---|
43 | } IMFS_device_t; |
---|
44 | |
---|
45 | typedef struct { |
---|
46 | IMFS_jnode_t *link_node; |
---|
47 | } IMFS_link_t; |
---|
48 | |
---|
49 | typedef struct { |
---|
50 | char *name; |
---|
51 | } IMFS_sym_link_t; |
---|
52 | |
---|
53 | typedef struct { |
---|
54 | pipe_control_t *pipe; |
---|
55 | } IMFS_fifo_t; |
---|
56 | |
---|
57 | typedef struct { |
---|
58 | void *context; |
---|
59 | } IMFS_generic_t; |
---|
60 | |
---|
61 | /* |
---|
62 | * IMFS "memfile" information |
---|
63 | * |
---|
64 | * The data structure for the in-memory "memfiles" is based on classic UNIX. |
---|
65 | * |
---|
66 | * block_ptr is a pointer to a block of IMFS_MEMFILE_BYTES_PER_BLOCK in |
---|
67 | * length which could be data or a table of pointers to blocks. |
---|
68 | * |
---|
69 | * Setting IMFS_MEMFILE_BYTES_PER_BLOCK to different values has a significant |
---|
70 | * impact on the maximum file size supported as well as the amount of |
---|
71 | * memory wasted due to internal file fragmentation. The following |
---|
72 | * is a list of maximum file sizes based on various settings |
---|
73 | * |
---|
74 | * max_filesize with blocks of 16 is 1,328 |
---|
75 | * max_filesize with blocks of 32 is 18,656 |
---|
76 | * max_filesize with blocks of 64 is 279,488 |
---|
77 | * max_filesize with blocks of 128 is 4,329,344 |
---|
78 | * max_filesize with blocks of 256 is 68,173,568 |
---|
79 | * max_filesize with blocks of 512 is 1,082,195,456 |
---|
80 | */ |
---|
81 | |
---|
82 | #define IMFS_MEMFILE_DEFAULT_BYTES_PER_BLOCK 128 |
---|
83 | extern int imfs_rq_memfile_bytes_per_block; |
---|
84 | extern int imfs_memfile_bytes_per_block; |
---|
85 | |
---|
86 | #define IMFS_MEMFILE_BYTES_PER_BLOCK imfs_memfile_bytes_per_block |
---|
87 | #define IMFS_MEMFILE_BLOCK_SLOTS \ |
---|
88 | (IMFS_MEMFILE_BYTES_PER_BLOCK / sizeof(void *)) |
---|
89 | |
---|
90 | typedef uint8_t *block_p; |
---|
91 | typedef block_p *block_ptr; |
---|
92 | |
---|
93 | typedef struct { |
---|
94 | off_t size; /* size of file in bytes */ |
---|
95 | block_ptr indirect; /* array of 128 data blocks pointers */ |
---|
96 | block_ptr doubly_indirect; /* 128 indirect blocks */ |
---|
97 | block_ptr triply_indirect; /* 128 doubly indirect blocks */ |
---|
98 | } IMFS_memfile_t; |
---|
99 | |
---|
100 | typedef struct { |
---|
101 | off_t size; /* size of file in bytes */ |
---|
102 | block_p direct; /* pointer to file image */ |
---|
103 | } IMFS_linearfile_t; |
---|
104 | |
---|
105 | /* |
---|
106 | * Important block numbers for "memfiles" |
---|
107 | */ |
---|
108 | |
---|
109 | #define FIRST_INDIRECT (0) |
---|
110 | #define LAST_INDIRECT (IMFS_MEMFILE_BLOCK_SLOTS - 1) |
---|
111 | |
---|
112 | #define FIRST_DOUBLY_INDIRECT (LAST_INDIRECT + 1) |
---|
113 | #define LAST_DOUBLY_INDIRECT \ |
---|
114 | (LAST_INDIRECT + \ |
---|
115 | (IMFS_MEMFILE_BLOCK_SLOTS * IMFS_MEMFILE_BLOCK_SLOTS)) |
---|
116 | |
---|
117 | #define FIRST_TRIPLY_INDIRECT (LAST_DOUBLY_INDIRECT + 1) |
---|
118 | #define LAST_TRIPLY_INDIRECT \ |
---|
119 | (LAST_DOUBLY_INDIRECT +\ |
---|
120 | (IMFS_MEMFILE_BLOCK_SLOTS * \ |
---|
121 | IMFS_MEMFILE_BLOCK_SLOTS * IMFS_MEMFILE_BLOCK_SLOTS)) |
---|
122 | |
---|
123 | #define IMFS_MEMFILE_MAXIMUM_SIZE \ |
---|
124 | (LAST_TRIPLY_INDIRECT * IMFS_MEMFILE_BYTES_PER_BLOCK) |
---|
125 | |
---|
126 | /* |
---|
127 | * What types of IMFS file systems entities there can be. |
---|
128 | */ |
---|
129 | |
---|
130 | typedef enum { |
---|
131 | IMFS_DIRECTORY = RTEMS_FILESYSTEM_DIRECTORY, |
---|
132 | IMFS_DEVICE = RTEMS_FILESYSTEM_DEVICE, |
---|
133 | IMFS_HARD_LINK = RTEMS_FILESYSTEM_HARD_LINK, |
---|
134 | IMFS_SYM_LINK = RTEMS_FILESYSTEM_SYM_LINK, |
---|
135 | IMFS_MEMORY_FILE = RTEMS_FILESYSTEM_MEMORY_FILE, |
---|
136 | IMFS_LINEAR_FILE, |
---|
137 | IMFS_FIFO, |
---|
138 | IMFS_GENERIC, |
---|
139 | IMFS_INVALID_NODE |
---|
140 | } IMFS_jnode_types_t; |
---|
141 | |
---|
142 | /* The IMFS_GENERIC does not count */ |
---|
143 | #define IMFS_TYPE_COUNT (IMFS_FIFO + 1) |
---|
144 | |
---|
145 | typedef union { |
---|
146 | IMFS_directory_t directory; |
---|
147 | IMFS_device_t device; |
---|
148 | IMFS_link_t hard_link; |
---|
149 | IMFS_sym_link_t sym_link; |
---|
150 | IMFS_memfile_t file; |
---|
151 | IMFS_linearfile_t linearfile; |
---|
152 | IMFS_fifo_t fifo; |
---|
153 | IMFS_generic_t generic; |
---|
154 | } IMFS_types_union; |
---|
155 | |
---|
156 | typedef IMFS_jnode_t *(*IMFS_node_control_initialize)( |
---|
157 | IMFS_jnode_t *node, |
---|
158 | const IMFS_types_union *info |
---|
159 | ); |
---|
160 | |
---|
161 | IMFS_jnode_t *IMFS_node_initialize_default( |
---|
162 | IMFS_jnode_t *node, |
---|
163 | const IMFS_types_union *info |
---|
164 | ); |
---|
165 | |
---|
166 | IMFS_jnode_t *IMFS_node_initialize_generic( |
---|
167 | IMFS_jnode_t *node, |
---|
168 | const IMFS_types_union *info |
---|
169 | ); |
---|
170 | |
---|
171 | typedef IMFS_jnode_t *(*IMFS_node_control_remove)( |
---|
172 | IMFS_jnode_t *node, |
---|
173 | const IMFS_jnode_t *root_node |
---|
174 | ); |
---|
175 | |
---|
176 | IMFS_jnode_t *IMFS_node_remove_default( |
---|
177 | IMFS_jnode_t *node, |
---|
178 | const IMFS_jnode_t *root_node |
---|
179 | ); |
---|
180 | |
---|
181 | typedef IMFS_jnode_t *(*IMFS_node_control_destroy)( IMFS_jnode_t *node ); |
---|
182 | |
---|
183 | IMFS_jnode_t *IMFS_node_destroy_default( IMFS_jnode_t *node ); |
---|
184 | |
---|
185 | typedef struct { |
---|
186 | IMFS_jnode_types_t imfs_type; |
---|
187 | const rtems_filesystem_file_handlers_r *handlers; |
---|
188 | IMFS_node_control_initialize node_initialize; |
---|
189 | IMFS_node_control_remove node_remove; |
---|
190 | IMFS_node_control_destroy node_destroy; |
---|
191 | } IMFS_node_control; |
---|
192 | |
---|
193 | /* |
---|
194 | * Major device number for the IMFS. This is not a real device number because |
---|
195 | * the IMFS is just a file system and does not have a driver. |
---|
196 | */ |
---|
197 | #define IMFS_DEVICE_MAJOR_NUMBER (0xfffe) |
---|
198 | |
---|
199 | #define IMFS_GENERIC_DEVICE_MAJOR_NUMBER (0xfffd) |
---|
200 | |
---|
201 | /* |
---|
202 | * Maximum length of a "basename" of an IMFS file/node. |
---|
203 | */ |
---|
204 | |
---|
205 | #define IMFS_NAME_MAX 32 |
---|
206 | |
---|
207 | /* |
---|
208 | * The control structure for an IMFS jnode. |
---|
209 | */ |
---|
210 | |
---|
211 | struct IMFS_jnode_tt { |
---|
212 | rtems_chain_node Node; /* for chaining them together */ |
---|
213 | IMFS_jnode_t *Parent; /* Parent node */ |
---|
214 | char name[IMFS_NAME_MAX+1]; /* "basename" */ |
---|
215 | mode_t st_mode; /* File mode */ |
---|
216 | unsigned short reference_count; |
---|
217 | nlink_t st_nlink; /* Link count */ |
---|
218 | ino_t st_ino; /* inode */ |
---|
219 | |
---|
220 | uid_t st_uid; /* User ID of owner */ |
---|
221 | gid_t st_gid; /* Group ID of owner */ |
---|
222 | |
---|
223 | time_t stat_atime; /* Time of last access */ |
---|
224 | time_t stat_mtime; /* Time of last modification */ |
---|
225 | time_t stat_ctime; /* Time of last status change */ |
---|
226 | const IMFS_node_control *control; |
---|
227 | IMFS_types_union info; |
---|
228 | }; |
---|
229 | |
---|
230 | #define IMFS_update_atime( _jnode ) \ |
---|
231 | do { \ |
---|
232 | struct timeval tv; \ |
---|
233 | gettimeofday( &tv, 0 ); \ |
---|
234 | _jnode->stat_atime = (time_t) tv.tv_sec; \ |
---|
235 | } while (0) |
---|
236 | |
---|
237 | #define IMFS_update_mtime( _jnode ) \ |
---|
238 | do { \ |
---|
239 | struct timeval tv; \ |
---|
240 | gettimeofday( &tv, 0 ); \ |
---|
241 | _jnode->stat_mtime = (time_t) tv.tv_sec; \ |
---|
242 | } while (0) |
---|
243 | |
---|
244 | #define IMFS_update_ctime( _jnode ) \ |
---|
245 | do { \ |
---|
246 | struct timeval tv; \ |
---|
247 | gettimeofday( &tv, 0 ); \ |
---|
248 | _jnode->stat_ctime = (time_t) tv.tv_sec; \ |
---|
249 | } while (0) |
---|
250 | |
---|
251 | #define IMFS_mtime_ctime_update( _jnode ) \ |
---|
252 | do { \ |
---|
253 | struct timeval tv; \ |
---|
254 | gettimeofday( &tv, 0 ); \ |
---|
255 | _jnode->stat_mtime = (time_t) tv.tv_sec; \ |
---|
256 | _jnode->stat_ctime = (time_t) tv.tv_sec; \ |
---|
257 | } while (0) |
---|
258 | |
---|
259 | typedef struct { |
---|
260 | int instance; |
---|
261 | ino_t ino_count; |
---|
262 | const IMFS_node_control *node_controls [IMFS_TYPE_COUNT]; |
---|
263 | } IMFS_fs_info_t; |
---|
264 | |
---|
265 | /* |
---|
266 | * Shared Data |
---|
267 | */ |
---|
268 | |
---|
269 | extern const IMFS_node_control IMFS_node_control_directory; |
---|
270 | extern const IMFS_node_control IMFS_node_control_device; |
---|
271 | extern const IMFS_node_control IMFS_node_control_hard_link; |
---|
272 | extern const IMFS_node_control IMFS_node_control_sym_link; |
---|
273 | extern const IMFS_node_control IMFS_node_control_memfile; |
---|
274 | extern const IMFS_node_control IMFS_node_control_linfile; |
---|
275 | extern const IMFS_node_control IMFS_node_control_fifo; |
---|
276 | extern const IMFS_node_control IMFS_node_control_default; |
---|
277 | |
---|
278 | extern const rtems_filesystem_operations_table miniIMFS_ops; |
---|
279 | extern const rtems_filesystem_operations_table IMFS_ops; |
---|
280 | extern const rtems_filesystem_operations_table fifoIMFS_ops; |
---|
281 | |
---|
282 | extern const rtems_filesystem_limits_and_options_t IMFS_LIMITS_AND_OPTIONS; |
---|
283 | |
---|
284 | /* |
---|
285 | * Routines |
---|
286 | */ |
---|
287 | |
---|
288 | extern int IMFS_initialize( |
---|
289 | rtems_filesystem_mount_table_entry_t *mt_entry, |
---|
290 | const void *data |
---|
291 | ); |
---|
292 | |
---|
293 | extern int fifoIMFS_initialize( |
---|
294 | rtems_filesystem_mount_table_entry_t *mt_entry, |
---|
295 | const void *data |
---|
296 | ); |
---|
297 | |
---|
298 | extern int miniIMFS_initialize( |
---|
299 | rtems_filesystem_mount_table_entry_t *mt_entry, |
---|
300 | const void *data |
---|
301 | ); |
---|
302 | |
---|
303 | extern int IMFS_initialize_support( |
---|
304 | rtems_filesystem_mount_table_entry_t *mt_entry, |
---|
305 | const rtems_filesystem_operations_table *op_table, |
---|
306 | const IMFS_node_control *const node_controls [IMFS_TYPE_COUNT] |
---|
307 | ); |
---|
308 | |
---|
309 | extern void IMFS_fsunmount( |
---|
310 | rtems_filesystem_mount_table_entry_t *mt_entry |
---|
311 | ); |
---|
312 | |
---|
313 | extern int rtems_tarfs_load( |
---|
314 | const char *mountpoint, |
---|
315 | uint8_t *tar_image, |
---|
316 | size_t tar_size |
---|
317 | ); |
---|
318 | |
---|
319 | extern void IMFS_dump( void ); |
---|
320 | |
---|
321 | /* |
---|
322 | * Return the size of the largest file which can be created |
---|
323 | * using the IMFS memory file type. |
---|
324 | */ |
---|
325 | extern int IMFS_memfile_maximum_size( void ); |
---|
326 | |
---|
327 | extern void IMFS_node_destroy( IMFS_jnode_t *node ); |
---|
328 | |
---|
329 | extern int IMFS_node_clone( rtems_filesystem_location_info_t *loc ); |
---|
330 | |
---|
331 | extern void IMFS_node_free( const rtems_filesystem_location_info_t *loc ); |
---|
332 | |
---|
333 | extern rtems_filesystem_node_types_t IMFS_node_type( |
---|
334 | const rtems_filesystem_location_info_t *loc |
---|
335 | ); |
---|
336 | |
---|
337 | extern int IMFS_stat( |
---|
338 | const rtems_filesystem_location_info_t *loc, |
---|
339 | struct stat *buf |
---|
340 | ); |
---|
341 | |
---|
342 | extern void IMFS_eval_path( |
---|
343 | rtems_filesystem_eval_path_context_t *ctx |
---|
344 | ); |
---|
345 | |
---|
346 | extern int IMFS_link( |
---|
347 | const rtems_filesystem_location_info_t *parentloc, |
---|
348 | const rtems_filesystem_location_info_t *targetloc, |
---|
349 | const char *name, |
---|
350 | size_t namelen |
---|
351 | ); |
---|
352 | |
---|
353 | extern int IMFS_chown( |
---|
354 | const rtems_filesystem_location_info_t *loc, |
---|
355 | uid_t owner, |
---|
356 | gid_t group |
---|
357 | ); |
---|
358 | |
---|
359 | extern int IMFS_mknod( |
---|
360 | const rtems_filesystem_location_info_t *parentloc, |
---|
361 | const char *name, |
---|
362 | size_t namelen, |
---|
363 | mode_t mode, |
---|
364 | dev_t dev |
---|
365 | ); |
---|
366 | |
---|
367 | extern IMFS_jnode_t *IMFS_allocate_node( |
---|
368 | IMFS_fs_info_t *fs_info, |
---|
369 | const IMFS_node_control *node_control, |
---|
370 | const char *name, |
---|
371 | size_t namelen, |
---|
372 | mode_t mode, |
---|
373 | const IMFS_types_union *info |
---|
374 | ); |
---|
375 | |
---|
376 | extern IMFS_jnode_t *IMFS_create_node_with_control( |
---|
377 | const rtems_filesystem_location_info_t *parentloc, |
---|
378 | const IMFS_node_control *node_control, |
---|
379 | const char *name, |
---|
380 | size_t namelen, |
---|
381 | mode_t mode, |
---|
382 | const IMFS_types_union *info |
---|
383 | ); |
---|
384 | |
---|
385 | extern bool IMFS_is_imfs_instance( |
---|
386 | const rtems_filesystem_location_info_t *loc |
---|
387 | ); |
---|
388 | |
---|
389 | extern int IMFS_make_generic_node( |
---|
390 | const char *path, |
---|
391 | mode_t mode, |
---|
392 | const IMFS_node_control *node_control, |
---|
393 | void *context |
---|
394 | ); |
---|
395 | |
---|
396 | extern int IMFS_mount( |
---|
397 | rtems_filesystem_mount_table_entry_t *mt_entry /* IN */ |
---|
398 | ); |
---|
399 | |
---|
400 | extern int IMFS_unmount( |
---|
401 | rtems_filesystem_mount_table_entry_t *mt_entry /* IN */ |
---|
402 | ); |
---|
403 | |
---|
404 | extern IMFS_jnode_t *IMFS_memfile_remove( |
---|
405 | IMFS_jnode_t *the_jnode /* IN/OUT */ |
---|
406 | ); |
---|
407 | |
---|
408 | extern int memfile_ftruncate( |
---|
409 | rtems_libio_t *iop, /* IN */ |
---|
410 | off_t length /* IN */ |
---|
411 | ); |
---|
412 | |
---|
413 | extern ssize_t imfs_dir_read( |
---|
414 | rtems_libio_t *iop, /* IN */ |
---|
415 | void *buffer, /* IN */ |
---|
416 | size_t count /* IN */ |
---|
417 | ); |
---|
418 | |
---|
419 | extern int memfile_open( |
---|
420 | rtems_libio_t *iop, /* IN */ |
---|
421 | const char *pathname, /* IN */ |
---|
422 | int oflag, /* IN */ |
---|
423 | mode_t mode /* IN */ |
---|
424 | ); |
---|
425 | |
---|
426 | extern ssize_t memfile_read( |
---|
427 | rtems_libio_t *iop, /* IN */ |
---|
428 | void *buffer, /* IN */ |
---|
429 | size_t count /* IN */ |
---|
430 | ); |
---|
431 | |
---|
432 | extern ssize_t memfile_write( |
---|
433 | rtems_libio_t *iop, /* IN */ |
---|
434 | const void *buffer, /* IN */ |
---|
435 | size_t count /* IN */ |
---|
436 | ); |
---|
437 | |
---|
438 | extern int device_open( |
---|
439 | rtems_libio_t *iop, /* IN */ |
---|
440 | const char *pathname, /* IN */ |
---|
441 | int oflag, /* IN */ |
---|
442 | mode_t mode /* IN */ |
---|
443 | ); |
---|
444 | |
---|
445 | extern int device_close( |
---|
446 | rtems_libio_t *iop /* IN */ |
---|
447 | ); |
---|
448 | |
---|
449 | extern ssize_t device_read( |
---|
450 | rtems_libio_t *iop, /* IN */ |
---|
451 | void *buffer, /* IN */ |
---|
452 | size_t count /* IN */ |
---|
453 | ); |
---|
454 | |
---|
455 | extern ssize_t device_write( |
---|
456 | rtems_libio_t *iop, /* IN */ |
---|
457 | const void *buffer, /* IN */ |
---|
458 | size_t count /* IN */ |
---|
459 | ); |
---|
460 | |
---|
461 | extern int device_ioctl( |
---|
462 | rtems_libio_t *iop, |
---|
463 | ioctl_command_t command, |
---|
464 | void *buffer |
---|
465 | ); |
---|
466 | |
---|
467 | extern int device_ftruncate( |
---|
468 | rtems_libio_t *iop, /* IN */ |
---|
469 | off_t length /* IN */ |
---|
470 | ); |
---|
471 | |
---|
472 | extern int IMFS_utime( |
---|
473 | const rtems_filesystem_location_info_t *loc, |
---|
474 | time_t actime, |
---|
475 | time_t modtime |
---|
476 | ); |
---|
477 | |
---|
478 | extern int IMFS_fchmod( |
---|
479 | const rtems_filesystem_location_info_t *loc, |
---|
480 | mode_t mode |
---|
481 | ); |
---|
482 | |
---|
483 | extern int IMFS_symlink( |
---|
484 | const rtems_filesystem_location_info_t *parentloc, |
---|
485 | const char *name, |
---|
486 | size_t namelen, |
---|
487 | const char *target |
---|
488 | ); |
---|
489 | |
---|
490 | extern ssize_t IMFS_readlink( |
---|
491 | const rtems_filesystem_location_info_t *loc, |
---|
492 | char *buf, |
---|
493 | size_t bufsize |
---|
494 | ); |
---|
495 | |
---|
496 | extern int IMFS_rename( |
---|
497 | const rtems_filesystem_location_info_t *oldparentloc, |
---|
498 | const rtems_filesystem_location_info_t *oldloc, |
---|
499 | const rtems_filesystem_location_info_t *newparentloc, |
---|
500 | const char *name, |
---|
501 | size_t namelen |
---|
502 | ); |
---|
503 | |
---|
504 | extern int IMFS_rmnod( |
---|
505 | const rtems_filesystem_location_info_t *parentloc, |
---|
506 | const rtems_filesystem_location_info_t *loc |
---|
507 | ); |
---|
508 | |
---|
509 | /* |
---|
510 | * Turn on IMFS assertions when RTEMS_DEBUG is defined. |
---|
511 | */ |
---|
512 | #ifdef RTEMS_DEBUG |
---|
513 | #include <assert.h> |
---|
514 | |
---|
515 | #define IMFS_assert(_x) assert(_x) |
---|
516 | #else |
---|
517 | #define IMFS_assert(_x) |
---|
518 | #endif |
---|
519 | |
---|
520 | static inline void IMFS_Set_handlers( rtems_filesystem_location_info_t *loc ) |
---|
521 | { |
---|
522 | IMFS_jnode_t *node = (IMFS_jnode_t *) loc->node_access; |
---|
523 | |
---|
524 | loc->handlers = node->control->handlers; |
---|
525 | } |
---|
526 | |
---|
527 | static inline void IMFS_add_to_directory( |
---|
528 | IMFS_jnode_t *dir, |
---|
529 | IMFS_jnode_t *node |
---|
530 | ) |
---|
531 | { |
---|
532 | node->Parent = dir; |
---|
533 | rtems_chain_append_unprotected( &dir->info.directory.Entries, &node->Node ); |
---|
534 | } |
---|
535 | |
---|
536 | static inline void IMFS_remove_from_directory( IMFS_jnode_t *node ) |
---|
537 | { |
---|
538 | IMFS_assert( node->Parent != NULL ); |
---|
539 | node->Parent = NULL; |
---|
540 | rtems_chain_extract_unprotected( &node->Node ); |
---|
541 | } |
---|
542 | |
---|
543 | static inline IMFS_jnode_types_t IMFS_type( const IMFS_jnode_t *node ) |
---|
544 | { |
---|
545 | return node->control->imfs_type; |
---|
546 | } |
---|
547 | |
---|
548 | static inline bool IMFS_is_directory( const IMFS_jnode_t *node ) |
---|
549 | { |
---|
550 | return node->control->imfs_type == IMFS_DIRECTORY; |
---|
551 | } |
---|
552 | |
---|
553 | static inline IMFS_jnode_t *IMFS_create_node( |
---|
554 | const rtems_filesystem_location_info_t *parentloc, |
---|
555 | IMFS_jnode_types_t type, |
---|
556 | const char *name, |
---|
557 | size_t namelen, |
---|
558 | mode_t mode, |
---|
559 | const IMFS_types_union *info |
---|
560 | ) |
---|
561 | { |
---|
562 | const IMFS_fs_info_t *fs_info = |
---|
563 | (const IMFS_fs_info_t *) parentloc->mt_entry->fs_info; |
---|
564 | |
---|
565 | return IMFS_create_node_with_control( |
---|
566 | parentloc, |
---|
567 | fs_info->node_controls [type], |
---|
568 | name, |
---|
569 | namelen, |
---|
570 | mode, |
---|
571 | info |
---|
572 | ); |
---|
573 | } |
---|
574 | |
---|
575 | static inline void *IMFS_generic_get_context_by_node( |
---|
576 | const IMFS_jnode_t *node |
---|
577 | ) |
---|
578 | { |
---|
579 | return node->info.generic.context; |
---|
580 | } |
---|
581 | |
---|
582 | static inline void *IMFS_generic_get_context_by_location( |
---|
583 | const rtems_filesystem_location_info_t *loc |
---|
584 | ) |
---|
585 | { |
---|
586 | const IMFS_jnode_t *node = (const IMFS_jnode_t *) loc->node_access; |
---|
587 | |
---|
588 | return IMFS_generic_get_context_by_node( node ); |
---|
589 | } |
---|
590 | |
---|
591 | static inline void *IMFS_generic_get_context_by_iop( |
---|
592 | const rtems_libio_t *iop |
---|
593 | ) |
---|
594 | { |
---|
595 | return IMFS_generic_get_context_by_location( &iop->pathinfo ); |
---|
596 | } |
---|
597 | |
---|
598 | static inline dev_t IMFS_generic_get_device_identifier_by_node( |
---|
599 | const IMFS_jnode_t *node |
---|
600 | ) |
---|
601 | { |
---|
602 | return rtems_filesystem_make_dev_t( |
---|
603 | IMFS_GENERIC_DEVICE_MAJOR_NUMBER, |
---|
604 | node->st_ino |
---|
605 | ); |
---|
606 | } |
---|
607 | |
---|
608 | #ifdef __cplusplus |
---|
609 | } |
---|
610 | #endif |
---|
611 | |
---|
612 | #endif |
---|
613 | /* end of include file */ |
---|