1 |
27 |
unneback |
#ifndef CYGONCE_IO_FILEIO_INODE_H
|
2 |
|
|
#define CYGONCE_IO_FILEIO_INODE_H
|
3 |
|
|
//=============================================================================
|
4 |
|
|
//
|
5 |
|
|
// inode.h
|
6 |
|
|
//
|
7 |
|
|
// Header describing eCos inodes
|
8 |
|
|
//
|
9 |
|
|
//=============================================================================
|
10 |
|
|
//####ECOSGPLCOPYRIGHTBEGIN####
|
11 |
|
|
// -------------------------------------------
|
12 |
|
|
// This file is part of eCos, the Embedded Configurable Operating System.
|
13 |
|
|
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
|
14 |
|
|
//
|
15 |
|
|
// eCos is free software; you can redistribute it and/or modify it under
|
16 |
|
|
// the terms of the GNU General Public License as published by the Free
|
17 |
|
|
// Software Foundation; either version 2 or (at your option) any later version.
|
18 |
|
|
//
|
19 |
|
|
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
|
20 |
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
21 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
22 |
|
|
// for more details.
|
23 |
|
|
//
|
24 |
|
|
// You should have received a copy of the GNU General Public License along
|
25 |
|
|
// with eCos; if not, write to the Free Software Foundation, Inc.,
|
26 |
|
|
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
|
27 |
|
|
//
|
28 |
|
|
// As a special exception, if other files instantiate templates or use macros
|
29 |
|
|
// or inline functions from this file, or you compile this file and link it
|
30 |
|
|
// with other works to produce a work based on this file, this file does not
|
31 |
|
|
// by itself cause the resulting work to be covered by the GNU General Public
|
32 |
|
|
// License. However the source code for this file must still be made available
|
33 |
|
|
// in accordance with section (3) of the GNU General Public License.
|
34 |
|
|
//
|
35 |
|
|
// This exception does not invalidate any other reasons why a work based on
|
36 |
|
|
// this file might be covered by the GNU General Public License.
|
37 |
|
|
//
|
38 |
|
|
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
|
39 |
|
|
// at http://sources.redhat.com/ecos/ecos-license/
|
40 |
|
|
// -------------------------------------------
|
41 |
|
|
//####ECOSGPLCOPYRIGHTEND####
|
42 |
|
|
//=============================================================================
|
43 |
|
|
//#####DESCRIPTIONBEGIN####
|
44 |
|
|
//
|
45 |
|
|
// Author(s): jlarmour
|
46 |
|
|
// Contributors:
|
47 |
|
|
// Date: 2002-01-18
|
48 |
|
|
// Purpose: Describe inodes
|
49 |
|
|
// Description: This header contains the definitions that may be useful to a
|
50 |
|
|
// filesystem implementation with the concept of inodes.
|
51 |
|
|
// There should remain no *requirement* for a FS to use inodes.
|
52 |
|
|
// Instead these are just useful functions and definitions.
|
53 |
|
|
//
|
54 |
|
|
// Usage:
|
55 |
|
|
// #include <cyg/fileio/inode.h>
|
56 |
|
|
// ...
|
57 |
|
|
//
|
58 |
|
|
//
|
59 |
|
|
//####DESCRIPTIONEND####
|
60 |
|
|
//
|
61 |
|
|
//=============================================================================
|
62 |
|
|
|
63 |
|
|
#include <cyg/infra/cyg_type.h>
|
64 |
|
|
#include <sys/types.h>
|
65 |
|
|
#include <time.h> // time_t
|
66 |
|
|
#include <cyg/fileio/fileio.h>
|
67 |
|
|
#include <cyg/io/io.h>
|
68 |
|
|
#include <limits.h>
|
69 |
|
|
|
70 |
|
|
// some members are named for compatibility for Linux inodes
|
71 |
|
|
typedef struct CYG_INODE_TAG {
|
72 |
|
|
cyg_uint32 i_ino; // inode number
|
73 |
|
|
mode_t i_mode; // mode
|
74 |
|
|
nlink_t i_nlink; // number of (hard) links
|
75 |
|
|
uid_t i_uid; // UID
|
76 |
|
|
gid_t i_gid; // GID
|
77 |
|
|
cyg_io_handle_t i_device; // underlying device
|
78 |
|
|
off_t i_size; // file size
|
79 |
|
|
time_t i_atime; // file access time
|
80 |
|
|
time_t i_mtime; // file modification time
|
81 |
|
|
time_t i_ctime; // file metadata change time
|
82 |
|
|
struct CYG_INODE_TAG *i_parent; // parent inode
|
83 |
|
|
|
84 |
|
|
// these duplicate the contents of a cyg_file, but that's okay
|
85 |
|
|
cyg_mtab_entry* i_mte; // mount table entry
|
86 |
|
|
struct CYG_FILEOPS_TAG *i_fop; // file operations
|
87 |
|
|
|
88 |
|
|
// inode cache related members
|
89 |
|
|
cyg_atomic i_count; // number of references to this inode
|
90 |
|
|
struct CYG_INODE_TAG *i_cache_prev; // previous in icache
|
91 |
|
|
struct CYG_INODE_TAG *i_cache_next; // next in icache
|
92 |
|
|
|
93 |
|
|
// This allows us to use a GCC extension to extend the size as appropriate
|
94 |
|
|
// for individual FS's requirements.
|
95 |
|
|
// Obviously anything here cannot be shared between FSs.
|
96 |
|
|
CYG_ADDRWORD i_private[];
|
97 |
|
|
} cyg_inode;
|
98 |
|
|
|
99 |
|
|
// There should be one cyg_inodecache per FS instance (to preserve inode number
|
100 |
|
|
// uniqueness)
|
101 |
|
|
typedef void (*cyg_inodecache_freecallback_t)( cyg_inode *);
|
102 |
|
|
typedef struct {
|
103 |
|
|
cyg_inode *head;
|
104 |
|
|
#if CYGNUM_IO_FILEIO_MAX_INODE_CACHE_DEAD > 0
|
105 |
|
|
cyg_inode *freeable;
|
106 |
|
|
cyg_atomic freeablelistlen;
|
107 |
|
|
#endif
|
108 |
|
|
cyg_inodecache_freecallback_t freecallback;
|
109 |
|
|
size_t privatespace;
|
110 |
|
|
// should be some locking eventually
|
111 |
|
|
} cyg_inodecache;
|
112 |
|
|
|
113 |
|
|
static __inline__ int
|
114 |
|
|
cyg_inodecache_init( cyg_inodecache *ic, size_t extraprivatespace,
|
115 |
|
|
cyg_inodecache_freecallback_t freecb )
|
116 |
|
|
{
|
117 |
|
|
ic->head = NULL;
|
118 |
|
|
#if CYGNUM_IO_FILEIO_MAX_INODE_CACHE_DEAD > 0
|
119 |
|
|
ic->freeable = NULL;
|
120 |
|
|
ic->freeablelistlen = 0;
|
121 |
|
|
#endif
|
122 |
|
|
ic->privatespace = extraprivatespace;
|
123 |
|
|
ic->freecallback = freecb;
|
124 |
|
|
return 0;
|
125 |
|
|
}
|
126 |
|
|
|
127 |
|
|
// Create an inode, with extra private space. Returns NULL on error.
|
128 |
|
|
__externC cyg_inode *
|
129 |
|
|
cyg_inode_create( cyg_inodecache *ic );
|
130 |
|
|
|
131 |
|
|
__externC cyg_inode *
|
132 |
|
|
cyg_inode_get( cyg_inodecache *ic, cyg_uint32 ino );
|
133 |
|
|
|
134 |
|
|
__externC void
|
135 |
|
|
cyg_inode_put( cyg_inodecache *ic, cyg_inode *ino );
|
136 |
|
|
|
137 |
|
|
__externC void
|
138 |
|
|
cyg_inodecache_destroy( cyg_inodecache *ic );
|
139 |
|
|
|
140 |
|
|
#endif // CYGONCE_IO_FILEIO_INODE_H
|
141 |
|
|
|
142 |
|
|
// EOF inode.h
|