Whamcloud - gitweb
Branch HEAD
[fs/lustre-release.git] / libcfs / 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 #define MINORBITS       8
34 #define MINORMASK       ((1U << MINORBITS) - 1)
35
36 #define MAJOR(dev)      ((unsigned int) ((dev) >> MINORBITS))
37 #define MINOR(dev)      ((unsigned int) ((dev) & MINORMASK))
38 #define NODEV           0
39 #define MKDEV(ma,mi)    (((ma) << MINORBITS) | (mi))
40
41
42 #ifdef __KERNEL__
43
44 struct file_operations
45 {
46     loff_t (*lseek)(struct file * file, loff_t offset, int origin);
47     ssize_t (*read) (struct file * file, char * buf, size_t nbytes, loff_t *ppos);
48     ssize_t (*write)(struct file * file, const char * buffer,
49         size_t count, loff_t *ppos);
50     int (*ioctl) (struct file *, unsigned int, ulong_ptr);
51     int (*open) (struct file *);
52     int (*release) (struct file *);
53 };
54
55 struct file {
56
57     cfs_handle_t            f_handle;
58     unsigned int            f_flags;
59     mode_t                  f_mode;
60     ulong_ptr           f_count;
61
62     //struct list_head      f_list;
63     //struct dentry *       f_dentry;
64
65     cfs_proc_entry_t *      proc_dentry;
66     cfs_file_operations_t * f_op;
67
68     size_t                  f_size;
69     loff_t                  f_pos;
70     unsigned int            f_uid, f_gid;
71     int                     f_error;
72
73     ulong_ptr           f_version;
74
75     void *                  private_data;
76
77     char                    f_name[1];
78
79 };
80
81 #define cfs_filp_size(f)               ((f)->f_size)
82 #define cfs_filp_poff(f)                (&(f)->f_pos)
83
84 cfs_file_t *cfs_filp_open(const char *name, int flags, int mode, int *err);
85 int cfs_filp_close(cfs_file_t *fp);
86 int cfs_filp_read(cfs_file_t *fp, void *buf, size_t nbytes, loff_t *pos);
87 int cfs_filp_write(cfs_file_t *fp, void *buf, size_t nbytes, loff_t *pos);
88 int cfs_filp_fsync(cfs_file_t *fp);
89 int cfs_get_file(cfs_file_t *fp);
90 int cfs_put_file(cfs_file_t *fp);
91 int cfs_file_count(cfs_file_t *fp);
92
93
94
95 /*
96  * CFS_FLOCK routines
97  */
98
99 typedef struct file_lock{
100     int         fl_type;
101     pid_t       fl_pid;
102     size_t      fl_len;
103     off_t       fl_start;
104     off_t       fl_end;
105 } cfs_flock_t; 
106
107 #define CFS_INT_LIMIT(x)                (~((x)1 << (sizeof(x)*8 - 1)))
108 #define CFS_OFFSET_MAX                  CFS_INT_LIMIT(loff_t)
109
110 #define cfs_flock_type(fl)                  ((fl)->fl_type)
111 #define cfs_flock_set_type(fl, type)        do { (fl)->fl_type = (type); } while(0)
112 #define cfs_flock_pid(fl)                   ((fl)->fl_pid)
113 #define cfs_flock_set_pid(fl, pid)          do { (fl)->fl_pid = (pid); } while(0)
114 #define cfs_flock_start(fl)                 ((fl)->fl_start)
115 #define cfs_flock_set_start(fl, start)      do { (fl)->fl_start = (start); } while(0)
116 #define cfs_flock_end(fl)                   ((fl)->fl_end)
117 #define cfs_flock_set_end(fl, end)          do { (fl)->fl_end = (end); } while(0)
118
119 #define ATTR_MODE       0x0001
120 #define ATTR_UID        0x0002
121 #define ATTR_GID        0x0004
122 #define ATTR_SIZE       0x0008
123 #define ATTR_ATIME      0x0010
124 #define ATTR_MTIME      0x0020
125 #define ATTR_CTIME      0x0040
126 #define ATTR_ATIME_SET  0x0080
127 #define ATTR_MTIME_SET  0x0100
128 #define ATTR_FORCE      0x0200  /* Not a change, but a change it */
129 #define ATTR_ATTR_FLAG  0x0400
130 #define ATTR_RAW        0x0800  /* file system, not vfs will massage attrs */
131 #define ATTR_FROM_OPEN  0x1000  /* called from open path, ie O_TRUNC */
132 //#define ATTR_CTIME_SET  0x2000
133 #define ATTR_BLOCKS     0x4000
134 #define ATTR_KILL_SUID  0
135 #define ATTR_KILL_SGID  0
136
137 #define in_group_p(x)   (0)
138
139 /*
140  * proc fs routines
141  */
142
143 int proc_init_fs();
144 void proc_destroy_fs();
145
146
147 /*
148  *  misc
149  */
150
151 static inline void *ERR_PTR(long_ptr error)
152 {
153         return (void *) error;
154 }
155
156 static inline long_ptr PTR_ERR(const void *ptr)
157 {
158         return (long_ptr) ptr;
159 }
160
161 static inline long_ptr IS_ERR(const void *ptr)
162 {
163         return (ulong_ptr)ptr > (ulong_ptr)-1000L;
164 }
165
166 #else  /* !__KERNEL__ */
167
168 #define CREATE_NEW          1
169 #define CREATE_ALWAYS       2
170 #define OPEN_EXISTING       3
171 #define OPEN_ALWAYS         4
172 #define TRUNCATE_EXISTING   5
173
174 #define SECTION_QUERY       0x0001
175 #define SECTION_MAP_WRITE   0x0002
176 #define SECTION_MAP_READ    0x0004
177 #define SECTION_MAP_EXECUTE 0x0008
178 #define SECTION_EXTEND_SIZE 0x0010
179
180 #define FILE_MAP_COPY       SECTION_QUERY
181 #define FILE_MAP_WRITE      SECTION_MAP_WRITE
182 #define FILE_MAP_READ       SECTION_MAP_READ
183 #define FILE_MAP_ALL_ACCESS SECTION_ALL_ACCESS
184
185
186 NTSYSAPI
187 HANDLE
188 NTAPI
189 CreateFileA(
190     IN LPCSTR lpFileName,
191     IN DWORD dwDesiredAccess,
192     IN DWORD dwShareMode,
193     IN PVOID lpSecurityAttributes,
194     IN DWORD dwCreationDisposition,
195     IN DWORD dwFlagsAndAttributes,
196     IN HANDLE hTemplateFile
197     );
198
199 #define CreateFile  CreateFileA
200
201 NTSYSAPI
202 BOOL
203 NTAPI
204 CloseHandle(
205     IN OUT HANDLE hObject
206     );
207
208 NTSYSAPI
209 HANDLE
210 NTAPI
211 CreateFileMappingA(
212     IN HANDLE hFile,
213     IN PVOID lpFileMappingAttributes,
214     IN DWORD flProtect,
215     IN DWORD dwMaximumSizeHigh,
216     IN DWORD dwMaximumSizeLow,
217     IN LPCSTR lpName
218     );
219 #define CreateFileMapping  CreateFileMappingA
220
221 NTSYSAPI
222 DWORD
223 NTAPI
224 GetFileSize(
225     IN HANDLE hFile,
226     OUT DWORD * lpFileSizeHigh
227     );
228
229 NTSYSAPI
230 PVOID
231 NTAPI
232 MapViewOfFile(
233     IN HANDLE hFileMappingObject,
234     IN DWORD dwDesiredAccess,
235     IN DWORD dwFileOffsetHigh,
236     IN DWORD dwFileOffsetLow,
237     IN SIZE_T dwNumberOfBytesToMap
238     );
239
240 NTSYSAPI
241 BOOL
242 NTAPI
243 UnmapViewOfFile(
244     IN PVOID lpBaseAddress
245     );
246
247 #endif /* __KERNEL__ */
248
249 typedef struct {
250         void    *d;
251 } cfs_dentry_t;
252
253
254 #endif /* __LIBCFS_WINNT_CFS_FS_H__*/