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 | */ |
---|
78 | typedef uint32_t rtems_rfs_ino; |
---|
79 | |
---|
80 | /** |
---|
81 | * The time in the file system. |
---|
82 | */ |
---|
83 | typedef 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 | */ |
---|
89 | typedef 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 | */ |
---|
100 | typedef 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 | */ |
---|
181 | typedef 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 handle The inode handle. |
---|
234 | * @return uint16_t The link count. |
---|
235 | */ |
---|
236 | static inline uint16_t |
---|
237 | rtems_rfs_inode_get_links (rtems_rfs_inode_handle* handle) |
---|
238 | { |
---|
239 | uint16_t links; |
---|
240 | links = rtems_rfs_read_u16 (&handle->node->links); |
---|
241 | if (links == 0xffff) |
---|
242 | links = 0; |
---|
243 | return links; |
---|
244 | } |
---|
245 | |
---|
246 | /** |
---|
247 | * Set the link count. |
---|
248 | * |
---|
249 | * @param handle The inode handle. |
---|
250 | * @prarm links The links. |
---|
251 | */ |
---|
252 | static inline void |
---|
253 | rtems_rfs_inode_set_links (rtems_rfs_inode_handle* handle, uint16_t links) |
---|
254 | { |
---|
255 | rtems_rfs_write_u16 (&handle->node->links, links); |
---|
256 | rtems_rfs_buffer_mark_dirty (&handle->buffer); |
---|
257 | } |
---|
258 | |
---|
259 | /** |
---|
260 | * Get the flags. |
---|
261 | * |
---|
262 | * @param handle The inode handle. |
---|
263 | * @return uint16_t The flags. |
---|
264 | */ |
---|
265 | static inline uint16_t |
---|
266 | rtems_rfs_inode_get_flags (rtems_rfs_inode_handle* handle) |
---|
267 | { |
---|
268 | return rtems_rfs_read_u16 (&handle->node->flags); |
---|
269 | } |
---|
270 | |
---|
271 | /** |
---|
272 | * Set the flags. |
---|
273 | * |
---|
274 | * @param handle The inode handle. |
---|
275 | * @prarm flags The flags. |
---|
276 | */ |
---|
277 | static inline void |
---|
278 | rtems_rfs_inode_set_flags (rtems_rfs_inode_handle* handle, uint16_t flags) |
---|
279 | { |
---|
280 | rtems_rfs_write_u16 (&handle->node->flags, flags); |
---|
281 | rtems_rfs_buffer_mark_dirty (&handle->buffer); |
---|
282 | } |
---|
283 | |
---|
284 | /** |
---|
285 | * Get the mode. |
---|
286 | * |
---|
287 | * @param handle The inode handle. |
---|
288 | * @return uint16_t The mode. |
---|
289 | */ |
---|
290 | static inline uint16_t |
---|
291 | rtems_rfs_inode_get_mode (rtems_rfs_inode_handle* handle) |
---|
292 | { |
---|
293 | return rtems_rfs_read_u16 (&handle->node->mode); |
---|
294 | } |
---|
295 | |
---|
296 | /** |
---|
297 | * Set the mode. |
---|
298 | * |
---|
299 | * @param handle The inode handle. |
---|
300 | * @prarm mode The mode. |
---|
301 | */ |
---|
302 | static inline void |
---|
303 | rtems_rfs_inode_set_mode (rtems_rfs_inode_handle* handle, uint16_t mode) |
---|
304 | { |
---|
305 | rtems_rfs_write_u16 (&handle->node->mode, mode); |
---|
306 | rtems_rfs_buffer_mark_dirty (&handle->buffer); |
---|
307 | } |
---|
308 | |
---|
309 | /** |
---|
310 | * Get the user id. |
---|
311 | * |
---|
312 | * @param handle The inode handle. |
---|
313 | * @return uint16_t The user id (uid). |
---|
314 | */ |
---|
315 | static inline uint16_t |
---|
316 | rtems_rfs_inode_get_uid (rtems_rfs_inode_handle* handle) |
---|
317 | { |
---|
318 | return rtems_rfs_read_u32 (&handle->node->owner) & 0xffff; |
---|
319 | } |
---|
320 | |
---|
321 | /** |
---|
322 | * Get the group id. |
---|
323 | * |
---|
324 | * @param handle The inode handle. |
---|
325 | * @return uint16_t The group id (gid). |
---|
326 | */ |
---|
327 | static inline uint16_t |
---|
328 | rtems_rfs_inode_get_gid (rtems_rfs_inode_handle* handle) |
---|
329 | { |
---|
330 | return (rtems_rfs_read_u32 (&handle->node->owner) >> 16) & 0xffff; |
---|
331 | } |
---|
332 | |
---|
333 | /** |
---|
334 | * Set the user id and group id. |
---|
335 | * |
---|
336 | * @param handle The inode handle. |
---|
337 | * @param uid The user id (uid). |
---|
338 | * @param gid The group id (gid). |
---|
339 | */ |
---|
340 | static inline void |
---|
341 | rtems_rfs_inode_set_uid_gid (rtems_rfs_inode_handle* handle, |
---|
342 | uint16_t uid, uint16_t gid) |
---|
343 | { |
---|
344 | rtems_rfs_write_u32 (&handle->node->owner, (((uint32_t) gid) << 16) | uid); |
---|
345 | rtems_rfs_buffer_mark_dirty (&handle->buffer); |
---|
346 | } |
---|
347 | |
---|
348 | /** |
---|
349 | * Get the block offset. |
---|
350 | * |
---|
351 | * @param handle The inode handle. |
---|
352 | * @return uint32_t The block offset. |
---|
353 | */ |
---|
354 | static inline uint16_t |
---|
355 | rtems_rfs_inode_get_block_offset (rtems_rfs_inode_handle* handle) |
---|
356 | { |
---|
357 | return rtems_rfs_read_u16 (&handle->node->block_offset); |
---|
358 | } |
---|
359 | |
---|
360 | /** |
---|
361 | * Set the block offset. |
---|
362 | * |
---|
363 | * @param handle The inode handle. |
---|
364 | * @param block_count The block offset. |
---|
365 | */ |
---|
366 | static inline void |
---|
367 | rtems_rfs_inode_set_block_offset (rtems_rfs_inode_handle* handle, |
---|
368 | uint16_t block_offset) |
---|
369 | { |
---|
370 | rtems_rfs_write_u16 (&handle->node->block_offset, block_offset); |
---|
371 | rtems_rfs_buffer_mark_dirty (&handle->buffer); |
---|
372 | } |
---|
373 | |
---|
374 | /** |
---|
375 | * Get the block count. |
---|
376 | * |
---|
377 | * @param handle The inode handle. |
---|
378 | * @return uint32_t The block count. |
---|
379 | */ |
---|
380 | static inline uint32_t |
---|
381 | rtems_rfs_inode_get_block_count (rtems_rfs_inode_handle* handle) |
---|
382 | { |
---|
383 | return rtems_rfs_read_u32 (&handle->node->block_count); |
---|
384 | } |
---|
385 | |
---|
386 | /** |
---|
387 | * Set the block count. |
---|
388 | * |
---|
389 | * @param handle The inode handle. |
---|
390 | * @param block_count The block count. |
---|
391 | */ |
---|
392 | static inline void |
---|
393 | rtems_rfs_inode_set_block_count (rtems_rfs_inode_handle* handle, uint32_t block_count) |
---|
394 | { |
---|
395 | rtems_rfs_write_u32 (&handle->node->block_count, block_count); |
---|
396 | rtems_rfs_buffer_mark_dirty (&handle->buffer); |
---|
397 | } |
---|
398 | |
---|
399 | /** |
---|
400 | * Get the atime. |
---|
401 | * |
---|
402 | * @param handle The inode handle. |
---|
403 | * @return rtems_rfs_time The atime. |
---|
404 | */ |
---|
405 | static inline rtems_rfs_time |
---|
406 | rtems_rfs_inode_get_atime (rtems_rfs_inode_handle* handle) |
---|
407 | { |
---|
408 | return rtems_rfs_read_u32 (&handle->node->atime); |
---|
409 | } |
---|
410 | |
---|
411 | /** |
---|
412 | * Set the atime. |
---|
413 | * |
---|
414 | * @param handle The inode handle. |
---|
415 | * @prarm atime The atime. |
---|
416 | */ |
---|
417 | static inline void |
---|
418 | rtems_rfs_inode_set_atime (rtems_rfs_inode_handle* handle, |
---|
419 | rtems_rfs_time atime) |
---|
420 | { |
---|
421 | rtems_rfs_write_u32 (&handle->node->atime, atime); |
---|
422 | rtems_rfs_buffer_mark_dirty (&handle->buffer); |
---|
423 | } |
---|
424 | |
---|
425 | /** |
---|
426 | * Get the mtime. |
---|
427 | * |
---|
428 | * @param handle The inode handle. |
---|
429 | * @return rtems_rfs_time The mtime. |
---|
430 | */ |
---|
431 | static inline rtems_rfs_time |
---|
432 | rtems_rfs_inode_get_mtime (rtems_rfs_inode_handle* handle) |
---|
433 | { |
---|
434 | return rtems_rfs_read_u32 (&handle->node->mtime); |
---|
435 | } |
---|
436 | |
---|
437 | /** |
---|
438 | * Set the mtime. |
---|
439 | * |
---|
440 | * @param handle The inode handle. |
---|
441 | * @prarm atime The mtime. |
---|
442 | */ |
---|
443 | static inline void |
---|
444 | rtems_rfs_inode_set_mtime (rtems_rfs_inode_handle* handle, |
---|
445 | rtems_rfs_time mtime) |
---|
446 | { |
---|
447 | rtems_rfs_write_u32 (&handle->node->mtime, mtime); |
---|
448 | rtems_rfs_buffer_mark_dirty (&handle->buffer); |
---|
449 | } |
---|
450 | |
---|
451 | /** |
---|
452 | * Get the ctime. |
---|
453 | * |
---|
454 | * @param handle The inode handle. |
---|
455 | * @return rtems_rfs_time The ctime. |
---|
456 | */ |
---|
457 | static inline rtems_rfs_time |
---|
458 | rtems_rfs_inode_get_ctime (rtems_rfs_inode_handle* handle) |
---|
459 | { |
---|
460 | return rtems_rfs_read_u32 (&handle->node->ctime); |
---|
461 | } |
---|
462 | |
---|
463 | /** |
---|
464 | * Set the ctime. |
---|
465 | * |
---|
466 | * @param handle The inode handle. |
---|
467 | * @prarm atime The ctime. |
---|
468 | */ |
---|
469 | static inline void |
---|
470 | rtems_rfs_inode_set_ctime (rtems_rfs_inode_handle* handle, |
---|
471 | rtems_rfs_time ctime) |
---|
472 | { |
---|
473 | rtems_rfs_write_u32 (&handle->node->ctime, ctime); |
---|
474 | rtems_rfs_buffer_mark_dirty (&handle->buffer); |
---|
475 | } |
---|
476 | |
---|
477 | /** |
---|
478 | * Get the block number. |
---|
479 | * |
---|
480 | * @param handle The inode handle. |
---|
481 | * @param block The block number to return. |
---|
482 | * @return uint32_t The block number. |
---|
483 | */ |
---|
484 | static inline uint32_t |
---|
485 | rtems_rfs_inode_get_block (rtems_rfs_inode_handle* handle, int block) |
---|
486 | { |
---|
487 | return rtems_rfs_read_u32 (&handle->node->data.blocks[block]); |
---|
488 | } |
---|
489 | |
---|
490 | /** |
---|
491 | * Set the block number for a given block index. |
---|
492 | * |
---|
493 | * @param handle The inode handle. |
---|
494 | * @param block The block index. |
---|
495 | * @param bno The block number. |
---|
496 | */ |
---|
497 | static inline void |
---|
498 | rtems_rfs_inode_set_block (rtems_rfs_inode_handle* handle, int block, uint32_t bno) |
---|
499 | { |
---|
500 | rtems_rfs_write_u32 (&handle->node->data.blocks[block], bno); |
---|
501 | rtems_rfs_buffer_mark_dirty (&handle->buffer); |
---|
502 | } |
---|
503 | |
---|
504 | /** |
---|
505 | * Get the last map block from the inode. |
---|
506 | * |
---|
507 | * @param handle The inode handle. |
---|
508 | * @return uint32_t The last map block number. |
---|
509 | */ |
---|
510 | static inline uint32_t |
---|
511 | rtems_rfs_inode_get_last_map_block (rtems_rfs_inode_handle* handle) |
---|
512 | { |
---|
513 | return rtems_rfs_read_u32 (&handle->node->last_map_block); |
---|
514 | } |
---|
515 | |
---|
516 | /** |
---|
517 | * Set the last map block. |
---|
518 | * |
---|
519 | * @param handle The inode handle. |
---|
520 | * @param block_count The last map block number. |
---|
521 | */ |
---|
522 | static inline void |
---|
523 | rtems_rfs_inode_set_last_map_block (rtems_rfs_inode_handle* handle, uint32_t last_map_block) |
---|
524 | { |
---|
525 | rtems_rfs_write_u32 (&handle->node->last_map_block, last_map_block); |
---|
526 | rtems_rfs_buffer_mark_dirty (&handle->buffer); |
---|
527 | } |
---|
528 | |
---|
529 | /** |
---|
530 | * Get the last data block from the inode. |
---|
531 | * |
---|
532 | * @param handle The inode handle. |
---|
533 | * @return uint32_t The last data block number. |
---|
534 | */ |
---|
535 | static inline uint32_t |
---|
536 | rtems_rfs_inode_get_last_data_block (rtems_rfs_inode_handle* handle) |
---|
537 | { |
---|
538 | return rtems_rfs_read_u32 (&handle->node->last_data_block); |
---|
539 | } |
---|
540 | |
---|
541 | /** |
---|
542 | * Set the last data block. |
---|
543 | * |
---|
544 | * @param handle The inode handle. |
---|
545 | * @param block_count The last data block number. |
---|
546 | */ |
---|
547 | static inline void |
---|
548 | rtems_rfs_inode_set_last_data_block (rtems_rfs_inode_handle* handle, uint32_t last_data_block) |
---|
549 | { |
---|
550 | rtems_rfs_write_u32 (&handle->node->last_data_block, last_data_block); |
---|
551 | rtems_rfs_buffer_mark_dirty (&handle->buffer); |
---|
552 | } |
---|
553 | |
---|
554 | /** |
---|
555 | * Allocate an inode number and return it. |
---|
556 | * |
---|
557 | * @param fs The file system data. |
---|
558 | * @param ino Return the ino. |
---|
559 | * @return int The error number (errno). No error if 0. |
---|
560 | */ |
---|
561 | int rtems_rfs_inode_alloc (rtems_rfs_file_system* fs, |
---|
562 | rtems_rfs_bitmap_bit goal, |
---|
563 | rtems_rfs_ino* ino); |
---|
564 | |
---|
565 | /** |
---|
566 | * Allocate an inode number and return it. |
---|
567 | * |
---|
568 | * @param fs The file system data. |
---|
569 | * @param ino The ino too free. |
---|
570 | * @return int The error number (errno). No error if 0. |
---|
571 | */ |
---|
572 | int rtems_rfs_inode_free (rtems_rfs_file_system* fs, |
---|
573 | rtems_rfs_ino ino); |
---|
574 | |
---|
575 | /** |
---|
576 | * Open the inode handle. This reads the inode into the buffer and sets the |
---|
577 | * data pointer. All data is in media byte order and needs to be accessed via |
---|
578 | * the supporting calls. |
---|
579 | * |
---|
580 | * @param fs The file system. |
---|
581 | * @param ino The inode number. |
---|
582 | * @param handle The handle to the inode we are opening. |
---|
583 | * @param load If true load the inode into memory from the media. |
---|
584 | * @return int The error number (errno). No error if 0. |
---|
585 | */ |
---|
586 | int rtems_rfs_inode_open (rtems_rfs_file_system* fs, |
---|
587 | rtems_rfs_ino ino, |
---|
588 | rtems_rfs_inode_handle* handle, |
---|
589 | bool load); |
---|
590 | |
---|
591 | /** |
---|
592 | * The close inode handle. All opened inodes need to be closed. |
---|
593 | * |
---|
594 | * @param fs The file system. |
---|
595 | * @param handle The handle to close. |
---|
596 | * @return int The error number (errno). No error if 0. |
---|
597 | */ |
---|
598 | int rtems_rfs_inode_close (rtems_rfs_file_system* fs, |
---|
599 | rtems_rfs_inode_handle* handle); |
---|
600 | |
---|
601 | /** |
---|
602 | * Load the inode into memory. |
---|
603 | * |
---|
604 | * @param fs The file system. |
---|
605 | * @param handle The inode handle to load. |
---|
606 | * @return int The error number (errno). No error if 0. |
---|
607 | */ |
---|
608 | int rtems_rfs_inode_load (rtems_rfs_file_system* fs, |
---|
609 | rtems_rfs_inode_handle* handle); |
---|
610 | |
---|
611 | /** |
---|
612 | * Unload the inode from memory. |
---|
613 | * |
---|
614 | * @param fs The file system. |
---|
615 | * @param handle The inode handle to unload. |
---|
616 | * @param update_ctime Update the ctime field of the inode. |
---|
617 | * @return int The error number (errno). No error if 0. |
---|
618 | */ |
---|
619 | int rtems_rfs_inode_unload (rtems_rfs_file_system* fs, |
---|
620 | rtems_rfs_inode_handle* handle, |
---|
621 | bool update_ctime); |
---|
622 | |
---|
623 | /** |
---|
624 | * Create an inode allocating, initialising and adding an entry to the parent |
---|
625 | * directory. |
---|
626 | * |
---|
627 | * @param fs The file system data. |
---|
628 | * @param parent The parent inode number to add the directory entry to. |
---|
629 | * @param name The name of the directory entryinode to create. |
---|
630 | * |
---|
631 | */ |
---|
632 | int rtems_rfs_inode_create (rtems_rfs_file_system* fs, |
---|
633 | rtems_rfs_ino parent, |
---|
634 | const char* name, |
---|
635 | size_t length, |
---|
636 | uint16_t mode, |
---|
637 | uint16_t links, |
---|
638 | uid_t uid, |
---|
639 | gid_t gid, |
---|
640 | rtems_rfs_ino* ino); |
---|
641 | |
---|
642 | /** |
---|
643 | * Delete the inode eraseing it and release the buffer to commit the write. You |
---|
644 | * need to load the inode again if you wish to use it again. |
---|
645 | * |
---|
646 | * @param fs The file system. |
---|
647 | * @param handle The inode handle to erase. |
---|
648 | * @return int The error number (errno). No error if 0. |
---|
649 | */ |
---|
650 | int rtems_rfs_inode_delete (rtems_rfs_file_system* fs, |
---|
651 | rtems_rfs_inode_handle* handle); |
---|
652 | |
---|
653 | /** |
---|
654 | * Initialise a new inode. |
---|
655 | * |
---|
656 | * @param handle The inode handle to initialise. |
---|
657 | * @param links The number of links to the inode. |
---|
658 | * @param mode The inode mode. |
---|
659 | * @param uid The user id. |
---|
660 | * @param gid The group id. |
---|
661 | * @return int The error number (errno). No error if 0. |
---|
662 | */ |
---|
663 | int rtems_rfs_inode_initialise (rtems_rfs_inode_handle* handle, |
---|
664 | uint16_t links, |
---|
665 | uint16_t mode, |
---|
666 | uid_t uid, |
---|
667 | gid_t gid); |
---|
668 | |
---|
669 | /** |
---|
670 | * Time stamp the inode with the current time. The ctime field is hanlded |
---|
671 | * automatically. |
---|
672 | * |
---|
673 | * @param handle The inode handle. |
---|
674 | * @param atime Update the atime field. |
---|
675 | * @param mtime UPdate the mtime field. |
---|
676 | * @return int The error number (errno). No error if 0 and ENXIO if no inode |
---|
677 | * loaded. |
---|
678 | */ |
---|
679 | int rtems_rfs_inode_time_stamp_now (rtems_rfs_inode_handle* handle, |
---|
680 | bool atime, |
---|
681 | bool mtime); |
---|
682 | |
---|
683 | /** |
---|
684 | * Calculate the size of data attached to the inode. |
---|
685 | * |
---|
686 | * @param fs The file system data. |
---|
687 | * @param handle The inode handle. |
---|
688 | * @return rtems_rfs_pos The data size in bytes in the block map attched to the |
---|
689 | * inode. |
---|
690 | */ |
---|
691 | rtems_rfs_pos rtems_rfs_inode_get_size (rtems_rfs_file_system* fs, |
---|
692 | rtems_rfs_inode_handle* handle); |
---|
693 | |
---|
694 | #endif |
---|
695 | |
---|