]> Pileus Git - ~andy/linux/blob - fs/kernfs/kernfs-internal.h
933ac8d5d07ae29082294db6a8d44057737135b3
[~andy/linux] / fs / kernfs / kernfs-internal.h
1 /*
2  * fs/kernfs/kernfs-internal.h - kernfs internal header file
3  *
4  * Copyright (c) 2001-3 Patrick Mochel
5  * Copyright (c) 2007 SUSE Linux Products GmbH
6  * Copyright (c) 2007, 2013 Tejun Heo <teheo@suse.de>
7  *
8  * This file is released under the GPLv2.
9  */
10
11 #ifndef __KERNFS_INTERNAL_H
12 #define __KERNFS_INTERNAL_H
13
14 #include <linux/lockdep.h>
15 #include <linux/fs.h>
16 #include <linux/rbtree.h>
17
18 #include <linux/kernfs.h>
19
20 struct sysfs_open_dirent;
21
22 /* type-specific structures for sysfs_dirent->s_* union members */
23 struct sysfs_elem_dir {
24         unsigned long           subdirs;
25         /* children rbtree starts here and goes through sd->s_rb */
26         struct rb_root          children;
27 };
28
29 struct sysfs_elem_symlink {
30         struct sysfs_dirent     *target_sd;
31 };
32
33 struct sysfs_elem_attr {
34         const struct kernfs_ops *ops;
35         struct sysfs_open_dirent *open;
36         loff_t                  size;
37 };
38
39 struct sysfs_inode_attrs {
40         struct iattr    ia_iattr;
41         void            *ia_secdata;
42         u32             ia_secdata_len;
43 };
44
45 /*
46  * sysfs_dirent - the building block of sysfs hierarchy.  Each and
47  * every sysfs node is represented by single sysfs_dirent.
48  *
49  * As long as s_count reference is held, the sysfs_dirent itself is
50  * accessible.  Dereferencing s_elem or any other outer entity
51  * requires s_active reference.
52  */
53 struct sysfs_dirent {
54         atomic_t                s_count;
55         atomic_t                s_active;
56 #ifdef CONFIG_DEBUG_LOCK_ALLOC
57         struct lockdep_map      dep_map;
58 #endif
59         struct sysfs_dirent     *s_parent;
60         const char              *s_name;
61
62         struct rb_node          s_rb;
63
64         union {
65                 struct completion       *completion;
66                 struct sysfs_dirent     *removed_list;
67         } u;
68
69         const void              *s_ns; /* namespace tag */
70         unsigned int            s_hash; /* ns + name hash */
71         union {
72                 struct sysfs_elem_dir           s_dir;
73                 struct sysfs_elem_symlink       s_symlink;
74                 struct sysfs_elem_attr          s_attr;
75         };
76
77         void                    *priv;
78
79         unsigned short          s_flags;
80         umode_t                 s_mode;
81         unsigned int            s_ino;
82         struct sysfs_inode_attrs *s_iattr;
83 };
84
85 #define SD_DEACTIVATED_BIAS             INT_MIN
86
87 #define SYSFS_TYPE_MASK                 0x000f
88 #define SYSFS_DIR                       0x0001
89 #define SYSFS_KOBJ_ATTR                 0x0002
90 #define SYSFS_KOBJ_LINK                 0x0004
91 #define SYSFS_COPY_NAME                 (SYSFS_DIR | SYSFS_KOBJ_LINK)
92 #define SYSFS_ACTIVE_REF                SYSFS_KOBJ_ATTR
93
94 #define SYSFS_FLAG_MASK                 ~SYSFS_TYPE_MASK
95 #define SYSFS_FLAG_REMOVED              0x0010
96 #define SYSFS_FLAG_NS                   0x0020
97 #define SYSFS_FLAG_HAS_SEQ_SHOW         0x0040
98 #define SYSFS_FLAG_HAS_MMAP             0x0080
99 #define SYSFS_FLAG_LOCKDEP              0x0100
100
101 static inline unsigned int sysfs_type(struct sysfs_dirent *sd)
102 {
103         return sd->s_flags & SYSFS_TYPE_MASK;
104 }
105
106 /*
107  * Context structure to be used while adding/removing nodes.
108  */
109 struct sysfs_addrm_cxt {
110         struct sysfs_dirent     *removed;
111 };
112
113 #include "../sysfs/sysfs.h"
114
115 /*
116  * inode.c
117  */
118 struct inode *sysfs_get_inode(struct super_block *sb, struct sysfs_dirent *sd);
119 void sysfs_evict_inode(struct inode *inode);
120 int sysfs_permission(struct inode *inode, int mask);
121 int sysfs_setattr(struct dentry *dentry, struct iattr *iattr);
122 int sysfs_getattr(struct vfsmount *mnt, struct dentry *dentry,
123                   struct kstat *stat);
124 int sysfs_setxattr(struct dentry *dentry, const char *name, const void *value,
125                    size_t size, int flags);
126 int sysfs_inode_init(void);
127
128 #endif  /* __KERNFS_INTERNAL_H */