Whamcloud - gitweb
Landing b_hd_newconfig on HEAD
[fs/lustre-release.git] / lnet / include / libcfs / winnt / winnt-fs.h
1 /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=4:tabstop=4:
3  *
4  *  Copyright (C) 2001 Cluster File Systems, Inc. <braam@clusterfs.com>
5  *
6  *   This file is part of Lustre, http://www.lustre.org.
7  *
8  *   Lustre is free software; you can redistribute it and/or
9  *   modify it under the terms of version 2 of the GNU General Public
10  *   License as published by the Free Software Foundation.
11  *
12  *   Lustre is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *
17  *   You should have received a copy of the GNU General Public License
18  *   along with Lustre; if not, write to the Free Software
19  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  *
21  * File operations & routines.
22  *
23  */
24
25 #ifndef __LIBCFS_WINNT_CFS_FS_H__
26 #define __LIBCFS_WINNT_CFS_FS_H__
27
28 #ifndef __LIBCFS_LIBCFS_H__
29 #error Do not #include this file directly. #include <libcfs/libcfs.h> instead
30 #endif
31
32
33 /*
34  * Platform defines
35  *
36  * cfs_rdev_t
37  */
38
39 typedef unsigned short cfs_rdev_t;
40
41 typedef unsigned int cfs_major_nr_t;
42 typedef unsigned int cfs_minor_nr_t;
43
44
45 #define MINORBITS       8
46 #define MINORMASK       ((1U << MINORBITS) - 1)
47
48 #define MAJOR(dev)      ((unsigned int) ((dev) >> MINORBITS))
49 #define MINOR(dev)      ((unsigned int) ((dev) & MINORMASK))
50 #define NODEV           0
51 #define MKDEV(ma,mi)    (((ma) << MINORBITS) | (mi))
52
53
54 static inline cfs_rdev_t cfs_rdev_build(cfs_major_nr_t major, cfs_minor_nr_t minor)
55 {
56     return MKDEV(major, minor);
57 }
58
59 static inline cfs_major_nr_t cfs_rdev_major(cfs_rdev_t rdev)
60 {
61     return MAJOR(rdev);
62 }
63
64 static inline cfs_minor_nr_t cfs_rdev_minor(cfs_rdev_t rdev)
65 {
66     return MINOR(rdev);
67 }
68
69
70 #ifdef __KERNEL__
71
72 struct file_operations
73 {
74     loff_t (*lseek)(struct file * file, loff_t offset, int origin);
75     ssize_t (*read) (struct file * file, char * buf, size_t nbytes, loff_t *ppos);
76     ssize_t (*write)(struct file * file, const char * buffer,
77         size_t count, loff_t *ppos);
78     int (*ioctl) (struct file *, unsigned int, ulong_ptr);
79     int (*open) (struct file *);
80     int (*release) (struct file *);
81 };
82
83 struct file {
84
85     cfs_handle_t            f_handle;
86     unsigned int            f_flags;
87     mode_t                  f_mode;
88     ulong_ptr           f_count;
89
90     //struct list_head      f_list;
91     //struct dentry *       f_dentry;
92
93     cfs_proc_entry_t *      proc_dentry;
94     cfs_file_operations_t * f_op;
95
96     size_t                  f_size;
97     loff_t                  f_pos;
98     unsigned int            f_uid, f_gid;
99     int                     f_error;
100
101     ulong_ptr           f_version;
102
103     void *                  private_data;
104
105     char                    f_name[1];
106
107 };
108
109 #define cfs_filp_size(f)               ((f)->f_size)
110 #define cfs_filp_poff(f)                (&(f)->f_pos)
111
112 cfs_file_t *cfs_filp_open(const char *name, int flags, int mode, int *err);
113 int cfs_filp_close(cfs_file_t *fp);
114 int cfs_filp_read(cfs_file_t *fp, void *buf, size_t nbytes, loff_t *pos);
115 int cfs_filp_write(cfs_file_t *fp, void *buf, size_t nbytes, loff_t *pos);
116 int cfs_filp_fsync(cfs_file_t *fp);
117 int cfs_get_file(cfs_file_t *fp);
118 int cfs_put_file(cfs_file_t *fp);
119 int cfs_file_count(cfs_file_t *fp);
120
121
122
123 /*
124  * CFS_FLOCK routines
125  */
126
127 typedef struct file_lock{
128     int         fl_type;
129     pid_t       fl_pid;
130     size_t      fl_len;
131     off_t       fl_start;
132     off_t       fl_end;
133 } cfs_flock_t; 
134
135 #define CFS_INT_LIMIT(x)                (~((x)1 << (sizeof(x)*8 - 1)))
136 #define CFS_OFFSET_MAX                  CFS_INT_LIMIT(loff_t)
137
138 #define cfs_flock_type(fl)                  ((fl)->fl_type)
139 #define cfs_flock_set_type(fl, type)        do { (fl)->fl_type = (type); } while(0)
140 #define cfs_flock_pid(fl)                   ((fl)->fl_pid)
141 #define cfs_flock_set_pid(fl, pid)          do { (fl)->fl_pid = (pid); } while(0)
142 #define cfs_flock_start(fl)                 ((fl)->fl_start)
143 #define cfs_flock_set_start(fl, start)      do { (fl)->fl_start = (start); } while(0)
144 #define cfs_flock_end(fl)                   ((fl)->fl_end)
145 #define cfs_flock_set_end(fl, end)          do { (fl)->fl_end = (end); } while(0)
146
147 #define ATTR_MODE       0x0001
148 #define ATTR_UID        0x0002
149 #define ATTR_GID        0x0004
150 #define ATTR_SIZE       0x0008
151 #define ATTR_ATIME      0x0010
152 #define ATTR_MTIME      0x0020
153 #define ATTR_CTIME      0x0040
154 #define ATTR_ATIME_SET  0x0080
155 #define ATTR_MTIME_SET  0x0100
156 #define ATTR_FORCE      0x0200  /* Not a change, but a change it */
157 #define ATTR_ATTR_FLAG  0x0400
158 #define ATTR_RAW        0x0800  /* file system, not vfs will massage attrs */
159 #define ATTR_FROM_OPEN  0x1000  /* called from open path, ie O_TRUNC */
160 //#define ATTR_CTIME_SET  0x2000
161 #define ATTR_BLOCKS     0x4000
162
163 #define in_group_p(x)   (0)
164
165 /*
166  * proc fs routines
167  */
168
169 int proc_init_fs();
170 void proc_destroy_fs();
171
172
173 /*
174  *  misc
175  */
176
177 static inline void *ERR_PTR(long_ptr error)
178 {
179         return (void *) error;
180 }
181
182 static inline long_ptr PTR_ERR(const void *ptr)
183 {
184         return (long_ptr) ptr;
185 }
186
187 static inline long_ptr IS_ERR(const void *ptr)
188 {
189         return (ulong_ptr)ptr > (ulong_ptr)-1000L;
190 }
191
192 #else  /* !__KERNEL__ */
193
194 #define CREATE_NEW          1
195 #define CREATE_ALWAYS       2
196 #define OPEN_EXISTING       3
197 #define OPEN_ALWAYS         4
198 #define TRUNCATE_EXISTING   5
199
200 #define SECTION_QUERY       0x0001
201 #define SECTION_MAP_WRITE   0x0002
202 #define SECTION_MAP_READ    0x0004
203 #define SECTION_MAP_EXECUTE 0x0008
204 #define SECTION_EXTEND_SIZE 0x0010
205
206 #define FILE_MAP_COPY       SECTION_QUERY
207 #define FILE_MAP_WRITE      SECTION_MAP_WRITE
208 #define FILE_MAP_READ       SECTION_MAP_READ
209 #define FILE_MAP_ALL_ACCESS SECTION_ALL_ACCESS
210
211
212 NTSYSAPI
213 HANDLE
214 NTAPI
215 CreateFileA(
216     IN LPCSTR lpFileName,
217     IN DWORD dwDesiredAccess,
218     IN DWORD dwShareMode,
219     IN PVOID lpSecurityAttributes,
220     IN DWORD dwCreationDisposition,
221     IN DWORD dwFlagsAndAttributes,
222     IN HANDLE hTemplateFile
223     );
224
225 #define CreateFile  CreateFileA
226
227 NTSYSAPI
228 BOOL
229 NTAPI
230 CloseHandle(
231     IN OUT HANDLE hObject
232     );
233
234 NTSYSAPI
235 HANDLE
236 NTAPI
237 CreateFileMappingA(
238     IN HANDLE hFile,
239     IN PVOID lpFileMappingAttributes,
240     IN DWORD flProtect,
241     IN DWORD dwMaximumSizeHigh,
242     IN DWORD dwMaximumSizeLow,
243     IN LPCSTR lpName
244     );
245 #define CreateFileMapping  CreateFileMappingA
246
247 NTSYSAPI
248 DWORD
249 NTAPI
250 GetFileSize(
251     IN HANDLE hFile,
252     OUT DWORD * lpFileSizeHigh
253     );
254
255 NTSYSAPI
256 PVOID
257 NTAPI
258 MapViewOfFile(
259     IN HANDLE hFileMappingObject,
260     IN DWORD dwDesiredAccess,
261     IN DWORD dwFileOffsetHigh,
262     IN DWORD dwFileOffsetLow,
263     IN SIZE_T dwNumberOfBytesToMap
264     );
265
266 NTSYSAPI
267 BOOL
268 NTAPI
269 UnmapViewOfFile(
270     IN PVOID lpBaseAddress
271     );
272
273 #endif /* __KERNEL__ */
274
275 typedef struct {
276         void    *d;
277 } cfs_dentry_t;
278
279
280 #endif /* __LIBCFS_WINNT_CFS_FS_H__*/