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