4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2012, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * libcfs/include/libcfs/winnt/winnt-fs.h
38 * File operations & routines.
41 #ifndef __LIBCFS_WINNT_CFS_FS_H__
42 #define __LIBCFS_WINNT_CFS_FS_H__
44 #ifndef __LIBCFS_LIBCFS_H__
45 #error Do not #include this file directly. #include <libcfs/libcfs.h> instead
50 #define MINORMASK ((1U << MINORBITS) - 1)
52 #define MAJOR(dev) ((unsigned int) ((dev) >> MINORBITS))
53 #define MINOR(dev) ((unsigned int) ((dev) & MINORMASK))
55 #define MKDEV(ma,mi) (((ma) << MINORBITS) | (mi))
57 #define PATH_MAX (260)
71 /* Internal kernel extensions */
74 #define FMODE_PWRITE FMODE_PREAD /* These go hand in hand */
76 /* File is being opened for execution. Primary users of this flag are
77 distributed filesystems that can use it to achieve correct ETXTBUSY
78 behavior for cross-node execution/opening_for_writing of files */
85 #define READA 2 /* read-ahead - don't block if no resources */
86 #define SWRITE 3 /* for ll_rw_block() - wait for buffer lock */
87 #define SPECIAL 4 /* For non-blockdevice requests in request queue */
88 #define READ_SYNC (READ | (1 << BIO_RW_SYNC))
89 #define WRITE_SYNC (WRITE | (1 << BIO_RW_SYNC))
90 #define WRITE_BARRIER ((1 << BIO_RW) | (1 << BIO_RW_BARRIER))
92 struct file_operations
95 loff_t (*llseek)(struct file * file, loff_t offset, int origin);
96 ssize_t (*read) (struct file * file, char * buf, size_t nbytes, loff_t *ppos);
97 ssize_t (*write)(struct file * file, const char * buffer,
98 size_t count, loff_t *ppos);
99 int (*ioctl) (struct file *, unsigned int, ulong_ptr_t);
100 int (*open) (struct inode*, struct file *);
101 int (*release) (struct inode*, struct file *);
106 cfs_handle_t f_handle;
107 unsigned int f_flags;
113 unsigned int f_uid, f_gid;
118 //struct list_head f_list;
119 struct dentry * f_dentry;
121 cfs_proc_entry_t * proc_dentry;
122 cfs_file_operations_t * f_op;
125 struct inode * f_inode;
130 #define filp_size(f) ((f)->f_size)
131 #define filp_poff(f) (&(f)->f_pos)
133 struct file *filp_open(const char *name, int flags, int mode);
134 int filp_close(struct file *fp, void *id);
135 int filp_read(struct file *fp, void *buf, size_t nbytes, loff_t *pos);
136 int filp_write(struct file *fp, void *buf, size_t nbytes, loff_t *pos);
137 int filp_fsync(struct file *fp);
138 int get_file(struct file *fp);
139 int fput(struct file *fp);
140 int file_count(struct file *fp);
141 #define cfs_filp_unlink(x, y) (KdBreakPoint(), 0)
154 #define INT_LIMIT(x) (~((x)1 << (sizeof(x)*8 - 1)))
155 #define OFFSET_MAX INT_LIMIT(loff_t)
157 #define flock_type(fl) ((fl)->fl_type)
158 #define flock_set_type(fl, type) do { (fl)->fl_type = (type); } while (0)
159 #define flock_pid(fl) ((fl)->fl_pid)
160 #define flock_set_pid(fl, pid) do { (fl)->fl_pid = (pid); } while (0)
161 #define flock_start(fl) ((fl)->fl_start)
162 #define flock_set_start(fl, st) do { (fl)->fl_start = (st); } while (0)
163 #define flock_end(fl) ((fl)->fl_end)
164 #define flock_set_end(fl, end) do { (fl)->fl_end = (end); } while (0)
166 #define ATTR_MODE 0x0001
167 #define ATTR_UID 0x0002
168 #define ATTR_GID 0x0004
169 #define ATTR_SIZE 0x0008
170 #define ATTR_ATIME 0x0010
171 #define ATTR_MTIME 0x0020
172 #define ATTR_CTIME 0x0040
173 #define ATTR_ATIME_SET 0x0080
174 #define ATTR_MTIME_SET 0x0100
175 #define ATTR_FORCE 0x0200 /* Not a change, but a change it */
176 #define ATTR_ATTR_FLAG 0x0400
177 #define ATTR_RAW 0x0800 /* file system, not vfs will massage attrs */
178 #define ATTR_FROM_OPEN 0x1000 /* called from open path, ie O_TRUNC */
179 //#define ATTR_CTIME_SET 0x2000
182 * set ATTR_BLOCKS to a high value to avoid any risk of collision with other
183 * ATTR_* attributes (see bug 13828): lustre/include/winnt/lustre_compat25.h
185 /* #define ATTR_BLOCKS 0x4000 */
186 #define ATTR_BLOCKS (1 << 27)
188 #define ATTR_KILL_SUID 0
189 #define ATTR_KILL_SGID 0
193 #define in_group_p(x) (0)
196 /* VFS structures for windows */
202 #define S_IFMT 00170000
203 #define S_IFSOCK 0140000
204 #define S_IFLNK 0120000
205 #define S_IFREG 0100000
206 #define S_IFBLK 0060000
207 #define S_IFDIR 0040000
208 #define S_IFCHR 0020000
209 #define S_IFIFO 0010000
210 #define S_ISUID 0004000
211 #define S_ISGID 0002000
212 #define S_ISVTX 0001000
214 /* Inode flags - they have nothing to superblock flags now */
216 #define S_SYNC 1 /* Writes are synced at once */
217 #define S_NOATIME 2 /* Do not update access times */
218 #define S_APPEND 4 /* Append-only file */
219 #define S_IMMUTABLE 8 /* Immutable file */
220 #define S_DEAD 16 /* removed, but still open directory */
221 #define S_NOQUOTA 32 /* Inode is not counted to quota */
222 #define S_DIRSYNC 64 /* Directory modifications are synchronous */
223 #define S_NOCMTIME 128 /* Do not update file c/mtime */
224 #define S_SWAPFILE 256 /* Do not truncate: swapon got its bmaps */
225 #define S_PRIVATE 512 /* Inode is fs-internal */
232 struct timespec i_atime;
233 struct timespec i_ctime;
234 struct timespec i_mtime;
235 struct timespec i_dtime;
247 #define I_FREEING 0x0001
250 cfs_atomic_t d_count;
255 struct inode * d_inode;
256 struct dentry* d_parent;
259 extern struct dentry *dget(struct dentry *de);
260 extern void dput(struct dentry *de);
261 static __inline struct dentry *lookup_one_len(const char *name, struct dentry *de, int len)
263 cfs_enter_debugger();
267 static inline loff_t i_size_read(const struct inode *inode)
269 cfs_enter_debugger();
270 return inode->i_size;
273 static inline void i_size_write(struct inode *inode, loff_t i_size)
275 cfs_enter_debugger();
276 inode->i_size = i_size;
299 struct dentry * mnt_root;
300 struct super_block *mnt_sb;
305 * quota definitions (linux/quota.h)
309 #define USRQUOTA 0 /* element used for user quotas */
310 #define GRPQUOTA 1 /* element used for group quotas */
317 typedef int (read_proc_t)(char *page, char **start, off_t off,
318 int count, int *eof, void *data);
320 struct file; /* forward ref */
321 typedef int (write_proc_t)(struct file *file, const char *buffer,
322 unsigned long count, void *data);
324 void proc_destory_subtree(cfs_proc_entry_t *entry);
327 void proc_destroy_fs();
333 HANDLE cfs_open_current_thread();
334 void cfs_close_thread_handle(HANDLE handle);
335 KAFFINITY cfs_query_thread_affinity();
336 int cfs_set_thread_affinity(KAFFINITY affinity);
337 int cfs_tie_thread_to_cpu(int cpu);
338 typedef PVOID mm_segment_t;
343 int cfs_set_thread_priority(KPRIORITY priority);
345 #define MAKE_MM_SEG(s) ((mm_segment_t)(ulong_ptr_t)(s))
346 #define KERNEL_DS MAKE_MM_SEG(0xFFFFFFFFUL)
347 #define USER_DS MAKE_MM_SEG(PAGE_OFFSET)
349 #define get_ds() (KERNEL_DS)
350 #define set_fs(x) do {} while(0)
351 #define get_fs() (NULL)
354 * radix tree (linux/radix_tree.h)
357 /* radix tree root structure */
358 struct radix_tree_root {
359 RTL_GENERIC_TABLE table;
362 /* #define RADIX_TREE_INIT(mask) {0}
364 #define RADIX_TREE(name, mask) \
365 struct radix_tree_root name RADIX_TREE_INIT(mask) */
367 VOID RadixInitTable(IN PRTL_GENERIC_TABLE Table);
368 #define INIT_RADIX_TREE(root, mask) RadixInitTable(&((root)->table))
370 /* all radix tree routines should be protected by external locks */
372 radix_tree_gang_lookup(struct radix_tree_root *root, void **results,
373 unsigned long first_index, unsigned int max_items);
374 void *radix_tree_lookup(struct radix_tree_root *root, unsigned long index);
375 int radix_tree_insert(struct radix_tree_root *root, unsigned long index,
377 void *radix_tree_delete(struct radix_tree_root *root, unsigned long index);
379 #else /* !__KERNEL__ */
381 #if !defined(_WINDOWS_)
384 #define CREATE_ALWAYS 2
385 #define OPEN_EXISTING 3
386 #define OPEN_ALWAYS 4
387 #define TRUNCATE_EXISTING 5
389 #define SECTION_QUERY 0x0001
390 #define SECTION_MAP_WRITE 0x0002
391 #define SECTION_MAP_READ 0x0004
392 #define SECTION_MAP_EXECUTE 0x0008
393 #define SECTION_EXTEND_SIZE 0x0010
395 #define FILE_MAP_COPY SECTION_QUERY
396 #define FILE_MAP_WRITE SECTION_MAP_WRITE
397 #define FILE_MAP_READ SECTION_MAP_READ
398 #define FILE_MAP_ALL_ACCESS SECTION_ALL_ACCESS
405 IN LPCSTR lpFileName,
406 IN DWORD dwDesiredAccess,
407 IN DWORD dwShareMode,
408 IN PVOID lpSecurityAttributes,
409 IN DWORD dwCreationDisposition,
410 IN DWORD dwFlagsAndAttributes,
411 IN HANDLE hTemplateFile
414 #define CreateFile CreateFileA
420 IN OUT HANDLE hObject
435 IN PVOID lpFileMappingAttributes,
437 IN DWORD dwMaximumSizeHigh,
438 IN DWORD dwMaximumSizeLow,
441 #define CreateFileMapping CreateFileMappingA
448 OUT DWORD * lpFileSizeHigh
455 IN HANDLE hFileMappingObject,
456 IN DWORD dwDesiredAccess,
457 IN DWORD dwFileOffsetHigh,
458 IN DWORD dwFileOffsetLow,
459 IN SIZE_T dwNumberOfBytesToMap
466 IN PVOID lpBaseAddress
470 #endif /* __KERNEL__ */
480 #define ERR_PTR(error) ((void *)(long_ptr_t)(error))
481 #define PTR_ERR(ptr) ((long)(long_ptr_t) (ptr))
482 #define IS_ERR(ptr) ((long)(((ulong_ptr_t) (ptr)) > (ulong_ptr_t)(-1000L)))
484 #endif /* __LIBCFS_WINNT_CFS_FS_H__*/