Whamcloud - gitweb
177f7d096c467ba9a47c1a5654ee9b2889ba8453
[fs/lustre-release.git] / libcfs / include / libcfs / darwin / darwin-fs.h
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
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.
9  *
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).
15  *
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
19  *
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
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  */
30 /*
31  * This file is part of Lustre, http://www.lustre.org/
32  * Lustre is a trademark of Sun Microsystems, Inc.
33  *
34  * libcfs/include/libcfs/darwin/darwin-fs.h
35  *
36  * Implementation of standard file system interfaces for XNU kernel.
37  */
38
39 #ifndef __LIBCFS_DARWIN_FS_H__
40 #define __LIBCFS_DARWIN_FS_H__
41
42 #ifndef __LIBCFS_LIBCFS_H__
43 #error Do not #include this file directly. #include <libcfs/libcfs.h> instead
44 #endif
45
46 #ifdef __KERNEL__
47
48 #include <sys/types.h>
49 #include <sys/systm.h>
50
51 #include <sys/kernel.h>
52 #include <sys/file.h>
53 #include <sys/time.h>
54 #include <sys/filedesc.h>
55 #include <sys/mount.h>
56 #include <sys/stat.h>
57 #include <sys/sysctl.h>
58 #include <sys/ubc.h>
59 #include <sys/mbuf.h>
60 #include <sys/namei.h>
61 #include <sys/fcntl.h>
62 #include <sys/lockf.h>
63 #include <stdarg.h>
64
65 #include <mach/mach_types.h>
66 #include <mach/time_value.h>
67 #include <kern/clock.h>
68 #include <sys/param.h>
69 #include <IOKit/system.h>
70
71 #include <libcfs/darwin/darwin-types.h>
72 #include <libcfs/darwin/darwin-lock.h>
73 #include <libcfs/darwin/darwin-mem.h>
74 #include <libcfs/list.h>
75
76 /*
77  * File operating APIs in kernel
78  */
79 #ifdef __DARWIN8__
80 /*
81  * Kernel file descriptor
82  */
83 struct file {
84         unsigned        f_flags;
85         vnode_t         f_vp;
86         vfs_context_t   f_ctxt;
87 };
88 #endif
89
90 int kern_file_size(struct file *fp, off_t *size);
91 #define filp_size(fp)                           \
92         ({                                      \
93                 off_t           __size;         \
94                 kern_file_size((fp), &__size);  \
95                 __size;                         \
96          })
97 #define filp_poff(fp)               (NULL)
98
99 struct file *kern_file_open(const char *name, int flags, int mode);
100 int kern_file_close(struct file *fp);
101 int kern_file_read(struct file *fp, void *buf, size_t nbytes, off_t *pos);
102 int kern_file_write(struct file *fp, void *buf, size_t nbytes, off_t *pos);
103 int kern_file_sync(struct file *fp);
104
105 #define filp_open(n, f, m)              kern_file_open(n, f, m)
106 #define filp_close(f, i)                kern_file_close(f)
107 #define filp_read(f, b, n, p)           kern_file_read(f, b, n, p)
108 #define filp_write(f, b, n, p)          kern_file_write(f, b, n, p)
109 #define filp_fsync(f)                   kern_file_sync(f)
110
111 int ref_file(struct file *fp);
112 int rele_file(struct file *fp);
113 int file_count(struct file *fp);
114 #define get_file(f)                     ref_file(f)
115 #define fput(f)                         rele_file(f)
116
117 #define INT_LIMIT(x)                    (~((x)1 << (sizeof(x)*8 - 1)))
118 #define OFFSET_MAX                      INT_LIMIT(loff_t)
119
120 #define file_lock                       flock
121 #define flock_type(fl)                  ((fl)->l_type)
122 #define flock_set_type(fl, type)        do { (fl)->l_type = (type); } while (0)
123 #define flock_pid(fl)                   ((fl)->l_pid)
124 #define flock_set_pid(fl, pid)          do { (fl)->l_pid = (pid); } while (0)
125 #define flock_start(fl)                 ((fl)->l_start)
126 #define flock_set_start(fl, st)         do { (fl)->l_start = (st); } while (0)
127
128 static inline loff_t flock_end(struct file_lock *fl)
129 {
130         return (fl->l_len == 0 ? OFFSET_MAX : (fl->l_start + fl->l_len));
131 }
132
133 static inline void flock_set_end(struct file_lock *fl, loff_t end)
134 {
135         if (end == OFFSET_MAX)
136                 fl->l_len = 0;
137         else
138                 fl->l_len = end - fl->l_start;
139 }
140
141 #define ATTR_MODE       0x0001
142 #define ATTR_UID        0x0002
143 #define ATTR_GID        0x0004
144 #define ATTR_SIZE       0x0008
145 #define ATTR_ATIME      0x0010
146 #define ATTR_MTIME      0x0020
147 #define ATTR_CTIME      0x0040
148 #define ATTR_ATIME_SET  0x0080
149 #define ATTR_MTIME_SET  0x0100
150 #define ATTR_FORCE      0x0200  /* Not a change, but a change it */
151 #define ATTR_ATTR_FLAG  0x0400
152 #define ATTR_RAW        0x0800  /* file system, not vfs will massage attrs */
153 #define ATTR_FROM_OPEN  0x1000  /* called from open path, ie O_TRUNC */
154 #define ATTR_CTIME_SET  0x2000
155 #define ATTR_BLOCKS     0x4000
156 #define ATTR_KILL_SUID  0
157 #define ATTR_KILL_SGID  0
158
159 #define in_group_p(x)   (0)
160
161 struct posix_acl_entry {
162         short                   e_tag;
163         unsigned short          e_perm;
164         unsigned int            e_id;
165 };
166
167 struct posix_acl {
168         atomic_t                a_refcount;
169         unsigned int            a_count;
170         struct posix_acl_entry  a_entries[0];
171 };
172
173 struct posix_acl *posix_acl_alloc(int count, int flags);
174 static inline struct posix_acl *posix_acl_from_xattr(const void *value,
175                                                      size_t size)
176 {
177         return posix_acl_alloc(0, 0);
178 }
179 #define posix_acl_from_xattr(a,b,c) posix_acl_from_xattr(b,c)
180
181 static inline void posix_acl_release(struct posix_acl *acl) {};
182 static inline int posix_acl_valid(const struct posix_acl *acl) { return 0; }
183 static inline struct posix_acl * posix_acl_dup(struct posix_acl *acl) 
184
185         return acl;
186 }
187 #endif  /* END __KERNEL__ */
188
189 struct dentry {
190         void    *d;
191 };
192
193 #ifndef O_SYNC
194 #define O_SYNC                                  0
195 #endif
196 #ifndef O_DIRECTORY
197 #define O_DIRECTORY                             0
198 #endif
199 #ifndef O_LARGEFILE
200 #define O_LARGEFILE                             0
201 #endif
202
203 #endif