Whamcloud - gitweb
da613ba1f2186260752a86de7555a632f813cd8a
[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  * Implementation of standard file system interfaces for XNU kernel.
5  *
6  *  Copyright (c) 2004 Cluster File Systems, Inc.
7  *
8  *   This file is part of Lustre, http://www.lustre.org.
9  *
10  *   Lustre is free software; you can redistribute it and/or modify it under
11  *   the terms of version 2 of the GNU General Public License as published by
12  *   the Free Software Foundation. Lustre is distributed in the hope that it
13  *   will be useful, but WITHOUT ANY WARRANTY; without even the implied
14  *   warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details. You should have received a
16  *   copy of the GNU General Public License along with Lustre; if not, write
17  *   to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
18  *   USA.
19  */
20 #ifndef __LIBCFS_DARWIN_FS_H__
21 #define __LIBCFS_DARWIN_FS_H__
22
23 #ifndef __LIBCFS_LIBCFS_H__
24 #error Do not #include this file directly. #include <libcfs/libcfs.h> instead
25 #endif
26
27 #ifdef __KERNEL__
28
29 #include <sys/types.h>
30 #include <sys/systm.h>
31
32 #include <sys/kernel.h>
33 #include <sys/file.h>
34 #include <sys/time.h>
35 #include <sys/filedesc.h>
36 #include <sys/mount.h>
37 #include <sys/stat.h>
38 #include <sys/sysctl.h>
39 #include <sys/ubc.h>
40 #include <sys/mbuf.h>
41 #include <sys/namei.h>
42 #include <sys/fcntl.h>
43 #include <sys/lockf.h>
44 #include <stdarg.h>
45
46 #include <mach/mach_types.h>
47 #include <mach/time_value.h>
48 #include <kern/clock.h>
49 #include <sys/param.h>
50 #include <IOKit/system.h>
51
52 #include <libcfs/darwin/darwin-types.h>
53 #include <libcfs/darwin/darwin-lock.h>
54 #include <libcfs/darwin/darwin-mem.h>
55 #include <libcfs/list.h>
56
57 /*
58  * File operating APIs in kernel
59  */
60 #ifdef __DARWIN8__
61 /*
62  * Kernel file descriptor
63  */
64 typedef struct cfs_kern_file {
65         int             f_flags;
66         vnode_t         f_vp;
67         vfs_context_t   f_ctxt;
68 } cfs_file_t;
69
70 #else
71
72 typedef struct file cfs_file_t;
73
74 #endif
75
76 int     kern_file_size(cfs_file_t *fp, off_t    *size);
77 #define cfs_filp_size(fp)                       \
78         ({                                      \
79                 off_t           __size;         \
80                 kern_file_size((fp), &__size);  \
81                 __size;                         \
82          })
83 #define cfs_filp_poff(fp)               (NULL)
84
85 cfs_file_t *kern_file_open(const char *name, int flags, int mode, int *err);
86 int kern_file_close(cfs_file_t *fp);
87 int kern_file_read(cfs_file_t *fp, void *buf, size_t nbytes, off_t *pos);
88 int kern_file_write(cfs_file_t *fp, void *buf, size_t nbytes, off_t *pos);
89 int kern_file_sync(cfs_file_t *fp);
90
91 #define cfs_filp_open(n, f, m, e)       kern_file_open(n, f, m, e)
92 #define cfs_filp_close(f)               kern_file_close(f)
93 #define cfs_filp_read(f, b, n, p)       kern_file_read(f, b, n, p)
94 #define cfs_filp_write(f, b, n, p)      kern_file_write(f, b, n, p)
95 #define cfs_filp_fsync(f)               kern_file_sync(f)
96
97 int ref_file(cfs_file_t *fp);
98 int rele_file(cfs_file_t *fp);
99 int file_count(cfs_file_t *fp);
100 #define cfs_get_file(f)                 ref_file(f)
101 #define cfs_put_file(f)                 rele_file(f)
102 #define cfs_file_count(f)               file_count(f)
103
104 #define CFS_INT_LIMIT(x)                (~((x)1 << (sizeof(x)*8 - 1)))
105 #define CFS_OFFSET_MAX                  CFS_INT_LIMIT(loff_t)
106
107 typedef struct flock                    cfs_flock_t;
108 #define cfs_flock_type(fl)              ((fl)->l_type)
109 #define cfs_flock_set_type(fl, type)    do { (fl)->l_type = (type); } while(0)
110 #define cfs_flock_pid(fl)               ((fl)->l_pid)
111 #define cfs_flock_set_pid(fl, pid)      do { (fl)->l_pid = (pid); } while(0)
112 #define cfs_flock_start(fl)             ((fl)->l_start)
113 #define cfs_flock_set_start(fl, start)  do { (fl)->l_start = (start); } while(0)
114
115 static inline loff_t cfs_flock_end(cfs_flock_t *fl)
116 {
117         return (fl->l_len == 0 ? CFS_OFFSET_MAX: (fl->l_start + fl->l_len));
118 }
119
120 static inline void cfs_flock_set_end(cfs_flock_t *fl, loff_t end)
121 {
122         if (end == CFS_OFFSET_MAX)
123                 fl->l_len = 0;
124         else
125                 fl->l_len = end - fl->l_start;
126 }
127
128 #define ATTR_MODE       0x0001
129 #define ATTR_UID        0x0002
130 #define ATTR_GID        0x0004
131 #define ATTR_SIZE       0x0008
132 #define ATTR_ATIME      0x0010
133 #define ATTR_MTIME      0x0020
134 #define ATTR_CTIME      0x0040
135 #define ATTR_ATIME_SET  0x0080
136 #define ATTR_MTIME_SET  0x0100
137 #define ATTR_FORCE      0x0200  /* Not a change, but a change it */
138 #define ATTR_ATTR_FLAG  0x0400
139 #define ATTR_RAW        0x0800  /* file system, not vfs will massage attrs */
140 #define ATTR_FROM_OPEN  0x1000  /* called from open path, ie O_TRUNC */
141 #define ATTR_CTIME_SET  0x2000
142 #define ATTR_BLOCKS     0x4000
143 #define ATTR_KILL_SUID  0
144 #define ATTR_KILL_SGID  0
145
146 #define in_group_p(x)   (0)
147
148 struct posix_acl_entry {
149         short                   e_tag;
150         unsigned short          e_perm;
151         unsigned int            e_id;
152 };
153
154 struct posix_acl {
155         atomic_t                a_refcount;
156         unsigned int            a_count;
157         struct posix_acl_entry  a_entries[0];
158 };
159
160 struct posix_acl *posix_acl_alloc(int count, int flags);
161 static inline struct posix_acl *posix_acl_from_xattr(const void *value, 
162                                                      size_t size)
163
164         return posix_acl_alloc(0, 0);
165 }
166 static inline void posix_acl_release(struct posix_acl *acl) {};
167 static inline int posix_acl_valid(const struct posix_acl *acl) { return 0; }
168 static inline struct posix_acl * posix_acl_dup(struct posix_acl *acl) 
169
170         return acl;
171 }
172
173 #else   /* !__KERNEL__ */
174
175 typedef struct file cfs_file_t;
176
177 #endif  /* END __KERNEL__ */
178
179 typedef struct {
180         void    *d;
181 } cfs_dentry_t;
182
183 #ifndef O_SYNC
184 #define O_SYNC                                  0
185 #endif
186 #ifndef O_DIRECTORY
187 #define O_DIRECTORY                             0
188 #endif
189 #ifndef O_LARGEFILE
190 #define O_LARGEFILE                             0
191 #endif
192
193 #endif