source: rtems/cpukit/libfs/src/rfs/rtems-rfs-dir.h @ c2ae79e

4.115
Last change on this file since c2ae79e was c2ae79e, checked in by Mathew Kallada <matkallada@…>, on 12/12/12 at 20:57:49

misc: Header File Doxygen Enhancement Task #3

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

  • Property mode set to 100644
File size: 6.0 KB
Line 
1/**
2 * @file
3 *
4 * @brief RTEMS File System Directory Support
5 *
6 * @ingroup rtems-rfs
7 *
8 * RTEMS File System Directory Support
9 *
10 * This file provides the directory support functions.
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#if !defined (_RTEMS_RFS_DIR_H_)
22#define _RTEMS_RFS_DIR_H_
23
24#include <dirent.h>
25
26#include <rtems/libio_.h>
27
28#include <rtems/rfs/rtems-rfs-data.h>
29#include <rtems/rfs/rtems-rfs-file-system.h>
30#include <rtems/rfs/rtems-rfs-inode.h>
31
32/**
33 * Define the offsets of the fields of a directory entry.
34 */
35#define RTEMS_RFS_DIR_ENTRY_INO  (0) /**< The ino offset in a directory
36                                      * entry. */
37#define RTEMS_RFS_DIR_ENTRY_HASH (4) /**< The hash offset in a directory
38                                      * entry. The hash is 32bits. We need at
39                                      * least 16bits and given the length and
40                                      * ino field are 4 the extra 2 bytes is
41                                      * not a big overhead.*/
42#define RTEMS_RFS_DIR_ENTRY_LEN  (8) /**< The length offset in a directory
43                                      * entry. */
44
45/**
46 * The length of the directory entry header.
47 */
48#define RTEMS_RFS_DIR_ENTRY_SIZE (4 + 4 + 2)
49
50/**
51 * The length when the remainder of the directory block is empty.
52 */
53#define RTEMS_RFS_DIR_ENTRY_EMPTY (0xffff)
54
55/**
56 * Return the hash of the entry.
57 *
58 * @param _e Pointer to the directory entry.
59 * @return uint32_t The hash.
60 */
61#define rtems_rfs_dir_entry_hash(_e) \
62  rtems_rfs_read_u32 (_e + RTEMS_RFS_DIR_ENTRY_HASH)
63
64/**
65 * Set the hash of the entry.
66 *
67 * @param _e Pointer to the directory entry.
68 * @param _h The hash.
69 */
70#define rtems_rfs_dir_set_entry_hash(_e, _h) \
71  rtems_rfs_write_u32 (_e + RTEMS_RFS_DIR_ENTRY_HASH, _h)
72
73/**
74 * Return the ino of the entry.
75 *
76 * @param _e Pointer to the directory entry.
77 * @return uint32_t The ino.
78 */
79#define rtems_rfs_dir_entry_ino(_e) \
80  rtems_rfs_read_u32 (_e + RTEMS_RFS_DIR_ENTRY_INO)
81
82/**
83 * Set the ino of the entry.
84 *
85 * @param _e Pointer to the directory entry.
86 * @param _i The ino.
87 */
88#define rtems_rfs_dir_set_entry_ino(_e, _i) \
89  rtems_rfs_write_u32 (_e + RTEMS_RFS_DIR_ENTRY_INO, _i)
90
91/**
92 * Return the length of the entry.
93 *
94 * @param _e Pointer to the directory entry.
95 * @return uint16_t The length.
96 */
97#define rtems_rfs_dir_entry_length(_e) \
98  rtems_rfs_read_u16 (_e + RTEMS_RFS_DIR_ENTRY_LEN)
99
100/**
101 * Set the length of the entry.
102 *
103 * @param _e Pointer to the directory entry.
104 * @param _l The length.
105 */
106#define rtems_rfs_dir_set_entry_length(_e, _l) \
107  rtems_rfs_write_u16 (_e + RTEMS_RFS_DIR_ENTRY_LEN, _l)
108
109/**
110 * Look up a directory entry in the directory pointed to by the inode. The look
111 * up is local to this directory. No need to decend.
112 *
113 * @param fs The file system.
114 * @param inode The inode of the directory to search.
115 * @param name The name to look up. The name may not be nul terminated.
116 * @param length The length of the name.
117 * @param ino The return inode number if there is no error.
118 * @param offset The offset in the directory for the entry.
119 * @return int The error number (errno). No error if 0.
120 */
121int rtems_rfs_dir_lookup_ino (rtems_rfs_file_system*  fs,
122                              rtems_rfs_inode_handle* inode,
123                              const char*             name,
124                              int                     length,
125                              rtems_rfs_ino*          ino,
126                              uint32_t*               offset);
127
128/**
129 * Add an entry to the directory returing the inode number allocated to the
130 * entry.
131 *
132 * @param fs The file system data.
133 * @param dir Pointer to the directory inode the entry is to be added too.
134 * @param name The name of the entry to be added.
135 * @param length The length of the name excluding a terminating 0.
136 * @param ino The ino of the entry.
137 * @return int The error number (errno). No error if 0.
138 */
139int rtems_rfs_dir_add_entry (rtems_rfs_file_system*  fs,
140                             rtems_rfs_inode_handle* dir,
141                             const char*             name,
142                             size_t                  length,
143                             rtems_rfs_ino           ino);
144
145/**
146 * Del an entry from the directory using an inode number as a key.
147 *
148 * @param fs The file system data.
149 * @param dir Pointer to the directory inode the entry is to be deleted from.
150 * @param ino The ino of the entry.
151 * @param offset The offset in the directory of the entry to delete. If 0
152 *               search from the start for the ino.
153 * @return int The error number (errno). No error if 0.
154 */
155int rtems_rfs_dir_del_entry (rtems_rfs_file_system*  fs,
156                             rtems_rfs_inode_handle* dir,
157                             rtems_rfs_ino           ino,
158                             uint32_t                offset);
159
160/**
161 * Read the directory entry from offset into the directory entry buffer and
162 * return the length of space this entry uses in the directory table.
163 *
164 * @param fs The file system data.
165 * @param dir The direct inode handler.
166 * @param offset The offset in the directory to read from.
167 * @param dirent Pointer to the dirent structure the entry is written into.
168 * @param length Set the length this entry takes in the directory.
169 * @return int The error number (errno). No error if 0.
170 */
171int rtems_rfs_dir_read (rtems_rfs_file_system*  fs,
172                        rtems_rfs_inode_handle* dir,
173                        rtems_rfs_pos_rel       offset,
174                        struct dirent*          dirent,
175                        size_t*                 length);
176
177/**
178 * Check if the directory is empty. The current and parent directory entries
179 * are ignored.
180 *
181 * @param fs The file system data
182 * @param dir The directory inode to check.
183 * @return int The error number (errno). No error if 0.
184 */
185int rtems_rfs_dir_empty (rtems_rfs_file_system*  fs,
186                         rtems_rfs_inode_handle* dir);
187
188#endif
Note: See TracBrowser for help on using the repository browser.