blob: 7ee97ef59184d190d31cafde86190bc3f593990b [file] [log] [blame]
Thomas Gleixner55716d22019-06-01 10:08:42 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Tejun Heoae6621b2013-11-28 14:54:31 -05002/*
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>
Tejun Heoae6621b2013-11-28 14:54:31 -05008 */
9
10#ifndef __KERNFS_INTERNAL_H
11#define __KERNFS_INTERNAL_H
12
13#include <linux/lockdep.h>
14#include <linux/fs.h>
Tejun Heofd7b9f72013-11-28 14:54:33 -050015#include <linux/mutex.h>
Tejun Heo23223922013-11-23 17:40:02 -050016#include <linux/xattr.h>
Tejun Heoae6621b2013-11-28 14:54:31 -050017
18#include <linux/kernfs.h>
David Howells23bf1b62018-11-01 23:07:26 +000019#include <linux/fs_context.h>
Tejun Heoae6621b2013-11-28 14:54:31 -050020
Tejun Heoc525aad2013-12-11 14:11:55 -050021struct kernfs_iattrs {
Ondrej Mosnacek05895212019-02-22 15:57:12 +010022 kuid_t ia_uid;
23 kgid_t ia_gid;
24 struct timespec64 ia_atime;
25 struct timespec64 ia_mtime;
26 struct timespec64 ia_ctime;
Tejun Heo23223922013-11-23 17:40:02 -050027
28 struct simple_xattrs xattrs;
Daniel Xu0c473832020-03-12 13:03:16 -070029 atomic_t nr_user_xattrs;
30 atomic_t user_xattr_size;
Tejun Heoae6621b2013-11-28 14:54:31 -050031};
32
Tejun Heo81c173c2014-02-03 14:03:00 -050033/* +1 to avoid triggering overflow warning when negating it */
34#define KN_DEACTIVATED_BIAS (INT_MIN + 1)
Tejun Heoae6621b2013-11-28 14:54:31 -050035
Tejun Heodf23fc32013-12-11 14:11:56 -050036/* KERNFS_TYPE_MASK and types are defined in include/linux/kernfs.h */
Tejun Heoae6621b2013-11-28 14:54:31 -050037
Tejun Heoba7443b2013-11-28 14:54:40 -050038/**
Tejun Heo324a56e2013-12-11 14:11:53 -050039 * kernfs_root - find out the kernfs_root a kernfs_node belongs to
40 * @kn: kernfs_node of interest
Tejun Heoba7443b2013-11-28 14:54:40 -050041 *
Tejun Heo324a56e2013-12-11 14:11:53 -050042 * Return the kernfs_root @kn belongs to.
Tejun Heoba7443b2013-11-28 14:54:40 -050043 */
Tejun Heo324a56e2013-12-11 14:11:53 -050044static inline struct kernfs_root *kernfs_root(struct kernfs_node *kn)
Tejun Heoba7443b2013-11-28 14:54:40 -050045{
46 /* if parent exists, it's always a dir; otherwise, @sd is a dir */
Tejun Heoadc5e8b2013-12-11 14:11:54 -050047 if (kn->parent)
48 kn = kn->parent;
49 return kn->dir.root;
Tejun Heoba7443b2013-11-28 14:54:40 -050050}
51
Tejun Heoae6621b2013-11-28 14:54:31 -050052/*
Tejun Heofa736a92013-11-28 14:54:44 -050053 * mount.c
54 */
Tejun Heoc525aad2013-12-11 14:11:55 -050055struct kernfs_super_info {
Tejun Heo7d568a82014-04-09 11:07:30 -040056 struct super_block *sb;
57
Tejun Heofa736a92013-11-28 14:54:44 -050058 /*
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 /*
Tejun Heo324a56e2013-12-11 14:11:53 -050065 * Each sb is associated with one namespace tag, currently the
Tejun Heoc525aad2013-12-11 14:11:55 -050066 * 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.
Tejun Heofa736a92013-11-28 14:54:44 -050069 */
70 const void *ns;
Tejun Heo7d568a82014-04-09 11:07:30 -040071
72 /* anchored at kernfs_root->supers, protected by kernfs_mutex */
73 struct list_head node;
Tejun Heofa736a92013-11-28 14:54:44 -050074};
Tejun Heoc525aad2013-12-11 14:11:55 -050075#define kernfs_info(SB) ((struct kernfs_super_info *)(SB->s_fs_info))
Tejun Heofa736a92013-11-28 14:54:44 -050076
Shaohua Li319ba912017-07-12 11:49:49 -070077static 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
Li Zefanf41c5932014-02-14 16:57:27 +080084extern const struct super_operations kernfs_sops;
Ayush Mittal26e28d62019-02-06 10:25:42 +053085extern struct kmem_cache *kernfs_node_cache, *kernfs_iattrs_cache;
Tejun Heofa736a92013-11-28 14:54:44 -050086
87/*
Tejun Heoffed24e2013-11-28 14:54:32 -050088 * inode.c
89 */
Andreas Gruenbachere72a1a82016-09-29 17:48:33 +020090extern const struct xattr_handler *kernfs_xattr_handlers[];
Tejun Heoc637b8a2013-12-11 14:11:58 -050091void kernfs_evict_inode(struct inode *inode);
92int kernfs_iop_permission(struct inode *inode, int mask);
93int kernfs_iop_setattr(struct dentry *dentry, struct iattr *iattr);
David Howellsa528d352017-01-31 16:46:22 +000094int kernfs_iop_getattr(const struct path *path, struct kstat *stat,
95 u32 request_mask, unsigned int query_flags);
Tejun Heoc637b8a2013-12-11 14:11:58 -050096ssize_t kernfs_iop_listxattr(struct dentry *dentry, char *buf, size_t size);
Dmitry Torokhov488dee92018-07-20 21:56:47 +000097int __kernfs_setattr(struct kernfs_node *kn, const struct iattr *iattr);
Tejun Heoffed24e2013-11-28 14:54:32 -050098
Tejun Heofd7b9f72013-11-28 14:54:33 -050099/*
100 * dir.c
101 */
Tejun Heoa797bfc2013-12-11 14:11:57 -0500102extern struct mutex kernfs_mutex;
103extern const struct dentry_operations kernfs_dops;
104extern const struct file_operations kernfs_dir_fops;
105extern const struct inode_operations kernfs_dir_iops;
Tejun Heofd7b9f72013-11-28 14:54:33 -0500106
Tejun Heoc637b8a2013-12-11 14:11:58 -0500107struct kernfs_node *kernfs_get_active(struct kernfs_node *kn);
108void kernfs_put_active(struct kernfs_node *kn);
Tejun Heo988cd7a2014-02-03 14:02:58 -0500109int kernfs_add_one(struct kernfs_node *kn);
Tejun Heodb4aad22014-01-17 09:58:25 -0500110struct kernfs_node *kernfs_new_node(struct kernfs_node *parent,
111 const char *name, umode_t mode,
Dmitry Torokhov488dee92018-07-20 21:56:47 +0000112 kuid_t uid, kgid_t gid,
Tejun Heodb4aad22014-01-17 09:58:25 -0500113 unsigned flags);
Tejun Heofd7b9f72013-11-28 14:54:33 -0500114
Tejun Heo414985a2013-11-28 14:54:34 -0500115/*
116 * file.c
117 */
Tejun Heoa797bfc2013-12-11 14:11:57 -0500118extern const struct file_operations kernfs_file_fops;
Tejun Heo414985a2013-11-28 14:54:34 -0500119
Tejun Heo0e67db22016-12-27 14:49:03 -0500120void kernfs_drain_open_files(struct kernfs_node *kn);
Tejun Heo414985a2013-11-28 14:54:34 -0500121
Tejun Heo2072f1a2013-11-28 14:54:35 -0500122/*
123 * symlink.c
124 */
Tejun Heoa797bfc2013-12-11 14:11:57 -0500125extern const struct inode_operations kernfs_symlink_iops;
Tejun Heo2072f1a2013-11-28 14:54:35 -0500126
Tejun Heoae6621b2013-11-28 14:54:31 -0500127#endif /* __KERNFS_INTERNAL_H */