Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * fs/kernfs/kernfs-internal.h - kernfs internal header file
0004  *
0005  * Copyright (c) 2001-3 Patrick Mochel
0006  * Copyright (c) 2007 SUSE Linux Products GmbH
0007  * Copyright (c) 2007, 2013 Tejun Heo <teheo@suse.de>
0008  */
0009 
0010 #ifndef __KERNFS_INTERNAL_H
0011 #define __KERNFS_INTERNAL_H
0012 
0013 #include <linux/lockdep.h>
0014 #include <linux/fs.h>
0015 #include <linux/mutex.h>
0016 #include <linux/rwsem.h>
0017 #include <linux/xattr.h>
0018 
0019 #include <linux/kernfs.h>
0020 #include <linux/fs_context.h>
0021 
0022 struct kernfs_iattrs {
0023     kuid_t          ia_uid;
0024     kgid_t          ia_gid;
0025     struct timespec64   ia_atime;
0026     struct timespec64   ia_mtime;
0027     struct timespec64   ia_ctime;
0028 
0029     struct simple_xattrs    xattrs;
0030     atomic_t        nr_user_xattrs;
0031     atomic_t        user_xattr_size;
0032 };
0033 
0034 struct kernfs_root {
0035     /* published fields */
0036     struct kernfs_node  *kn;
0037     unsigned int        flags;  /* KERNFS_ROOT_* flags */
0038 
0039     /* private fields, do not use outside kernfs proper */
0040     struct idr      ino_idr;
0041     u32         last_id_lowbits;
0042     u32         id_highbits;
0043     struct kernfs_syscall_ops *syscall_ops;
0044 
0045     /* list of kernfs_super_info of this root, protected by kernfs_rwsem */
0046     struct list_head    supers;
0047 
0048     wait_queue_head_t   deactivate_waitq;
0049     struct rw_semaphore kernfs_rwsem;
0050 };
0051 
0052 /* +1 to avoid triggering overflow warning when negating it */
0053 #define KN_DEACTIVATED_BIAS     (INT_MIN + 1)
0054 
0055 /* KERNFS_TYPE_MASK and types are defined in include/linux/kernfs.h */
0056 
0057 /**
0058  * kernfs_root - find out the kernfs_root a kernfs_node belongs to
0059  * @kn: kernfs_node of interest
0060  *
0061  * Return the kernfs_root @kn belongs to.
0062  */
0063 static inline struct kernfs_root *kernfs_root(struct kernfs_node *kn)
0064 {
0065     /* if parent exists, it's always a dir; otherwise, @sd is a dir */
0066     if (kn->parent)
0067         kn = kn->parent;
0068     return kn->dir.root;
0069 }
0070 
0071 /*
0072  * mount.c
0073  */
0074 struct kernfs_super_info {
0075     struct super_block  *sb;
0076 
0077     /*
0078      * The root associated with this super_block.  Each super_block is
0079      * identified by the root and ns it's associated with.
0080      */
0081     struct kernfs_root  *root;
0082 
0083     /*
0084      * Each sb is associated with one namespace tag, currently the
0085      * network namespace of the task which mounted this kernfs
0086      * instance.  If multiple tags become necessary, make the following
0087      * an array and compare kernfs_node tag against every entry.
0088      */
0089     const void      *ns;
0090 
0091     /* anchored at kernfs_root->supers, protected by kernfs_rwsem */
0092     struct list_head    node;
0093 };
0094 #define kernfs_info(SB) ((struct kernfs_super_info *)(SB->s_fs_info))
0095 
0096 static inline struct kernfs_node *kernfs_dentry_node(struct dentry *dentry)
0097 {
0098     if (d_really_is_negative(dentry))
0099         return NULL;
0100     return d_inode(dentry)->i_private;
0101 }
0102 
0103 static inline void kernfs_set_rev(struct kernfs_node *parent,
0104                   struct dentry *dentry)
0105 {
0106     dentry->d_time = parent->dir.rev;
0107 }
0108 
0109 static inline void kernfs_inc_rev(struct kernfs_node *parent)
0110 {
0111     parent->dir.rev++;
0112 }
0113 
0114 static inline bool kernfs_dir_changed(struct kernfs_node *parent,
0115                       struct dentry *dentry)
0116 {
0117     if (parent->dir.rev != dentry->d_time)
0118         return true;
0119     return false;
0120 }
0121 
0122 extern const struct super_operations kernfs_sops;
0123 extern struct kmem_cache *kernfs_node_cache, *kernfs_iattrs_cache;
0124 
0125 /*
0126  * inode.c
0127  */
0128 extern const struct xattr_handler *kernfs_xattr_handlers[];
0129 void kernfs_evict_inode(struct inode *inode);
0130 int kernfs_iop_permission(struct user_namespace *mnt_userns,
0131               struct inode *inode, int mask);
0132 int kernfs_iop_setattr(struct user_namespace *mnt_userns, struct dentry *dentry,
0133                struct iattr *iattr);
0134 int kernfs_iop_getattr(struct user_namespace *mnt_userns,
0135                const struct path *path, struct kstat *stat,
0136                u32 request_mask, unsigned int query_flags);
0137 ssize_t kernfs_iop_listxattr(struct dentry *dentry, char *buf, size_t size);
0138 int __kernfs_setattr(struct kernfs_node *kn, const struct iattr *iattr);
0139 
0140 /*
0141  * dir.c
0142  */
0143 extern const struct dentry_operations kernfs_dops;
0144 extern const struct file_operations kernfs_dir_fops;
0145 extern const struct inode_operations kernfs_dir_iops;
0146 
0147 struct kernfs_node *kernfs_get_active(struct kernfs_node *kn);
0148 void kernfs_put_active(struct kernfs_node *kn);
0149 int kernfs_add_one(struct kernfs_node *kn);
0150 struct kernfs_node *kernfs_new_node(struct kernfs_node *parent,
0151                     const char *name, umode_t mode,
0152                     kuid_t uid, kgid_t gid,
0153                     unsigned flags);
0154 
0155 /*
0156  * file.c
0157  */
0158 extern const struct file_operations kernfs_file_fops;
0159 
0160 void kernfs_drain_open_files(struct kernfs_node *kn);
0161 
0162 /*
0163  * symlink.c
0164  */
0165 extern const struct inode_operations kernfs_symlink_iops;
0166 
0167 /*
0168  * kernfs locks
0169  */
0170 extern struct kernfs_global_locks *kernfs_locks;
0171 #endif  /* __KERNFS_INTERNAL_H */