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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rtems-20020807/] [cpukit/] [libfs/] [src/] [imfs/] [imfs.h] - Blame information for rev 1026

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

Line No. Rev Author Line
1 1026 ivang
/*
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
 *  imfs.h,v 1.15 2002/01/04 18:30:58 joel 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
typedef struct {
98
  off_t      size;             /* size of file in bytes */
99
  block_p    direct;           /* pointer to file image */
100
} IMFS_linearfile_t;
101
 
102
/*
103
 *  Important block numbers for "memfiles"
104
 */
105
 
106
#define FIRST_INDIRECT           (0)
107
#define LAST_INDIRECT            (IMFS_MEMFILE_BLOCK_SLOTS - 1)
108
 
109
#define FIRST_DOUBLY_INDIRECT    (LAST_INDIRECT + 1)
110
#define LAST_DOUBLY_INDIRECT     \
111
   (LAST_INDIRECT + \
112
     (IMFS_MEMFILE_BLOCK_SLOTS * IMFS_MEMFILE_BLOCK_SLOTS))
113
 
114
#define FIRST_TRIPLY_INDIRECT    (LAST_DOUBLY_INDIRECT + 1)
115
#define LAST_TRIPLY_INDIRECT \
116
   (LAST_DOUBLY_INDIRECT +\
117
     (IMFS_MEMFILE_BLOCK_SLOTS * \
118
        IMFS_MEMFILE_BLOCK_SLOTS * IMFS_MEMFILE_BLOCK_SLOTS))
119
 
120
#define IMFS_MEMFILE_MAXIMUM_SIZE \
121
  (LAST_TRIPLY_INDIRECT * IMFS_MEMFILE_BYTES_PER_BLOCK)
122
 
123
/*
124
 *  What types of IMFS file systems entities there can be.
125
 */
126
 
127
#define IMFS_jnode_types_t rtems_filesystem_node_types_t
128
#define IMFS_DIRECTORY     RTEMS_FILESYSTEM_DIRECTORY
129
#define IMFS_DEVICE        RTEMS_FILESYSTEM_DEVICE
130
#define IMFS_HARD_LINK     RTEMS_FILESYSTEM_HARD_LINK
131
#define IMFS_SYM_LINK      RTEMS_FILESYSTEM_SYM_LINK
132
#define IMFS_MEMORY_FILE   RTEMS_FILESYSTEM_MEMORY_FILE
133
#define IMFS_LINEAR_FILE   (IMFS_MEMORY_FILE + 1)
134
 
135
#define IMFS_NUMBER_OF_TYPES  (IMFS_LINEAR_FILE + 1)
136
 
137
typedef union {
138
  IMFS_directory_t   directory;
139
  IMFS_device_t      device;
140
  IMFS_link_t        hard_link;
141
  IMFS_sym_link_t    sym_link;
142
  IMFS_memfile_t     file;
143
  IMFS_linearfile_t  linearfile;
144
} IMFS_types_union;
145
 
146
/*
147
 *  Maximum length of a "basename" of an IMFS file/node.
148
 */
149
 
150
#define IMFS_NAME_MAX  32
151
 
152
/*
153
 *  The control structure for an IMFS jnode.
154
 */
155
 
156
struct IMFS_jnode_tt {
157
  Chain_Node          Node;                  /* for chaining them together */
158
  IMFS_jnode_t       *Parent;                /* Parent node */
159
  char                name[IMFS_NAME_MAX+1]; /* "basename" */
160
  mode_t              st_mode;               /* File mode */
161
  nlink_t             st_nlink;              /* Link count */
162
  ino_t               st_ino;                /* inode */
163
 
164
  uid_t               st_uid;                /* User ID of owner */
165
  gid_t               st_gid;                /* Group ID of owner */
166
 
167
  time_t              stat_atime;            /* Time of last access */
168
  time_t              stat_mtime;            /* Time of last modification */
169
  time_t              stat_ctime;            /* Time of last status change */
170
  IMFS_jnode_types_t  type;                  /* Type of this entry */
171
  IMFS_types_union    info;
172
};
173
 
174
#define IMFS_update_atime( _jnode )         \
175
  do {                                      \
176
    struct timeval tv;                      \
177
    gettimeofday( &tv, 0 );                 \
178
    _jnode->stat_atime  = (time_t) tv.tv_sec; \
179
  } while (0)
180
 
