RTEMS  5.0.0
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
36 extern "C" {
37 #endif
38 
39 /*
40  * Data types
41  */
42 
43 struct IMFS_jnode_tt;
44 typedef struct IMFS_jnode_tt IMFS_jnode_t;
45 
68 #define IMFS_MEMFILE_DEFAULT_BYTES_PER_BLOCK 128
69  extern int imfs_rq_memfile_bytes_per_block;
70  extern int imfs_memfile_bytes_per_block;
71 
72 #define IMFS_MEMFILE_BYTES_PER_BLOCK imfs_memfile_bytes_per_block
73 #define IMFS_MEMFILE_BLOCK_SLOTS \
74  (IMFS_MEMFILE_BYTES_PER_BLOCK / sizeof(void *))
75 
76 typedef uint8_t *block_p;
77 typedef block_p *block_ptr;
78 
79 /*
80  * Important block numbers for "memfiles"
81  */
82 #define FIRST_INDIRECT (0)
83 #define LAST_INDIRECT (IMFS_MEMFILE_BLOCK_SLOTS - 1)
84 
85 #define FIRST_DOUBLY_INDIRECT (LAST_INDIRECT + 1)
86 #define LAST_DOUBLY_INDIRECT \
87  (LAST_INDIRECT + \
88  (IMFS_MEMFILE_BLOCK_SLOTS * IMFS_MEMFILE_BLOCK_SLOTS))
89 
90 #define FIRST_TRIPLY_INDIRECT (LAST_DOUBLY_INDIRECT + 1)
91 #define LAST_TRIPLY_INDIRECT \
92  (LAST_DOUBLY_INDIRECT +\
93  (IMFS_MEMFILE_BLOCK_SLOTS * \
94  IMFS_MEMFILE_BLOCK_SLOTS * IMFS_MEMFILE_BLOCK_SLOTS))
95 
96 #define IMFS_MEMFILE_MAXIMUM_SIZE \
97  (LAST_TRIPLY_INDIRECT * IMFS_MEMFILE_BYTES_PER_BLOCK)
98 
120 typedef IMFS_jnode_t *(*IMFS_node_control_initialize)(
121  IMFS_jnode_t *node,
122  void *arg
123 );
124 
136  IMFS_jnode_t *node,
137  void *arg
138 );
139 
140 IMFS_jnode_t *IMFS_node_initialize_directory(
141  IMFS_jnode_t *node,
142  void *arg
143 );
144 
157  IMFS_jnode_t *node,
158  void *arg
159 );
160 
172 typedef IMFS_jnode_t *(*IMFS_node_control_remove)(
173  IMFS_jnode_t *node
174 );
175 
186  IMFS_jnode_t *node
187 );
188 
189 IMFS_jnode_t *IMFS_node_remove_directory( IMFS_jnode_t *node );
190 
198 typedef void (*IMFS_node_control_destroy)( IMFS_jnode_t *node );
199 
208 
212 typedef struct {
213  const rtems_filesystem_file_handlers_r *handlers;
214  IMFS_node_control_initialize node_initialize;
215  IMFS_node_control_remove node_remove;
216  IMFS_node_control_destroy node_destroy;
218 
219 typedef struct {
220  IMFS_node_control node_control;
221  size_t node_size;
223 
231 /*
232  * Maximum length of a "basename" of an IMFS file/node.
233  */
234 
235 #define IMFS_NAME_MAX _POSIX_NAME_MAX
236 
237 /*
238 
239  * The control structure for an IMFS jnode.
240  */
241 
243  rtems_chain_node Node; /* for chaining them together */
244  IMFS_jnode_t *Parent; /* Parent node */
245  const char *name; /* "basename" (not \0 terminated) */
246  uint16_t namelen; /* Length of "basename" */
247  uint16_t flags; /* Node flags */
248  mode_t st_mode; /* File mode */
249  unsigned short reference_count;
250  nlink_t st_nlink; /* Link count */
251 
252  uid_t st_uid; /* User ID of owner */
253  gid_t st_gid; /* Group ID of owner */
254 
255  time_t stat_atime; /* Time of last access */
256  time_t stat_mtime; /* Time of last modification */
257  time_t stat_ctime; /* Time of last status change */
258  const IMFS_node_control *control;
259 };
260 
261 #define IMFS_NODE_FLAG_NAME_ALLOCATED 0x1
262 
263 typedef struct {
264  IMFS_jnode_t Node;
265  rtems_chain_control Entries;
268 
269 typedef struct {
270  IMFS_jnode_t Node;
271  rtems_device_major_number major;
272  rtems_device_minor_number minor;
273 } IMFS_device_t;
274 
275 typedef struct {
276  IMFS_jnode_t Node;
277  IMFS_jnode_t *link_node;
278 } IMFS_link_t;
279 
280 typedef struct {
281  IMFS_jnode_t Node;
282  char *name;
284 
285 typedef struct {
286  IMFS_jnode_t Node;
287  size_t size; /* size of file in bytes */
289 
290 typedef struct {
291  IMFS_filebase_t File;
292  block_ptr indirect; /* array of 128 data blocks pointers */
293  block_ptr doubly_indirect; /* 128 indirect blocks */
294  block_ptr triply_indirect; /* 128 doubly indirect blocks */
296 
297 typedef struct {
298  IMFS_filebase_t File;
299  block_p direct; /* pointer to file image */
301 
302 /* Support copy on write for linear files */
303 typedef union {
304  IMFS_jnode_t Node;
305  IMFS_filebase_t File;
306  IMFS_memfile_t Memfile;
307  IMFS_linearfile_t Linearfile;
308 } IMFS_file_t;
309 
310 typedef struct {
311  IMFS_jnode_t Node;
312  pipe_control_t *pipe;
313 } IMFS_fifo_t;
314 
315 typedef struct {
316  IMFS_jnode_t Node;
317  void *context;
319 
320 static inline IMFS_directory_t *IMFS_iop_to_directory(
321  const rtems_libio_t *iop
322 )
323 {
324  return (IMFS_directory_t *) iop->pathinfo.node_access;
325 }
326 
327 static inline IMFS_device_t *IMFS_iop_to_device( const rtems_libio_t *iop )
328 {
329  return (IMFS_device_t *) iop->pathinfo.node_access;
330 }
331 
332 static inline IMFS_file_t *IMFS_iop_to_file( const rtems_libio_t *iop )
333 {
334  return (IMFS_file_t *) iop->pathinfo.node_access;
335 }
336 
337 static inline IMFS_memfile_t *IMFS_iop_to_memfile( const rtems_libio_t *iop )
338 {
339  return (IMFS_memfile_t *) iop->pathinfo.node_access;
340 }
341 
342 static inline time_t _IMFS_get_time( void )
343 {
344  struct bintime now;
345 
346  /* Use most efficient way to get the time in seconds (CLOCK_REALTIME) */
347  _Timecounter_Getbintime( &now );
348 
349  return now.sec;
350 }
351 
352 static inline void IMFS_update_atime( IMFS_jnode_t *jnode )
353 {
354  jnode->stat_atime = _IMFS_get_time();
355 }
356 
357 static inline void IMFS_update_mtime( IMFS_jnode_t *jnode )
358 {
359  jnode->stat_mtime = _IMFS_get_time();
360 }
361 
362 static inline void IMFS_update_ctime( IMFS_jnode_t *jnode )
363 {
364  jnode->stat_ctime = _IMFS_get_time();
365 }
366 
367 static inline void IMFS_mtime_ctime_update( IMFS_jnode_t *jnode )
368 {
369  time_t now;
370 
371  now = _IMFS_get_time();
372 
373  jnode->stat_mtime = now;
374  jnode->stat_ctime = now;
375 }
376 
377 typedef struct {
378  const IMFS_mknod_control *directory;
379  const IMFS_mknod_control *device;
380  const IMFS_mknod_control *file;
381  const IMFS_mknod_control *fifo;
383 
384 typedef struct {
385  IMFS_directory_t Root_directory;
386  const IMFS_mknod_controls *mknod_controls;
388 
389 typedef struct {
390  IMFS_fs_info_t *fs_info;
392  const IMFS_mknod_controls *mknod_controls;
394 
395 /*
396  * Shared Data
397  */
398 
399 extern const IMFS_mknod_control IMFS_mknod_control_dir_default;
400 extern const IMFS_mknod_control IMFS_mknod_control_dir_minimal;
401 extern const IMFS_mknod_control IMFS_mknod_control_device;
402 extern const IMFS_mknod_control IMFS_mknod_control_memfile;
403 extern const IMFS_node_control IMFS_node_control_linfile;
404 extern const IMFS_mknod_control IMFS_mknod_control_fifo;
405 extern const IMFS_mknod_control IMFS_mknod_control_enosys;
406 
407 extern const rtems_filesystem_limits_and_options_t IMFS_LIMITS_AND_OPTIONS;
408 
409 /*
410  * Routines
411  */
412 
413 extern int IMFS_initialize(
415  const void *data
416 );
417 
418 extern int IMFS_initialize_support(
420  const void *data
421 );
422 
426 extern void IMFS_fsunmount(
428 );
429 
481 extern int rtems_tarfs_load(
482  const char *mountpoint,
483  uint8_t *tar_image,
484  size_t tar_size
485 );
486 
490 extern void IMFS_node_destroy( IMFS_jnode_t *node );
491 
496 
500 extern void IMFS_node_free( const rtems_filesystem_location_info_t *loc );
501 
507 extern int IMFS_stat(
509  struct stat *buf
510 );
511 
512 extern int IMFS_stat_file(
514  struct stat *buf
515 );
516 
520 extern void IMFS_eval_path(
522 );
523 
531 extern int IMFS_link(
532  const rtems_filesystem_location_info_t *parentloc,
533  const rtems_filesystem_location_info_t *targetloc,
534  const char *name,
535  size_t namelen
536 );
537 
544 extern int IMFS_chown(
546  uid_t owner,
547  gid_t group
548 );
549 
555 extern int IMFS_mknod(
556  const rtems_filesystem_location_info_t *parentloc,
557  const char *name,
558  size_t namelen,
559  mode_t mode,
560  dev_t dev
561 );
562 
563 extern IMFS_jnode_t *IMFS_initialize_node(
564  IMFS_jnode_t *node,
565  const IMFS_node_control *node_control,
566  const char *name,
567  size_t namelen,
568  mode_t mode,
569  void *arg
570 );
571 
579  const rtems_filesystem_location_info_t *parentloc,
580  const IMFS_node_control *node_control,
581  size_t node_size,
582  const char *name,
583  size_t namelen,
584  mode_t mode,
585  void *arg
586 );
587 
588 static inline bool IMFS_is_imfs_instance(
590 )
591 {
592  return loc->mt_entry->ops->clonenod_h == IMFS_node_clone;
593 }
594 
620 #define IMFS_GENERIC_INITIALIZER( handlers, init, destroy ) \
621  { \
622  ( handlers ), \
623  ( init ), \
624  IMFS_node_remove_default, \
625  ( destroy ) \
626  }
627 
687 extern int IMFS_make_generic_node(
688  const char *path,
689  mode_t mode,
690  const IMFS_node_control *node_control,
691  void *context
692 );
693 
704 extern int IMFS_mount(
705  rtems_filesystem_mount_table_entry_t *mt_entry /* IN */
706 );
707 
711 extern int IMFS_unmount(
712  rtems_filesystem_mount_table_entry_t *mt_entry /* IN */
713 );
714 
726 extern ssize_t IMFS_memfile_write(
727  IMFS_memfile_t *memfile,
728  off_t start,
729  const unsigned char *source,
730  unsigned int length
731 );
732 
743 extern int device_open(
744  rtems_libio_t *iop, /* IN */
745  const char *pathname, /* IN */
746  int oflag, /* IN */
747  mode_t mode /* IN */
748 );
749 
750 extern int device_close(
751  rtems_libio_t *iop /* IN */
752 );
753 
754 extern ssize_t device_read(
755  rtems_libio_t *iop, /* IN */
756  void *buffer, /* IN */
757  size_t count /* IN */
758 );
759 
760 extern ssize_t device_write(
761  rtems_libio_t *iop, /* IN */
762  const void *buffer, /* IN */
763  size_t count /* IN */
764 );
765 
766 extern int device_ioctl(
767  rtems_libio_t *iop,
768  ioctl_command_t command,
769  void *buffer
770 );
771 
772 extern int device_ftruncate(
773  rtems_libio_t *iop, /* IN */
774  off_t length /* IN */
775 );
776 
786 extern int IMFS_utime(
788  time_t actime,
789  time_t modtime
790 );
791 
795 extern int IMFS_fchmod(
797  mode_t mode
798 );
799 
807 extern int IMFS_symlink(
808  const rtems_filesystem_location_info_t *parentloc,
809  const char *name,
810  size_t namelen,
811  const char *target
812 );
813 
821 extern ssize_t IMFS_readlink(
823  char *buf,
824  size_t bufsize
825 );
826 
833 extern int IMFS_rename(
834  const rtems_filesystem_location_info_t *oldparentloc,
835  const rtems_filesystem_location_info_t *oldloc,
836  const rtems_filesystem_location_info_t *newparentloc,
837  const char *name,
838  size_t namelen
839 );
846 extern int IMFS_rmnod(
847  const rtems_filesystem_location_info_t *parentloc,
849 );
850 
851 /*
852  * Turn on IMFS assertions when RTEMS_DEBUG is defined.
853  */
854 #ifdef RTEMS_DEBUG
855  #include <assert.h>
856 
857  #define IMFS_assert(_x) assert(_x)
858 #else
859  #define IMFS_assert(_x)
860 #endif
861 
862 static inline void IMFS_Set_handlers( rtems_filesystem_location_info_t *loc )
863 {
864  IMFS_jnode_t *node = (IMFS_jnode_t *) loc->node_access;
865 
866  loc->handlers = node->control->handlers;
867 }
868 
869 static inline void IMFS_add_to_directory(
870  IMFS_jnode_t *dir_node,
871  IMFS_jnode_t *entry_node
872 )
873 {
874  IMFS_directory_t *dir = (IMFS_directory_t *) dir_node;
875 
876  entry_node->Parent = dir_node;
877  rtems_chain_append_unprotected( &dir->Entries, &entry_node->Node );
878 }
879 
880 static inline void IMFS_remove_from_directory( IMFS_jnode_t *node )
881 {
882  IMFS_assert( node->Parent != NULL );
883  node->Parent = NULL;
884  rtems_chain_extract_unprotected( &node->Node );
885 }
886 
887 static inline bool IMFS_is_directory( const IMFS_jnode_t *node )
888 {
889  return S_ISDIR( node->st_mode );
890 }
891 
892 #define IMFS_STAT_FMT_HARD_LINK 0
893 
894 static inline bool IMFS_is_hard_link( mode_t mode )
895 {
896  return ( mode & S_IFMT ) == IMFS_STAT_FMT_HARD_LINK;
897 }
898 
899 static inline ino_t IMFS_node_to_ino( const IMFS_jnode_t *node )
900 {
901  return (ino_t) ((uintptr_t) node);
902 }
903 
911 static inline void *IMFS_generic_get_context_by_node(
912  const IMFS_jnode_t *node
913 )
914 {
915  const IMFS_generic_t *generic = (const IMFS_generic_t *) node;
916 
917  return generic->context;
918 }
919 
920 static inline void *IMFS_generic_get_context_by_location(
922 )
923 {
924  return loc->node_access_2;
925 }
926 
927 static inline void *IMFS_generic_get_context_by_iop(
928  const rtems_libio_t *iop
929 )
930 {
931  return IMFS_generic_get_context_by_location( &iop->pathinfo );
932 }
933 
934 static inline dev_t IMFS_generic_get_device_identifier_by_node(
935  const IMFS_jnode_t *node
936 )
937 {
938  return rtems_filesystem_make_dev_t_from_pointer( node );
939 }
940 
941 #ifdef __cplusplus
942 }
943 #endif
944 
945 #endif
946 /* end of include file */
void IMFS_fsunmount(rtems_filesystem_mount_table_entry_t *mt_entry)
Unmount this instance of IMFS.
Definition: imfs_fsunmount.c:35
Definition: chain.h:65
Contain file system specific information which is required to support fpathconf().
Definition: libio.h:1289
POSIX FIFO/pipe File System Support.
Definition: imfs.h:263
IMFS_jnode_t * IMFS_node_remove_default(IMFS_jnode_t *node)
Returns the node and does nothing else.
Definition: imfs_node.c:101
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
Definition: imfs.h:384
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:25
IMFS_jnode_t *(* IMFS_node_control_initialize)(IMFS_jnode_t *node, void *arg)
Initializes an IMFS node.
Definition: imfs.h:120
int IMFS_mount(rtems_filesystem_mount_table_entry_t *mt_entry)
Mount an IMFS.
Definition: imfs_mount.c:26
void IMFS_node_free(const rtems_filesystem_location_info_t *loc)
Free an IMFS node.
Definition: imfs_node.c:90
Definition: imfs.h:303
Definition: chain.h:83
IMFS_jnode_t * IMFS_node_initialize_default(IMFS_jnode_t *node, void *arg)
Returns the node and does nothing else.
Definition: imfs_initsupp.c:100
Definition: imfs.h:290
Definition: imfs.h:389
Definition: rtemscompat1.h:15
File system node operations table.
Definition: libio.h:1005
Definition: imfs.h:297
void IMFS_eval_path(rtems_filesystem_eval_path_context_t *ctx)
IMFS evaluation node support.
Definition: imfs_eval.c:175
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
int IMFS_node_clone(rtems_filesystem_location_info_t *loc)
Clone an IMFS node.
Definition: imfs_node.c:74
IMFS node control.
Definition: imfs.h:212
void(* IMFS_node_control_destroy)(IMFS_jnode_t *node)
Destroys an IMFS node.
Definition: imfs.h:198
Definition: imfs.h:219
int IMFS_stat(const rtems_filesystem_location_info_t *loc, struct stat *buf)
Perform a status processing for the IMFS.
Definition: imfs_stat.c:26
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:30
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:43
Definition: imfs.h:242
void IMFS_node_destroy_default(IMFS_jnode_t *node)
Frees the node.
Definition: imfs_node.c:108
Definition: imfs.h:285
int IMFS_fchmod(const rtems_filesystem_location_info_t *loc, mode_t mode)
Change the IMFS file mode.
Definition: imfs_fchmod.c:23
int rtems_tarfs_load(const char *mountpoint, uint8_t *tar_image, size_t tar_size)
RTEMS load tarfs.
Definition: imfs_load_tar.c:33
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:27
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:27
Definition: intercom.c:74
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:172
Mount table entry.
Definition: libio.h:1606
void IMFS_node_destroy(IMFS_jnode_t *node)
Destroy an IMFS node.
Definition: imfs_node.c:83
int IMFS_unmount(rtems_filesystem_mount_table_entry_t *mt_entry)
Unmount an IMFS.
Definition: imfs_unmount.c:26
File system operations table.
Definition: libio.h:472
void _Timecounter_Getbintime(struct bintime *bt)
Returns the wall clock time in the bintime format.
LibIO Internal Interface.
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:26
Definition: pipe.h:38
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:56
Path evaluation context.
Definition: libio.h:84
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:25
Definition: imfs.h:377
unsigned context
Definition: tlb.h:108
An open file data structure.
Definition: libio.h:1320
unsigned size
Definition: tte.h:74
Definition: imfs.h:310
Definition: imfs.h:315
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:42
Timecounter API.
Definition: imfs.h:269
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:26
#define NULL
Requests a GPIO pin group configuration.
Definition: bestcomm_api.h:77
File system location.
Definition: fs.h:53
Definition: mongoose.c:442
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:25