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