RTEMS 5.2
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
imfs.h
Go to the documentation of this file.
1
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.org/license/LICENSE.
14 */
15
16#ifndef _RTEMS_IMFS_H
17#define _RTEMS_IMFS_H
18
19#include <sys/time.h>
20#include <limits.h>
21
22#include <rtems/libio_.h>
23#include <rtems/pipe.h>
25
35#ifdef __cplusplus
36extern "C" {
37#endif
38
39/*
40 * Data types
41 */
42
43struct IMFS_jnode_tt;
44typedef struct IMFS_jnode_tt IMFS_jnode_t;
45
68#define IMFS_MEMFILE_DEFAULT_BYTES_PER_BLOCK 128
69 extern const int imfs_memfile_bytes_per_block;
70
71#define IMFS_MEMFILE_BYTES_PER_BLOCK imfs_memfile_bytes_per_block
72#define IMFS_MEMFILE_BLOCK_SLOTS \
73 (IMFS_MEMFILE_BYTES_PER_BLOCK / sizeof(void *))
74
75typedef uint8_t *block_p;
76typedef block_p *block_ptr;
77
78/*
79 * Important block numbers for "memfiles"
80 */
81#define FIRST_INDIRECT (0)
82#define LAST_INDIRECT (IMFS_MEMFILE_BLOCK_SLOTS - 1)
83
84#define FIRST_DOUBLY_INDIRECT (LAST_INDIRECT + 1)
85#define LAST_DOUBLY_INDIRECT \
86 (LAST_INDIRECT + \
87 (IMFS_MEMFILE_BLOCK_SLOTS * IMFS_MEMFILE_BLOCK_SLOTS))
88
89#define FIRST_TRIPLY_INDIRECT (LAST_DOUBLY_INDIRECT + 1)
90#define LAST_TRIPLY_INDIRECT \
91 (LAST_DOUBLY_INDIRECT +\
92 (IMFS_MEMFILE_BLOCK_SLOTS * \
93 IMFS_MEMFILE_BLOCK_SLOTS * IMFS_MEMFILE_BLOCK_SLOTS))
94
95#define IMFS_MEMFILE_MAXIMUM_SIZE \
96 (LAST_TRIPLY_INDIRECT * IMFS_MEMFILE_BYTES_PER_BLOCK)
97
119typedef IMFS_jnode_t *(*IMFS_node_control_initialize)(
120 IMFS_jnode_t *node,
121 void *arg
122);
123
135 IMFS_jnode_t *node,
136 void *arg
137);
138
139IMFS_jnode_t *IMFS_node_initialize_directory(
140 IMFS_jnode_t *node,
141 void *arg
142);
143
156 IMFS_jnode_t *node,
157 void *arg
158);
159
171typedef IMFS_jnode_t *(*IMFS_node_control_remove)(
172 IMFS_jnode_t *node
173);
174
185 IMFS_jnode_t *node
186);
187
188IMFS_jnode_t *IMFS_node_remove_directory( IMFS_jnode_t *node );
189
198
207
216
220typedef struct {
221 const rtems_filesystem_file_handlers_r *handlers;
222 IMFS_node_control_initialize node_initialize;
223 IMFS_node_control_remove node_remove;
224 IMFS_node_control_destroy node_destroy;
226
227typedef struct {
228 IMFS_node_control node_control;
229 size_t node_size;
231
239/*
240 * Maximum length of a "basename" of an IMFS file/node.
241 */
242
243#define IMFS_NAME_MAX _POSIX_NAME_MAX
244
245/*
246
247 * The control structure for an IMFS jnode.
248 */
249
251 rtems_chain_node Node; /* for chaining them together */
252 IMFS_jnode_t *Parent; /* Parent node */
253 const char *name; /* "basename" (not \0 terminated) */
254 uint16_t namelen; /* Length of "basename" */
255 mode_t st_mode; /* File mode */
256 unsigned short reference_count;
257 nlink_t st_nlink; /* Link count */
258
259 uid_t st_uid; /* User ID of owner */
260 gid_t st_gid; /* Group ID of owner */
261
262 time_t stat_atime; /* Time of last access */
263 time_t stat_mtime; /* Time of last modification */
264 time_t stat_ctime; /* Time of last status change */
266};
267
268typedef struct {
269 IMFS_jnode_t Node;
270 rtems_chain_control Entries;
273
274typedef struct {
275 IMFS_jnode_t Node;
276 rtems_device_major_number major;
277 rtems_device_minor_number minor;
279
280typedef struct {
281 IMFS_jnode_t Node;
282 IMFS_jnode_t *link_node;
284
285typedef struct {
286 IMFS_jnode_t Node;
287 char *name;
289
290typedef struct {
291 IMFS_jnode_t Node;
292 size_t size; /* size of file in bytes */
294
295typedef struct {
296 IMFS_filebase_t File;
297 block_ptr indirect; /* array of 128 data blocks pointers */
298 block_ptr doubly_indirect; /* 128 indirect blocks */
299 block_ptr triply_indirect; /* 128 doubly indirect blocks */
301
302typedef struct {
303 IMFS_filebase_t File;
304 block_p direct; /* pointer to file image */
306
307/* Support copy on write for linear files */
308typedef union {
309 IMFS_jnode_t Node;
310 IMFS_filebase_t File;
311 IMFS_memfile_t Memfile;
312 IMFS_linearfile_t Linearfile;
314
315typedef struct {
316 IMFS_jnode_t Node;
317 pipe_control_t *pipe;
319
320typedef struct {
321 IMFS_jnode_t Node;
322 void *context;
324
325typedef struct {
326 const void *data;
327 size_t size;
329
330static inline IMFS_jnode_t *IMFS_iop_to_node( const rtems_libio_t *iop )
331{
332 return (IMFS_jnode_t *) iop->pathinfo.node_access;
333}
334
335static inline IMFS_directory_t *IMFS_iop_to_directory(
336 const rtems_libio_t *iop
337)
338{
339 return (IMFS_directory_t *) iop->pathinfo.node_access;
340}
341
342static inline IMFS_device_t *IMFS_iop_to_device( const rtems_libio_t *iop )
343{
344 return (IMFS_device_t *) iop->pathinfo.node_access;
345}
346
347static inline IMFS_file_t *IMFS_iop_to_file( const rtems_libio_t *iop )
348{
349 return (IMFS_file_t *) iop->pathinfo.node_access;
350}
351
352static inline IMFS_memfile_t *IMFS_iop_to_memfile( const rtems_libio_t *iop )
353{
354 return (IMFS_memfile_t *) iop->pathinfo.node_access;
355}
356
357static inline time_t _IMFS_get_time( void )
358{
359 struct bintime now;
360
361 /* Use most efficient way to get the time in seconds (CLOCK_REALTIME) */
363
364 return now.sec;
365}
366
367static inline void IMFS_update_atime( IMFS_jnode_t *jnode )
368{
369 jnode->stat_atime = _IMFS_get_time();
370}
371
372static inline void IMFS_update_mtime( IMFS_jnode_t *jnode )
373{
374 jnode->stat_mtime = _IMFS_get_time();
375}
376
377static inline void IMFS_update_ctime( IMFS_jnode_t *jnode )
378{
379 jnode->stat_ctime = _IMFS_get_time();
380}
381
382static inline void IMFS_mtime_ctime_update( IMFS_jnode_t *jnode )
383{
384 time_t now;
385
386 now = _IMFS_get_time();
387
388 jnode->stat_mtime = now;
389 jnode->stat_ctime = now;
390}
391
392typedef struct {
393 const IMFS_mknod_control *directory;
396 const IMFS_mknod_control *fifo;
398
399typedef struct {
400 IMFS_directory_t Root_directory;
401 const IMFS_mknod_controls *mknod_controls;
403
404typedef struct {
405 IMFS_fs_info_t *fs_info;
407 const IMFS_mknod_controls *mknod_controls;
409
410/*
411 * Shared Data
412 */
413
414extern const IMFS_mknod_control IMFS_mknod_control_dir_default;
415extern const IMFS_mknod_control IMFS_mknod_control_dir_minimal;
416extern const IMFS_mknod_control IMFS_mknod_control_device;
417extern const IMFS_mknod_control IMFS_mknod_control_memfile;
418extern const IMFS_node_control IMFS_node_control_linfile;
419extern const IMFS_mknod_control IMFS_mknod_control_fifo;
420extern const IMFS_mknod_control IMFS_mknod_control_enosys;
421
422extern const rtems_filesystem_limits_and_options_t IMFS_LIMITS_AND_OPTIONS;
423
424/*
425 * Routines
426 */
427
428extern int IMFS_initialize(
430 const void *data
431);
432
433extern int IMFS_initialize_support(
435 const void *data
436);
437
441extern void IMFS_fsunmount(
443);
444
496extern int rtems_tarfs_load(
497 const char *mountpoint,
498 uint8_t *tar_image,
499 size_t tar_size
500);
501
505extern void IMFS_node_destroy( IMFS_jnode_t *node );
506
511
515extern void IMFS_node_free( const rtems_filesystem_location_info_t *loc );
516
522extern int IMFS_stat(
524 struct stat *buf
525);
526
527extern int IMFS_stat_file(
529 struct stat *buf
530);
531
535extern void IMFS_eval_path(
537);
538
542extern void IMFS_eval_path_devfs(
544);
545
553extern int IMFS_link(
554 const rtems_filesystem_location_info_t *parentloc,
555 const rtems_filesystem_location_info_t *targetloc,
556 const char *name,
557 size_t namelen
558);
559
566extern int IMFS_chown(
568 uid_t owner,
569 gid_t group
570);
571
577extern int IMFS_mknod(
578 const rtems_filesystem_location_info_t *parentloc,
579 const char *name,
580 size_t namelen,
581 mode_t mode,
582 dev_t dev
583);
584
585extern IMFS_jnode_t *IMFS_initialize_node(
586 IMFS_jnode_t *node,
587 const IMFS_node_control *node_control,
588 const char *name,
589 size_t namelen,
590 mode_t mode,
591 void *arg
592);
593
601 const rtems_filesystem_location_info_t *parentloc,
602 const IMFS_node_control *node_control,
603 size_t node_size,
604 const char *name,
605 size_t namelen,
606 mode_t mode,
607 void *arg
608);
609
610static inline bool IMFS_is_imfs_instance(
612)
613{
614 return loc->mt_entry->ops->clonenod_h == IMFS_node_clone;
615}
616
624#define IMFS_NODE_CONTROL_INITIALIZER( handlers, init, destroy ) \
625 { \
626 ( handlers ), \
627 ( init ), \
628 IMFS_node_remove_default, \
629 ( destroy ) \
630 }
631
644#define IMFS_NODE_INITIALIZER( node_control, name, namelen, mode ) \
645 { \
646 { NULL, NULL }, \
647 NULL, \
648 ( name ), \
649 ( namelen ), \
650 ( mode ), \
651 0, \
652 0, \
653 0, \
654 0, \
655 0, \
656 0, \
657 0, \
658 ( node_control ) \
659 }
660
674static inline void IMFS_node_preinitialize(
675 IMFS_jnode_t *node,
676 const IMFS_node_control *node_control,
677 const char *name,
678 size_t namelen,
679 mode_t mode
680)
681{
682 node->control = node_control;
683 node->name = name;
684 node->namelen = namelen;
685 node->st_mode = mode;
686}
687
701int IMFS_add_node( const char *path, IMFS_jnode_t *node, void *arg );
702
703extern int IMFS_make_node(
704 const char *path,
705 mode_t mode,
706 const IMFS_node_control *node_control,
707 size_t node_size,
708 void *context
709);
710
722extern int IMFS_make_linearfile(
723 const char *path,
724 mode_t mode,
725 const void *data,
726 size_t size
727);
728
747/* Provided for backward compatibility */
748#define IMFS_GENERIC_INITIALIZER( handlers, init, destroy ) \
749 IMFS_NODE_CONTROL_INITIALIZER( handlers, init, destroy )
750
758#define IMFS_GENERIC_CONTROL_INITIALIZER( handlers, init, destroy ) \
759 IMFS_NODE_CONTROL_INITIALIZER( handlers, init, destroy )
760
771#define IMFS_GENERIC_NODE_INITIALIZER( node_control, name, namelen, mode ) \
772 { IMFS_NODE_INITIALIZER( node_control, name, namelen, mode ), NULL }
773
787static inline void IMFS_generic_node_preinitialize(
788 IMFS_generic_t *node,
789 const IMFS_node_control *node_control,
790 const char *name,
791 size_t namelen,
792 mode_t mode
793)
794{
795 IMFS_node_preinitialize( &node->Node, node_control, name, namelen, mode );
796}
797
858extern int IMFS_make_generic_node(
859 const char *path,
860 mode_t mode,
861 const IMFS_node_control *node_control,
862 void *context
863);
864
875extern int IMFS_mount(
876 rtems_filesystem_mount_table_entry_t *mt_entry /* IN */
877);
878
882extern int IMFS_unmount(
883 rtems_filesystem_mount_table_entry_t *mt_entry /* IN */
884);
885
897extern ssize_t IMFS_memfile_write(
898 IMFS_memfile_t *memfile,
899 off_t start,
900 const unsigned char *source,
901 unsigned int length
902);
903
914extern int device_open(
915 rtems_libio_t *iop, /* IN */
916 const char *pathname, /* IN */
917 int oflag, /* IN */
918 mode_t mode /* IN */
919);
920
921extern int device_close(
922 rtems_libio_t *iop /* IN */
923);
924
925extern ssize_t device_read(
926 rtems_libio_t *iop, /* IN */
927 void *buffer, /* IN */
928 size_t count /* IN */
929);
930
931extern ssize_t device_write(
932 rtems_libio_t *iop, /* IN */
933 const void *buffer, /* IN */
934 size_t count /* IN */
935);
936
937extern int device_ioctl(
938 rtems_libio_t *iop,
939 ioctl_command_t command,
940 void *buffer
941);
942
943extern int device_ftruncate(
944 rtems_libio_t *iop, /* IN */
945 off_t length /* IN */
946);
947
957extern int IMFS_utime(
959 time_t actime,
960 time_t modtime
961);
962
966extern int IMFS_fchmod(
968 mode_t mode
969);
970
978extern int IMFS_symlink(
979 const rtems_filesystem_location_info_t *parentloc,
980 const char *name,
981 size_t namelen,
982 const char *target
983);
984
992extern ssize_t IMFS_readlink(
994 char *buf,
995 size_t bufsize
996);
997
1004extern int IMFS_rename(
1005 const rtems_filesystem_location_info_t *oldparentloc,
1007 const rtems_filesystem_location_info_t *newparentloc,
1008 const char *name,
1009 size_t namelen
1010);
1017extern int IMFS_rmnod(
1018 const rtems_filesystem_location_info_t *parentloc,
1020);
1021
1022/*
1023 * Turn on IMFS assertions when RTEMS_DEBUG is defined.
1024 */
1025#ifdef RTEMS_DEBUG
1026 #include <assert.h>
1027
1028 #define IMFS_assert(_x) assert(_x)
1029#else
1030 #define IMFS_assert(_x)
1031#endif
1032
1033static inline void IMFS_Set_handlers( rtems_filesystem_location_info_t *loc )
1034{
1035 IMFS_jnode_t *node = (IMFS_jnode_t *) loc->node_access;
1036
1037 loc->handlers = node->control->handlers;
1038}
1039
1040static inline void IMFS_add_to_directory(
1041 IMFS_jnode_t *dir_node,
1042 IMFS_jnode_t *entry_node
1043)
1044{
1045 IMFS_directory_t *dir = (IMFS_directory_t *) dir_node;
1046
1047 entry_node->Parent = dir_node;
1048 rtems_chain_append_unprotected( &dir->Entries, &entry_node->Node );
1049}
1050
1051static inline void IMFS_remove_from_directory( IMFS_jnode_t *node )
1052{
1053 IMFS_assert( node->Parent != NULL );
1054 node->Parent = NULL;
1055 rtems_chain_extract_unprotected( &node->Node );
1056}
1057
1058static inline bool IMFS_is_directory( const IMFS_jnode_t *node )
1059{
1060 return S_ISDIR( node->st_mode );
1061}
1062
1063#define IMFS_STAT_FMT_HARD_LINK 0
1064
1065static inline bool IMFS_is_hard_link( mode_t mode )
1066{
1067 return ( mode & S_IFMT ) == IMFS_STAT_FMT_HARD_LINK;
1068}
1069
1070static inline ino_t IMFS_node_to_ino( const IMFS_jnode_t *node )
1071{
1072 return (ino_t) ((uintptr_t) node);
1073}
1074
1082static inline void *IMFS_generic_get_context_by_node(
1083 const IMFS_jnode_t *node
1084)
1085{
1086 const IMFS_generic_t *generic = (const IMFS_generic_t *) node;
1087
1088 return generic->context;
1089}
1090
1091static inline void *IMFS_generic_get_context_by_location(
1093)
1094{
1095 return loc->node_access_2;
1096}
1097
1098static inline void *IMFS_generic_get_context_by_iop(
1099 const rtems_libio_t *iop
1100)
1101{
1102 return IMFS_generic_get_context_by_location( &iop->pathinfo );
1103}
1104
1105static inline dev_t IMFS_generic_get_device_identifier_by_node(
1106 const IMFS_jnode_t *node
1107)
1108{
1109 return rtems_filesystem_make_dev_t_from_pointer( node );
1110}
1111
1112#ifdef __cplusplus
1113}
1114#endif
1116#endif
1117/* end of include file */
Information for the Assert Handler.
#define NULL
Requests a GPIO pin group configuration.
Definition: bestcomm_api.h:77
RTEMS_INLINE_ROUTINE void rtems_chain_append_unprotected(rtems_chain_control *the_chain, rtems_chain_node *the_node)
Append a node on the end of a chain (unprotected).
Definition: chain.h:679
RTEMS_INLINE_ROUTINE void rtems_chain_extract_unprotected(rtems_chain_node *the_node)
Extract the specified node from a chain (unprotected).
Definition: chain.h:590
void IMFS_do_nothing_destroy(IMFS_jnode_t *node)
Does nothing.
Definition: imfs_node.c:106
IMFS_jnode_t * IMFS_node_initialize_default(IMFS_jnode_t *node, void *arg)
Returns the node and does nothing else.
Definition: imfs_initsupp.c:72
IMFS_jnode_t * IMFS_node_remove_default(IMFS_jnode_t *node)
Returns the node and does nothing else.
Definition: imfs_node.c:99
void(* IMFS_node_control_destroy)(IMFS_jnode_t *node)
Destroys an IMFS node.
Definition: imfs.h:197
IMFS_jnode_t *(* IMFS_node_control_remove)(IMFS_jnode_t *node)
Prepares the removal of an IMFS node from its parent directory.
Definition: imfs.h:171
IMFS_jnode_t * IMFS_node_initialize_generic(IMFS_jnode_t *node, void *arg)
Returns the node and sets the generic node context.
Definition: imfs_make_generic_node.c:31
IMFS_jnode_t *(* IMFS_node_control_initialize)(IMFS_jnode_t *node, void *arg)
Initializes an IMFS node.
Definition: imfs.h:119
int IMFS_make_generic_node(const char *path, mode_t mode, const IMFS_node_control *node_control, void *context)
Makes a generic IMFS node.
Definition: imfs_make_generic_node.c:43
void IMFS_node_destroy_default(IMFS_jnode_t *node)
Frees the node.
Definition: imfs_node_destroy_default.c:44
int IMFS_chown(const rtems_filesystem_location_info_t *loc, uid_t owner, gid_t group)
Change the owner of IMFS.
Definition: imfs_chown.c:28
int IMFS_rmnod(const rtems_filesystem_location_info_t *parentloc, const rtems_filesystem_location_info_t *loc)
IMFS node removal handler.
Definition: imfs_rmnod.c:27
int IMFS_link(const rtems_filesystem_location_info_t *parentloc, const rtems_filesystem_location_info_t *targetloc, const char *name, size_t namelen)
Create a new IMFS link node.
Definition: imfs_link.c:26
int IMFS_rename(const rtems_filesystem_location_info_t *oldparentloc, const rtems_filesystem_location_info_t *oldloc, const rtems_filesystem_location_info_t *newparentloc, const char *name, size_t namelen)
Rename the IMFS.
Definition: imfs_rename.c:50
void IMFS_fsunmount(rtems_filesystem_mount_table_entry_t *mt_entry)
Unmount this instance of IMFS.
Definition: imfs_fsunmount.c:36
int IMFS_make_linearfile(const char *path, mode_t mode, const void *data, size_t size)
Makes a linear IMFS file.
Definition: imfs_make_linfile.c:34
void IMFS_node_free(const rtems_filesystem_location_info_t *loc)
Free an IMFS node.
Definition: imfs_node.c:88
int IMFS_unmount(rtems_filesystem_mount_table_entry_t *mt_entry)
Unmount an IMFS.
Definition: imfs_unmount.c:27
void IMFS_node_destroy(IMFS_jnode_t *node)
Destroy an IMFS node.
Definition: imfs_node.c:81
int IMFS_symlink(const rtems_filesystem_location_info_t *parentloc, const char *name, size_t namelen, const char *target)
Create a new IMFS symbolic link node.
Definition: imfs_symlink.c:28
int IMFS_add_node(const char *path, IMFS_jnode_t *node, void *arg)
Adds an IMFS node.
Definition: imfs_add_node.c:42
int IMFS_node_clone(rtems_filesystem_location_info_t *loc)
Clone an IMFS node.
Definition: imfs_node.c:72
int IMFS_utime(const rtems_filesystem_location_info_t *loc, time_t actime, time_t modtime)
Set IMFS file access and modification times.
Definition: imfs_utime.c:26
int IMFS_mount(rtems_filesystem_mount_table_entry_t *mt_entry)
Mount an IMFS.
Definition: imfs_mount.c:27
int IMFS_mknod(const rtems_filesystem_location_info_t *parentloc, const char *name, size_t namelen, mode_t mode, dev_t dev)
Create an IMFS node.
Definition: imfs_mknod.c:44
int rtems_tarfs_load(const char *mountpoint, uint8_t *tar_image, size_t tar_size)
RTEMS load tarfs.
Definition: imfs_load_tar.c:27
void IMFS_eval_path(rtems_filesystem_eval_path_context_t *ctx)
IMFS evaluation node support.
Definition: imfs_eval.c:176
IMFS_jnode_t * IMFS_create_node(const rtems_filesystem_location_info_t *parentloc, const IMFS_node_control *node_control, size_t node_size, const char *name, size_t namelen, mode_t mode, void *arg)
Create an IMFS node.
Definition: imfs_creat.c:26
int IMFS_stat(const rtems_filesystem_location_info_t *loc, struct stat *buf)
Perform a status processing for the IMFS.
Definition: imfs_stat.c:27
ssize_t IMFS_readlink(const rtems_filesystem_location_info_t *loc, char *buf, size_t bufsize)
Put IMFS symbolic link into buffer.
Definition: imfs_symlink.c:57
int IMFS_fchmod(const rtems_filesystem_location_info_t *loc, mode_t mode)
Change the IMFS file mode.
Definition: imfs_fchmod.c:24
void IMFS_eval_path_devfs(rtems_filesystem_eval_path_context_t *ctx)
IMFS device filesystem evaluation node support.
Definition: imfs_eval_devfs.c:123
void _Timecounter_Getbintime(struct bintime *bt)
Returns the wall clock time in the bintime format.
LibIO Internal Interface.
POSIX FIFO/pipe File System Support.
Timecounter API.
Definition: chain.h:68
Definition: imfs.h:274
Definition: imfs.h:268
Definition: imfs.h:315
Definition: imfs.h:290
Definition: imfs.h:399
Definition: imfs.h:320
Definition: imfs.h:250
Definition: imfs.h:325
Definition: imfs.h:302
Definition: imfs.h:295
Definition: imfs.h:227
Definition: imfs.h:392
Definition: imfs.h:404
IMFS node control.
Definition: imfs.h:220
File system node operations table.
Definition: libio.h:1005
File system operations table.
Definition: libio.h:472
Definition: intercom.c:74
Definition: rtemscompat1.h:15
Definition: mongoose.c:442
Definition: pipe.h:38
Path evaluation context.
Definition: libio.h:84
Contain file system specific information which is required to support fpathconf().
Definition: libio.h:1289
File system location.
Definition: fs.h:53
Mount table entry.
Definition: libio.h:1604
An open file data structure.
Definition: libio.h:1320
unsigned context
Definition: tlb.h:1
unsigned size
Definition: tte.h:1
Definition: chain.h:86
Definition: imfs.h:308