181
#define IMFS_update_mtime( _jnode )         \
182
  do {                                      \
183
    struct timeval tv;                      \
184
    gettimeofday( &tv, 0 );                 \
185
    _jnode->stat_mtime  = (time_t) tv.tv_sec; \
186
  } while (0)
187
 
188
#define IMFS_update_ctime( _jnode )         \
189
  do {                                      \
190
    struct timeval tv;                      \
191
    gettimeofday( &tv, 0 );                 \
192
    _jnode->stat_ctime  = (time_t) tv.tv_sec; \
193
  } while (0)
194
 
195
#define IMFS_atime_mtime_update( _jnode )   \
196
  do {                                      \
197
    struct timeval tv;                      \
198
    gettimeofday( &tv, 0 );                 \
199
    _jnode->stat_mtime  = (time_t) tv.tv_sec; \
200
    _jnode->stat_atime  = (time_t) tv.tv_sec; \
201
  } while (0)
202
 
203
typedef struct {
204
  ino_t                             ino_count;
205
  rtems_filesystem_file_handlers_r *linearfile_handlers;
206
  rtems_filesystem_file_handlers_r *memfile_handlers;
207
  rtems_filesystem_file_handlers_r *directory_handlers;
208
} IMFS_fs_info_t;
209
 
210
#if UNUSED
211
/* FIXME: Unused, we might want to remove it */
212
#define increment_and_check_linkcounts( _fs_info )                  \
213
  ((IMFS_fs_info_t * )_fs_info)->link_counts++;                     \
214
  if ( ((IMFS_fs_info_t * )_fs_info)->link_counts  > MAXSYMLINKS )  \
215
    rtems_set_errno_and_return_minus_one( ELOOP )
216
#endif
217
 
218
#define decrement_linkcounts(  _fs_info )             \
219
  ((IMFS_fs_info_t * )_fs_info)->link_counts--;
220
 
221
/*
222
 *  Type defination for tokens returned from IMFS_get_token
223
 */
224
 
225
typedef enum {
226
  IMFS_NO_MORE_PATH,
227
  IMFS_CURRENT_DIR,
228
  IMFS_UP_DIR,
229
  IMFS_NAME,
230
  IMFS_INVALID_TOKEN
231
} IMFS_token_types;
232
 
233
/*
234
 *  Shared Data
235
 */
236
 
237
extern rtems_filesystem_file_handlers_r       IMFS_directory_handlers;
238
extern rtems_filesystem_file_handlers_r       IMFS_device_handlers;
239
extern rtems_filesystem_file_handlers_r       IMFS_link_handlers;
240
extern rtems_filesystem_file_handlers_r       IMFS_linearfile_handlers;
241
extern rtems_filesystem_file_handlers_r       IMFS_memfile_handlers;
242
extern rtems_filesystem_operations_table      IMFS_ops;
243
extern rtems_filesystem_operations_table      miniIMFS_ops;
244
extern rtems_filesystem_limits_and_options_t  IMFS_LIMITS_AND_OPTIONS;
245
 
246
/*
247
 *  Routines
248
 */
249
 
250
int IMFS_initialize(
251
   rtems_filesystem_mount_table_entry_t *mt_entry
252
);
253
 
254
int miniIMFS_initialize(
255
   rtems_filesystem_mount_table_entry_t *mt_entry
256
);
257
 
258
int IMFS_initialize_support(
259
   rtems_filesystem_mount_table_entry_t *mt_entry,
260
   rtems_filesystem_operations_table    *op_table,
261
   rtems_filesystem_file_handlers_r     *linearfile_handlers,
262
   rtems_filesystem_file_handlers_r     *memfile_handlers,
263
   rtems_filesystem_file_handlers_r     *directory_handlers
264
);
265
 
266
int IMFS_fsunmount(
267
   rtems_filesystem_mount_table_entry_t *mt_entry
268
);
269
 
270
int rtems_tarfs_load(
271
   char          *mountpoint,
272
   unsigned char *addr,
273
   unsigned long length
274
);
275
 
276
/*
277
 * Returns the number of characters copied from path to token.
278
 */
279
IMFS_token_types IMFS_get_token(
280
  const char       *path,
281
  char             *token,
282
  int              *token_len
283
);
284
 
285
void IMFS_dump( void );
286
 
