31f0dbe1881b3fa2e5e8e3347a30cd5b70df0c09
[platform/adaptation/renesas_rcar/renesas_kernel.git] / 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 #include <linux/mutex.h>
18
19 #include <linux/kernfs.h>
20
21 struct sysfs_open_dirent;
22
23 /* type-specific structures for sysfs_dirent->s_* union members */
24 struct sysfs_elem_dir {
25         unsigned long           subdirs;
26         /* children rbtree starts here and goes through sd->s_rb */
27         struct rb_root          children;
28 };
29
30 struct sysfs_elem_symlink {
31         struct sysfs_dirent     *target_sd;
32 };
33
34 struct sysfs_elem_attr {
35         const struct kernfs_ops *ops;
36         struct sysfs_open_dirent *open;
37         loff_t                  size;
38 };
39
40 struct sysfs_inode_attrs {
41         struct iattr    ia_iattr;
42         void            *ia_secdata;
43         u32             ia_secdata_len;
44 };
45
46 /*
47  * sysfs_dirent - the building block of sysfs hierarchy.  Each and
48  * every sysfs node is represented by single sysfs_dirent.
49  *
50  * As long as s_count reference is held, the sysfs_dirent itself is
51  * accessible.  Dereferencing s_elem or any other outer entity
52  * requires s_active reference.
53  */
54 struct sysfs_dirent {
55         atomic_t                s_count;
56         atomic_t                s_active;
57 #ifdef CONFIG_DEBUG_LOCK_ALLOC
58         struct lockdep_map      dep_map;
59 #endif
60         struct sysfs_dirent     *s_parent;
61         const char              *s_name;
62
63         struct rb_node          s_rb;
64
65         union {
66                 struct completion       *completion;
67                 struct sysfs_dirent     *removed_list;
68         } u;
69
70         const void              *s_ns; /* namespace tag */
71         unsigned int            s_hash; /* ns + name hash */
72         union {
73                 struct sysfs_elem_dir           s_dir;
74                 struct sysfs_elem_symlink       s_symlink;
75                 struct sysfs_elem_attr          s_attr;
76         };
77
78         void                    *priv;
79
80         unsigned short          s_flags;
81         umode_t                 s_mode;
82         unsigned int            s_ino;
83         struct sysfs_inode_attrs *s_iattr;
84 };
85
86 #define SD_DEACTIVATED_BIAS             INT_MIN
87
88 #define SYSFS_TYPE_MASK                 0x000f
89 #define SYSFS_DIR                       0x0001
90 #define SYSFS_KOBJ_ATTR                 0x0002
91 #define SYSFS_KOBJ_LINK                 0x0004
92 #define SYSFS_COPY_NAME                 (SYSFS_DIR | SYSFS_KOBJ_LINK)
93 #define SYSFS_ACTIVE_REF                SYSFS_KOBJ_ATTR
94
95 #define SYSFS_FLAG_MASK                 ~SYSFS_TYPE_MASK
96 #define SYSFS_FLAG_REMOVED              0x0010
97 #define SYSFS_FLAG_NS                   0x0020
98 #define SYSFS_FLAG_HAS_SEQ_SHOW         0x0040
99 #define SYSFS_FLAG_HAS_MMAP             0x0080
100 #define SYSFS_FLAG_LOCKDEP              0x0100
101
102 static inline unsigned int sysfs_type(struct sysfs_dirent *sd)
103 {
104         return sd->s_flags & SYSFS_TYPE_MASK;
105 }
106
107 /*
108  * Context structure to be used while adding/removing nodes.
109  */
110 struct sysfs_addrm_cxt {
111         struct sysfs_dirent     *removed;
112 };
113
114 #include "../sysfs/sysfs.h"
115
116 /*
117  * inode.c
118  */
119 struct inode *sysfs_get_inode(struct super_block *sb, struct sysfs_dirent *sd);
120 void sysfs_evict_inode(struct inode *inode);
121 int sysfs_permission(struct inode *inode, int mask);
122 int sysfs_setattr(struct dentry *dentry, struct iattr *iattr);
123 int sysfs_getattr(struct vfsmount *mnt, struct dentry *dentry,
124                   struct kstat *stat);
125 int sysfs_setxattr(struct dentry *dentry, const char *name, const void *value,
126                    size_t size, int flags);
127 int sysfs_inode_init(void);
128
129 /*
130  * dir.c
131  */
132 extern struct mutex sysfs_mutex;
133 extern const struct dentry_operations sysfs_dentry_ops;
134 extern const struct file_operations sysfs_dir_operations;
135 extern const struct inode_operations sysfs_dir_inode_operations;
136
137 struct sysfs_dirent *sysfs_get_active(struct sysfs_dirent *sd);
138 void sysfs_put_active(struct sysfs_dirent *sd);
139 void sysfs_addrm_start(struct sysfs_addrm_cxt *acxt);
140 int sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd,
141                   struct sysfs_dirent *parent_sd);
142 void sysfs_addrm_finish(struct sysfs_addrm_cxt *acxt);
143 struct sysfs_dirent *sysfs_new_dirent(const char *name, umode_t mode, int type);
144
145 #endif  /* __KERNFS_INTERNAL_H */