1 | /* |
---|
2 | * Header file for the In-Memory File System |
---|
3 | * |
---|
4 | * COPYRIGHT (c) 1989-1998. |
---|
5 | * On-Line Applications Research Corporation (OAR). |
---|
6 | * Copyright assigned to U.S. Government, 1994. |
---|
7 | * |
---|
8 | * The license and distribution terms for this file may be |
---|
9 | * found in the file LICENSE in this distribution or at |
---|
10 | * http://www.OARcorp.com/rtems/license.html. |
---|
11 | * |
---|
12 | * $Id$ |
---|
13 | */ |
---|
14 | |
---|
15 | #ifndef __IMFS_h |
---|
16 | #define __IMFS_h |
---|
17 | |
---|
18 | #ifdef __cplusplus |
---|
19 | extern "C" { |
---|
20 | #endif |
---|
21 | |
---|
22 | #include <rtems.h> |
---|
23 | #include <chain.h> |
---|
24 | |
---|
25 | #include <sys/types.h> |
---|
26 | #include <limits.h> |
---|
27 | #include <rtems/libio.h> |
---|
28 | |
---|
29 | /* |
---|
30 | * File name macros |
---|
31 | */ |
---|
32 | |
---|
33 | #define IMFS_is_valid_name_char( _ch ) ( 1 ) |
---|
34 | |
---|
35 | #define IMFS_is_separator( _ch ) \ |
---|
36 | rtems_filesystem_is_separator( _ch ) |
---|
37 | |
---|
38 | /* |
---|
39 | * Data types |
---|
40 | */ |
---|
41 | |
---|
42 | struct IMFS_jnode_tt; |
---|
43 | typedef struct IMFS_jnode_tt IMFS_jnode_t; |
---|
44 | |
---|
45 | typedef struct { |
---|
46 | Chain_Control Entries; |
---|
47 | rtems_filesystem_mount_table_entry_t *mt_fs; |
---|
48 | } IMFS_directory_t; |
---|
49 | |
---|
50 | typedef struct { |
---|
51 | rtems_device_major_number major; |
---|
52 | rtems_device_minor_number minor; |
---|
53 | } IMFS_device_t; |
---|
54 | |
---|
55 | typedef struct { |
---|
56 | IMFS_jnode_t *link_node; |
---|
57 | } IMFS_link_t; |
---|
58 | |
---|
59 | typedef struct { |
---|
60 | const char *name; |
---|
61 | } IMFS_sym_link_t; |
---|
62 | |
---|
63 | /* |
---|
64 | * IMFS "memfile" information |
---|
65 | * |
---|
66 | * The data structure for the in-memory "memfiles" is based on classic UNIX. |
---|
67 | * |
---|
68 | * block_ptr is a pointer to a block of IMFS_MEMFILE_BYTES_PER_BLOCK in |
---|
69 | * length which could be data or a table of pointers to blocks. |
---|
70 | */ |
---|
71 | |
---|
72 | #define IMFS_MEMFILE_BYTES_PER_BLOCK 64 /* 512 */ |
---|
73 | #define IMFS_MEMFILE_BLOCK_SLOTS \ |
---|
74 | (IMFS_MEMFILE_BYTES_PER_BLOCK / sizeof(void *)) |
---|
75 | |
---|
76 | typedef unsigned char * block_p; |
---|
77 | typedef block_p *block_ptr; |
---|
78 | |
---|
79 | typedef struct { |
---|
80 | off_t size; /* size of file in bytes */ |
---|
81 | block_ptr indirect; /* array of 128 data blocks pointers */ |
---|
82 | block_ptr doubly_indirect; /* 128 indirect blocks */ |
---|
83 | block_ptr triply_indirect; /* 128 doubly indirect blocks */ |
---|
84 | } IMFS_memfile_t; |
---|
85 | |
---|
86 | /* |
---|
87 | * Important block numbers for "memfiles" |
---|
88 | */ |
---|
89 | |
---|
90 | #define FIRST_INDIRECT (0) |
---|
91 | #define LAST_INDIRECT (IMFS_MEMFILE_BLOCK_SLOTS - 1) |
---|
92 | |
---|
93 | #define FIRST_DOUBLY_INDIRECT (LAST_INDIRECT + 1) |
---|
94 | #define LAST_DOUBLY_INDIRECT \ |
---|
95 | (LAST_INDIRECT + \ |
---|
96 | (IMFS_MEMFILE_BLOCK_SLOTS * IMFS_MEMFILE_BLOCK_SLOTS)) |
---|
97 | |
---|
98 | #define FIRST_TRIPLY_INDIRECT (LAST_DOUBLY_INDIRECT + 1) |
---|
99 | #define LAST_TRIPLY_INDIRECT \ |
---|
100 | (LAST_DOUBLY_INDIRECT +\ |
---|
101 | (IMFS_MEMFILE_BLOCK_SLOTS * \ |
---|
102 | IMFS_MEMFILE_BLOCK_SLOTS * IMFS_MEMFILE_BLOCK_SLOTS)) |
---|
103 | |
---|
104 | #define IMFS_MEMFILE_MAXIMUM_SIZE \ |
---|
105 | (LAST_TRIPLY_INDIRECT * IMFS_MEMFILE_BYTES_PER_BLOCK) |
---|
106 | |
---|
107 | /* |
---|
108 | * What types of IMFS file systems entities there can be. |
---|
109 | */ |
---|
110 | |
---|
111 | #define IMFS_jnode_types_t rtems_filesystem_node_types_t |
---|
112 | #define IMFS_DIRECTORY RTEMS_FILESYSTEM_DIRECTORY |
---|
113 | #define IMFS_DEVICE RTEMS_FILESYSTEM_DEVICE |
---|
114 | #define IMFS_HARD_LINK RTEMS_FILESYSTEM_HARD_LINK |
---|
115 | #define IMFS_SYM_LINK RTEMS_FILESYSTEM_SYM_LINK |
---|
116 | #define IMFS_MEMORY_FILE RTEMS_FILESYSTEM_MEMORY_FILE |
---|
117 | |
---|
118 | #define IMFS_NUMBER_OF_TYPES (IMFS_MEMORY_FILE + 1) |
---|
119 | |
---|
120 | typedef union { |
---|
121 | IMFS_directory_t directory; |
---|
122 | IMFS_device_t device; |
---|
123 | IMFS_link_t hard_link; |
---|
124 | IMFS_sym_link_t sym_link; |
---|
125 | IMFS_memfile_t file; |
---|
126 | } IMFS_types_union; |
---|
127 | |
---|
128 | /* |
---|
129 | * Maximum length of a "basename" of an IMFS file/node. |
---|
130 | */ |
---|
131 | |
---|
132 | #define IMFS_NAME_MAX 32 |
---|
133 | |
---|
134 | /* |
---|
135 | * The control structure for an IMFS jnode. |
---|
136 | */ |
---|
137 | |
---|
138 | struct IMFS_jnode_tt { |
---|
139 | Chain_Node Node; /* for chaining them together */ |
---|
140 | IMFS_jnode_t *Parent; /* Parent node */ |
---|
141 | char name[IMFS_NAME_MAX+1]; /* "basename" */ |
---|
142 | mode_t st_mode; /* File mode */ |
---|
143 | nlink_t st_nlink; /* Link count */ |
---|
144 | ino_t st_ino; /* inode */ |
---|
145 | |
---|
146 | uid_t st_uid; /* User ID of owner */ |
---|
147 | gid_t st_gid; /* Group ID of owner */ |
---|
148 | |
---|
149 | time_t st_atime; /* Time of last access */ |
---|
150 | time_t st_mtime; /* Time of last modification */ |
---|
151 | time_t st_ctime; /* Time of last status change */ |
---|
152 | IMFS_jnode_types_t type; /* Type of this entry */ |
---|
153 | IMFS_types_union info; |
---|
154 | }; |
---|
155 | |
---|
156 | #define IMFS_update_atime( _jnode ) \ |
---|
157 | do { \ |
---|
158 | struct timeval tv; \ |
---|
159 | gettimeofday( &tv, 0 ); \ |
---|
160 | _jnode->st_atime = (time_t) tv.tv_sec; \ |
---|
161 | } while (0) |
---|
162 | |
---|
163 | #define IMFS_update_mtime( _jnode ) \ |
---|
164 | do { \ |
---|
165 | struct timeval tv; \ |
---|
166 | gettimeofday( &tv, 0 ); \ |
---|
167 | _jnode->st_mtime = (time_t) tv.tv_sec; \ |
---|
168 | } while (0) |
---|
169 | |
---|
170 | #define IMFS_update_ctime( _jnode ) \ |
---|
171 | do { \ |
---|
172 | struct timeval tv; \ |
---|
173 | gettimeofday( &tv, 0 ); \ |
---|
174 | _jnode->st_ctime = (time_t) tv.tv_sec; \ |
---|
175 | } while (0) |
---|
176 | |
---|
177 | #define IMFS_atime_mtime_update( _jnode ) \ |
---|
178 | do { \ |
---|
179 | struct timeval tv; \ |
---|
180 | gettimeofday( &tv, 0 ); \ |
---|
181 | _jnode->st_mtime = (time_t) tv.tv_sec; \ |
---|
182 | _jnode->st_atime = (time_t) tv.tv_sec; \ |
---|
183 | } while (0) |
---|
184 | |
---|
185 | typedef struct { |
---|
186 | ino_t ino_count; |
---|
187 | } IMFS_fs_info_t; |
---|
188 | |
---|
189 | #define increment_and_check_linkcounts( _fs_info ) \ |
---|
190 | ((IMFS_fs_info_t * )_fs_info)->link_counts++; \ |
---|
191 | if ( ((IMFS_fs_info_t * )_fs_info)->link_counts > MAXSYMLINKS ) \ |
---|
192 | set_errno_and_return_minus_one( ELOOP ) |
---|
193 | |
---|
194 | #define decrement_linkcounts( _fs_info ) \ |
---|
195 | ((IMFS_fs_info_t * )_fs_info)->link_counts--; |
---|
196 | |
---|
197 | /* |
---|
198 | * Type defination for tokens returned from IMFS_get_token |
---|
199 | */ |
---|
200 | |
---|
201 | typedef enum { |
---|
202 | IMFS_NO_MORE_PATH, |
---|
203 | IMFS_CURRENT_DIR, |
---|
204 | IMFS_UP_DIR, |
---|
205 | IMFS_NAME, |
---|
206 | IMFS_INVALID_TOKEN |
---|
207 | } IMFS_token_types; |
---|
208 | |
---|
209 | /* |
---|
210 | * Shared Data |
---|
211 | */ |
---|
212 | |
---|
213 | extern rtems_filesystem_file_handlers_r device_handlers; |
---|
214 | extern rtems_filesystem_file_handlers_r memfile_handlers; |
---|
215 | extern rtems_filesystem_file_handlers_r dir_handlers; |
---|
216 | extern rtems_filesystem_file_handlers_r null_handlers; |
---|
217 | extern rtems_filesystem_operations_table IMFS_ops; |
---|
218 | extern rtems_filesystem_limits_and_options_t IMFS_LIMITS_AND_OPTIONS; |
---|
219 | |
---|
220 | /* |
---|
221 | * Routines |
---|
222 | */ |
---|
223 | |
---|
224 | int IMFS_initialize( |
---|
225 | rtems_filesystem_mount_table_entry_t *mt_entry |
---|
226 | ); |
---|
227 | |
---|
228 | int IMFS_fsunmount( |
---|
229 | rtems_filesystem_mount_table_entry_t *mt_entry |
---|
230 | ); |
---|
231 | |
---|
232 | |
---|
233 | /* |
---|
234 | * Returns the number of characters copied from path to token. |
---|
235 | */ |
---|
236 | IMFS_token_types IMFS_get_token( |
---|
237 | const char *path, |
---|
238 | char *token, |
---|
239 | int *token_len |
---|
240 | ); |
---|
241 | |
---|
242 | void IMFS_dump( void ); |
---|
243 | |
---|
244 | void IMFS_initialize_jnode( |
---|
245 | IMFS_jnode_t *the_jnode, |
---|
246 | IMFS_jnode_types_t type, |
---|
247 | IMFS_jnode_t *the_parent, |
---|
248 | char *name, |
---|
249 | mode_t mode |
---|
250 | ); |
---|
251 | |
---|
252 | IMFS_jnode_t *IMFS_find_match_in_dir( |
---|
253 | IMFS_jnode_t *directory, /* IN */ |
---|
254 | char *name /* IN */ |
---|
255 | ); |
---|
256 | |
---|
257 | rtems_filesystem_node_types_t IMFS_node_type( |
---|
258 | rtems_filesystem_location_info_t *pathloc /* IN */ |
---|
259 | ); |
---|
260 | |
---|
261 | int IMFS_stat( |
---|
262 | rtems_filesystem_location_info_t *loc, /* IN */ |
---|
263 | struct stat *buf /* OUT */ |
---|
264 | ); |
---|
265 | |
---|
266 | int IMFS_evaluate_link( |
---|
267 | rtems_filesystem_location_info_t *node, /* IN/OUT */ |
---|
268 | int flags /* IN */ |
---|
269 | ); |
---|
270 | |
---|
271 | int IMFS_eval_path( |
---|
272 | const char *pathname, /* IN */ |
---|
273 | int flags, /* IN */ |
---|
274 | rtems_filesystem_location_info_t *pathloc /* IN/OUT */ |
---|
275 | ); |
---|
276 | |
---|
277 | |
---|
278 | int IMFS_link( |
---|
279 | rtems_filesystem_location_info_t *to_loc, /* IN */ |
---|
280 | rtems_filesystem_location_info_t *parent_loc, /* IN */ |
---|
281 | const char *token /* IN */ |
---|
282 | ); |
---|
283 | |
---|
284 | int IMFS_unlink( |
---|
285 | rtems_filesystem_location_info_t *pathloc /* IN */ |
---|
286 | ); |
---|
287 | |
---|
288 | int IMFS_chown( |
---|
289 | rtems_filesystem_location_info_t *pathloc, /* IN */ |
---|
290 | uid_t owner, /* IN */ |
---|
291 | gid_t group /* IN */ |
---|
292 | ); |
---|
293 | |
---|
294 | int IMFS_freenodinfo( |
---|
295 | rtems_filesystem_location_info_t *pathloc /* IN */ |
---|
296 | ); |
---|
297 | |
---|
298 | int IMFS_rmnod( |
---|
299 | rtems_filesystem_location_info_t *pathloc /* IN */ |
---|
300 | ); |
---|
301 | |
---|
302 | int IMFS_mknod( |
---|
303 | const char *path, /* IN */ |
---|
304 | mode_t mode, /* IN */ |
---|
305 | dev_t dev, /* IN */ |
---|
306 | rtems_filesystem_location_info_t *pathloc /* IN/OUT */ |
---|
307 | ); |
---|
308 | |
---|
309 | IMFS_jnode_t *IMFS_create_node( |
---|
310 | rtems_filesystem_location_info_t *parent_loc, /* IN */ |
---|
311 | IMFS_jnode_types_t type, /* IN */ |
---|
312 | char *name, /* IN */ |
---|
313 | mode_t mode, /* IN */ |
---|
314 | IMFS_types_union *info /* IN */ |
---|
315 | ); |
---|
316 | |
---|
317 | int IMFS_evaluate_for_make( |
---|
318 | const char *path, /* IN */ |
---|
319 | rtems_filesystem_location_info_t *pathloc, /* IN/OUT */ |
---|
320 | const char **name /* OUT */ |
---|
321 | ); |
---|
322 | |
---|
323 | int IMFS_mount( |
---|
324 | rtems_filesystem_mount_table_entry_t *mt_entry /* IN */ |
---|
325 | ); |
---|
326 | |
---|
327 | int IMFS_unmount( |
---|
328 | rtems_filesystem_mount_table_entry_t *mt_entry /* IN */ |
---|
329 | ); |
---|
330 | |
---|
331 | int IMFS_freenod( |
---|
332 | rtems_filesystem_location_info_t *node /* IN/OUT */ |
---|
333 | ); |
---|
334 | |
---|
335 | int IMFS_memfile_remove( |
---|
336 | IMFS_jnode_t *the_jnode /* IN/OUT */ |
---|
337 | ); |
---|
338 | |
---|
339 | int memfile_ftruncate( |
---|
340 | rtems_libio_t *iop, /* IN */ |
---|
341 | off_t length /* IN */ |
---|
342 | ); |
---|
343 | int imfs_dir_open( |
---|
344 | rtems_libio_t *iop, /* IN */ |
---|
345 | const char *pathname, /* IN */ |
---|
346 | unsigned32 flag, /* IN */ |
---|
347 | unsigned32 mode /* IN */ |
---|
348 | ); |
---|
349 | int imfs_dir_close( |
---|
350 | rtems_libio_t *iop /* IN */ |
---|
351 | ); |
---|
352 | int imfs_dir_read( |
---|
353 | rtems_libio_t *iop, /* IN */ |
---|
354 | void *buffer, /* IN */ |
---|
355 | unsigned32 count /* IN */ |
---|
356 | ); |
---|
357 | int imfs_dir_lseek( |
---|
358 | rtems_libio_t *iop, /* IN */ |
---|
359 | off_t offset, /* IN */ |
---|
360 | int whence /* IN */ |
---|
361 | ); |
---|
362 | int imfs_dir_fstat( |
---|
363 | rtems_filesystem_location_info_t *loc, /* IN */ |
---|
364 | struct stat *buf /* OUT */ |
---|
365 | ); |
---|
366 | int memfile_open( |
---|
367 | rtems_libio_t *iop, /* IN */ |
---|
368 | const char *pathname, /* IN */ |
---|
369 | unsigned32 flag, /* IN */ |
---|
370 | unsigned32 mode /* IN */ |
---|
371 | ); |
---|
372 | int memfile_close( |
---|
373 | rtems_libio_t *iop /* IN */ |
---|
374 | ); |
---|
375 | int memfile_read( |
---|
376 | rtems_libio_t *iop, /* IN */ |
---|
377 | void *buffer, /* IN */ |
---|
378 | unsigned32 count /* IN */ |
---|
379 | ); |
---|
380 | int memfile_write( |
---|
381 | rtems_libio_t *iop, /* IN */ |
---|
382 | const void *buffer, /* IN */ |
---|
383 | unsigned32 count /* IN */ |
---|
384 | ); |
---|
385 | int memfile_ioctl( |
---|
386 | rtems_libio_t *iop, /* IN */ |
---|
387 | unsigned32 command, /* IN */ |
---|
388 | void *buffer /* IN */ |
---|
389 | ); |
---|
390 | int memfile_lseek( |
---|
391 | rtems_libio_t *iop, /* IN */ |
---|
392 | off_t offset, /* IN */ |
---|
393 | int whence /* IN */ |
---|
394 | ); |
---|
395 | int device_open( |
---|
396 | rtems_libio_t *iop, /* IN */ |
---|
397 | const char *pathname, /* IN */ |
---|
398 | unsigned32 flag, /* IN */ |
---|
399 | unsigned32 mode /* IN */ |
---|
400 | ); |
---|
401 | int device_close( |
---|
402 | rtems_libio_t *iop /* IN */ |
---|
403 | ); |
---|
404 | int device_read( |
---|
405 | rtems_libio_t *iop, /* IN */ |
---|
406 | void *buffer, /* IN */ |
---|
407 | unsigned32 count /* IN */ |
---|
408 | ); |
---|
409 | int device_write( |
---|
410 | rtems_libio_t *iop, /* IN */ |
---|
411 | const void *buffer, /* IN */ |
---|
412 | unsigned32 count /* IN */ |
---|
413 | ); |
---|
414 | int device_ioctl( |
---|
415 | rtems_libio_t *iop, /* IN */ |
---|
416 | unsigned32 command, /* IN */ |
---|
417 | void *buffer /* IN */ |
---|
418 | ); |
---|
419 | int device_lseek( |
---|
420 | rtems_libio_t *iop, /* IN */ |
---|
421 | off_t offset, /* IN */ |
---|
422 | int whence /* IN */ |
---|
423 | ); |
---|
424 | int IMFS_utime( |
---|
425 | rtems_filesystem_location_info_t *pathloc, /* IN */ |
---|
426 | time_t actime, /* IN */ |
---|
427 | time_t modtime /* IN */ |
---|
428 | ); |
---|
429 | int IMFS_fchmod( |
---|
430 | rtems_filesystem_location_info_t *loc, |
---|
431 | mode_t mode |
---|
432 | ); |
---|
433 | |
---|
434 | int IMFS_symlink( |
---|
435 | rtems_filesystem_location_info_t *parent_loc, /* IN */ |
---|
436 | const char *link_name, |
---|
437 | const char *node_name |
---|
438 | ); |
---|
439 | |
---|
440 | int IMFS_readlink( |
---|
441 | rtems_filesystem_location_info_t *loc, /* IN */ |
---|
442 | char *buf, /* OUT */ |
---|
443 | size_t bufsize |
---|
444 | ); |
---|
445 | |
---|
446 | int IMFS_fdatasync( |
---|
447 | rtems_libio_t *iop |
---|
448 | ); |
---|
449 | |
---|
450 | int IMFS_fcntl( |
---|
451 | int cmd, |
---|
452 | rtems_libio_t *iop |
---|
453 | ); |
---|
454 | |
---|
455 | #ifdef __cplusplus |
---|
456 | } |
---|
457 | #endif |
---|
458 | |
---|
459 | #endif |
---|
460 | /* end of include file */ |
---|