blob: 38e3a163e5ad8fa9a48a0a8e32ad9a693e359b11 [file] [log] [blame]
Tejun Heoae6621b2013-11-28 14:54:31 -05001/*
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>
Tejun Heofd7b9f72013-11-28 14:54:33 -050017#include <linux/mutex.h>
Tejun Heoae6621b2013-11-28 14:54:31 -050018
19#include <linux/kernfs.h>
20
21struct sysfs_open_dirent;
22
23/* type-specific structures for sysfs_dirent->s_* union members */
24struct 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
30struct sysfs_elem_symlink {
31 struct sysfs_dirent *target_sd;
32};
33
34struct sysfs_elem_attr {
35 const struct kernfs_ops *ops;
36 struct sysfs_open_dirent *open;
37 loff_t size;
38};
39
40struct 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 */
54struct 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
102static 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 */
110struct sysfs_addrm_cxt {
111 struct sysfs_dirent *removed;
112};
113
114#include "../sysfs/sysfs.h"
115
Tejun Heoffed24e2013-11-28 14:54:32 -0500116/*
117 * inode.c
118 */
119struct inode *sysfs_get_inode(struct super_block *sb, struct sysfs_dirent *sd);
120void sysfs_evict_inode(struct inode *inode);
121int sysfs_permission(struct inode *inode, int mask);
122int sysfs_setattr(struct dentry *dentry, struct iattr *iattr);
123int sysfs_getattr(struct vfsmount *mnt, struct dentry *dentry,
124 struct kstat *stat);
125int sysfs_setxattr(struct dentry *dentry, const char *name, const void *value,
126 size_t size, int flags);
127int sysfs_inode_init(void);
128
Tejun Heofd7b9f72013-11-28 14:54:33 -0500129/*
130 * dir.c
131 */
132extern struct mutex sysfs_mutex;
133extern const struct dentry_operations sysfs_dentry_ops;
134extern const struct file_operations sysfs_dir_operations;
135extern const struct inode_operations sysfs_dir_inode_operations;
136
137struct sysfs_dirent *sysfs_get_active(struct sysfs_dirent *sd);
138void sysfs_put_active(struct sysfs_dirent *sd);
139void sysfs_addrm_start(struct sysfs_addrm_cxt *acxt);
140int sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd,
141 struct sysfs_dirent *parent_sd);
142void sysfs_addrm_finish(struct sysfs_addrm_cxt *acxt);
143struct sysfs_dirent *sysfs_new_dirent(const char *name, umode_t mode, int type);
144
Tejun Heo414985a2013-11-28 14:54:34 -0500145/*
146 * file.c
147 */
148extern const struct file_operations kernfs_file_operations;
149
150void sysfs_unmap_bin_file(struct sysfs_dirent *sd);
151
Tejun Heoae6621b2013-11-28 14:54:31 -0500152#endif /* __KERNFS_INTERNAL_H */