RTEMS CPU Kit with SuperCore  4.10.99.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 <limits.h>
20 
21 #include <rtems/libio_.h>
22 #include <rtems/pipe.h>
23 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
37 /*
38  * Data types
39  */
40 
41 struct IMFS_jnode_tt;
42 typedef struct IMFS_jnode_tt IMFS_jnode_t;
43 
66 #define IMFS_MEMFILE_DEFAULT_BYTES_PER_BLOCK 128
67  extern int imfs_rq_memfile_bytes_per_block;
68  extern int imfs_memfile_bytes_per_block;
69 
70 #define IMFS_MEMFILE_BYTES_PER_BLOCK imfs_memfile_bytes_per_block
71 #define IMFS_MEMFILE_BLOCK_SLOTS \
72  (IMFS_MEMFILE_BYTES_PER_BLOCK / sizeof(void *))
73 
74 typedef uint8_t *block_p;
75 typedef block_p *block_ptr;
76 
77 /*
78  * Important block numbers for "memfiles"
79  */
80 #define FIRST_INDIRECT (0)
81 #define LAST_INDIRECT (IMFS_MEMFILE_BLOCK_SLOTS - 1)
82 
83 #define FIRST_DOUBLY_INDIRECT (LAST_INDIRECT + 1)
84 #define LAST_DOUBLY_INDIRECT \
85  (LAST_INDIRECT + \
86  (IMFS_MEMFILE_BLOCK_SLOTS * IMFS_MEMFILE_BLOCK_SLOTS))
87 
88 #define FIRST_TRIPLY_INDIRECT (LAST_DOUBLY_INDIRECT + 1)
89 #define LAST_TRIPLY_INDIRECT \
90  (LAST_DOUBLY_INDIRECT +\
91  (IMFS_MEMFILE_BLOCK_SLOTS * \
92  IMFS_MEMFILE_BLOCK_SLOTS * IMFS_MEMFILE_BLOCK_SLOTS))
93 
94 #define IMFS_MEMFILE_MAXIMUM_SIZE \
95  (LAST_TRIPLY_INDIRECT * IMFS_MEMFILE_BYTES_PER_BLOCK)
96 
118 typedef IMFS_jnode_t *(*IMFS_node_control_initialize)(
119  IMFS_jnode_t *node,
120  void *arg
121 );
122 
134  IMFS_jnode_t *node,
135  void *arg
136 );
137 
138 IMFS_jnode_t *IMFS_node_initialize_directory(
139  IMFS_jnode_t *node,
140  void *arg
141 );
142 
155  IMFS_jnode_t *node,
156  void *arg
157 );
158 
170 typedef IMFS_jnode_t *(*IMFS_node_control_remove)(
171  IMFS_jnode_t *node
172 );
173 
184  IMFS_jnode_t *node
185 );
186 
187 IMFS_jnode_t *IMFS_node_remove_directory( IMFS_jnode_t *node );
188 
196 typedef void (*IMFS_node_control_destroy)( IMFS_jnode_t *node );
197 
206 
210 typedef struct {
211  const rtems_filesystem_file_handlers_r *handlers;
212  IMFS_node_control_initialize node_initialize;
213  IMFS_node_control_remove node_remove;
214  IMFS_node_control_destroy node_destroy;
216 
217 typedef struct {
218  IMFS_node_control node_control;
219  size_t node_size;
221 
229 /*
230  * Maximum length of a "basename" of an IMFS file/node.
231  */
232 
233 #define IMFS_NAME_MAX _POSIX_NAME_MAX
234 
235 /*
236 
237  * The control structure for an IMFS jnode.
238  */
239 
241  rtems_chain_node Node; /* for chaining them together */
242  IMFS_jnode_t *Parent; /* Parent node */
243  const char *name; /* "basename" (not \0 terminated) */
244  uint16_t namelen; /* Length of "basename" */
245  uint16_t flags; /* Node flags */
246  mode_t st_mode; /* File mode */
247  unsigned short reference_count;
248  nlink_t st_nlink; /* Link count */
249 
250  uid_t st_uid; /* User ID of owner */
251  gid_t st_gid; /* Group ID of owner */
252 
253  time_t stat_atime; /* Time of last access */
254  time_t stat_mtime; /* Time of last modification */
255  time_t stat_ctime; /* Time of last status change */
256  const IMFS_node_control *control;
257 };
258 
259 #define IMFS_NODE_FLAG_NAME_ALLOCATED 0x1
260 
261 typedef struct {
262  IMFS_jnode_t Node;
263  rtems_chain_control Entries;
264  rtems_filesystem_mount_table_entry_t *mt_fs;
266 
267 typedef struct {
268  IMFS_jnode_t Node;
269  rtems_device_major_number major;
270  rtems_device_minor_number minor;
271 } IMFS_device_t;
272 
273 typedef struct {
274  IMFS_jnode_t Node;
275  IMFS_jnode_t *link_node;
276 } IMFS_link_t;
277 
278 typedef struct {
279  IMFS_jnode_t Node;
280  char *name;
282 
283 typedef struct {
284  IMFS_jnode_t Node;
285  size_t size; /* size of file in bytes */
287 
288 typedef struct {
289  IMFS_filebase_t File;
290  block_ptr indirect; /* array of 128 data blocks pointers */
291  block_ptr doubly_indirect; /* 128 indirect blocks */
292  block_ptr triply_indirect; /* 128 doubly indirect blocks */
294 
295 typedef struct {
296  IMFS_filebase_t File;
297  block_p direct; /* pointer to file image */
299 
300 /* Support copy on write for linear files */
301 typedef union {
302  IMFS_jnode_t Node;
303  IMFS_filebase_t File;
304  IMFS_memfile_t Memfile;
305  IMFS_linearfile_t Linearfile;
306 } IMFS_file_t;
307 
308 typedef struct {
309  IMFS_jnode_t Node;
310  pipe_control_t *pipe;
311 } IMFS_fifo_t;
312 
313 typedef struct {
314  IMFS_jnode_t Node;
315  void *context;
317 
318 static inline IMFS_directory_t *IMFS_iop_to_directory(
319  const rtems_libio_t *iop
320 )
321 {
322  return (IMFS_directory_t *) iop->pathinfo.node_access;
323 }
324 
325 static inline IMFS_device_t *IMFS_iop_to_device( const rtems_libio_t *iop )
326 {
327  return (IMFS_device_t *) iop->pathinfo.node_access;
328 }
329 
330 static inline IMFS_file_t *IMFS_iop_to_file( const rtems_libio_t *iop )
331 {
332  return (IMFS_file_t *) iop->pathinfo.node_access;
333 }
334 
335 static inline IMFS_memfile_t *IMFS_iop_to_memfile( const rtems_libio_t *iop )
336 {
337  return (IMFS_memfile_t *) iop->pathinfo.node_access;
338 }
339 
340 static inline void IMFS_update_atime( IMFS_jnode_t *jnode )
341 {
342  struct timeval now;
343 
344  gettimeofday( &now, 0 );
345 
346  jnode->stat_atime = now.tv_sec;
347 }
348 
349 static inline void IMFS_update_mtime( IMFS_jnode_t *jnode )
350 {
351  struct timeval now;
352 
353  gettimeofday( &now, 0 );
354 
355  jnode->stat_mtime = now.tv_sec;
356 }
357 
358 static inline void IMFS_update_ctime( IMFS_jnode_t *jnode )
359 {
360  struct timeval now;
361 
362  gettimeofday( &now, 0 );
363 
364  jnode->stat_ctime = now.tv_sec;
365 }
366 
367 static inline void IMFS_mtime_ctime_update( IMFS_jnode_t *jnode )
368 {
369  struct timeval now;
370 
371  gettimeofday( &now, 0 );
372 
373  jnode->stat_mtime = now.tv_sec;
374  jnode->stat_ctime = now.tv_sec;
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;
391  const rtems_filesystem_operations_table *ops;
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(
414  rtems_filesystem_mount_table_entry_t *mt_entry,
415  const void *data
416 );
417 
418 extern int IMFS_initialize_support(
419  rtems_filesystem_mount_table_entry_t *mt_entry,
420  const void *data
421 );
422 
426 extern void IMFS_fsunmount(
427  rtems_filesystem_mount_table_entry_t *mt_entry
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(
521  rtems_filesystem_eval_path_context_t *ctx
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) 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.
This is used to manage each element (node) which is placed on a chain.
Definition: chain.h:65
POSIX FIFO/pipe File System Support.
Definition: imfs.h:261
IMFS_jnode_t * IMFS_node_remove_default(IMFS_jnode_t *node)
Returns the node and does nothing else.
RTEMS_INLINE_ROUTINE void rtems_chain_extract_unprotected(rtems_chain_node *the_node)
Extract the specified node from a chain (unprotected).
Definition: chain.h:584
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.
IMFS_jnode_t *(* IMFS_node_control_initialize)(IMFS_jnode_t *node, void *arg)
Initializes an IMFS node.
Definition: imfs.h:118
int IMFS_mount(rtems_filesystem_mount_table_entry_t *mt_entry)
Mount an IMFS.
void IMFS_node_free(const rtems_filesystem_location_info_t *loc)
Free an IMFS node.
Definition: imfs.h:301
This is used to manage a chain.
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.h:288
Definition: imfs.h:389
Definition: imfs.h:295
void IMFS_eval_path(rtems_filesystem_eval_path_context_t *ctx)
IMFS evaluation node support.
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:692
int IMFS_node_clone(rtems_filesystem_location_info_t *loc)
Clone an IMFS node.
IMFS node control.
Definition: imfs.h:210
void(* IMFS_node_control_destroy)(IMFS_jnode_t *node)
Destroys an IMFS node.
Definition: imfs.h:196
Definition: imfs.h:217
int IMFS_stat(const rtems_filesystem_location_info_t *loc, struct stat *buf)
Perform a status processing for the IMFS.
IMFS_jnode_t * IMFS_node_initialize_generic(IMFS_jnode_t *node, void *arg)
Returns the node and sets the generic node context.
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.h:240
void IMFS_node_destroy_default(IMFS_jnode_t *node)
Frees the node.
Definition: imfs.h:283
int IMFS_fchmod(const rtems_filesystem_location_info_t *loc, mode_t mode)
Change the IMFS file mode.
int rtems_tarfs_load(const char *mountpoint, uint8_t *tar_image, size_t tar_size)
RTEMS load tarfs.
int IMFS_chown(const rtems_filesystem_location_info_t *loc, uid_t owner, gid_t group)
Change the owner of IMFS.
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.
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:170
void IMFS_node_destroy(IMFS_jnode_t *node)
Destroy an IMFS node.
int IMFS_unmount(rtems_filesystem_mount_table_entry_t *mt_entry)
Unmount an IMFS.
int IMFS_rmnod(const rtems_filesystem_location_info_t *parentloc, const rtems_filesystem_location_info_t *loc)
IMFS node removal handler.
Definition: pipe.h:37
ssize_t IMFS_readlink(const rtems_filesystem_location_info_t *loc, char *buf, size_t bufsize)
Put IMFS symbolic link into buffer.
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.h:377
Definition: imfs.h:308
Definition: imfs.h:313
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.h:267
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.
File system location.
Definition: fs.h:53
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.