Whamcloud - gitweb
Merge b1_5 from b1_4 (20061213_1244)
[fs/lustre-release.git] / libsysio / include / fs.h
1 /*
2  *    This Cplant(TM) source code is the property of Sandia National
3  *    Laboratories.
4  *
5  *    This Cplant(TM) source code is copyrighted by Sandia National
6  *    Laboratories.
7  *
8  *    The redistribution of this Cplant(TM) source code is subject to the
9  *    terms of the GNU Lesser General Public License
10  *    (see cit/LGPL or http://www.gnu.org/licenses/lgpl.html)
11  *
12  *    Cplant(TM) Copyright 1998-2003 Sandia Corporation. 
13  *    Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive
14  *    license for use of this work by or on behalf of the US Government.
15  *    Export of this program may require a license from the United States
16  *    Government.
17  */
18
19 /*
20  * This library is free software; you can redistribute it and/or
21  * modify it under the terms of the GNU Lesser General Public
22  * License as published by the Free Software Foundation; either
23  * version 2.1 of the License, or (at your option) any later version.
24  * 
25  * This library is distributed in the hope that it will be useful,
26  * but WITHOUT ANY WARRANTY; without even the implied warranty of
27  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28  * Lesser General Public License for more details.
29  * 
30  * You should have received a copy of the GNU Lesser General Public
31  * License along with this library; if not, write to the Free Software
32  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
33  *
34  * Questions or comments about this library should be sent to:
35  *
36  * Lee Ward
37  * Sandia National Laboratories, New Mexico
38  * P.O. Box 5800
39  * Albuquerque, NM 87185-1110
40  *
41  * lee@sandia.gov
42  */
43
44 /*
45  * File system or volume support.
46  */
47
48 struct filesys;
49
50 struct pnode;
51 struct mount;
52
53 /*
54  * File system switch operations.
55  */
56 struct fssw_ops {
57         int     (*fsswop_mount)(const char *source,
58                                 unsigned flags,
59                                 const void *data,
60                                 struct pnode *tocover,
61                                 struct mount **mntp);
62 };
63
64 /*
65  * File system switch entry record.
66  *
67  * Each available file system or volume access driver is represented by
68  * one of these switch entries in the switch.
69  */
70 struct fsswent {
71         const char *fssw_name;                          /* entry name */
72         LIST_ENTRY(fsswent) fssw_link;                  /* link to next */
73         struct fssw_ops fssw_ops;                       /* operations */
74 };
75
76 /*
77  * Init file system switch entry record.
78  */
79 #define FSSWENT_INIT(fsswent, name, ops) \
80         do { \
81                 (fsswent)->fssw_name = (name); \
82                 (fsswent)->fssw_ops = (ops); \
83         } while (0)
84
85 struct inode;
86
87 /*
88  * File system operations.
89  */
90 struct filesys_ops {
91         void    (*fsop_gone)(struct filesys *);
92 };
93
94 /*
95  * Define the desired size of the file system record's inode table. This should
96  * probably be something fancy that tries to use up a system page, or the
97  * like. I'm not feeling adventurous right now though. It is prime though.
98  * That should help out the hash.
99  */
100 #ifndef FS_ITBLSIZ
101 #define FS_ITBLSIZ      503
102 #endif
103
104 /*
105  * Inode list head record.
106  */
107 LIST_HEAD(itable_entry, inode);
108
109 /*
110  * A filesys record is maintained for each active file system or volume.
111  */
112 struct filesys {
113         dev_t   fs_dev;                                 /* device ID */
114         unsigned fs_ref;                                /* soft ref count */
115         unsigned fs_flags;                              /* flags (see below) */
116         struct filesys_ops fs_ops;                      /* operations */
117         void    *fs_private;                            /* driver data */
118         struct itable_entry fs_itbl[FS_ITBLSIZ];        /* inodes hash */
119         unsigned long fs_id;                            /* ID */
120         size_t  fs_bsize;                               /* block size */
121 };
122
123 #define FS_F_RO                 0x01                    /* read-only */
124
125 /*
126  * Init file system record.
127  */
128 #define FS_INIT(fs, flags, ops, private) \
129         do { \
130                 size_t  __i; \
131                 struct itable_entry *__head; \
132  \
133                 (fs)->fs_ref = 1; \
134                 (fs)->fs_flags = (flags); \
135                 (fs)->fs_ops = *(ops); \
136                 (fs)->fs_private = (private); \
137                 __i = FS_ITBLSIZ; \
138                 __head = (fs)->fs_itbl; \
139                 do { \
140                         LIST_INIT(__head); \
141                         __head++; \
142                 } while (--__i); \
143         } while (0)
144
145 /*
146  * Reference file system record.
147  */
148 #define FS_REF(fs) \
149         do { \
150                 ++(fs)->fs_ref; \
151                 assert((fs)->fs_ref); \
152         } while (0)
153
154 /*
155  * Release reference to file system record.
156  */
157 #define FS_RELE(fs) \
158         do { \
159                 assert((fs)->fs_ref); \
160                 if (!--(fs)->fs_ref) \
161                         _sysio_fs_gone(fs); \
162         } while (0)
163
164 extern struct fsswent *_sysio_fssw_lookup(const char *name);
165 extern int _sysio_fssw_register(const char *name, struct fssw_ops *ops);
166 extern struct filesys * _sysio_fs_new(struct filesys_ops *ops,
167                                       unsigned mask,
168                                       void *private);
169 extern void _sysio_fs_gone(struct filesys *fs);
170 #ifdef ZERO_SUM_MEMORY
171 extern void _sysio_fssw_shutdown(void);
172 #endif