source: rtems/cpukit/libfs/src/rfs/rtems-rfs-inode.h @ e354eb4f

4.115
Last change on this file since e354eb4f was e354eb4f, checked in by Alex Ivanov <alexivanov97@…>, on 01/08/13 at 14:02:58

libfs: Doxygen Clean Up Task #1

http://www.google-melange.com/gci/task/view/google/gci2012/8120204

Patch committed with fixes for whitespace issues.

  • Property mode set to 100644
File size: 18.5 KB
Line 
1/**
2 * @file
3 *
4 * @brief RTEMS File System Information Node
5 *
6 * @ingroup rtems-rfs
7 *
8 * RTEMS File System Information Node.
9 *
10 * The information nodes hold the data about all nodes in the file system.
11 */
12
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.com/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
27#include <rtems/rfs/rtems-rfs-data.h>
28#include <rtems/rfs/rtems-rfs-file-system.h>
29
30/**
31 * The RFS mode definitions. Currently map to the C library ones.
32 */
33#define RTEMS_RFS_S_ISUID  S_ISUID  /**< Set user id on execution */
34#define RTEMS_RFS_S_ISGID  S_ISGID  /**< Set group id on execution */
35#define RTEMS_RFS_S_ISVTX  S_ISVTX  /**< Save swapped text even after use */
36#define RTEMS_RFS_S_IREAD  S_IREAD  /**< Read permission, owner */
37#define RTEMS_RFS_S_IWRITE S_IWRITE /**< Write permission, owner */
38#define RTEMS_RFS_S_IEXEC  S_IEXEC  /**< Execute/search permission, owner */
39#define RTEMS_RFS_S_ENFMT  S_ENFMT  /**< Enforcement-mode locking */
40#define RTEMS_RFS_S_IFMT   S_IFMT   /**< Type of file */
41#define RTEMS_RFS_S_IFDIR  S_IFDIR  /**< Directory */
42#define RTEMS_RFS_S_IFCHR  S_IFCHR  /**< Character special */
43#define RTEMS_RFS_S_IFBLK  S_IFBLK  /**< Block special */
44#define RTEMS_RFS_S_IFREG  S_IFREG  /**< Regular */
45#define RTEMS_RFS_S_IFLNK  S_IFLNK  /**< Symbolic link */
46#define RTEMS_RFS_S_IFSOCK S_IFSOCK /**< Socket */
47#define RTEMS_RFS_S_IFIFO  S_IFIFO  /**< Fifo */
48#define RTEMS_RFS_S_IRWXU  S_IRWXU
49#define RTEMS_RFS_S_IRUSR  S_IRUSR  /**< Read permission, owner */
50#define RTEMS_RFS_S_IWUSR  S_IWUSR  /**< Write permission, owner */
51#define RTEMS_RFS_S_IXUSR  S_IXUSR  /**< Execute/search permission, owner */
52#define RTEMS_RFS_S_IRWXG  S_IRWXG
53#define RTEMS_RFS_S_IRGRP  S_IRGRP  /**< Read permission, group */
54#define RTEMS_RFS_S_IWGRP  S_IWGRP  /**< Write permission, grougroup */
55#define RTEMS_RFS_S_IXGRP  S_IXGRP  /**< Execute/search permission, group */
56#define RTEMS_RFS_S_IRWXO  S_IRWXO
57#define RTEMS_RFS_S_IROTH  S_IROTH  /**< Read permission, other */
58#define RTEMS_RFS_S_IWOTH  S_IWOTH  /**< Write permission, other */
59#define RTEMS_RFS_S_IXOTH  S_IXOTH  /**< Execute/search permission, other */
60
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
69/**
70 * Permissions of a symlink.
71 */
72#define RTEMS_RFS_S_SYMLINK \
73  RTEMS_RFS_S_IFLNK | RTEMS_RFS_S_IRWXU | RTEMS_RFS_S_IRWXG | RTEMS_RFS_S_IRWXO
74
75/**
76 * The inode number or ino.
77 */
78typedef uint32_t rtems_rfs_ino;
79
80/**
81 * The time in the file system.
82 */
83typedef uint32_t rtems_rfs_time;
84
85/**
86 * The size of a block value on disk. This include the inodes and indirect
87 * tables.
88 */
89typedef uint32_t rtems_rfs_inode_block;
90
91/**
92 * The size of the data name field in the inode.
93 */
94#define RTEMS_RFS_INODE_DATA_NAME_SIZE \
95  (RTEMS_RFS_INODE_BLOCKS * sizeof (rtems_rfs_inode_block))
96
97/**
98 * The inode.
99 */
100typedef struct _rtems_rfs_inode
101{
102  /**
103   * The number of links to the inode.
104   */
105  uint16_t links;
106
107  /**
108   * The mode of the node.
109   */
110  uint16_t mode;
111
112  /**
113   * The owner of the node.
114   */
115  uint32_t owner;
116
117  /**
118   * Reserved.
119   */
120  uint16_t flags;
121
122  /**
123   * Amount of data held in the last block data.
124   */
125  uint16_t block_offset;
126
127  /**
128   * Number of blocks held by this file.
129   */
130  uint32_t block_count;
131
132  /**
133   * The access time. The last time the file was read.
134   */
135  rtems_rfs_time atime;
136
137  /**
138   * The modified time. The last time the file was written too.
139   */
140  rtems_rfs_time mtime;
141
142  /**
143   * The change time. The last time the inode was written too.
144   */
145  rtems_rfs_time ctime;
146
147  /**
148   * Blocks. These are the block numbers used by the node or table of
149   * nodes. The flags indicate the mode the blocks are being held in. In the
150   * direct table mode the blocks are entries in this table. In the indirect
151   * mode the blocks point to blocks that hold the block numbers. The data can
152   * also be a name if it fits. For example a symbolic link.
153   */
154  union
155  {
156    rtems_rfs_inode_block blocks[RTEMS_RFS_INODE_BLOCKS];
157    uint8_t               name[RTEMS_RFS_INODE_DATA_NAME_SIZE];
158  } data;
159
160  /**
161   * The last block map block. Used as the goal when allocating a new block for
162   * use in the map.
163   */
164  rtems_rfs_inode_block last_map_block;
165
166  /**
167   * The last data block. Used as the goal when allocating a new block.
168   */
169  rtems_rfs_inode_block last_data_block;
170
171} rtems_rfs_inode;
172
173/**
174 * The size of an inode.
175 */
176#define RTEMS_RFS_INODE_SIZE (sizeof (rtems_rfs_inode))
177
178/**
179 * RFS Inode Handle.
180 */
181typedef struct _rtems_rfs_inode_handle
182{
183  /**
184   * Handles can be linked as a list for easy processing.
185   */
186  rtems_chain_node link;
187
188  /**
189   * The ino for this handle.
190   */
191  rtems_rfs_ino ino;
192
193  /**
194   * The pointer to the inode.
195   */
196  rtems_rfs_inode* node;
197
198  /**
199   * The buffer that contains this inode.
200   */
201  rtems_rfs_buffer_handle buffer;
202
203  /**
204   * The block number that holds the inode.
205   */
206  rtems_rfs_buffer_block block;
207
208  /**
209   * The offset into the block for the inode.
210   */
211  int offset;
212
213  /**
214   * Number of load requests.
215   */
216  int loads;
217
218} rtems_rfs_inode_handle;
219
220/**
221 * Is the inode loaded ?
222 */
223#define rtems_rfs_inode_is_loaded(_h) ((_h)->node)
224
225/**
226 * Get the inode ino for a handle.
227 */
228#define rtems_rfs_inode_ino(_h) ((_h)->ino)
229
230/**
231 * Get the link count.
232 *
233 * @param[in] handle is the inode handle.
234 *
235 * @retval links The link count.
236 */
237static inline uint16_t
238rtems_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
247/**
248 * Set the link count.
249 *
250 * @param[in] handle is the inode handle.
251 * @param[in] links are the links.
252 */
253static inline void
254rtems_rfs_inode_set_links (rtems_rfs_inode_handle* handle, uint16_t links)
255{
256  rtems_rfs_write_u16 (&handle->node->links, links);
257  rtems_rfs_buffer_mark_dirty (&handle->buffer);
258}
259
260/**
261 * Get the flags.
262 *
263 * @param[in] handle is the inode handle.
264 *
265 * @retval flags The flags.
266 */
267static inline uint16_t
268rtems_rfs_inode_get_flags (rtems_rfs_inode_handle* handle)
269{
270  return rtems_rfs_read_u16 (&handle->node->flags);
271}
272
273/**
274 * Set the flags.
275 *
276 * @param[in] handle is the inode handle.
277 * @param[in] flags are the flags.
278 */
279static inline void
280rtems_rfs_inode_set_flags (rtems_rfs_inode_handle* handle, uint16_t flags)
281{
282  rtems_rfs_write_u16 (&handle->node->flags, flags);
283  rtems_rfs_buffer_mark_dirty (&handle->buffer);
284}
285
286/**
287 * Get the mode.
288 *
289 * @param[in] handle is the inode handle.
290 *
291 * @retval mode The mode.
292 */
293static inline uint16_t
294rtems_rfs_inode_get_mode (rtems_rfs_inode_handle* handle)
295{
296  return rtems_rfs_read_u16 (&handle->node->mode);
297}
298
299/**
300 * Set the mode.
301 *
302 * @param[in] handle is the inode handle.
303 * @param[in] mode is the mode.
304 */
305static inline void
306rtems_rfs_inode_set_mode (rtems_rfs_inode_handle* handle, uint16_t mode)
307{
308  rtems_rfs_write_u16 (&handle->node->mode, mode);
309  rtems_rfs_buffer_mark_dirty (&handle->buffer);
310}
311
312/**
313 * Get the user id.
314 *
315 * @param[in] handle is the inode handle.
316 *
317 * @retval uid The used id.
318 */
319static inline uint16_t
320rtems_rfs_inode_get_uid (rtems_rfs_inode_handle* handle)
321{
322  return rtems_rfs_read_u32 (&handle->node->owner) & 0xffff;
323}
324
325/**
326 * Get the group id.
327 *
328 * @param[in] handle is the inode handle.
329 *
330 * @retval gid The grpup id.
331 */
332static inline uint16_t
333rtems_rfs_inode_get_gid (rtems_rfs_inode_handle* handle)
334{
335  return (rtems_rfs_read_u32 (&handle->node->owner) >> 16) & 0xffff;
336}
337
338/**
339 * Set the user id and group id.
340 *
341 * @param[in] handle is the inode handle.
342 * @param[in] uid is the user id (uid).
343 * @param[in] gid is the group id (gid).
344 */
345static inline void
346rtems_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);
350  rtems_rfs_buffer_mark_dirty (&handle->buffer);
351}
352
353/**
354 * Get the block offset.
355 *
356 * @param[in] handle is the inode handle.
357 *
358 * @retval offset The block offset.
359 */
360static inline uint16_t
361rtems_rfs_inode_get_block_offset (rtems_rfs_inode_handle* handle)
362{
363  return rtems_rfs_read_u16 (&handle->node->block_offset);
364}
365
366/**
367 * Set the block offset.
368 *
369 * @param[in] handle is the inode handle.
370 * @param[in] block_count is the block offset.
371 */
372static inline void
373rtems_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);
377  rtems_rfs_buffer_mark_dirty (&handle->buffer);
378}
379
380/**
381 * Get the block count.
382 *
383 * @param[in] handle is the inode handle.
384 *
385 * @retval count The block count.
386 */
387static inline uint32_t
388rtems_rfs_inode_get_block_count (rtems_rfs_inode_handle* handle)
389{
390  return rtems_rfs_read_u32 (&handle->node->block_count);
391}
392
393/**
394 * Set the block count.
395 *
396 * @param[in] handle is the inode handle.
397 * @param[in] block_count is the block count.
398 */
399static inline void
400rtems_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);
403  rtems_rfs_buffer_mark_dirty (&handle->buffer);
404}
405
406/**
407 * Get the atime.
408 *
409 * @param[in] handle is the inode handle.
410 *
411 * @retval atime The atime.
412 */
413static inline rtems_rfs_time
414rtems_rfs_inode_get_atime (rtems_rfs_inode_handle* handle)
415{
416  return rtems_rfs_read_u32 (&handle->node->atime);
417}
418
419/**
420 * Set the atime.
421 *
422 * @param[in] handle is the inode handle.
423 * @param[in] atime The atime.
424 */
425static inline void
426rtems_rfs_inode_set_atime (rtems_rfs_inode_handle* handle,
427                           rtems_rfs_time          atime)
428{
429  rtems_rfs_write_u32 (&handle->node->atime, atime);
430  rtems_rfs_buffer_mark_dirty (&handle->buffer);
431}
432
433/**
434 * Get the mtime.
435 *
436 * @param[in] handle is the inode handle.
437 *
438 * @retval mtime The mtime.
439 */
440static inline rtems_rfs_time
441rtems_rfs_inode_get_mtime (rtems_rfs_inode_handle* handle)
442{
443  return rtems_rfs_read_u32 (&handle->node->mtime);
444}
445
446/**
447 * Set the mtime.
448 *
449 * @param[in] handle is the inode handle.
450 * @param[in] mtime The mtime.
451 */
452static inline void
453rtems_rfs_inode_set_mtime (rtems_rfs_inode_handle* handle,
454                           rtems_rfs_time          mtime)
455{
456  rtems_rfs_write_u32 (&handle->node->mtime, mtime);
457  rtems_rfs_buffer_mark_dirty (&handle->buffer);
458}
459
460/**
461 * Get the ctime.
462 *
463 * @param[in] handle is the inode handle.
464 *
465 * @retval ctime The ctime.
466 */
467static inline rtems_rfs_time
468rtems_rfs_inode_get_ctime (rtems_rfs_inode_handle* handle)
469{
470  return rtems_rfs_read_u32 (&handle->node->ctime);
471}
472
473/**
474 * Set the ctime.
475 *
476 * @param[in] handle is the inode handle.
477 * @param[in] ctime The ctime.
478 */
479static inline void
480rtems_rfs_inode_set_ctime (rtems_rfs_inode_handle* handle,
481                           rtems_rfs_time          ctime)
482{
483  rtems_rfs_write_u32 (&handle->node->ctime, ctime);
484  rtems_rfs_buffer_mark_dirty (&handle->buffer);
485}
486
487/**
488 * Get the block number.
489 *
490 * @param[in] handle is the inode handle.
491 * @param[in] block is the block number to return.
492 *
493 * @retval block The block number.
494 */
495static inline uint32_t
496rtems_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
501/**
502 * Set the block number for a given block index.
503 *
504 * @param[in] handle is the inode handle.
505 * @param[in] block is the block index.
506 * @param[in] bno is the block number.
507 */
508static inline void
509rtems_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);
512  rtems_rfs_buffer_mark_dirty (&handle->buffer);
513}
514
515/**
516 * Get the last map block from the inode.
517 *
518 * @param[in] handle is the inode handle.
519 *
520 * @retval block The last map block number.
521 */
522static inline uint32_t
523rtems_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
528/**
529 * Set the last map block.
530 *
531 * @param[in] handle is the inode handle.
532 * @param[in] block_count is last map block number.
533 */
534static inline void
535rtems_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);
538  rtems_rfs_buffer_mark_dirty (&handle->buffer);
539}
540
541/**
542 * Get the last data block from the inode.
543 *
544 * @param[in] handle is the inode handle.
545 *
546 * @retval block The last data block number.
547 *
548 */
549static inline uint32_t
550rtems_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
555/**
556 * Set the last data block.
557 *
558 * @param[in] handle is the inode handle.
559 * @param[in] block_count is the last data block number.
560 */
561static inline void
562rtems_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);
565  rtems_rfs_buffer_mark_dirty (&handle->buffer);
566}
567
568/**
569 * Allocate an inode number and return it.
570 *
571 * @param[in] fs is the file system data.
572 * @param[out] ino will contain the ino.
573 *
574 * @retval 0 Successful operation.
575 * @retval error_code An error occurred.
576 */
577int rtems_rfs_inode_alloc (rtems_rfs_file_system* fs,
578                           rtems_rfs_bitmap_bit   goal,
579                           rtems_rfs_ino*         ino);
580
581/**
582 * Free an inode.
583 *
584 * @param[in] fs is the file system data.
585 * @param[in] ino is the ino too free.
586 *
587 * @retval 0 Successful operation.
588 * @retval error_code An error occurred.
589 */
590int rtems_rfs_inode_free (rtems_rfs_file_system* fs,
591                          rtems_rfs_ino          ino);
592
593/**
594 * Open the inode handle. This reads the inode into the buffer and sets the
595 * data pointer. All data is in media byte order and needs to be accessed via
596 * the supporting calls.
597 *
598 * @param[in] fs is the file system.
599 * @param[in] ino is the inode number.
600 * @param[in] handle is the handle to the inode we are opening.
601 * @param[in] load If true load the inode into memory from the media.
602 *
603 * @retval 0 Successful operation.
604 * @retval error_code An error occurred.
605 */
606int rtems_rfs_inode_open (rtems_rfs_file_system*  fs,
607                          rtems_rfs_ino           ino,
608                          rtems_rfs_inode_handle* handle,
609                          bool                    load);
610
611/**
612 * The close inode handle. All opened inodes need to be closed.
613 *
614 * @param[in] fs is the file system.
615 * @param[in] handle is the handle to close.
616 *
617 * @retval 0 Successful operation.
618 * @retval error_code An error occurred.
619 */
620int rtems_rfs_inode_close (rtems_rfs_file_system*  fs,
621                           rtems_rfs_inode_handle* handle);
622
623/**
624 * Load the inode into memory.
625 *
626 * @param[in] fs is the file system.
627 * @param[in] handle is the inode handle to load.
628 *
629 * @retval 0 Successful operation.
630 * @retval error_code An error occurred.
631 */
632int rtems_rfs_inode_load (rtems_rfs_file_system*  fs,
633                          rtems_rfs_inode_handle* handle);
634
635/**
636 * Unload the inode from memory.
637 *
638 * @param[in] fs is the file system.
639 * @param[in] handle is the inode handle to unload.
640 * @param[in] update_ctime Update the ctime field of the inode.
641 *
642 * @retval 0 Successful operation.
643 * @retval error_code An error occurred.
644 */
645int rtems_rfs_inode_unload (rtems_rfs_file_system*  fs,
646                            rtems_rfs_inode_handle* handle,
647                            bool                    update_ctime);
648
649/**
650 * Create an inode allocating, initialising and adding an entry to the parent
651 * directory.
652 *
653 * @param[in] fs is the file system data.
654 * @param[in] parent is the parent inode number to add the directory entry to.
655 * @param[in] name is a pointer to the name of the directory entryinode
656 *             to create.
657 *
658 */
659int rtems_rfs_inode_create (rtems_rfs_file_system*  fs,
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
669/**
670 * Delete the inode eraseing it and release the buffer to commit the write. You
671 * need to load the inode again if you wish to use it again.
672 *
673 * @param[in] fs is the file system.
674 * @param[in] handle is the inode handle to erase.
675 *
676 * @retval 0 Successful operation.
677 * @retval error_code An error occurred.
678 */
679int rtems_rfs_inode_delete (rtems_rfs_file_system*  fs,
680                            rtems_rfs_inode_handle* handle);
681
682/**
683 * Initialise a new inode.
684 *
685 * @param[in] handle is the inode handle to initialise.
686 * @param[in] links are the number of links to the inode.
687 * @param[in] mode is the inode mode.
688 * @param[in] uid is the user id.
689 * @param[in] gid is the group id.
690 *
691 * @retval 0 Successful operation.
692 * @retval error_code An error occurred.
693 */
694int rtems_rfs_inode_initialise (rtems_rfs_inode_handle* handle,
695                                uint16_t                links,
696                                uint16_t                mode,
697                                uid_t                   uid,
698                                gid_t                   gid);
699
700/**
701 * Time stamp the inode with the current time. The ctime field is hanlded
702 * automatically.
703 *
704 * @param[in] handle is the inode handle.
705 * @param[in] atime Update the atime field.
706 * @param[in] mtime UPdate the mtime field.
707 *
708 * @retval 0 Successful operation.
709 * @retval ENXIO No inode is loaded.
710 * @retval error_code An error occurred.
711 */
712int rtems_rfs_inode_time_stamp_now (rtems_rfs_inode_handle* handle,
713                                    bool                    atime,
714                                    bool                    mtime);
715
716/**
717 * Calculate the size of data attached to the inode.
718 *
719 * @param[in] fs is the file system data.
720 * @param[in] handle is the inode handle.
721 *
722 * @retval size The data size in bytes in the block map attched to the inode.
723 */
724rtems_rfs_pos rtems_rfs_inode_get_size (rtems_rfs_file_system*  fs,
725                                        rtems_rfs_inode_handle* handle);
726
727#endif
728
Note: See TracBrowser for help on using the repository browser.