Files
kernel/include/linux/file.h
T

115 lines
2.9 KiB
C
Raw Normal View History

/* SPDX-License-Identifier: GPL-2.0 */
2005-04-16 15:20:36 -07:00
/*
* Wrapper functions for accessing the file_struct fd array.
*/
#ifndef __LINUX_FILE_H
#define __LINUX_FILE_H
#include <linux/compiler.h>
#include <linux/types.h>
2008-04-24 07:44:08 -04:00
#include <linux/posix_types.h>
#include <linux/errno.h>
2005-04-16 15:20:36 -07:00
2008-04-24 07:44:08 -04:00
struct file;
2006-12-06 20:32:52 -08:00
extern void fput(struct file *);
2018-11-21 10:32:39 -07:00
extern void fput_many(struct file *, unsigned int);
2005-04-16 15:20:36 -07:00
struct file_operations;
2020-01-07 09:59:24 -08:00
struct task_struct;
struct vfsmount;
struct dentry;
2018-06-09 09:40:05 -04:00
struct inode;
2009-08-09 00:52:35 +04:00
struct path;
2018-06-09 09:40:05 -04:00
extern struct file *alloc_file_pseudo(struct inode *, struct vfsmount *,
const char *, int flags, const struct file_operations *);
2018-06-17 14:15:10 -04:00
extern struct file *alloc_file_clone(struct file *, int flags,
const struct file_operations *);
2005-04-16 15:20:36 -07:00
static inline void fput_light(struct file *file, int fput_needed)
{
2010-12-13 19:38:08 -05:00
if (fput_needed)
2005-04-16 15:20:36 -07:00
fput(file);
}
2012-08-27 19:55:01 -04:00
struct fd {
struct file *file;
2014-03-03 09:36:58 -08:00
unsigned int flags;
2012-08-27 19:55:01 -04:00
};
2014-03-03 09:36:58 -08:00
#define FDPUT_FPUT 1
#define FDPUT_POS_UNLOCK 2
2012-08-27 19:55:01 -04:00
static inline void fdput(struct fd fd)
{
2014-03-03 09:36:58 -08:00
if (fd.flags & FDPUT_FPUT)
2012-08-27 19:55:01 -04:00
fput(fd.file);
}
extern struct file *fget(unsigned int fd);
2018-11-21 10:32:39 -07:00
extern struct file *fget_many(unsigned int fd, unsigned int refs);
2014-03-04 14:54:22 -05:00
extern struct file *fget_raw(unsigned int fd);
2020-01-07 09:59:24 -08:00
extern struct file *fget_task(struct task_struct *task, unsigned int fd);
2014-03-04 14:54:22 -05:00
extern unsigned long __fdget(unsigned int fd);
extern unsigned long __fdget_raw(unsigned int fd);
extern unsigned long __fdget_pos(unsigned int fd);
extern void __f_unlock_pos(struct file *);
2014-03-04 14:54:22 -05:00
static inline struct fd __to_fd(unsigned long v)
{
return (struct fd){(struct file *)(v & ~3),v & 3};
}
2012-08-27 19:55:01 -04:00
static inline struct fd fdget(unsigned int fd)
{
2014-03-04 14:54:22 -05:00
return __to_fd(__fdget(fd));
2012-08-27 19:55:01 -04:00
}
static inline struct fd fdget_raw(unsigned int fd)
{
2014-03-04 14:54:22 -05:00
return __to_fd(__fdget_raw(fd));
2012-08-27 19:55:01 -04:00
}
static inline struct fd fdget_pos(int fd)
{
return __to_fd(__fdget_pos(fd));
}
static inline void fdput_pos(struct fd f)
{
if (f.flags & FDPUT_POS_UNLOCK)
__f_unlock_pos(f.file);
fdput(f);
}
extern int f_dupfd(unsigned int from, struct file *file, unsigned flags);
2012-08-21 12:11:46 -04:00
extern int replace_fd(unsigned fd, struct file *file, unsigned flags);
extern void set_close_on_exec(unsigned int fd, int flag);
extern bool get_close_on_exec(unsigned int fd);
extern int __get_unused_fd_flags(unsigned flags, unsigned long nofile);
2012-08-12 17:18:05 -04:00
extern int get_unused_fd_flags(unsigned flags);
extern void put_unused_fd(unsigned int fd);
2005-04-16 15:20:36 -07:00
extern void fd_install(unsigned int fd, struct file *file);
2005-04-16 15:20:36 -07:00
extern int __receive_fd(struct file *file, int __user *ufd,
unsigned int o_flags);
2021-08-31 18:36:24 +08:00
extern int receive_fd(struct file *file, unsigned int o_flags);
static inline int receive_fd_user(struct file *file, int __user *ufd,
unsigned int o_flags)
{
if (ufd == NULL)
return -EFAULT;
return __receive_fd(file, ufd, o_flags);
}
int receive_fd_replace(int new_fd, struct file *file, unsigned int o_flags);
2012-06-24 09:56:45 +04:00
extern void flush_delayed_fput(void);
extern void __fput_sync(struct file *);
extern unsigned int sysctl_nr_open_min, sysctl_nr_open_max;
2005-04-16 15:20:36 -07:00
#endif /* __LINUX_FILE_H */