File indexing completed on 2025-05-11 08:24:13
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034 #ifndef _RTEMS_IMFS_H
0035 #define _RTEMS_IMFS_H
0036
0037 #include <sys/time.h>
0038 #include <limits.h>
0039
0040 #include <rtems/libio_.h>
0041 #include <rtems/pipe.h>
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052 #ifdef __cplusplus
0053 extern "C" {
0054 #endif
0055
0056
0057
0058
0059
0060 struct IMFS_jnode_tt;
0061 typedef struct IMFS_jnode_tt IMFS_jnode_t;
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085 #define IMFS_MEMFILE_DEFAULT_BYTES_PER_BLOCK 128
0086 extern const int imfs_memfile_bytes_per_block;
0087
0088 #define IMFS_MEMFILE_BYTES_PER_BLOCK imfs_memfile_bytes_per_block
0089 #define IMFS_MEMFILE_BLOCK_SLOTS \
0090 (IMFS_MEMFILE_BYTES_PER_BLOCK / sizeof(void *))
0091
0092 typedef uint8_t *block_p;
0093 typedef block_p *block_ptr;
0094
0095
0096
0097
0098 #define FIRST_INDIRECT (0)
0099 #define LAST_INDIRECT (IMFS_MEMFILE_BLOCK_SLOTS - 1)
0100
0101 #define FIRST_DOUBLY_INDIRECT (LAST_INDIRECT + 1)
0102 #define LAST_DOUBLY_INDIRECT \
0103 (LAST_INDIRECT + \
0104 (IMFS_MEMFILE_BLOCK_SLOTS * IMFS_MEMFILE_BLOCK_SLOTS))
0105
0106 #define FIRST_TRIPLY_INDIRECT (LAST_DOUBLY_INDIRECT + 1)
0107 #define LAST_TRIPLY_INDIRECT \
0108 (LAST_DOUBLY_INDIRECT +\
0109 (IMFS_MEMFILE_BLOCK_SLOTS * \
0110 IMFS_MEMFILE_BLOCK_SLOTS * IMFS_MEMFILE_BLOCK_SLOTS))
0111
0112 #define IMFS_MEMFILE_MAXIMUM_SIZE \
0113 (LAST_TRIPLY_INDIRECT * IMFS_MEMFILE_BYTES_PER_BLOCK)
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136 typedef IMFS_jnode_t *(*IMFS_node_control_initialize)(
0137 IMFS_jnode_t *node,
0138 void *arg
0139 );
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149
0150
0151 IMFS_jnode_t *IMFS_node_initialize_default(
0152 IMFS_jnode_t *node,
0153 void *arg
0154 );
0155
0156 IMFS_jnode_t *IMFS_node_initialize_directory(
0157 IMFS_jnode_t *node,
0158 void *arg
0159 );
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172 IMFS_jnode_t *IMFS_node_initialize_generic(
0173 IMFS_jnode_t *node,
0174 void *arg
0175 );
0176
0177
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188 typedef IMFS_jnode_t *(*IMFS_node_control_remove)(
0189 IMFS_jnode_t *node
0190 );
0191
0192
0193
0194
0195
0196
0197
0198
0199
0200
0201 IMFS_jnode_t *IMFS_node_remove_default(
0202 IMFS_jnode_t *node
0203 );
0204
0205 IMFS_jnode_t *IMFS_node_remove_directory( IMFS_jnode_t *node );
0206
0207
0208
0209
0210
0211
0212
0213
0214 typedef void (*IMFS_node_control_destroy)( IMFS_jnode_t *node );
0215
0216
0217
0218
0219
0220
0221
0222
0223 void IMFS_node_destroy_default( IMFS_jnode_t *node );
0224
0225
0226
0227
0228
0229
0230
0231
0232 void IMFS_do_nothing_destroy( IMFS_jnode_t *node );
0233
0234
0235
0236
0237 typedef struct {
0238 const rtems_filesystem_file_handlers_r *handlers;
0239 IMFS_node_control_initialize node_initialize;
0240 IMFS_node_control_remove node_remove;
0241 IMFS_node_control_destroy node_destroy;
0242 } IMFS_node_control;
0243
0244 typedef struct {
0245 IMFS_node_control node_control;
0246 size_t node_size;
0247 } IMFS_mknod_control;
0248
0249
0250
0251
0252
0253
0254
0255
0256
0257
0258
0259
0260 #define IMFS_NAME_MAX _POSIX_NAME_MAX
0261
0262
0263
0264
0265
0266
0267 struct IMFS_jnode_tt {
0268 rtems_chain_node Node;
0269 IMFS_jnode_t *Parent;
0270 const char *name;
0271 uint16_t namelen;
0272 mode_t st_mode;
0273 unsigned short reference_count;
0274 nlink_t st_nlink;
0275
0276 uid_t st_uid;
0277 gid_t st_gid;
0278
0279 time_t stat_atime;
0280 time_t stat_mtime;
0281 time_t stat_ctime;
0282 const IMFS_node_control *control;
0283 };
0284
0285 typedef struct {
0286 IMFS_jnode_t Node;
0287 rtems_chain_control Entries;
0288 rtems_filesystem_mount_table_entry_t *mt_fs;
0289 } IMFS_directory_t;
0290
0291 typedef struct {
0292 IMFS_jnode_t Node;
0293 rtems_device_major_number major;
0294 rtems_device_minor_number minor;
0295 } IMFS_device_t;
0296
0297 typedef struct {
0298 IMFS_jnode_t Node;
0299 IMFS_jnode_t *link_node;
0300 } IMFS_link_t;
0301
0302 typedef struct {
0303 IMFS_jnode_t Node;
0304 char *name;
0305 } IMFS_sym_link_t;
0306
0307 typedef struct {
0308 IMFS_jnode_t Node;
0309 size_t size;
0310 } IMFS_filebase_t;
0311
0312 typedef struct {
0313 IMFS_filebase_t File;
0314 block_ptr indirect;
0315 block_ptr doubly_indirect;
0316 block_ptr triply_indirect;
0317 } IMFS_memfile_t;
0318
0319 typedef struct {
0320 IMFS_filebase_t File;
0321 block_p direct;
0322 } IMFS_linearfile_t;
0323
0324
0325 typedef union {
0326 IMFS_jnode_t Node;
0327 IMFS_filebase_t File;
0328 IMFS_memfile_t Memfile;
0329 IMFS_linearfile_t Linearfile;
0330 } IMFS_file_t;
0331
0332 typedef struct {
0333 IMFS_jnode_t Node;
0334 pipe_control_t *pipe;
0335 } IMFS_fifo_t;
0336
0337 typedef struct {
0338 IMFS_jnode_t Node;
0339 void *context;
0340 } IMFS_generic_t;
0341
0342 typedef struct {
0343 const void *data;
0344 size_t size;
0345 } IMFS_linearfile_context;
0346
0347 static inline IMFS_jnode_t *IMFS_iop_to_node( const rtems_libio_t *iop )
0348 {
0349 return (IMFS_jnode_t *) iop->pathinfo.node_access;
0350 }
0351
0352 static inline IMFS_directory_t *IMFS_iop_to_directory(
0353 const rtems_libio_t *iop
0354 )
0355 {
0356 return (IMFS_directory_t *) iop->pathinfo.node_access;
0357 }
0358
0359 static inline IMFS_device_t *IMFS_iop_to_device( const rtems_libio_t *iop )
0360 {
0361 return (IMFS_device_t *) iop->pathinfo.node_access;
0362 }
0363
0364 static inline IMFS_file_t *IMFS_iop_to_file( const rtems_libio_t *iop )
0365 {
0366 return (IMFS_file_t *) iop->pathinfo.node_access;
0367 }
0368
0369 static inline IMFS_memfile_t *IMFS_iop_to_memfile( const rtems_libio_t *iop )
0370 {
0371 return (IMFS_memfile_t *) iop->pathinfo.node_access;
0372 }
0373
0374 typedef struct {
0375 const IMFS_mknod_control *directory;
0376 const IMFS_mknod_control *device;
0377 const IMFS_mknod_control *file;
0378 const IMFS_mknod_control *fifo;
0379 } IMFS_mknod_controls;
0380
0381 typedef struct {
0382 IMFS_directory_t Root_directory;
0383 const IMFS_mknod_controls *mknod_controls;
0384 } IMFS_fs_info_t;
0385
0386 typedef struct {
0387 IMFS_fs_info_t *fs_info;
0388 const rtems_filesystem_operations_table *ops;
0389 const IMFS_mknod_controls *mknod_controls;
0390 } IMFS_mount_data;
0391
0392
0393
0394
0395
0396 extern const IMFS_mknod_control IMFS_mknod_control_dir_default;
0397 extern const IMFS_mknod_control IMFS_mknod_control_dir_minimal;
0398 extern const IMFS_mknod_control IMFS_mknod_control_device;
0399 extern const IMFS_mknod_control IMFS_mknod_control_memfile;
0400 extern const IMFS_node_control IMFS_node_control_linfile;
0401 extern const IMFS_mknod_control IMFS_mknod_control_fifo;
0402 extern const IMFS_mknod_control IMFS_mknod_control_enosys;
0403
0404 extern const rtems_filesystem_limits_and_options_t IMFS_LIMITS_AND_OPTIONS;
0405
0406
0407
0408
0409
0410 extern int IMFS_initialize(
0411 rtems_filesystem_mount_table_entry_t *mt_entry,
0412 const void *data
0413 );
0414
0415 extern int IMFS_initialize_support(
0416 rtems_filesystem_mount_table_entry_t *mt_entry,
0417 const void *data
0418 );
0419
0420
0421
0422
0423 extern void IMFS_fsunmount(
0424 rtems_filesystem_mount_table_entry_t *mt_entry
0425 );
0426
0427
0428
0429
0430
0431
0432
0433
0434
0435
0436
0437
0438
0439
0440
0441
0442
0443
0444
0445
0446
0447
0448
0449
0450
0451
0452
0453
0454
0455
0456
0457
0458
0459
0460
0461
0462
0463
0464
0465
0466
0467
0468
0469
0470
0471
0472
0473
0474
0475
0476
0477
0478 extern int rtems_tarfs_load(
0479 const char *mountpoint,
0480 const void *tar_image,
0481 size_t tar_size
0482 );
0483
0484
0485
0486
0487 extern void IMFS_node_destroy( IMFS_jnode_t *node );
0488
0489
0490
0491
0492 extern int IMFS_node_clone( rtems_filesystem_location_info_t *loc );
0493
0494
0495
0496
0497 extern void IMFS_node_free( const rtems_filesystem_location_info_t *loc );
0498
0499
0500
0501
0502
0503
0504 extern int IMFS_stat(
0505 const rtems_filesystem_location_info_t *loc,
0506 struct stat *buf
0507 );
0508
0509 extern int IMFS_stat_file(
0510 const rtems_filesystem_location_info_t *loc,
0511 struct stat *buf
0512 );
0513
0514
0515
0516
0517 extern void IMFS_eval_path(
0518 rtems_filesystem_eval_path_context_t *ctx
0519 );
0520
0521
0522
0523
0524 extern void IMFS_eval_path_devfs(
0525 rtems_filesystem_eval_path_context_t *ctx
0526 );
0527
0528
0529
0530
0531
0532
0533
0534
0535 extern int IMFS_link(
0536 const rtems_filesystem_location_info_t *parentloc,
0537 const rtems_filesystem_location_info_t *targetloc,
0538 const char *name,
0539 size_t namelen
0540 );
0541
0542
0543
0544
0545
0546
0547
0548 extern int IMFS_chown(
0549 const rtems_filesystem_location_info_t *loc,
0550 uid_t owner,
0551 gid_t group
0552 );
0553
0554
0555
0556
0557
0558
0559 extern int IMFS_mknod(
0560 const rtems_filesystem_location_info_t *parentloc,
0561 const char *name,
0562 size_t namelen,
0563 mode_t mode,
0564 dev_t dev
0565 );
0566
0567 extern IMFS_jnode_t *IMFS_initialize_node(
0568 IMFS_jnode_t *node,
0569 const IMFS_node_control *node_control,
0570 const char *name,
0571 size_t namelen,
0572 mode_t mode,
0573 void *arg
0574 );
0575
0576
0577
0578
0579
0580
0581
0582 extern IMFS_jnode_t *IMFS_create_node(
0583 const rtems_filesystem_location_info_t *parentloc,
0584 const IMFS_node_control *node_control,
0585 size_t node_size,
0586 const char *name,
0587 size_t namelen,
0588 mode_t mode,
0589 void *arg
0590 );
0591
0592 static inline bool IMFS_is_imfs_instance(
0593 const rtems_filesystem_location_info_t *loc
0594 )
0595 {
0596 return loc->mt_entry->ops->clonenod_h == IMFS_node_clone;
0597 }
0598
0599
0600
0601
0602
0603
0604
0605
0606 #define IMFS_NODE_CONTROL_INITIALIZER( handlers, init, destroy ) \
0607 { \
0608 ( handlers ), \
0609 ( init ), \
0610 IMFS_node_remove_default, \
0611 ( destroy ) \
0612 }
0613
0614
0615
0616
0617
0618
0619
0620
0621
0622
0623
0624
0625
0626 #define IMFS_NODE_INITIALIZER( node_control, name, namelen, mode ) \
0627 { \
0628 { NULL, NULL }, \
0629 NULL, \
0630 ( name ), \
0631 ( namelen ), \
0632 ( mode ), \
0633 0, \
0634 0, \
0635 0, \
0636 0, \
0637 0, \
0638 0, \
0639 0, \
0640 ( node_control ) \
0641 }
0642
0643
0644
0645
0646
0647
0648
0649
0650
0651
0652
0653
0654
0655
0656 static inline void IMFS_node_preinitialize(
0657 IMFS_jnode_t *node,
0658 const IMFS_node_control *node_control,
0659 const char *name,
0660 size_t namelen,
0661 mode_t mode
0662 )
0663 {
0664 node->control = node_control;
0665 node->name = name;
0666 node->namelen = namelen;
0667 node->st_mode = mode;
0668 }
0669
0670
0671
0672
0673
0674
0675
0676
0677
0678
0679
0680
0681
0682
0683 int IMFS_add_node( const char *path, IMFS_jnode_t *node, void *arg );
0684
0685 extern int IMFS_make_node(
0686 const char *path,
0687 mode_t mode,
0688 const IMFS_node_control *node_control,
0689 size_t node_size,
0690 void *context
0691 );
0692
0693
0694
0695
0696
0697
0698
0699
0700
0701
0702
0703
0704 extern int IMFS_make_linearfile(
0705 const char *path,
0706 mode_t mode,
0707 const void *data,
0708 size_t size
0709 );
0710
0711
0712
0713
0714
0715
0716
0717
0718
0719
0720
0721
0722
0723
0724
0725
0726
0727
0728
0729
0730 #define IMFS_GENERIC_INITIALIZER( handlers, init, destroy ) \
0731 IMFS_NODE_CONTROL_INITIALIZER( handlers, init, destroy )
0732
0733
0734
0735
0736
0737
0738
0739
0740 #define IMFS_GENERIC_CONTROL_INITIALIZER( handlers, init, destroy ) \
0741 IMFS_NODE_CONTROL_INITIALIZER( handlers, init, destroy )
0742
0743
0744
0745
0746
0747
0748
0749
0750
0751
0752
0753 #define IMFS_GENERIC_NODE_INITIALIZER( node_control, name, namelen, mode ) \
0754 { IMFS_NODE_INITIALIZER( node_control, name, namelen, mode ), NULL }
0755
0756
0757
0758
0759
0760
0761
0762
0763
0764
0765
0766
0767
0768
0769 static inline void IMFS_generic_node_preinitialize(
0770 IMFS_generic_t *node,
0771 const IMFS_node_control *node_control,
0772 const char *name,
0773 size_t namelen,
0774 mode_t mode
0775 )
0776 {
0777 IMFS_node_preinitialize( &node->Node, node_control, name, namelen, mode );
0778 }
0779
0780
0781
0782
0783
0784
0785
0786
0787
0788
0789
0790
0791
0792
0793
0794
0795
0796
0797
0798
0799
0800
0801
0802
0803
0804
0805
0806
0807
0808
0809
0810
0811
0812
0813
0814
0815
0816
0817
0818
0819
0820
0821
0822
0823
0824
0825
0826
0827
0828
0829
0830
0831
0832
0833
0834
0835
0836
0837
0838
0839
0840 extern int IMFS_make_generic_node(
0841 const char *path,
0842 mode_t mode,
0843 const IMFS_node_control *node_control,
0844 void *context
0845 );
0846
0847
0848
0849
0850
0851
0852
0853
0854
0855
0856
0857 extern int IMFS_mount(
0858 rtems_filesystem_mount_table_entry_t *mt_entry
0859 );
0860
0861
0862
0863
0864 extern int IMFS_unmount(
0865 rtems_filesystem_mount_table_entry_t *mt_entry
0866 );
0867
0868
0869
0870
0871
0872
0873
0874
0875
0876
0877
0878
0879 extern ssize_t IMFS_memfile_write(
0880 IMFS_memfile_t *memfile,
0881 off_t start,
0882 const unsigned char *source,
0883 unsigned int length
0884 );
0885
0886
0887
0888
0889
0890
0891
0892
0893
0894
0895
0896 extern int device_open(
0897 rtems_libio_t *iop,
0898 const char *pathname,
0899 int oflag,
0900 mode_t mode
0901 );
0902
0903 extern int device_close(
0904 rtems_libio_t *iop
0905 );
0906
0907 extern ssize_t device_read(
0908 rtems_libio_t *iop,
0909 void *buffer,
0910 size_t count
0911 );
0912
0913 extern ssize_t device_write(
0914 rtems_libio_t *iop,
0915 const void *buffer,
0916 size_t count
0917 );
0918
0919 extern int device_ioctl(
0920 rtems_libio_t *iop,
0921 ioctl_command_t command,
0922 void *buffer
0923 );
0924
0925 extern int device_ftruncate(
0926 rtems_libio_t *iop,
0927 off_t length
0928 );
0929
0930
0931
0932
0933
0934
0935
0936
0937
0938
0939 extern int IMFS_utimens(
0940 const rtems_filesystem_location_info_t *loc,
0941 struct timespec times[2]
0942 );
0943
0944
0945
0946
0947 extern int IMFS_fchmod(
0948 const rtems_filesystem_location_info_t *loc,
0949 mode_t mode
0950 );
0951
0952
0953
0954
0955
0956
0957
0958
0959 extern int IMFS_symlink(
0960 const rtems_filesystem_location_info_t *parentloc,
0961 const char *name,
0962 size_t namelen,
0963 const char *target
0964 );
0965
0966
0967
0968
0969
0970
0971
0972
0973 extern ssize_t IMFS_readlink(
0974 const rtems_filesystem_location_info_t *loc,
0975 char *buf,
0976 size_t bufsize
0977 );
0978
0979
0980
0981
0982
0983
0984
0985 extern int IMFS_rename(
0986 const rtems_filesystem_location_info_t *oldparentloc,
0987 const rtems_filesystem_location_info_t *oldloc,
0988 const rtems_filesystem_location_info_t *newparentloc,
0989 const char *name,
0990 size_t namelen
0991 );
0992
0993
0994
0995
0996
0997
0998 extern int IMFS_rmnod(
0999 const rtems_filesystem_location_info_t *parentloc,
1000 const rtems_filesystem_location_info_t *loc
1001 );
1002
1003
1004
1005
1006 #ifdef RTEMS_DEBUG
1007 #include <assert.h>
1008
1009 #define IMFS_assert(_x) assert(_x)
1010 #else
1011 #define IMFS_assert(_x)
1012 #endif
1013
1014 static inline void IMFS_Set_handlers( rtems_filesystem_location_info_t *loc )
1015 {
1016 IMFS_jnode_t *node = (IMFS_jnode_t *) loc->node_access;
1017
1018 loc->handlers = node->control->handlers;
1019 }
1020
1021 static inline void IMFS_add_to_directory(
1022 IMFS_jnode_t *dir_node,
1023 IMFS_jnode_t *entry_node
1024 )
1025 {
1026 IMFS_directory_t *dir = (IMFS_directory_t *) dir_node;
1027
1028 entry_node->Parent = dir_node;
1029 rtems_chain_append_unprotected( &dir->Entries, &entry_node->Node );
1030 }
1031
1032 static inline void IMFS_remove_from_directory( IMFS_jnode_t *node )
1033 {
1034 IMFS_assert( node->Parent != NULL );
1035 node->Parent = NULL;
1036 rtems_chain_extract_unprotected( &node->Node );
1037 }
1038
1039 static inline bool IMFS_is_directory( const IMFS_jnode_t *node )
1040 {
1041 return S_ISDIR( node->st_mode );
1042 }
1043
1044 #define IMFS_STAT_FMT_HARD_LINK 0
1045
1046 static inline bool IMFS_is_hard_link( mode_t mode )
1047 {
1048 return ( mode & S_IFMT ) == IMFS_STAT_FMT_HARD_LINK;
1049 }
1050
1051 static inline ino_t IMFS_node_to_ino( const IMFS_jnode_t *node )
1052 {
1053 return (ino_t) ((uintptr_t) node);
1054 }
1055
1056
1057
1058
1059
1060
1061
1062
1063 static inline void *IMFS_generic_get_context_by_node(
1064 const IMFS_jnode_t *node
1065 )
1066 {
1067 const IMFS_generic_t *generic = (const IMFS_generic_t *) node;
1068
1069 return generic->context;
1070 }
1071
1072 static inline void *IMFS_generic_get_context_by_location(
1073 const rtems_filesystem_location_info_t *loc
1074 )
1075 {
1076 return loc->node_access_2;
1077 }
1078
1079 static inline void *IMFS_generic_get_context_by_iop(
1080 const rtems_libio_t *iop
1081 )
1082 {
1083 return IMFS_generic_get_context_by_location( &iop->pathinfo );
1084 }
1085
1086 static inline dev_t IMFS_generic_get_device_identifier_by_node(
1087 const IMFS_jnode_t *node
1088 )
1089 {
1090 return rtems_filesystem_make_dev_t_from_pointer( node );
1091 }
1092
1093 #ifdef __cplusplus
1094 }
1095 #endif
1096
1097 #endif
1098