1 #ifndef __LIBCFS_DARWIN_CFS_FS_H__
2 #define __LIBCFS_DARWIN_CFS_FS_H__
4 #ifndef __LIBCFS_LIBCFS_H__
5 #error Do not #include this file directly. #include <libcfs/libcfs.h> instead
10 #include <sys/types.h>
11 #include <sys/systm.h>
13 * __APPLE_API_PRIVATE is defined before include user.h
14 * Doing this way to get the define of uthread, it's not good
15 * but I do need to know what's inside uthread.
17 #ifndef __APPLE_API_PRIVATE
18 #define __APPLE_API_PRIVATE
19 #include <sys/vnode.h>
20 #undef __APPLE_API_PRIVATE
22 #include <sys/vnode.h>
25 #include <sys/kernel.h>
28 #include <sys/filedesc.h>
30 #include <sys/mount.h>
31 #include <sys/sysctl.h>
34 #include <sys/namei.h>
35 #include <sys/fcntl.h>
36 #include <sys/lockf.h>
39 #include <mach/mach_types.h>
40 #include <mach/mach_traps.h>
41 #include <mach/time_value.h>
42 #include <kern/clock.h>
43 #include <sys/param.h>
44 #include <IOKit/system.h>
46 #include <libcfs/darwin/darwin-types.h>
47 #include <libcfs/darwin/darwin-lock.h>
48 #include <libcfs/darwin/darwin-mem.h>
49 #include <libcfs/list.h>
52 * File operating APIs in kernel
54 typedef struct file cfs_file_t;
56 int filp_node_size(cfs_file_t *fp, off_t *size);
57 #define cfs_filp_size(fp) \
60 filp_node_size((fp), &__size); \
63 #define cfs_filp_poff(fp) (NULL)
65 cfs_file_t *filp_open(const char *name, int flags, int mode, int *err);
66 int filp_close(cfs_file_t *fp);
67 int filp_read(cfs_file_t *fp, void *buf, size_t nbytes, off_t *pos);
68 int filp_write(cfs_file_t *fp, void *buf, size_t nbytes, off_t *pos);
69 int filp_fsync(cfs_file_t *fp);
71 #define cfs_filp_open(n, f, m, e) filp_open(n, f, m, e)
72 #define cfs_filp_close(f) filp_close(f)
73 #define cfs_filp_read(f, b, n, p) filp_read(f, b, n, p)
74 #define cfs_filp_write(f, b, n, p) filp_write(f, b, n, p)
75 #define cfs_filp_fsync(f) filp_fsync(f)
77 int ref_file(cfs_file_t *fp);
78 int rele_file(cfs_file_t *fp);
79 int file_count(cfs_file_t *fp);
80 #define cfs_get_file(f) ref_file(f)
81 #define cfs_put_file(f) rele_file(f)
82 #define cfs_file_count(f) file_count(f)
84 #define CFS_INT_LIMIT(x) (~((x)1 << (sizeof(x)*8 - 1)))
85 #define CFS_OFFSET_MAX CFS_INT_LIMIT(loff_t)
87 typedef struct flock cfs_flock_t;
88 #define CFS_FLOCK_TYPE(fl) ((fl)->l_type)
89 #define CFS_FLOCK_SET_TYPE(fl, type) do { (fl)->l_type = (type); } while(0)
90 #define CFS_FLOCK_PID(fl) ((fl)->l_pid)
91 #define CFS_FLOCK_SET_PID(fl, pid) do { (fl)->l_pid = (pid); } while(0)
92 #define CFS_FLOCK_START(fl) ((fl)->l_start)
93 #define CFS_FLOCK_SET_START(fl, start) do { (fl)->l_start = (start); } while(0)
94 #define CFS_FLOCK_END(fl) ((fl)->l_len == 0? CFS_OFFSET_MAX: ((fl)->l_start + (fl)->l_en))
95 #define CFS_FLOCK_SET_END(fl, end) \
97 if (end == CFS_OFFSET_MAX) \
100 (fl)->l_len = (end) - (fl)->l_start;\
106 typedef unsigned short umode_t;
108 #define ATTR_MODE 0x0001
109 #define ATTR_UID 0x0002
110 #define ATTR_GID 0x0004
111 #define ATTR_SIZE 0x0008
112 #define ATTR_ATIME 0x0010
113 #define ATTR_MTIME 0x0020
114 #define ATTR_CTIME 0x0040
115 #define ATTR_ATIME_SET 0x0080
116 #define ATTR_MTIME_SET 0x0100
117 #define ATTR_FORCE 0x0200 /* Not a change, but a change it */
118 #define ATTR_ATTR_FLAG 0x0400
119 #define ATTR_RAW 0x0800 /* file system, not vfs will massage attrs */
120 #define ATTR_FROM_OPEN 0x1000 /* called from open path, ie O_TRUNC */
121 #define ATTR_CTIME_SET 0x2000
123 #define in_group_p(x) (0)
128 #define O_DIRECTORY 0
129 #define O_LARGEFILE 0