Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * Wrapper functions for accessing the file_struct fd array.
0004  */
0005 
0006 #ifndef __LINUX_FILE_H
0007 #define __LINUX_FILE_H
0008 
0009 #include <linux/compiler.h>
0010 #include <linux/types.h>
0011 #include <linux/posix_types.h>
0012 #include <linux/errno.h>
0013 
0014 struct file;
0015 
0016 extern void fput(struct file *);
0017 
0018 struct file_operations;
0019 struct task_struct;
0020 struct vfsmount;
0021 struct dentry;
0022 struct inode;
0023 struct path;
0024 extern struct file *alloc_file_pseudo(struct inode *, struct vfsmount *,
0025     const char *, int flags, const struct file_operations *);
0026 extern struct file *alloc_file_clone(struct file *, int flags,
0027     const struct file_operations *);
0028 
0029 static inline void fput_light(struct file *file, int fput_needed)
0030 {
0031     if (fput_needed)
0032         fput(file);
0033 }
0034 
0035 struct fd {
0036     struct file *file;
0037     unsigned int flags;
0038 };
0039 #define FDPUT_FPUT       1
0040 #define FDPUT_POS_UNLOCK 2
0041 
0042 static inline void fdput(struct fd fd)
0043 {
0044     if (fd.flags & FDPUT_FPUT)
0045         fput(fd.file);
0046 }
0047 
0048 extern struct file *fget(unsigned int fd);
0049 extern struct file *fget_raw(unsigned int fd);
0050 extern struct file *fget_task(struct task_struct *task, unsigned int fd);
0051 extern unsigned long __fdget(unsigned int fd);
0052 extern unsigned long __fdget_raw(unsigned int fd);
0053 extern unsigned long __fdget_pos(unsigned int fd);
0054 extern void __f_unlock_pos(struct file *);
0055 
0056 static inline struct fd __to_fd(unsigned long v)
0057 {
0058     return (struct fd){(struct file *)(v & ~3),v & 3};
0059 }
0060 
0061 static inline struct fd fdget(unsigned int fd)
0062 {
0063     return __to_fd(__fdget(fd));
0064 }
0065 
0066 static inline struct fd fdget_raw(unsigned int fd)
0067 {
0068     return __to_fd(__fdget_raw(fd));
0069 }
0070 
0071 static inline struct fd fdget_pos(int fd)
0072 {
0073     return __to_fd(__fdget_pos(fd));
0074 }
0075 
0076 static inline void fdput_pos(struct fd f)
0077 {
0078     if (f.flags & FDPUT_POS_UNLOCK)
0079         __f_unlock_pos(f.file);
0080     fdput(f);
0081 }
0082 
0083 extern int f_dupfd(unsigned int from, struct file *file, unsigned flags);
0084 extern int replace_fd(unsigned fd, struct file *file, unsigned flags);
0085 extern void set_close_on_exec(unsigned int fd, int flag);
0086 extern bool get_close_on_exec(unsigned int fd);
0087 extern int __get_unused_fd_flags(unsigned flags, unsigned long nofile);
0088 extern int get_unused_fd_flags(unsigned flags);
0089 extern void put_unused_fd(unsigned int fd);
0090 
0091 extern void fd_install(unsigned int fd, struct file *file);
0092 
0093 extern int __receive_fd(struct file *file, int __user *ufd,
0094             unsigned int o_flags);
0095 
0096 extern int receive_fd(struct file *file, unsigned int o_flags);
0097 
0098 static inline int receive_fd_user(struct file *file, int __user *ufd,
0099                   unsigned int o_flags)
0100 {
0101     if (ufd == NULL)
0102         return -EFAULT;
0103     return __receive_fd(file, ufd, o_flags);
0104 }
0105 int receive_fd_replace(int new_fd, struct file *file, unsigned int o_flags);
0106 
0107 extern void flush_delayed_fput(void);
0108 extern void __fput_sync(struct file *);
0109 
0110 extern unsigned int sysctl_nr_open_min, sysctl_nr_open_max;
0111 
0112 #endif /* __LINUX_FILE_H */