]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - cddl/contrib/opensolaris/lib/libzpool/common/sys/zfs_context.h
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / cddl / contrib / opensolaris / lib / libzpool / common / sys / zfs_context.h
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23  * Copyright (c) 2013 by Delphix. All rights reserved.
24  * Copyright (c) 2012, Joyent, Inc. All rights reserved.
25  */
26
27 #ifndef _SYS_ZFS_CONTEXT_H
28 #define _SYS_ZFS_CONTEXT_H
29
30 #ifdef  __cplusplus
31 extern "C" {
32 #endif
33
34 #define _SYS_MUTEX_H
35 #define _SYS_RWLOCK_H
36 #define _SYS_CONDVAR_H
37 #define _SYS_SYSTM_H
38 #define _SYS_T_LOCK_H
39 #define _SYS_VNODE_H
40 #define _SYS_VFS_H
41 #define _SYS_SUNDDI_H
42 #define _SYS_CALLB_H
43 #define _SYS_SCHED_H_
44
45 #include <solaris.h>
46 #include <stdio.h>
47 #include <stdlib.h>
48 #include <stddef.h>
49 #include <stdarg.h>
50 #include <fcntl.h>
51 #include <unistd.h>
52 #include <errno.h>
53 #include <string.h>
54 #include <strings.h>
55 #include <thread.h>
56 #include <assert.h>
57 #include <limits.h>
58 #include <dirent.h>
59 #include <time.h>
60 #include <math.h>
61 #include <umem.h>
62 #include <inttypes.h>
63 #include <fsshare.h>
64 #include <pthread.h>
65 #include <sys/debug.h>
66 #include <sys/note.h>
67 #include <sys/types.h>
68 #include <sys/cred.h>
69 #include <sys/atomic.h>
70 #include <sys/sysmacros.h>
71 #include <sys/bitmap.h>
72 #include <sys/resource.h>
73 #include <sys/byteorder.h>
74 #include <sys/list.h>
75 #include <sys/time.h>
76 #include <sys/uio.h>
77 #include <sys/mntent.h>
78 #include <sys/mnttab.h>
79 #include <sys/zfs_debug.h>
80 #include <sys/sdt.h>
81 #include <sys/kstat.h>
82 #include <sys/u8_textprep.h>
83 #include <sys/kernel.h>
84 #include <sys/disk.h>
85 #include <sys/sysevent.h>
86 #include <sys/sysevent/eventdefs.h>
87 #include <sys/sysevent/dev.h>
88 #include <machine/atomic.h>
89 #include <sys/debug.h>
90 #ifdef illumos
91 #include "zfs.h"
92 #endif
93
94 #define ZFS_EXPORTS_PATH        "/etc/zfs/exports"
95
96 /*
97  * Debugging
98  */
99
100 /*
101  * Note that we are not using the debugging levels.
102  */
103
104 #define CE_CONT         0       /* continuation         */
105 #define CE_NOTE         1       /* notice               */
106 #define CE_WARN         2       /* warning              */
107 #define CE_PANIC        3       /* panic                */
108 #define CE_IGNORE       4       /* print nothing        */
109
110 /*
111  * ZFS debugging
112  */
113
114 #define ZFS_LOG(...)    do {  } while (0)
115
116 typedef u_longlong_t      rlim64_t;
117 #define RLIM64_INFINITY ((rlim64_t)-3)
118
119 #ifdef ZFS_DEBUG
120 extern void dprintf_setup(int *argc, char **argv);
121 #endif /* ZFS_DEBUG */
122
123 extern void cmn_err(int, const char *, ...);
124 extern void vcmn_err(int, const char *, __va_list);
125 extern void panic(const char *, ...);
126 extern void vpanic(const char *, __va_list);
127
128 #define fm_panic        panic
129
130 extern int aok;
131
132 /*
133  * DTrace SDT probes have different signatures in userland than they do in
134  * kernel.  If they're being used in kernel code, re-define them out of
135  * existence for their counterparts in libzpool.
136  */
137
138 #ifdef DTRACE_PROBE
139 #undef  DTRACE_PROBE
140 #endif  /* DTRACE_PROBE */
141 #ifdef illumos
142 #define DTRACE_PROBE(a) \
143         ZFS_PROBE0(#a)
144 #endif
145
146 #ifdef DTRACE_PROBE1
147 #undef  DTRACE_PROBE1
148 #endif  /* DTRACE_PROBE1 */
149 #ifdef illumos
150 #define DTRACE_PROBE1(a, b, c) \
151         ZFS_PROBE1(#a, (unsigned long)c)
152 #endif
153
154 #ifdef DTRACE_PROBE2
155 #undef  DTRACE_PROBE2
156 #endif  /* DTRACE_PROBE2 */
157 #ifdef illumos
158 #define DTRACE_PROBE2(a, b, c, d, e) \
159         ZFS_PROBE2(#a, (unsigned long)c, (unsigned long)e)
160 #endif
161
162 #ifdef DTRACE_PROBE3
163 #undef  DTRACE_PROBE3
164 #endif  /* DTRACE_PROBE3 */
165 #ifdef illumos
166 #define DTRACE_PROBE3(a, b, c, d, e, f, g) \
167         ZFS_PROBE3(#a, (unsigned long)c, (unsigned long)e, (unsigned long)g)
168 #endif
169
170 #ifdef DTRACE_PROBE4
171 #undef  DTRACE_PROBE4
172 #endif  /* DTRACE_PROBE4 */
173 #ifdef illumos
174 #define DTRACE_PROBE4(a, b, c, d, e, f, g, h, i) \
175         ZFS_PROBE4(#a, (unsigned long)c, (unsigned long)e, (unsigned long)g, \
176         (unsigned long)i)
177 #endif
178
179 #ifdef illumos
180 /*
181  * We use the comma operator so that this macro can be used without much
182  * additional code.  For example, "return (EINVAL);" becomes
183  * "return (SET_ERROR(EINVAL));".  Note that the argument will be evaluated
184  * twice, so it should not have side effects (e.g. something like:
185  * "return (SET_ERROR(log_error(EINVAL, info)));" would log the error twice).
186  */
187 #define SET_ERROR(err)  (ZFS_SET_ERROR(err), err)
188 #else   /* !illumos */
189
190 #define DTRACE_PROBE(a) ((void)0)
191 #define DTRACE_PROBE1(a, b, c)  ((void)0)
192 #define DTRACE_PROBE2(a, b, c, d, e)    ((void)0)
193 #define DTRACE_PROBE3(a, b, c, d, e, f, g)      ((void)0)
194 #define DTRACE_PROBE4(a, b, c, d, e, f, g, h, i)        ((void)0)
195
196 #define SET_ERROR(err) (err)
197 #endif  /* !illumos */
198
199 /*
200  * Threads
201  */
202 #define curthread       ((void *)(uintptr_t)thr_self())
203
204 typedef struct kthread kthread_t;
205
206 #define thread_create(stk, stksize, func, arg, len, pp, state, pri)     \
207         zk_thread_create(func, arg)
208 #define thread_exit() thr_exit(NULL)
209 #define thread_join(t)  panic("libzpool cannot join threads")
210
211 #define newproc(f, a, cid, pri, ctp, pid)       (ENOSYS)
212
213 /* in libzpool, p0 exists only to have its address taken */
214 struct proc {
215         uintptr_t       this_is_never_used_dont_dereference_it;
216 };
217
218 extern struct proc p0;
219 #define curproc         (&p0)
220
221 #define PS_NONE         -1
222
223 extern kthread_t *zk_thread_create(void (*func)(), void *arg);
224
225 #define issig(why)      (FALSE)
226 #define ISSIG(thr, why) (FALSE)
227
228 /*
229  * Mutexes
230  */
231 typedef struct kmutex {
232         void            *m_owner;
233         boolean_t       initialized;
234         mutex_t         m_lock;
235 } kmutex_t;
236
237 #define MUTEX_DEFAULT   USYNC_THREAD
238 #undef  MUTEX_HELD
239 #undef  MUTEX_NOT_HELD
240 #define MUTEX_HELD(m)   ((m)->m_owner == curthread)
241 #define MUTEX_NOT_HELD(m) (!MUTEX_HELD(m))
242 #define _mutex_held(m)  pthread_mutex_isowned_np(m)
243
244 /*
245  * Argh -- we have to get cheesy here because the kernel and userland
246  * have different signatures for the same routine.
247  */
248 //extern int _mutex_init(mutex_t *mp, int type, void *arg);
249 //extern int _mutex_destroy(mutex_t *mp);
250 //extern int _mutex_owned(mutex_t *mp);
251
252 #define mutex_init(mp, b, c, d)         zmutex_init((kmutex_t *)(mp))
253 #define mutex_destroy(mp)               zmutex_destroy((kmutex_t *)(mp))
254 #define mutex_owned(mp)                 zmutex_owned((kmutex_t *)(mp))
255
256 extern void zmutex_init(kmutex_t *mp);
257 extern void zmutex_destroy(kmutex_t *mp);
258 extern int zmutex_owned(kmutex_t *mp);
259 extern void mutex_enter(kmutex_t *mp);
260 extern void mutex_exit(kmutex_t *mp);
261 extern int mutex_tryenter(kmutex_t *mp);
262 extern void *mutex_owner(kmutex_t *mp);
263
264 /*
265  * RW locks
266  */
267 typedef struct krwlock {
268         int             rw_count;
269         void            *rw_owner;
270         boolean_t       initialized;
271         rwlock_t        rw_lock;
272 } krwlock_t;
273
274 typedef int krw_t;
275
276 #define RW_READER       0
277 #define RW_WRITER       1
278 #define RW_DEFAULT      USYNC_THREAD
279
280 #undef RW_READ_HELD
281 #define RW_READ_HELD(x)         ((x)->rw_owner == NULL && (x)->rw_count > 0)
282
283 #undef RW_WRITE_HELD
284 #define RW_WRITE_HELD(x)        ((x)->rw_owner == curthread)
285 #define RW_LOCK_HELD(x)         rw_lock_held(x)
286
287 #undef RW_LOCK_HELD
288 #define RW_LOCK_HELD(x)         (RW_READ_HELD(x) || RW_WRITE_HELD(x))
289
290 extern void rw_init(krwlock_t *rwlp, char *name, int type, void *arg);
291 extern void rw_destroy(krwlock_t *rwlp);
292 extern void rw_enter(krwlock_t *rwlp, krw_t rw);
293 extern int rw_tryenter(krwlock_t *rwlp, krw_t rw);
294 extern int rw_tryupgrade(krwlock_t *rwlp);
295 extern void rw_exit(krwlock_t *rwlp);
296 extern int rw_lock_held(krwlock_t *rwlp);
297 #define rw_downgrade(rwlp) do { } while (0)
298
299 extern uid_t crgetuid(cred_t *cr);
300 extern uid_t crgetruid(cred_t *cr);
301 extern gid_t crgetgid(cred_t *cr);
302 extern int crgetngroups(cred_t *cr);
303 extern gid_t *crgetgroups(cred_t *cr);
304
305 /*
306  * Condition variables
307  */
308 typedef cond_t kcondvar_t;
309
310 #define CV_DEFAULT      USYNC_THREAD
311
312 extern void cv_init(kcondvar_t *cv, char *name, int type, void *arg);
313 extern void cv_destroy(kcondvar_t *cv);
314 extern void cv_wait(kcondvar_t *cv, kmutex_t *mp);
315 extern clock_t cv_timedwait(kcondvar_t *cv, kmutex_t *mp, clock_t abstime);
316 extern void cv_signal(kcondvar_t *cv);
317 extern void cv_broadcast(kcondvar_t *cv);
318
319 /*
320  * Thread-specific data
321  */
322 #define tsd_get(k) pthread_getspecific(k)
323 #define tsd_set(k, v) pthread_setspecific(k, v)
324 #define tsd_create(kp, d) pthread_key_create(kp, d)
325 #define tsd_destroy(kp) /* nothing */
326
327 /*
328  * Kernel memory
329  */
330 #define KM_SLEEP                UMEM_NOFAIL
331 #define KM_PUSHPAGE             KM_SLEEP
332 #define KM_NOSLEEP              UMEM_DEFAULT
333 #define KM_NODEBUG              0
334 #define KMC_NODEBUG             UMC_NODEBUG
335 #define KMC_NOTOUCH             0       /* not needed for userland caches */
336 #define kmem_alloc(_s, _f)      umem_alloc(_s, _f)
337 #define kmem_zalloc(_s, _f)     umem_zalloc(_s, _f)
338 #define kmem_free(_b, _s)       umem_free(_b, _s)
339 #define kmem_size()             (physmem * PAGESIZE)
340 #define kmem_cache_create(_a, _b, _c, _d, _e, _f, _g, _h, _i) \
341         umem_cache_create(_a, _b, _c, _d, _e, _f, _g, _h, _i)
342 #define kmem_cache_destroy(_c)  umem_cache_destroy(_c)
343 #define kmem_cache_alloc(_c, _f) umem_cache_alloc(_c, _f)
344 #define kmem_cache_free(_c, _b) umem_cache_free(_c, _b)
345 #define kmem_debugging()        0
346 #define kmem_cache_reap_now(_c)         /* nothing */
347 #define kmem_cache_set_move(_c, _cb)    /* nothing */
348 #define POINTER_INVALIDATE(_pp)         /* nothing */
349 #define POINTER_IS_VALID(_p)    0
350
351 typedef umem_cache_t kmem_cache_t;
352
353 typedef enum kmem_cbrc {
354         KMEM_CBRC_YES,
355         KMEM_CBRC_NO,
356         KMEM_CBRC_LATER,
357         KMEM_CBRC_DONT_NEED,
358         KMEM_CBRC_DONT_KNOW
359 } kmem_cbrc_t;
360
361 /*
362  * Task queues
363  */
364 typedef struct taskq taskq_t;
365 typedef uintptr_t taskqid_t;
366 typedef void (task_func_t)(void *);
367
368 #define TASKQ_PREPOPULATE       0x0001
369 #define TASKQ_CPR_SAFE          0x0002  /* Use CPR safe protocol */
370 #define TASKQ_DYNAMIC           0x0004  /* Use dynamic thread scheduling */
371 #define TASKQ_THREADS_CPU_PCT   0x0008  /* Scale # threads by # cpus */
372 #define TASKQ_DC_BATCH          0x0010  /* Mark threads as batch */
373
374 #define TQ_SLEEP        KM_SLEEP        /* Can block for memory */
375 #define TQ_NOSLEEP      KM_NOSLEEP      /* cannot block for memory; may fail */
376 #define TQ_NOQUEUE      0x02            /* Do not enqueue if can't dispatch */
377 #define TQ_FRONT        0x08            /* Queue in front */
378
379 extern taskq_t *system_taskq;
380
381 extern taskq_t  *taskq_create(const char *, int, pri_t, int, int, uint_t);
382 #define taskq_create_proc(a, b, c, d, e, p, f) \
383             (taskq_create(a, b, c, d, e, f))
384 #define taskq_create_sysdc(a, b, d, e, p, dc, f) \
385             (taskq_create(a, b, maxclsyspri, d, e, f))
386 extern taskqid_t taskq_dispatch(taskq_t *, task_func_t, void *, uint_t);
387 extern void     taskq_destroy(taskq_t *);
388 extern void     taskq_wait(taskq_t *);
389 extern int      taskq_member(taskq_t *, void *);
390 extern void     system_taskq_init(void);
391 extern void     system_taskq_fini(void);
392
393 #define taskq_dispatch_safe(tq, func, arg, flags, task)                 \
394         taskq_dispatch((tq), (func), (arg), (flags))
395
396 #define XVA_MAPSIZE     3
397 #define XVA_MAGIC       0x78766174
398
399 /*
400  * vnodes
401  */
402 typedef struct vnode {
403         uint64_t        v_size;
404         int             v_fd;
405         char            *v_path;
406 } vnode_t;
407
408 #define AV_SCANSTAMP_SZ 32              /* length of anti-virus scanstamp */
409
410 typedef struct xoptattr {
411         timestruc_t     xoa_createtime; /* Create time of file */
412         uint8_t         xoa_archive;
413         uint8_t         xoa_system;
414         uint8_t         xoa_readonly;
415         uint8_t         xoa_hidden;
416         uint8_t         xoa_nounlink;
417         uint8_t         xoa_immutable;
418         uint8_t         xoa_appendonly;
419         uint8_t         xoa_nodump;
420         uint8_t         xoa_settable;
421         uint8_t         xoa_opaque;
422         uint8_t         xoa_av_quarantined;
423         uint8_t         xoa_av_modified;
424         uint8_t         xoa_av_scanstamp[AV_SCANSTAMP_SZ];
425         uint8_t         xoa_reparse;
426         uint8_t         xoa_offline;
427         uint8_t         xoa_sparse;
428 } xoptattr_t;
429
430 typedef struct vattr {
431         uint_t          va_mask;        /* bit-mask of attributes */
432         u_offset_t      va_size;        /* file size in bytes */
433 } vattr_t;
434
435
436 typedef struct xvattr {
437         vattr_t         xva_vattr;      /* Embedded vattr structure */
438         uint32_t        xva_magic;      /* Magic Number */
439         uint32_t        xva_mapsize;    /* Size of attr bitmap (32-bit words) */
440         uint32_t        *xva_rtnattrmapp;       /* Ptr to xva_rtnattrmap[] */
441         uint32_t        xva_reqattrmap[XVA_MAPSIZE];    /* Requested attrs */
442         uint32_t        xva_rtnattrmap[XVA_MAPSIZE];    /* Returned attrs */
443         xoptattr_t      xva_xoptattrs;  /* Optional attributes */
444 } xvattr_t;
445
446 typedef struct vsecattr {
447         uint_t          vsa_mask;       /* See below */
448         int             vsa_aclcnt;     /* ACL entry count */
449         void            *vsa_aclentp;   /* pointer to ACL entries */
450         int             vsa_dfaclcnt;   /* default ACL entry count */
451         void            *vsa_dfaclentp; /* pointer to default ACL entries */
452         size_t          vsa_aclentsz;   /* ACE size in bytes of vsa_aclentp */
453 } vsecattr_t;
454
455 #define AT_TYPE         0x00001
456 #define AT_MODE         0x00002
457 #define AT_UID          0x00004
458 #define AT_GID          0x00008
459 #define AT_FSID         0x00010
460 #define AT_NODEID       0x00020
461 #define AT_NLINK        0x00040
462 #define AT_SIZE         0x00080
463 #define AT_ATIME        0x00100
464 #define AT_MTIME        0x00200
465 #define AT_CTIME        0x00400
466 #define AT_RDEV         0x00800
467 #define AT_BLKSIZE      0x01000
468 #define AT_NBLOCKS      0x02000
469 #define AT_SEQ          0x08000
470 #define AT_XVATTR       0x10000
471
472 #define CRCREAT         0
473
474 extern int fop_getattr(vnode_t *vp, vattr_t *vap);
475
476 #define VOP_CLOSE(vp, f, c, o, cr, ct)  0
477 #define VOP_PUTPAGE(vp, of, sz, fl, cr, ct)     0
478 #define VOP_GETATTR(vp, vap, cr)  fop_getattr((vp), (vap));
479
480 #define VOP_FSYNC(vp, f, cr, ct)        fsync((vp)->v_fd)
481
482 #define VN_RELE(vp)                     vn_close(vp, 0, NULL, NULL)
483 #define VN_RELE_ASYNC(vp, taskq)        vn_close(vp, 0, NULL, NULL)
484
485 #define vn_lock(vp, type)
486 #define VOP_UNLOCK(vp, type)
487 #ifdef VFS_LOCK_GIANT
488 #undef VFS_LOCK_GIANT
489 #endif
490 #define VFS_LOCK_GIANT(mp)      0
491 #ifdef VFS_UNLOCK_GIANT
492 #undef VFS_UNLOCK_GIANT
493 #endif
494 #define VFS_UNLOCK_GIANT(vfslocked)
495
496 extern int vn_open(char *path, int x1, int oflags, int mode, vnode_t **vpp,
497     int x2, int x3);
498 extern int vn_openat(char *path, int x1, int oflags, int mode, vnode_t **vpp,
499     int x2, int x3, vnode_t *vp, int fd);
500 extern int vn_rdwr(int uio, vnode_t *vp, void *addr, ssize_t len,
501     offset_t offset, int x1, int x2, rlim64_t x3, void *x4, ssize_t *residp);
502 extern void vn_close(vnode_t *vp, int openflag, cred_t *cr, kthread_t *td);
503
504 #define vn_remove(path, x1, x2)         remove(path)
505 #define vn_rename(from, to, seg)        rename((from), (to))
506 #define vn_is_readonly(vp)              B_FALSE
507
508 extern vnode_t *rootdir;
509
510 #include <sys/file.h>           /* for FREAD, FWRITE, etc */
511 #define FTRUNC  O_TRUNC
512
513 /*
514  * Random stuff
515  */
516 #define ddi_get_lbolt()         (gethrtime() >> 23)
517 #define ddi_get_lbolt64()       (gethrtime() >> 23)
518 #define hz      119     /* frequency when using gethrtime() >> 23 for lbolt */
519
520 extern void delay(clock_t ticks);
521
522 #define SEC_TO_TICK(sec)        ((sec) * hz)
523 #define NSEC_TO_TICK(usec)      ((usec) / (NANOSEC / hz))
524
525 #define gethrestime_sec() time(NULL)
526 #define gethrestime(t) \
527         do {\
528                 (t)->tv_sec = gethrestime_sec();\
529                 (t)->tv_nsec = 0;\
530         } while (0);
531
532 #define max_ncpus       64
533
534 #define minclsyspri     60
535 #define maxclsyspri     99
536
537 #define CPU_SEQID       (thr_self() & (max_ncpus - 1))
538
539 #define kcred           NULL
540 #define CRED()          NULL
541
542 #ifndef ptob
543 #define ptob(x)         ((x) * PAGESIZE)
544 #endif
545
546 extern uint64_t physmem;
547
548 extern int highbit(ulong_t i);
549 extern int random_get_bytes(uint8_t *ptr, size_t len);
550 extern int random_get_pseudo_bytes(uint8_t *ptr, size_t len);
551
552 extern void kernel_init(int);
553 extern void kernel_fini(void);
554
555 struct spa;
556 extern void nicenum(uint64_t num, char *buf);
557 extern void show_pool_stats(struct spa *);
558
559 typedef struct callb_cpr {
560         kmutex_t        *cc_lockp;
561 } callb_cpr_t;
562
563 #define CALLB_CPR_INIT(cp, lockp, func, name)   {               \
564         (cp)->cc_lockp = lockp;                                 \
565 }
566
567 #define CALLB_CPR_SAFE_BEGIN(cp) {                              \
568         ASSERT(MUTEX_HELD((cp)->cc_lockp));                     \
569 }
570
571 #define CALLB_CPR_SAFE_END(cp, lockp) {                         \
572         ASSERT(MUTEX_HELD((cp)->cc_lockp));                     \
573 }
574
575 #define CALLB_CPR_EXIT(cp) {                                    \
576         ASSERT(MUTEX_HELD((cp)->cc_lockp));                     \
577         mutex_exit((cp)->cc_lockp);                             \
578 }
579
580 #define zone_dataset_visible(x, y)      (1)
581 #define INGLOBALZONE(z)                 (1)
582
583 extern char *kmem_asprintf(const char *fmt, ...);
584 #define strfree(str) kmem_free((str), strlen(str) + 1)
585
586 /*
587  * Hostname information
588  */
589 extern struct utsname utsname;
590 extern char hw_serial[];        /* for userland-emulated hostid access */
591 extern int ddi_strtoul(const char *str, char **nptr, int base,
592     unsigned long *result);
593
594 extern int ddi_strtoull(const char *str, char **nptr, int base,
595     u_longlong_t *result);
596
597 /* ZFS Boot Related stuff. */
598
599 struct _buf {
600         intptr_t        _fd;
601 };
602
603 struct bootstat {
604         uint64_t st_size;
605 };
606
607 typedef struct ace_object {
608         uid_t           a_who;
609         uint32_t        a_access_mask;
610         uint16_t        a_flags;
611         uint16_t        a_type;
612         uint8_t         a_obj_type[16];
613         uint8_t         a_inherit_obj_type[16];
614 } ace_object_t;
615
616
617 #define ACE_ACCESS_ALLOWED_OBJECT_ACE_TYPE      0x05
618 #define ACE_ACCESS_DENIED_OBJECT_ACE_TYPE       0x06
619 #define ACE_SYSTEM_AUDIT_OBJECT_ACE_TYPE        0x07
620 #define ACE_SYSTEM_ALARM_OBJECT_ACE_TYPE        0x08
621
622 extern struct _buf *kobj_open_file(char *name);
623 extern int kobj_read_file(struct _buf *file, char *buf, unsigned size,
624     unsigned off);
625 extern void kobj_close_file(struct _buf *file);
626 extern int kobj_get_filesize(struct _buf *file, uint64_t *size);
627 extern int zfs_secpolicy_snapshot_perms(const char *name, cred_t *cr);
628 extern int zfs_secpolicy_rename_perms(const char *from, const char *to,
629     cred_t *cr);
630 extern int zfs_secpolicy_destroy_perms(const char *name, cred_t *cr);
631 extern zoneid_t getzoneid(void);
632 /* Random compatibility stuff. */
633 #define lbolt   (gethrtime() >> 23)
634 #define lbolt64 (gethrtime() >> 23)
635
636 extern uint64_t physmem;
637
638 #define gethrestime_sec()       time(NULL)
639
640 #define pwrite64(d, p, n, o)    pwrite(d, p, n, o)
641 #define readdir64(d)            readdir(d)
642 #define SIGPENDING(td)          (0)
643 #define root_mount_wait()       do { } while (0)
644 #define root_mounted()          (1)
645
646 struct file {
647         void *dummy;
648 };
649
650 #define FCREAT  O_CREAT
651 #define FOFFMAX 0x0
652
653 /* SID stuff */
654 typedef struct ksiddomain {
655         uint_t  kd_ref;
656         uint_t  kd_len;
657         char    *kd_name;
658 } ksiddomain_t;
659
660 ksiddomain_t *ksid_lookupdomain(const char *);
661 void ksiddomain_rele(ksiddomain_t *);
662
663 typedef uint32_t        idmap_rid_t;
664
665 #define DDI_SLEEP       KM_SLEEP
666 #define ddi_log_sysevent(_a, _b, _c, _d, _e, _f, _g)    (0)
667
668 #define SX_SYSINIT(name, lock, desc)
669
670 #define SYSCTL_DECL(...)
671 #define SYSCTL_NODE(...)
672 #define SYSCTL_INT(...)
673 #define SYSCTL_UINT(...)
674 #define SYSCTL_ULONG(...)
675 #define SYSCTL_QUAD(...)
676 #define SYSCTL_UQUAD(...)
677 #ifdef TUNABLE_INT
678 #undef TUNABLE_INT
679 #undef TUNABLE_ULONG
680 #undef TUNABLE_QUAD
681 #endif
682 #define TUNABLE_INT(...)
683 #define TUNABLE_ULONG(...)
684 #define TUNABLE_QUAD(...)
685
686 /* Errors */
687
688 #ifndef ERESTART
689 #define ERESTART        (-1)
690 #endif
691
692 #ifdef illumos
693 /*
694  * Cyclic information
695  */
696 extern kmutex_t cpu_lock;
697
698 typedef uintptr_t cyclic_id_t;
699 typedef uint16_t cyc_level_t;
700 typedef void (*cyc_func_t)(void *);
701
702 #define CY_LOW_LEVEL    0
703 #define CY_INFINITY     INT64_MAX
704 #define CYCLIC_NONE     ((cyclic_id_t)0)
705
706 typedef struct cyc_time {
707         hrtime_t cyt_when;
708         hrtime_t cyt_interval;
709 } cyc_time_t;
710
711 typedef struct cyc_handler {
712         cyc_func_t cyh_func;
713         void *cyh_arg;
714         cyc_level_t cyh_level;
715 } cyc_handler_t;
716
717 extern cyclic_id_t cyclic_add(cyc_handler_t *, cyc_time_t *);
718 extern void cyclic_remove(cyclic_id_t);
719 extern int cyclic_reprogram(cyclic_id_t, hrtime_t);
720 #endif  /* illumos */
721
722 #ifdef  __cplusplus
723 }
724 #endif
725
726 #endif  /* _SYS_ZFS_CONTEXT_H */