Whamcloud - gitweb
b=16098
[fs/lustre-release.git] / libcfs / include / libcfs / darwin / darwin-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/darwin/darwin-fs.h
37  *
38  * Implementation of standard file system interfaces for XNU kernel.
39  */
40
41 #ifndef __LIBCFS_DARWIN_FS_H__
42 #define __LIBCFS_DARWIN_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 #ifdef __KERNEL__
49
50 #include <sys/types.h>
51 #include <sys/systm.h>
52
53 #include <sys/kernel.h>
54 #include <sys/file.h>
55 #include <sys/time.h>
56 #include <sys/filedesc.h>
57 #include <sys/mount.h>
58 #include <sys/stat.h>
59 #include <sys/sysctl.h>
60 #include <sys/ubc.h>
61 #include <sys/mbuf.h>
62 #include <sys/namei.h>
63 #include <sys/fcntl.h>
64 #include <sys/lockf.h>
65 #include <stdarg.h>
66
67 #include <mach/mach_types.h>
68 #include <mach/time_value.h>
69 #include <kern/clock.h>
70 #include <sys/param.h>
71 #include <IOKit/system.h>
72
73 #include <libcfs/darwin/darwin-types.h>
74 #include <libcfs/darwin/darwin-lock.h>
75 #include <libcfs/darwin/darwin-mem.h>
76 #include <libcfs/list.h>
77
78 /*
79  * File operating APIs in kernel
80  */
81 #ifdef __DARWIN8__
82 /*
83  * Kernel file descriptor
84  */
85 typedef struct cfs_kern_file {
86         int             f_flags;
87         vnode_t         f_vp;
88         vfs_context_t   f_ctxt;
89 } cfs_file_t;
90
91 #else
92
93 typedef struct file cfs_file_t;
94
95 #endif
96
97 int     kern_file_size(cfs_file_t *fp, off_t    *size);
98 #define cfs_filp_size(fp)                       \
99         ({                                      \
100                 off_t           __size;         \
101                 kern_file_size((fp), &__size);  \
102                 __size;                         \
103          })
104 #define cfs_filp_poff(fp)               (NULL)
105
106 cfs_file_t *kern_file_open(const char *name, int flags, int mode, int *err);
107 int kern_file_close(cfs_file_t *fp);
108 int kern_file_read(cfs_file_t *fp, void *buf, size_t nbytes, off_t *pos);
109 int kern_file_write(cfs_file_t *fp, void *buf, size_t nbytes, off_t *pos);
110 int kern_file_sync(cfs_file_t *fp);
111
112 #define cfs_filp_open(n, f, m, e)       kern_file_open(n, f, m, e)
113 #define cfs_filp_close(f)               kern_file_close(f)
114 #define cfs_filp_read(f, b, n, p)       kern_file_read(f, b, n, p)
115 #define cfs_filp_write(f, b, n, p)      kern_file_write(f, b, n, p)
116 #define cfs_filp_fsync(f)               kern_file_sync(f)
117
118 int ref_file(cfs_file_t *fp);
119 int rele_file(cfs_file_t *fp);
120 int file_count(cfs_file_t *fp);
121 #define cfs_get_file(f)                 ref_file(f)
122 #define cfs_put_file(f)                 rele_file(f)
123 #define cfs_file_count(f)               file_count(f)
124
125 #define CFS_INT_LIMIT(x)                (~((x)1 << (sizeof(x)*8 - 1)))
126 #define CFS_OFFSET_MAX                  CFS_INT_LIMIT(loff_t)
127
128 typedef struct flock                    cfs_flock_t;
129 #define cfs_flock_type(fl)              ((fl)->l_type)
130 #define cfs_flock_set_type(fl, type)    do { (fl)->l_type = (type); } while(0)
131 #define cfs_flock_pid(fl)               ((fl)->l_pid)
132 #define cfs_flock_set_pid(fl, pid)      do { (fl)->l_pid = (pid); } while(0)
133 #define cfs_flock_start(fl)             ((fl)->l_start)
134 #define cfs_flock_set_start(fl, start)  do { (fl)->l_start = (start); } while(0)
135
136 static inline loff_t cfs_flock_end(cfs_flock_t *fl)
137 {
138         return (fl->l_len == 0 ? CFS_OFFSET_MAX: (fl->l_start + fl->l_len));
139 }
140
141 static inline void cfs_flock_set_end(cfs_flock_t *fl, loff_t end)
142 {
143         if (end == CFS_OFFSET_MAX)
144                 fl->l_len = 0;
145         else
146                 fl->l_len = end - fl->l_start;
147 }
148
149 #define ATTR_MODE       0x0001
150 #define ATTR_UID        0x0002
151 #define ATTR_GID        0x0004
152 #define ATTR_SIZE       0x0008
153 #define ATTR_ATIME      0x0010
154 #define ATTR_MTIME      0x0020
155 #define ATTR_CTIME      0x0040
156 #define ATTR_ATIME_SET  0x0080
157 #define ATTR_MTIME_SET  0x0100
158 #define ATTR_FORCE      0x0200  /* Not a change, but a change it */
159 #define ATTR_ATTR_FLAG  0x0400
160 #define ATTR_RAW        0x0800  /* file system, not vfs will massage attrs */
161 #define ATTR_FROM_OPEN  0x1000  /* called from open path, ie O_TRUNC */
162 #define ATTR_CTIME_SET  0x2000
163 #define ATTR_BLOCKS     0x4000
164 #define ATTR_KILL_SUID  0
165 #define ATTR_KILL_SGID  0
166
167 #define in_group_p(x)   (0)
168
169 struct posix_acl_entry {
170         short                   e_tag;
171         unsigned short          e_perm;
172         unsigned int            e_id;
173 };
174
175 struct posix_acl {
176         atomic_t                a_refcount;
177         unsigned int            a_count;
178         struct posix_acl_entry  a_entries[0];
179 };
180
181 struct posix_acl *posix_acl_alloc(int count, int flags);
182 static inline struct posix_acl *posix_acl_from_xattr(const void *value, 
183                                                      size_t size)
184
185         return posix_acl_alloc(0, 0);
186 }
187 static inline void posix_acl_release(struct posix_acl *acl) {};
188 static inline int posix_acl_valid(const struct posix_acl *acl) { return 0; }
189 static inline struct posix_acl * posix_acl_dup(struct posix_acl *acl) 
190
191         return acl;
192 }
193
194 #else   /* !__KERNEL__ */
195
196 typedef struct file cfs_file_t;
197
198 #endif  /* END __KERNEL__ */
199
200 typedef struct {
201         void    *d;
202 } cfs_dentry_t;
203
204 #ifndef O_SYNC
205 #define O_SYNC                                  0
206 #endif
207 #ifndef O_DIRECTORY
208 #define O_DIRECTORY                             0
209 #endif
210 #ifndef O_LARGEFILE
211 #define O_LARGEFILE                             0
212 #endif
213
214 #endif