287
void IMFS_initialize_jnode(
288
  IMFS_jnode_t        *the_jnode,
289
  IMFS_jnode_types_t   type,
290
  IMFS_jnode_t        *the_parent,
291
  char                *name,
292
  mode_t               mode
293
);
294
 
295
IMFS_jnode_t *IMFS_find_match_in_dir(
296
  IMFS_jnode_t *directory,                         /* IN */
297
  char         *name                               /* IN */
298
);
299
 
300
rtems_filesystem_node_types_t IMFS_node_type(
301
  rtems_filesystem_location_info_t    *pathloc     /* IN */
302
);
303
 
304
int IMFS_stat(
305
  rtems_filesystem_location_info_t *loc,           /* IN  */
306
  struct stat                      *buf            /* OUT */
307
);
308
 
309
int IMFS_Set_handlers(
310
  rtems_filesystem_location_info_t   *loc
311
);
312
 
313
int IMFS_evaluate_link(
314
  rtems_filesystem_location_info_t *node,        /* IN/OUT */
315
  int                               flags        /* IN     */
316
);
317
 
318
int IMFS_eval_path(
319
  const char                        *pathname,     /* IN     */
320
  int                               flags,         /* IN     */
321
  rtems_filesystem_location_info_t  *pathloc       /* IN/OUT */
322
);
323
 
324
 
325
int IMFS_link(
326
  rtems_filesystem_location_info_t  *to_loc,      /* IN */
327
  rtems_filesystem_location_info_t  *parent_loc,  /* IN */
328
  const char                        *token        /* IN */
329
);
330
 
331
int IMFS_unlink(
332
  rtems_filesystem_location_info_t  *pathloc       /* IN */
333
);
334
 
335
int IMFS_chown(
336
  rtems_filesystem_location_info_t  *pathloc,      /* IN */
337
  uid_t                              owner,        /* IN */
338
  gid_t                              group         /* IN */
339
);
340
 
341
int IMFS_freenodinfo(
342
  rtems_filesystem_location_info_t  *pathloc       /* IN */
343
);
344
 
345
int IMFS_mknod(
346
  const char                        *path,         /* IN */
347
  mode_t                             mode,         /* IN */
348
  dev_t                              dev,          /* IN */
349
  rtems_filesystem_location_info_t  *pathloc       /* IN/OUT */
350
);
351
 
352
IMFS_jnode_t *IMFS_create_node(
353
  rtems_filesystem_location_info_t  *parent_loc,   /* IN  */
354
  IMFS_jnode_types_t                 type,         /* IN  */
355
  char                              *name,         /* IN  */
356
  mode_t                             mode,         /* IN  */
357
  IMFS_types_union                  *info          /* IN  */
358
);
359
 
360
int IMFS_evaluate_for_make(
361
  const char                         *path,        /* IN     */
362
  rtems_filesystem_location_info_t   *pathloc,     /* IN/OUT */
363
  const char                        **name         /* OUT    */
364
);
365
 
366
int IMFS_mount(
367
  rtems_filesystem_mount_table_entry_t *mt_entry  /* IN */
368
);
369
 
370
int IMFS_unmount(
371
  rtems_filesystem_mount_table_entry_t *mt_entry  /* IN */
372
);
373
 
374
int IMFS_freenod(
375
  rtems_filesystem_location_info_t  *node         /* IN/OUT */
376
);
377
 
378
int IMFS_memfile_remove(
379
 IMFS_jnode_t  *the_jnode         /* IN/OUT */
380
);
381
 
382
int memfile_ftruncate(
383
  rtems_libio_t *iop,               /* IN  */
384
  off_t          length             /* IN  */
385
);
386
 
387
int imfs_dir_open(
388
  rtems_libio_t *iop,             /* IN  */
389
  const char    *pathname,        /* IN  */
390
  unsigned32     flag,            /* IN  */
391
  unsigned32     mode             /* IN  */
392
);
393
 
394
int imfs_dir_close(
395
  rtems_libio_t *iop             /* IN  */
396
);
397
 
398
int imfs_dir_read(
399
  rtems_libio_t *iop,              /* IN  */
400
  void          *buffer,           /* IN  */
401
  unsigned32     count             /* IN  */
402
);
403
 
404
int imfs_dir_lseek(
405
  rtems_libio_t        *iop,              /* IN  */
406
  off_t                 offset,           /* IN  */
407
  int                   whence            /* IN  */
408
);
409
 
