RTEMS  5.1
rtems-rfs-inode.h
Go to the documentation of this file.
1 
13 /*
14  * COPYRIGHT (c) 2010 Chris Johns <chrisj@rtems.org>
15  *
16  * The license and distribution terms for this file may be
17  * found in the file LICENSE in this distribution or at
18  * http://www.rtems.org/license/LICENSE.
19  */
20 
21 
22 #if !defined (_RTEMS_RFS_INODE_H_)
23 #define _RTEMS_RFS_INODE_H_
24 
25 #include <sys/stat.h>
26 
29 
33 #define RTEMS_RFS_S_ISUID S_ISUID
34 #define RTEMS_RFS_S_ISGID S_ISGID
35 #define RTEMS_RFS_S_ISVTX S_ISVTX
36 #define RTEMS_RFS_S_IREAD S_IREAD
37 #define RTEMS_RFS_S_IWRITE S_IWRITE
38 #define RTEMS_RFS_S_IEXEC S_IEXEC
39 #define RTEMS_RFS_S_ENFMT S_ENFMT
40 #define RTEMS_RFS_S_IFMT S_IFMT
41 #define RTEMS_RFS_S_IFDIR S_IFDIR
42 #define RTEMS_RFS_S_IFCHR S_IFCHR
43 #define RTEMS_RFS_S_IFBLK S_IFBLK
44 #define RTEMS_RFS_S_IFREG S_IFREG
45 #define RTEMS_RFS_S_IFLNK S_IFLNK
46 #define RTEMS_RFS_S_IFSOCK S_IFSOCK
47 #define RTEMS_RFS_S_IFIFO S_IFIFO
48 #define RTEMS_RFS_S_IRWXU S_IRWXU
49 #define RTEMS_RFS_S_IRUSR S_IRUSR
50 #define RTEMS_RFS_S_IWUSR S_IWUSR
51 #define RTEMS_RFS_S_IXUSR S_IXUSR
52 #define RTEMS_RFS_S_IRWXG S_IRWXG
53 #define RTEMS_RFS_S_IRGRP S_IRGRP
54 #define RTEMS_RFS_S_IWGRP S_IWGRP
55 #define RTEMS_RFS_S_IXGRP S_IXGRP
56 #define RTEMS_RFS_S_IRWXO S_IRWXO
57 #define RTEMS_RFS_S_IROTH S_IROTH
58 #define RTEMS_RFS_S_IWOTH S_IWOTH
59 #define RTEMS_RFS_S_IXOTH S_IXOTH
61 #define RTEMS_RFS_S_ISBLK(m) S_ISBLK(m)
62 #define RTEMS_RFS_S_ISCHR(m) S_ISCHR(m)
63 #define RTEMS_RFS_S_ISDIR(m) S_ISDIR(m)
64 #define RTEMS_RFS_S_ISFIFO(m) S_ISFIFO(m)
65 #define RTEMS_RFS_S_ISREG(m) S_ISREG(m)
66 #define RTEMS_RFS_S_ISLNK(m) S_ISLNK(m)
67 #define RTEMS_RFS_S_ISSOCK(m) S_ISSOCK(m)
68 
72 #define RTEMS_RFS_S_SYMLINK \
73  RTEMS_RFS_S_IFLNK | RTEMS_RFS_S_IRWXU | RTEMS_RFS_S_IRWXG | RTEMS_RFS_S_IRWXO
74 
78 typedef uint32_t rtems_rfs_ino;
79 
83 typedef uint32_t rtems_rfs_time;
84 
89 typedef uint32_t rtems_rfs_inode_block;
90 
94 #define RTEMS_RFS_INODE_DATA_NAME_SIZE \
95  (RTEMS_RFS_INODE_BLOCKS * sizeof (rtems_rfs_inode_block))
96 
100 typedef struct _rtems_rfs_inode
101 {
105  uint16_t links;
106 
110  uint16_t mode;
111 
115  uint32_t owner;
116 
120  uint16_t flags;
121 
125  uint16_t block_offset;
126 
130  uint32_t block_count;
131 
136 
141 
146 
154  union
155  {
157  uint8_t name[RTEMS_RFS_INODE_DATA_NAME_SIZE];
158  } data;
159 
165 
170 
172 
176 #define RTEMS_RFS_INODE_SIZE (sizeof (rtems_rfs_inode))
177 
182 {
187 
192 
197 
202 
207 
211  int offset;
212 
216  int loads;
217 
219 
223 #define rtems_rfs_inode_is_loaded(_h) ((_h)->node)
224 
228 #define rtems_rfs_inode_ino(_h) ((_h)->ino)
229 
237 static inline uint16_t
238 rtems_rfs_inode_get_links (rtems_rfs_inode_handle* handle)
239 {
240  uint16_t links;
241  links = rtems_rfs_read_u16 (&handle->node->links);
242  if (links == 0xffff)
243  links = 0;
244  return links;
245 }
246 
253 static inline void
254 rtems_rfs_inode_set_links (rtems_rfs_inode_handle* handle, uint16_t links)
255 {
256  rtems_rfs_write_u16 (&handle->node->links, links);
258 }
259 
267 static inline uint16_t
268 rtems_rfs_inode_get_flags (rtems_rfs_inode_handle* handle)
269 {
270  return rtems_rfs_read_u16 (&handle->node->flags);
271 }
272 
279 static inline void
280 rtems_rfs_inode_set_flags (rtems_rfs_inode_handle* handle, uint16_t flags)
281 {
282  rtems_rfs_write_u16 (&handle->node->flags, flags);
284 }
285 
293 static inline uint16_t
294 rtems_rfs_inode_get_mode (rtems_rfs_inode_handle* handle)
295 {
296  return rtems_rfs_read_u16 (&handle->node->mode);
297 }
298 
305 static inline void
306 rtems_rfs_inode_set_mode (rtems_rfs_inode_handle* handle, uint16_t mode)
307 {
308  rtems_rfs_write_u16 (&handle->node->mode, mode);
310 }
311 
319 static inline uint16_t
320 rtems_rfs_inode_get_uid (rtems_rfs_inode_handle* handle)
321 {
322  return rtems_rfs_read_u32 (&handle->node->owner) & 0xffff;
323 }
324 
332 static inline uint16_t
333 rtems_rfs_inode_get_gid (rtems_rfs_inode_handle* handle)
334 {
335  return (rtems_rfs_read_u32 (&handle->node->owner) >> 16) & 0xffff;
336 }
337 
345 static inline void
346 rtems_rfs_inode_set_uid_gid (rtems_rfs_inode_handle* handle,
347  uint16_t uid, uint16_t gid)
348 {
349  rtems_rfs_write_u32 (&handle->node->owner, (((uint32_t) gid) << 16) | uid);
351 }
352 
360 static inline uint16_t
361 rtems_rfs_inode_get_block_offset (rtems_rfs_inode_handle* handle)
362 {
363  return rtems_rfs_read_u16 (&handle->node->block_offset);
364 }
365 
372 static inline void
373 rtems_rfs_inode_set_block_offset (rtems_rfs_inode_handle* handle,
374  uint16_t block_offset)
375 {
376  rtems_rfs_write_u16 (&handle->node->block_offset, block_offset);
378 }
379 
387 static inline uint32_t
388 rtems_rfs_inode_get_block_count (rtems_rfs_inode_handle* handle)
389 {
390  return rtems_rfs_read_u32 (&handle->node->block_count);
391 }
392 
399 static inline void
400 rtems_rfs_inode_set_block_count (rtems_rfs_inode_handle* handle, uint32_t block_count)
401 {
402  rtems_rfs_write_u32 (&handle->node->block_count, block_count);
404 }
405 
413 static inline rtems_rfs_time
414 rtems_rfs_inode_get_atime (rtems_rfs_inode_handle* handle)
415 {
416  return rtems_rfs_read_u32 (&handle->node->atime);
417 }
418 
425 static inline void
426 rtems_rfs_inode_set_atime (rtems_rfs_inode_handle* handle,
427  rtems_rfs_time atime)
428 {
429  rtems_rfs_write_u32 (&handle->node->atime, atime);
431 }
432 
440 static inline rtems_rfs_time
441 rtems_rfs_inode_get_mtime (rtems_rfs_inode_handle* handle)
442 {
443  return rtems_rfs_read_u32 (&handle->node->mtime);
444 }
445 
452 static inline void
453 rtems_rfs_inode_set_mtime (rtems_rfs_inode_handle* handle,
454  rtems_rfs_time mtime)
455 {
456  rtems_rfs_write_u32 (&handle->node->mtime, mtime);
458 }
459 
467 static inline rtems_rfs_time
468 rtems_rfs_inode_get_ctime (rtems_rfs_inode_handle* handle)
469 {
470  return rtems_rfs_read_u32 (&handle->node->ctime);
471 }
472 
479 static inline void
480 rtems_rfs_inode_set_ctime (rtems_rfs_inode_handle* handle,
481  rtems_rfs_time ctime)
482 {
483  rtems_rfs_write_u32 (&handle->node->ctime, ctime);
485 }
486 
495 static inline uint32_t
496 rtems_rfs_inode_get_block (rtems_rfs_inode_handle* handle, int block)
497 {
498  return rtems_rfs_read_u32 (&handle->node->data.blocks[block]);
499 }
500 
508 static inline void
509 rtems_rfs_inode_set_block (rtems_rfs_inode_handle* handle, int block, uint32_t bno)
510 {
511  rtems_rfs_write_u32 (&handle->node->data.blocks[block], bno);
513 }
514 
522 static inline uint32_t
523 rtems_rfs_inode_get_last_map_block (rtems_rfs_inode_handle* handle)
524 {
525  return rtems_rfs_read_u32 (&handle->node->last_map_block);
526 }
527 
534 static inline void
535 rtems_rfs_inode_set_last_map_block (rtems_rfs_inode_handle* handle, uint32_t last_map_block)
536 {
537  rtems_rfs_write_u32 (&handle->node->last_map_block, last_map_block);
539 }
540 
549 static inline uint32_t
550 rtems_rfs_inode_get_last_data_block (rtems_rfs_inode_handle* handle)
551 {
552  return rtems_rfs_read_u32 (&handle->node->last_data_block);
553 }
554 
561 static inline void
562 rtems_rfs_inode_set_last_data_block (rtems_rfs_inode_handle* handle, uint32_t last_data_block)
563 {
564  rtems_rfs_write_u32 (&handle->node->last_data_block, last_data_block);
566 }
567 
579  rtems_rfs_ino* ino);
580 
591  rtems_rfs_ino ino);
592 
607  rtems_rfs_ino ino,
608  rtems_rfs_inode_handle* handle,
609  bool load);
610 
621  rtems_rfs_inode_handle* handle);
622 
633  rtems_rfs_inode_handle* handle);
634 
646  rtems_rfs_inode_handle* handle,
647  bool update_ctime);
648 
660  rtems_rfs_ino parent,
661  const char* name,
662  size_t length,
663  uint16_t mode,
664  uint16_t links,
665  uid_t uid,
666  gid_t gid,
667  rtems_rfs_ino* ino);
668 
680  rtems_rfs_inode_handle* handle);
681 
695  uint16_t links,
696  uint16_t mode,
697  uid_t uid,
698  gid_t gid);
699 
713  bool atime,
714  bool mtime);
715 
725  rtems_rfs_inode_handle* handle);
726 
727 #endif
728 
int rtems_rfs_inode_open(rtems_rfs_file_system *fs, rtems_rfs_ino ino, rtems_rfs_inode_handle *handle, bool load)
Definition: rtems-rfs-inode.c:53
struct _rtems_rfs_inode rtems_rfs_inode
Definition: chain.h:68
RTEMS File System Data.
int rtems_rfs_inode_delete(rtems_rfs_file_system *fs, rtems_rfs_inode_handle *handle)
Definition: rtems-rfs-inode.c:320
#define RTEMS_RFS_INODE_BLOCKS
Definition: rtems-rfs-file-system.h:67
int32_t rtems_rfs_bitmap_bit
Definition: rtems-rfs-bitmaps.h:84
#define rtems_rfs_read_u16(_d)
Definition: rtems-rfs-data.h:50
uint32_t rtems_rfs_inode_block
Definition: rtems-rfs-inode.h:89
uint32_t block_count
Definition: rtems-rfs-inode.h:130
int rtems_rfs_inode_time_stamp_now(rtems_rfs_inode_handle *handle, bool atime, bool mtime)
Definition: rtems-rfs-inode.c:394
RTEMS File System Data.
#define RTEMS_RFS_INODE_DATA_NAME_SIZE
Definition: rtems-rfs-inode.h:94
uint16_t mode
Definition: rtems-rfs-inode.h:110
struct _rtems_rfs_inode_handle rtems_rfs_inode_handle
int rtems_rfs_inode_unload(rtems_rfs_file_system *fs, rtems_rfs_inode_handle *handle, bool update_ctime)
Definition: rtems-rfs-inode.c:145
int rtems_rfs_inode_alloc(rtems_rfs_file_system *fs, rtems_rfs_bitmap_bit goal, rtems_rfs_ino *ino)
Definition: rtems-rfs-inode.c:32
Definition: rtems-rfs-file-system.h:123
rtems_rfs_time mtime
Definition: rtems-rfs-inode.h:140
uint64_t rtems_rfs_pos
Definition: rtems-rfs-file-system.h:90
uint32_t rtems_rfs_buffer_block
Definition: rtems-rfs-buffer.h:62
uint32_t rtems_rfs_ino
Definition: rtems-rfs-inode.h:78
int rtems_rfs_inode_initialise(rtems_rfs_inode_handle *handle, uint16_t links, uint16_t mode, uid_t uid, gid_t gid)
Definition: rtems-rfs-inode.c:373
uint16_t flags
Definition: rtems-rfs-inode.h:120
rtems_rfs_time atime
Definition: rtems-rfs-inode.h:135
uint16_t block_offset
Definition: rtems-rfs-inode.h:125
rtems_rfs_inode * node
Definition: rtems-rfs-inode.h:196
uint32_t owner
Definition: rtems-rfs-inode.h:115
rtems_rfs_buffer_block block
Definition: rtems-rfs-inode.h:206
int offset
Definition: rtems-rfs-inode.h:211
int rtems_rfs_inode_close(rtems_rfs_file_system *fs, rtems_rfs_inode_handle *handle)
Definition: rtems-rfs-inode.c:91
Definition: rtems-rfs-inode.h:181
int rtems_rfs_inode_free(rtems_rfs_file_system *fs, rtems_rfs_ino ino)
Definition: rtems-rfs-inode.c:44
Definition: rtems-rfs-inode.h:100
rtems_rfs_inode_block last_data_block
Definition: rtems-rfs-inode.h:169
rtems_chain_node link
Definition: rtems-rfs-inode.h:186
rtems_rfs_inode_block last_map_block
Definition: rtems-rfs-inode.h:164
#define rtems_rfs_write_u16(_d, _v)
Definition: rtems-rfs-data.h:72
uint32_t rtems_rfs_time
Definition: rtems-rfs-inode.h:83
int rtems_rfs_inode_load(rtems_rfs_file_system *fs, rtems_rfs_inode_handle *handle)
Definition: rtems-rfs-inode.c:114
Definition: rtems-rfs-buffer.h:91
union _rtems_rfs_inode::@3972 data
#define rtems_rfs_buffer_mark_dirty(_h)
Definition: rtems-rfs-buffer.h:144
int rtems_rfs_inode_create(rtems_rfs_file_system *fs, rtems_rfs_ino parent, const char *name, size_t length, uint16_t mode, uint16_t links, uid_t uid, gid_t gid, rtems_rfs_ino *ino)
Definition: rtems-rfs-inode.c:179
rtems_rfs_ino ino
Definition: rtems-rfs-inode.h:191
#define rtems_rfs_read_u32(_d)
Definition: rtems-rfs-data.h:57
rtems_rfs_time ctime
Definition: rtems-rfs-inode.h:145
uint16_t links
Definition: rtems-rfs-inode.h:105
rtems_rfs_pos rtems_rfs_inode_get_size(rtems_rfs_file_system *fs, rtems_rfs_inode_handle *handle)
Definition: rtems-rfs-inode.c:410
#define rtems_rfs_write_u32(_d, _v)
Definition: rtems-rfs-data.h:81
rtems_rfs_buffer_handle buffer
Definition: rtems-rfs-inode.h:201
int loads
Definition: rtems-rfs-inode.h:216