Commit | Line | Data |
---|---|---|
55716d26 | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
ae6621b0 TH |
2 | /* |
3 | * fs/kernfs/kernfs-internal.h - kernfs internal header file | |
4 | * | |
5 | * Copyright (c) 2001-3 Patrick Mochel | |
6 | * Copyright (c) 2007 SUSE Linux Products GmbH | |
7 | * Copyright (c) 2007, 2013 Tejun Heo <teheo@suse.de> | |
ae6621b0 TH |
8 | */ |
9 | ||
10 | #ifndef __KERNFS_INTERNAL_H | |
11 | #define __KERNFS_INTERNAL_H | |
12 | ||
13 | #include <linux/lockdep.h> | |
14 | #include <linux/fs.h> | |
fd7b9f7b | 15 | #include <linux/mutex.h> |
2322392b | 16 | #include <linux/xattr.h> |
ae6621b0 TH |
17 | |
18 | #include <linux/kernfs.h> | |
23bf1b6b | 19 | #include <linux/fs_context.h> |
ae6621b0 | 20 | |
c525aadd | 21 | struct kernfs_iattrs { |
05895219 OM |
22 | kuid_t ia_uid; |
23 | kgid_t ia_gid; | |
24 | struct timespec64 ia_atime; | |
25 | struct timespec64 ia_mtime; | |
26 | struct timespec64 ia_ctime; | |
2322392b TH |
27 | |
28 | struct simple_xattrs xattrs; | |
0c47383b DX |
29 | atomic_t nr_user_xattrs; |
30 | atomic_t user_xattr_size; | |
ae6621b0 TH |
31 | }; |
32 | ||
81c173cb TH |
33 | /* +1 to avoid triggering overflow warning when negating it */ |
34 | #define KN_DEACTIVATED_BIAS (INT_MIN + 1) | |
ae6621b0 | 35 | |
df23fc39 | 36 | /* KERNFS_TYPE_MASK and types are defined in include/linux/kernfs.h */ |
ae6621b0 | 37 | |
ba7443bc | 38 | /** |
324a56e1 TH |
39 | * kernfs_root - find out the kernfs_root a kernfs_node belongs to |
40 | * @kn: kernfs_node of interest | |
ba7443bc | 41 | * |
324a56e1 | 42 | * Return the kernfs_root @kn belongs to. |
ba7443bc | 43 | */ |
324a56e1 | 44 | static inline struct kernfs_root *kernfs_root(struct kernfs_node *kn) |
ba7443bc TH |
45 | { |
46 | /* if parent exists, it's always a dir; otherwise, @sd is a dir */ | |
adc5e8b5 TH |
47 | if (kn->parent) |
48 | kn = kn->parent; | |
49 | return kn->dir.root; | |
ba7443bc TH |
50 | } |
51 | ||
fa736a95 TH |
52 | /* |
53 | * mount.c | |
54 | */ | |
c525aadd | 55 | struct kernfs_super_info { |
7d568a83 TH |
56 | struct super_block *sb; |
57 | ||
fa736a95 TH |
58 | /* |
59 | * The root associated with this super_block. Each super_block is | |
60 | * identified by the root and ns it's associated with. | |
61 | */ | |
62 | struct kernfs_root *root; | |
63 | ||
64 | /* | |
324a56e1 | 65 | * Each sb is associated with one namespace tag, currently the |
c525aadd TH |
66 | * network namespace of the task which mounted this kernfs |
67 | * instance. If multiple tags become necessary, make the following | |
68 | * an array and compare kernfs_node tag against every entry. | |
fa736a95 TH |
69 | */ |
70 | const void *ns; | |
7d568a83 TH |
71 | |
72 | /* anchored at kernfs_root->supers, protected by kernfs_mutex */ | |
73 | struct list_head node; | |
fa736a95 | 74 | }; |
c525aadd | 75 | #define kernfs_info(SB) ((struct kernfs_super_info *)(SB->s_fs_info)) |
fa736a95 | 76 | |
319ba91d SL |
77 | static inline struct kernfs_node *kernfs_dentry_node(struct dentry *dentry) |
78 | { | |
79 | if (d_really_is_negative(dentry)) | |
80 | return NULL; | |
81 | return d_inode(dentry)->i_private; | |
82 | } | |
83 | ||
f41c5934 | 84 | extern const struct super_operations kernfs_sops; |
26e28d68 | 85 | extern struct kmem_cache *kernfs_node_cache, *kernfs_iattrs_cache; |
fa736a95 | 86 | |
ffed24e2 TH |
87 | /* |
88 | * inode.c | |
89 | */ | |
e72a1a8b | 90 | extern const struct xattr_handler *kernfs_xattr_handlers[]; |
c637b8ac TH |
91 | void kernfs_evict_inode(struct inode *inode); |
92 | int kernfs_iop_permission(struct inode *inode, int mask); | |
93 | int kernfs_iop_setattr(struct dentry *dentry, struct iattr *iattr); | |
a528d35e DH |
94 | int kernfs_iop_getattr(const struct path *path, struct kstat *stat, |
95 | u32 request_mask, unsigned int query_flags); | |
c637b8ac | 96 | ssize_t kernfs_iop_listxattr(struct dentry *dentry, char *buf, size_t size); |
488dee96 | 97 | int __kernfs_setattr(struct kernfs_node *kn, const struct iattr *iattr); |
ffed24e2 | 98 | |
fd7b9f7b TH |
99 | /* |
100 | * dir.c | |
101 | */ | |
a797bfc3 TH |
102 | extern struct mutex kernfs_mutex; |
103 | extern const struct dentry_operations kernfs_dops; | |
104 | extern const struct file_operations kernfs_dir_fops; | |
105 | extern const struct inode_operations kernfs_dir_iops; | |
fd7b9f7b | 106 | |
c637b8ac TH |
107 | struct kernfs_node *kernfs_get_active(struct kernfs_node *kn); |
108 | void kernfs_put_active(struct kernfs_node *kn); | |
988cd7af | 109 | int kernfs_add_one(struct kernfs_node *kn); |
db4aad20 TH |
110 | struct kernfs_node *kernfs_new_node(struct kernfs_node *parent, |
111 | const char *name, umode_t mode, | |
488dee96 | 112 | kuid_t uid, kgid_t gid, |
db4aad20 | 113 | unsigned flags); |
fd7b9f7b | 114 | |
414985ae TH |
115 | /* |
116 | * file.c | |
117 | */ | |
a797bfc3 | 118 | extern const struct file_operations kernfs_file_fops; |
414985ae | 119 | |
0e67db2f | 120 | void kernfs_drain_open_files(struct kernfs_node *kn); |
414985ae | 121 | |
2072f1af TH |
122 | /* |
123 | * symlink.c | |
124 | */ | |
a797bfc3 | 125 | extern const struct inode_operations kernfs_symlink_iops; |
2072f1af | 126 | |
ae6621b0 | 127 | #endif /* __KERNFS_INTERNAL_H */ |