410
int imfs_dir_fstat(
411
  rtems_filesystem_location_info_t *loc,         /* IN  */
412
  struct stat                      *buf          /* OUT */
413
);
414
 
415
int imfs_dir_rmnod(
416
  rtems_filesystem_location_info_t      *pathloc       /* IN */
417
);
418
 
419
int linearfile_read(
420
  rtems_libio_t *iop,             /* IN  */
421
  void          *buffer,          /* IN  */
422
  unsigned32     count            /* IN  */
423
);
424
 
425
int linearfile_lseek(
426
  rtems_libio_t        *iop,        /* IN  */
427
  off_t                 offset,     /* IN  */
428
  int                   whence      /* IN  */
429
);
430
 
431
int memfile_open(
432
  rtems_libio_t *iop,             /* IN  */
433
  const char    *pathname,        /* IN  */
434
  unsigned32     flag,            /* IN  */
435
  unsigned32     mode             /* IN  */
436
);
437
 
438
int memfile_close(
439
  rtems_libio_t *iop             /* IN  */
440
);
441
 
442
int memfile_read(
443
  rtems_libio_t *iop,             /* IN  */
444
  void          *buffer,          /* IN  */
445
  unsigned32     count            /* IN  */
446
);
447
 
448
int memfile_write(
449
  rtems_libio_t *iop,             /* IN  */
450
  const void    *buffer,          /* IN  */
451
  unsigned32     count            /* IN  */
452
);
453
 
454
int memfile_ioctl(
455
  rtems_libio_t *iop,             /* IN  */
456
  unsigned32     command,         /* IN  */
457
  void          *buffer           /* IN  */
458
);
459
 
460
int memfile_lseek(
461
  rtems_libio_t        *iop,        /* IN  */
462
  off_t                 offset,     /* IN  */
463
  int                   whence      /* IN  */
464
);
465
 
466
int memfile_rmnod(
467
  rtems_filesystem_location_info_t      *pathloc       /* IN */
468
);
469
 
470
int device_open(
471
  rtems_libio_t *iop,            /* IN  */
472
  const char    *pathname,       /* IN  */
473
  unsigned32     flag,           /* IN  */
474
  unsigned32     mode            /* IN  */
475
);
476
 
477
int device_close(
478
  rtems_libio_t *iop             /* IN  */
479
);
480
 
481
int device_read(
482
  rtems_libio_t *iop,            /* IN  */
483
  void          *buffer,         /* IN  */
484
  unsigned32     count           /* IN  */
485
);
486
 
487
int device_write(
488
  rtems_libio_t *iop,               /* IN  */
489
  const void    *buffer,            /* IN  */
490
  unsigned32     count              /* IN  */
491
);
492
 
493
int device_ioctl(
494
  rtems_libio_t *iop,               /* IN  */
495
  unsigned32     command,           /* IN  */
496
  void          *buffer             /* IN  */
497
);
498
 
499
int device_lseek(
500
  rtems_libio_t *iop,               /* IN  */
501
  off_t          offset,            /* IN  */
502
  int            whence             /* IN  */
503
);
504
 
505
int IMFS_utime(
506
  rtems_filesystem_location_info_t  *pathloc,       /* IN */
507
  time_t                             actime,        /* IN */
508
  time_t                             modtime        /* IN */
509
);
510
 
511
int IMFS_fchmod(
512
  rtems_filesystem_location_info_t *loc,
513
  mode_t                            mode
514
);
515
 
516
int IMFS_symlink(
517
  rtems_filesystem_location_info_t  *parent_loc,  /* IN */
518
  const char                        *link_name,
519
  const char                        *node_name
520
);
521
 
522
int IMFS_readlink(
523
 rtems_filesystem_location_info_t   *loc,         /* IN */
524
 char                               *buf,         /* OUT */
525
 size_t                             bufsize
526
);
527
 
528
int IMFS_fdatasync(
529
  rtems_libio_t *iop
530
);
531
 
532
int IMFS_fcntl(
533
  int            cmd,
534
  rtems_libio_t *iop
535
);
536
 
537
int IMFS_rmnod(
538
  rtems_filesystem_location_info_t      *pathloc       /* IN */
539
);
540
 
541
#ifdef __cplusplus
542
}
543
#endif
544
 
545
#endif
546
/* end of include file */

powered by: WebSVN 2.1.0

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