PageRenderTime 23ms CodeModel.GetById 19ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/core/10.4/fusefs/fuse_kludges.c

http://macfuse.googlecode.com/
C | 54 lines | 23 code | 8 blank | 23 comment | 0 complexity | 3dffad44844a00bbf07e8a8b59e8cf65 MD5 | raw file
 1/*
 2 * Copyright (C) 2006-2008 Google. All Rights Reserved.
 3 * Amit Singh <singh@>
 4 */
 5
 6#include "fuse_kludges.h"
 7
 8#if M_MACFUSE_ENABLE_EXCHANGE
 9
10extern void
11fuse_kludge_exchange(vnode_t v1, vnode_t v2)
12{
13    char *tmp_v_name = ((struct fuse_kludge_vnode *)v1)->v_name;
14    ((struct fuse_kludge_vnode *)v1)->v_name =
15        ((struct fuse_kludge_vnode *)v2)->v_name;
16    ((struct fuse_kludge_vnode *)v2)->v_name = tmp_v_name;
17
18    vnode_t tmp_v_parent = ((struct fuse_kludge_vnode *)v1)->v_parent;
19    ((struct fuse_kludge_vnode *)v1)->v_parent =
20        ((struct fuse_kludge_vnode *)v2)->v_parent;
21    ((struct fuse_kludge_vnode *)v2)->v_parent = tmp_v_parent;
22}
23
24#endif /* M_MACFUSE_ENABLE_EXCHANGE */
25
26#define MNT_KERN_FLAG_OFFSET 64
27
28#define MNTK_LOCK_LOCAL 0x00100000
29#define MNTK_UNMOUNT    0x01000000
30
31void
32vfs_setlocklocal(mount_t mp)
33{
34    /*
35     * Horrible, horrible kludge. Dangerous to boot. "Boot", heh.
36     * The issue is that we really need to do vfs_setlocklocal(mp),
37     * otherwise we won't have VFS-provided advisory file locking.
38     * Since the kernel's extended attributes needs to create files
39     * with O_EXLOCK set, we need advisory locking for extended
40     * attributes to work properly. Since ACLs depend on extended
41     * attributes, vfs_setlocklocal(mp) keeps becoming critical.
42     *
43     * The kludge is, well, just setting the flag "by hand". This
44     * means I'm hardcoding the offset of the flag word field in the
45     * mount structure, which is internal to the kernel (not exposed
46     * through the KPIs).
47     *
48     * If the field offset changes in future (not likely, but not
49     * guaranteed to remain the same either), the following operation
50     * could result in weird behavior, including a kernel panic.
51     *
52     */
53    *(int *)((char *)mp + MNT_KERN_FLAG_OFFSET) |= MNTK_LOCK_LOCAL;
54}