RTEMS CPU Kit with SuperCore  4.10.99.0
rtems/imfs.h
Go to the documentation of this file.
00001 
00007 /*
00008  *  COPYRIGHT (c) 1989-2011.
00009  *  On-Line Applications Research Corporation (OAR).
00010  *
00011  *  The license and distribution terms for this file may be
00012  *  found in the file LICENSE in this distribution or at
00013  *  http://www.rtems.org/license/LICENSE.
00014  */
00015 
00016 #ifndef _RTEMS_IMFS_H
00017 #define _RTEMS_IMFS_H
00018 
00019 #include <limits.h>
00020 
00021 #include <rtems/libio_.h>
00022 #include <rtems/pipe.h>
00023 
00033 #ifdef __cplusplus
00034 extern "C" {
00035 #endif
00036 
00037 /*
00038  *  Data types
00039  */
00040 
00041 struct IMFS_jnode_tt;
00042 typedef struct IMFS_jnode_tt IMFS_jnode_t;
00043 
00044 typedef struct {
00045   rtems_chain_control                    Entries;
00046   rtems_filesystem_mount_table_entry_t  *mt_fs;
00047 }  IMFS_directory_t;
00048 
00049 typedef struct {
00050   rtems_device_major_number  major;
00051   rtems_device_minor_number  minor;
00052 }  IMFS_device_t;
00053 
00054 typedef struct {
00055   IMFS_jnode_t  *link_node;
00056 } IMFS_link_t;
00057 
00058 typedef struct {
00059   char *name;
00060 } IMFS_sym_link_t;
00061 
00062 typedef struct {
00063   pipe_control_t  *pipe;
00064 } IMFS_fifo_t;
00065 
00066 typedef struct {
00067   void *context;
00068 } IMFS_generic_t;
00069 
00092 #define IMFS_MEMFILE_DEFAULT_BYTES_PER_BLOCK     128
00093   extern int imfs_rq_memfile_bytes_per_block;
00094   extern int imfs_memfile_bytes_per_block;
00095 
00096 #define IMFS_MEMFILE_BYTES_PER_BLOCK imfs_memfile_bytes_per_block
00097 #define IMFS_MEMFILE_BLOCK_SLOTS \
00098   (IMFS_MEMFILE_BYTES_PER_BLOCK / sizeof(void *))
00099 
00100 typedef uint8_t *block_p;
00101 typedef block_p *block_ptr;
00102 
00103 typedef struct {
00104   off_t         size;             /* size of file in bytes */
00105   block_ptr     indirect;         /* array of 128 data blocks pointers */
00106   block_ptr     doubly_indirect;  /* 128 indirect blocks */
00107   block_ptr     triply_indirect;  /* 128 doubly indirect blocks */
00108 } IMFS_memfile_t;
00109 
00110 typedef struct {
00111   off_t         size;             /* size of file in bytes */
00112   block_p       direct;           /* pointer to file image */
00113 } IMFS_linearfile_t;
00114 
00115 /*
00116  *  Important block numbers for "memfiles"
00117  */
00118 #define FIRST_INDIRECT           (0)
00119 #define LAST_INDIRECT            (IMFS_MEMFILE_BLOCK_SLOTS - 1)
00120 
00121 #define FIRST_DOUBLY_INDIRECT    (LAST_INDIRECT + 1)
00122 #define LAST_DOUBLY_INDIRECT     \
00123    (LAST_INDIRECT + \
00124      (IMFS_MEMFILE_BLOCK_SLOTS * IMFS_MEMFILE_BLOCK_SLOTS))
00125 
00126 #define FIRST_TRIPLY_INDIRECT    (LAST_DOUBLY_INDIRECT + 1)
00127 #define LAST_TRIPLY_INDIRECT \
00128    (LAST_DOUBLY_INDIRECT +\
00129      (IMFS_MEMFILE_BLOCK_SLOTS * \
00130         IMFS_MEMFILE_BLOCK_SLOTS * IMFS_MEMFILE_BLOCK_SLOTS))
00131 
00132 #define IMFS_MEMFILE_MAXIMUM_SIZE \
00133   (LAST_TRIPLY_INDIRECT * IMFS_MEMFILE_BYTES_PER_BLOCK)
00134 
00135 /*
00136  *  What types of IMFS file systems entities there can be.
00137  */
00138 typedef enum {
00139   IMFS_DIRECTORY = RTEMS_FILESYSTEM_DIRECTORY,
00140   IMFS_DEVICE = RTEMS_FILESYSTEM_DEVICE,
00141   IMFS_HARD_LINK = RTEMS_FILESYSTEM_HARD_LINK,
00142   IMFS_SYM_LINK =  RTEMS_FILESYSTEM_SYM_LINK,
00143   IMFS_MEMORY_FILE = RTEMS_FILESYSTEM_MEMORY_FILE,
00144   IMFS_LINEAR_FILE,
00145   IMFS_FIFO,
00146   IMFS_GENERIC,
00147   IMFS_INVALID_NODE
00148 } IMFS_jnode_types_t;
00149 
00150 /* The IMFS_GENERIC does not count */
00151 #define IMFS_TYPE_COUNT (IMFS_FIFO + 1)
00152 
00153 typedef union {
00154   IMFS_directory_t   directory;
00155   IMFS_device_t      device;
00156   IMFS_link_t        hard_link;
00157   IMFS_sym_link_t    sym_link;
00158   IMFS_memfile_t     file;
00159   IMFS_linearfile_t  linearfile;
00160   IMFS_fifo_t        fifo;
00161   IMFS_generic_t     generic;
00162 } IMFS_types_union;
00163 
00184 typedef IMFS_jnode_t *(*IMFS_node_control_initialize)(
00185   IMFS_jnode_t *node,
00186   const IMFS_types_union *info
00187 );
00188 
00199 IMFS_jnode_t *IMFS_node_initialize_default(
00200   IMFS_jnode_t *node,
00201   const IMFS_types_union *info
00202 );
00203 
00214 IMFS_jnode_t *IMFS_node_initialize_generic(
00215   IMFS_jnode_t *node,
00216   const IMFS_types_union *info
00217 );
00218 
00230 typedef IMFS_jnode_t *(*IMFS_node_control_remove)(
00231   IMFS_jnode_t *node
00232 );
00233 
00243 IMFS_jnode_t *IMFS_node_remove_default(
00244   IMFS_jnode_t *node
00245 );
00246 
00256 typedef IMFS_jnode_t *(*IMFS_node_control_destroy)( IMFS_jnode_t *node );
00257 
00267 IMFS_jnode_t *IMFS_node_destroy_default( IMFS_jnode_t *node );
00268 
00272 typedef struct {
00273   IMFS_jnode_types_t imfs_type;
00274   const rtems_filesystem_file_handlers_r *handlers;
00275   IMFS_node_control_initialize node_initialize;
00276   IMFS_node_control_remove node_remove;
00277   IMFS_node_control_destroy node_destroy;
00278 } IMFS_node_control;
00279 
00287 /*
00288  * Major device number for the IMFS. This is not a real device number because
00289  * the IMFS is just a file system and does not have a driver.
00290  */
00291 #define IMFS_DEVICE_MAJOR_NUMBER (0xfffe)
00292 
00298 #define IMFS_GENERIC_DEVICE_MAJOR_NUMBER (0xfffd)
00299 
00300 /*
00301  *  Maximum length of a "basename" of an IMFS file/node.
00302  */
00303 
00304 #define IMFS_NAME_MAX  32
00305 
00306 /*
00307  *  The control structure for an IMFS jnode.
00308  */
00309 
00310 struct IMFS_jnode_tt {
00311   rtems_chain_node    Node;                  /* for chaining them together */
00312   IMFS_jnode_t       *Parent;                /* Parent node */
00313   char                name[IMFS_NAME_MAX+1]; /* "basename" */
00314   mode_t              st_mode;               /* File mode */
00315   unsigned short      reference_count;
00316   nlink_t             st_nlink;              /* Link count */
00317   ino_t               st_ino;                /* inode */
00318 
00319   uid_t               st_uid;                /* User ID of owner */
00320   gid_t               st_gid;                /* Group ID of owner */
00321 
00322   time_t              stat_atime;            /* Time of last access */
00323   time_t              stat_mtime;            /* Time of last modification */
00324   time_t              stat_ctime;            /* Time of last status change */
00325   const IMFS_node_control *control;
00326   IMFS_types_union    info;
00327 };
00328 
00329 static inline void IMFS_update_atime( IMFS_jnode_t *jnode )
00330 {
00331   struct timeval now;
00332 
00333   gettimeofday( &now, 0 );
00334 
00335   jnode->stat_atime = now.tv_sec;
00336 }
00337 
00338 static inline void IMFS_update_mtime( IMFS_jnode_t *jnode )
00339 {
00340   struct timeval now;
00341 
00342   gettimeofday( &now, 0 );
00343 
00344   jnode->stat_mtime = now.tv_sec;
00345 }
00346 
00347 static inline void IMFS_update_ctime( IMFS_jnode_t *jnode )
00348 {
00349   struct timeval now;
00350 
00351   gettimeofday( &now, 0 );
00352 
00353   jnode->stat_ctime = now.tv_sec;
00354 }
00355 
00356 static inline void IMFS_mtime_ctime_update( IMFS_jnode_t *jnode )
00357 {
00358   struct timeval now;
00359 
00360   gettimeofday( &now, 0 );
00361 
00362   jnode->stat_mtime = now.tv_sec;
00363   jnode->stat_ctime = now.tv_sec;
00364 }
00365 
00366 typedef struct {
00367   int instance;
00368   ino_t ino_count;
00369   const IMFS_node_control *node_controls [IMFS_TYPE_COUNT];
00370 } IMFS_fs_info_t;
00371 
00372 /*
00373  *  Shared Data
00374  */
00375 
00376 extern const IMFS_node_control IMFS_node_control_directory;
00377 extern const IMFS_node_control IMFS_node_control_device;
00378 extern const IMFS_node_control IMFS_node_control_hard_link;
00379 extern const IMFS_node_control IMFS_node_control_sym_link;
00380 extern const IMFS_node_control IMFS_node_control_memfile;
00381 extern const IMFS_node_control IMFS_node_control_linfile;
00382 extern const IMFS_node_control IMFS_node_control_fifo;
00383 extern const IMFS_node_control IMFS_node_control_enosys;
00384 
00385 extern const rtems_filesystem_operations_table miniIMFS_ops;
00386 extern const rtems_filesystem_operations_table IMFS_ops;
00387 extern const rtems_filesystem_operations_table fifoIMFS_ops;
00388 
00389 extern const rtems_filesystem_limits_and_options_t  IMFS_LIMITS_AND_OPTIONS;
00390 
00391 /*
00392  *  Routines
00393  */
00394 
00395 extern int IMFS_initialize(
00396    rtems_filesystem_mount_table_entry_t *mt_entry,
00397    const void                           *data
00398 );
00399 
00400 extern int fifoIMFS_initialize(
00401   rtems_filesystem_mount_table_entry_t  *mt_entry,
00402   const void                            *data
00403 );
00404 
00405 extern int miniIMFS_initialize(
00406    rtems_filesystem_mount_table_entry_t *mt_entry,
00407    const void                           *data
00408 );
00409 
00413 extern int IMFS_initialize_support(
00414   rtems_filesystem_mount_table_entry_t *mt_entry,
00415   const rtems_filesystem_operations_table *op_table,
00416   const IMFS_node_control *const node_controls [IMFS_TYPE_COUNT]
00417 );
00421 extern void IMFS_fsunmount(
00422    rtems_filesystem_mount_table_entry_t *mt_entry
00423 );
00424 
00476 extern int rtems_tarfs_load(
00477    const char *mountpoint,
00478    uint8_t *tar_image,
00479    size_t tar_size
00480 );
00481 
00491 extern void IMFS_dump( void );
00492 
00500 extern int IMFS_memfile_maximum_size( void );
00501 
00505 extern void IMFS_node_destroy( IMFS_jnode_t *node );
00506 
00510 extern int IMFS_node_clone( rtems_filesystem_location_info_t *loc );
00511 
00515 extern void IMFS_node_free( const rtems_filesystem_location_info_t *loc );
00516 
00523 extern rtems_filesystem_node_types_t IMFS_node_type(
00524   const rtems_filesystem_location_info_t *loc
00525 );
00526 
00532 extern int IMFS_stat(
00533   const rtems_filesystem_location_info_t *loc,
00534   struct stat *buf
00535 );
00536 
00540 extern void IMFS_eval_path(
00541   rtems_filesystem_eval_path_context_t *ctx
00542 );
00543 
00551 extern int IMFS_link(
00552   const rtems_filesystem_location_info_t *parentloc,
00553   const rtems_filesystem_location_info_t *targetloc,
00554   const char *name,
00555   size_t namelen
00556 );
00557 
00564 extern int IMFS_chown(
00565   const rtems_filesystem_location_info_t *loc,
00566   uid_t owner,
00567   gid_t group
00568 );
00569 
00575 extern int IMFS_mknod(
00576   const rtems_filesystem_location_info_t *parentloc,
00577   const char *name,
00578   size_t namelen,
00579   mode_t mode,
00580   dev_t dev
00581 );
00582 
00588 extern IMFS_jnode_t *IMFS_allocate_node(
00589   IMFS_fs_info_t *fs_info,
00590   const IMFS_node_control *node_control,
00591   const char *name,
00592   size_t namelen,
00593   mode_t mode,
00594   const IMFS_types_union *info
00595 );
00596 
00603 extern IMFS_jnode_t *IMFS_create_node_with_control(
00604   const rtems_filesystem_location_info_t *parentloc,
00605   const IMFS_node_control *node_control,
00606   const char *name,
00607   size_t namelen,
00608   mode_t mode,
00609   const IMFS_types_union *info
00610 );
00611 
00612 extern bool IMFS_is_imfs_instance(
00613   const rtems_filesystem_location_info_t *loc
00614 );
00615 
00673 extern int IMFS_make_generic_node(
00674   const char *path,
00675   mode_t mode,
00676   const IMFS_node_control *node_control,
00677   void *context
00678 );
00679 
00690 extern int IMFS_mount(
00691   rtems_filesystem_mount_table_entry_t *mt_entry  /* IN */
00692 );
00693 
00697 extern int IMFS_unmount(
00698   rtems_filesystem_mount_table_entry_t *mt_entry  /* IN */
00699 );
00700 
00701 extern IMFS_jnode_t *IMFS_memfile_remove(
00702  IMFS_jnode_t  *the_jnode         /* IN/OUT */
00703 );
00704 
00710 extern int memfile_ftruncate(
00711   rtems_libio_t *iop,               /* IN  */
00712   off_t          length             /* IN  */
00713 );
00714 
00729 extern ssize_t imfs_dir_read(
00730   rtems_libio_t *iop,              /* IN  */
00731   void          *buffer,           /* IN  */
00732   size_t         count             /* IN  */
00733 );
00734 
00752 extern int memfile_open(
00753   rtems_libio_t *iop,             /* IN  */
00754   const char    *pathname,        /* IN  */
00755   int            oflag,           /* IN  */
00756   mode_t         mode             /* IN  */
00757 );
00758 
00764 extern ssize_t memfile_read(
00765   rtems_libio_t *iop,             /* IN  */
00766   void          *buffer,          /* IN  */
00767   size_t         count            /* IN  */
00768 );
00769 
00775 extern ssize_t memfile_write(
00776   rtems_libio_t *iop,             /* IN  */
00777   const void    *buffer,          /* IN  */
00778   size_t         count            /* IN  */
00779 );
00780 
00791 extern int device_open(
00792   rtems_libio_t *iop,            /* IN  */
00793   const char    *pathname,       /* IN  */
00794   int            oflag,          /* IN  */
00795   mode_t         mode            /* IN  */
00796 );
00797 
00798 extern int device_close(
00799   rtems_libio_t *iop             /* IN  */
00800 );
00801 
00802 extern ssize_t device_read(
00803   rtems_libio_t *iop,            /* IN  */
00804   void          *buffer,         /* IN  */
00805   size_t         count           /* IN  */
00806 );
00807 
00808 extern ssize_t device_write(
00809   rtems_libio_t *iop,               /* IN  */
00810   const void    *buffer,            /* IN  */
00811   size_t         count              /* IN  */
00812 );
00813 
00814 extern int device_ioctl(
00815   rtems_libio_t   *iop,
00816   ioctl_command_t  command,
00817   void            *buffer
00818 );
00819 
00820 extern int device_ftruncate(
00821   rtems_libio_t *iop,               /* IN  */
00822   off_t          length             /* IN  */
00823 );
00824 
00834 extern int IMFS_utime(
00835   const rtems_filesystem_location_info_t *loc,
00836   time_t actime,
00837   time_t modtime
00838 );
00839 
00843 extern int IMFS_fchmod(
00844   const rtems_filesystem_location_info_t *loc,
00845   mode_t mode
00846 );
00847 
00855 extern int IMFS_symlink(
00856   const rtems_filesystem_location_info_t *parentloc,
00857   const char *name,
00858   size_t namelen,
00859   const char *target
00860 );
00861 
00869 extern ssize_t IMFS_readlink(
00870   const rtems_filesystem_location_info_t *loc,
00871   char *buf,
00872   size_t bufsize
00873 );
00874 
00881 extern int IMFS_rename(
00882   const rtems_filesystem_location_info_t *oldparentloc,
00883   const rtems_filesystem_location_info_t *oldloc,
00884   const rtems_filesystem_location_info_t *newparentloc,
00885   const char *name,
00886   size_t namelen
00887 );
00894 extern int IMFS_rmnod(
00895   const rtems_filesystem_location_info_t *parentloc,
00896   const rtems_filesystem_location_info_t *loc
00897 );
00898 
00899 /*
00900  *  Turn on IMFS assertions when RTEMS_DEBUG is defined.
00901  */
00902 #ifdef RTEMS_DEBUG
00903   #include <assert.h>
00904 
00905   #define IMFS_assert(_x) assert(_x)
00906 #else
00907   #define IMFS_assert(_x)
00908 #endif
00909 
00910 static inline void IMFS_Set_handlers( rtems_filesystem_location_info_t *loc )
00911 {
00912   IMFS_jnode_t *node = (IMFS_jnode_t *) loc->node_access;
00913 
00914   loc->handlers = node->control->handlers;
00915 }
00916 
00917 static inline void IMFS_add_to_directory(
00918   IMFS_jnode_t *dir,
00919   IMFS_jnode_t *node
00920 )
00921 {
00922   node->Parent = dir;
00923   rtems_chain_append_unprotected( &dir->info.directory.Entries, &node->Node );
00924 }
00925 
00926 static inline void IMFS_remove_from_directory( IMFS_jnode_t *node )
00927 {
00928   IMFS_assert( node->Parent != NULL );
00929   node->Parent = NULL;
00930   rtems_chain_extract_unprotected( &node->Node );
00931 }
00932 
00933 static inline IMFS_jnode_types_t IMFS_type( const IMFS_jnode_t *node )
00934 {
00935   return node->control->imfs_type;
00936 }
00937 
00938 static inline bool IMFS_is_directory( const IMFS_jnode_t *node )
00939 {
00940   return node->control->imfs_type == IMFS_DIRECTORY;
00941 }
00942 
00943 static inline IMFS_jnode_t *IMFS_create_node(
00944   const rtems_filesystem_location_info_t *parentloc,
00945   IMFS_jnode_types_t type,
00946   const char *name,
00947   size_t namelen,
00948   mode_t mode,
00949   const IMFS_types_union *info
00950 )
00951 {
00952   const IMFS_fs_info_t *fs_info =
00953     (const IMFS_fs_info_t *) parentloc->mt_entry->fs_info;
00954 
00955   return IMFS_create_node_with_control(
00956     parentloc,
00957     fs_info->node_controls [type],
00958     name,
00959     namelen,
00960     mode,
00961     info
00962   );
00963 }
00964 
00972 static inline void *IMFS_generic_get_context_by_node(
00973   const IMFS_jnode_t *node
00974 )
00975 {
00976   return node->info.generic.context;
00977 }
00978 
00979 static inline void *IMFS_generic_get_context_by_location(
00980   const rtems_filesystem_location_info_t *loc
00981 )
00982 {
00983   return loc->node_access_2;
00984 }
00985 
00986 static inline void *IMFS_generic_get_context_by_iop(
00987   const rtems_libio_t *iop
00988 )
00989 {
00990   return IMFS_generic_get_context_by_location( &iop->pathinfo );
00991 }
00992 
00993 static inline dev_t IMFS_generic_get_device_identifier_by_node(
00994   const IMFS_jnode_t *node
00995 )
00996 {
00997   return rtems_filesystem_make_dev_t(
00998     IMFS_GENERIC_DEVICE_MAJOR_NUMBER,
00999     node->st_ino
01000   );
01001 }
01002 
01003 #ifdef __cplusplus
01004 }
01005 #endif
01006 
01007 #endif
01008 /* end of include file */