155716d26SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */ 2ae6621b0STejun Heo /* 3ae6621b0STejun Heo * fs/kernfs/kernfs-internal.h - kernfs internal header file 4ae6621b0STejun Heo * 5ae6621b0STejun Heo * Copyright (c) 2001-3 Patrick Mochel 6ae6621b0STejun Heo * Copyright (c) 2007 SUSE Linux Products GmbH 7ae6621b0STejun Heo * Copyright (c) 2007, 2013 Tejun Heo <teheo@suse.de> 8ae6621b0STejun Heo */ 9ae6621b0STejun Heo 10ae6621b0STejun Heo #ifndef __KERNFS_INTERNAL_H 11ae6621b0STejun Heo #define __KERNFS_INTERNAL_H 12ae6621b0STejun Heo 13ae6621b0STejun Heo #include <linux/lockdep.h> 14ae6621b0STejun Heo #include <linux/fs.h> 15fd7b9f7bSTejun Heo #include <linux/mutex.h> 162322392bSTejun Heo #include <linux/xattr.h> 17ae6621b0STejun Heo 18ae6621b0STejun Heo #include <linux/kernfs.h> 1923bf1b6bSDavid Howells #include <linux/fs_context.h> 20ae6621b0STejun Heo 21c525aaddSTejun Heo struct kernfs_iattrs { 2205895219SOndrej Mosnacek kuid_t ia_uid; 2305895219SOndrej Mosnacek kgid_t ia_gid; 2405895219SOndrej Mosnacek struct timespec64 ia_atime; 2505895219SOndrej Mosnacek struct timespec64 ia_mtime; 2605895219SOndrej Mosnacek struct timespec64 ia_ctime; 272322392bSTejun Heo 282322392bSTejun Heo struct simple_xattrs xattrs; 290c47383bSDaniel Xu atomic_t nr_user_xattrs; 300c47383bSDaniel Xu atomic_t user_xattr_size; 31ae6621b0STejun Heo }; 32ae6621b0STejun Heo 3381c173cbSTejun Heo /* +1 to avoid triggering overflow warning when negating it */ 3481c173cbSTejun Heo #define KN_DEACTIVATED_BIAS (INT_MIN + 1) 35ae6621b0STejun Heo 36df23fc39STejun Heo /* KERNFS_TYPE_MASK and types are defined in include/linux/kernfs.h */ 37ae6621b0STejun Heo 38ba7443bcSTejun Heo /** 39324a56e1STejun Heo * kernfs_root - find out the kernfs_root a kernfs_node belongs to 40324a56e1STejun Heo * @kn: kernfs_node of interest 41ba7443bcSTejun Heo * 42324a56e1STejun Heo * Return the kernfs_root @kn belongs to. 43ba7443bcSTejun Heo */ 44324a56e1STejun Heo static inline struct kernfs_root *kernfs_root(struct kernfs_node *kn) 45ba7443bcSTejun Heo { 46ba7443bcSTejun Heo /* if parent exists, it's always a dir; otherwise, @sd is a dir */ 47adc5e8b5STejun Heo if (kn->parent) 48adc5e8b5STejun Heo kn = kn->parent; 49adc5e8b5STejun Heo return kn->dir.root; 50ba7443bcSTejun Heo } 51ba7443bcSTejun Heo 52ae6621b0STejun Heo /* 53fa736a95STejun Heo * mount.c 54fa736a95STejun Heo */ 55c525aaddSTejun Heo struct kernfs_super_info { 567d568a83STejun Heo struct super_block *sb; 577d568a83STejun Heo 58fa736a95STejun Heo /* 59fa736a95STejun Heo * The root associated with this super_block. Each super_block is 60fa736a95STejun Heo * identified by the root and ns it's associated with. 61fa736a95STejun Heo */ 62fa736a95STejun Heo struct kernfs_root *root; 63fa736a95STejun Heo 64fa736a95STejun Heo /* 65324a56e1STejun Heo * Each sb is associated with one namespace tag, currently the 66c525aaddSTejun Heo * network namespace of the task which mounted this kernfs 67c525aaddSTejun Heo * instance. If multiple tags become necessary, make the following 68c525aaddSTejun Heo * an array and compare kernfs_node tag against every entry. 69fa736a95STejun Heo */ 70fa736a95STejun Heo const void *ns; 717d568a83STejun Heo 727d568a83STejun Heo /* anchored at kernfs_root->supers, protected by kernfs_mutex */ 737d568a83STejun Heo struct list_head node; 74fa736a95STejun Heo }; 75c525aaddSTejun Heo #define kernfs_info(SB) ((struct kernfs_super_info *)(SB->s_fs_info)) 76fa736a95STejun Heo 77319ba91dSShaohua Li static inline struct kernfs_node *kernfs_dentry_node(struct dentry *dentry) 78319ba91dSShaohua Li { 79319ba91dSShaohua Li if (d_really_is_negative(dentry)) 80319ba91dSShaohua Li return NULL; 81319ba91dSShaohua Li return d_inode(dentry)->i_private; 82319ba91dSShaohua Li } 83319ba91dSShaohua Li 84f41c5934SLi Zefan extern const struct super_operations kernfs_sops; 8526e28d68SAyush Mittal extern struct kmem_cache *kernfs_node_cache, *kernfs_iattrs_cache; 86fa736a95STejun Heo 87fa736a95STejun Heo /* 88ffed24e2STejun Heo * inode.c 89ffed24e2STejun Heo */ 90e72a1a8bSAndreas Gruenbacher extern const struct xattr_handler *kernfs_xattr_handlers[]; 91c637b8acSTejun Heo void kernfs_evict_inode(struct inode *inode); 92*549c7297SChristian Brauner int kernfs_iop_permission(struct user_namespace *mnt_userns, 93*549c7297SChristian Brauner struct inode *inode, int mask); 94*549c7297SChristian Brauner int kernfs_iop_setattr(struct user_namespace *mnt_userns, struct dentry *dentry, 95*549c7297SChristian Brauner struct iattr *iattr); 96*549c7297SChristian Brauner int kernfs_iop_getattr(struct user_namespace *mnt_userns, 97*549c7297SChristian Brauner const struct path *path, struct kstat *stat, 98a528d35eSDavid Howells u32 request_mask, unsigned int query_flags); 99c637b8acSTejun Heo ssize_t kernfs_iop_listxattr(struct dentry *dentry, char *buf, size_t size); 100488dee96SDmitry Torokhov int __kernfs_setattr(struct kernfs_node *kn, const struct iattr *iattr); 101ffed24e2STejun Heo 102fd7b9f7bSTejun Heo /* 103fd7b9f7bSTejun Heo * dir.c 104fd7b9f7bSTejun Heo */ 105a797bfc3STejun Heo extern struct mutex kernfs_mutex; 106a797bfc3STejun Heo extern const struct dentry_operations kernfs_dops; 107a797bfc3STejun Heo extern const struct file_operations kernfs_dir_fops; 108a797bfc3STejun Heo extern const struct inode_operations kernfs_dir_iops; 109fd7b9f7bSTejun Heo 110c637b8acSTejun Heo struct kernfs_node *kernfs_get_active(struct kernfs_node *kn); 111c637b8acSTejun Heo void kernfs_put_active(struct kernfs_node *kn); 112988cd7afSTejun Heo int kernfs_add_one(struct kernfs_node *kn); 113db4aad20STejun Heo struct kernfs_node *kernfs_new_node(struct kernfs_node *parent, 114db4aad20STejun Heo const char *name, umode_t mode, 115488dee96SDmitry Torokhov kuid_t uid, kgid_t gid, 116db4aad20STejun Heo unsigned flags); 117fd7b9f7bSTejun Heo 118414985aeSTejun Heo /* 119414985aeSTejun Heo * file.c 120414985aeSTejun Heo */ 121a797bfc3STejun Heo extern const struct file_operations kernfs_file_fops; 122414985aeSTejun Heo 1230e67db2fSTejun Heo void kernfs_drain_open_files(struct kernfs_node *kn); 124414985aeSTejun Heo 1252072f1afSTejun Heo /* 1262072f1afSTejun Heo * symlink.c 1272072f1afSTejun Heo */ 128a797bfc3STejun Heo extern const struct inode_operations kernfs_symlink_iops; 1292072f1afSTejun Heo 130ae6621b0STejun Heo #endif /* __KERNFS_INTERNAL_H */ 131