OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [lib/] [libc/] [imfs.h] - Blame information for rev 623

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.