summaryrefslogtreecommitdiff
path: root/include/linux/file.h
diff options
context:
space:
mode:
authorAl Viro <viro@zeniv.linux.org.uk>2024-05-31 16:34:25 -0400
committerAl Viro <viro@zeniv.linux.org.uk>2024-08-12 22:01:15 -0400
commitde12c3391bce10504c0e7bd767516c74110cfce1 (patch)
tree6434fad961912914e5213298f50d4f77cb2f9694 /include/linux/file.h
parent88a2f6468d013ca1163490dbddfc95135d1c27a1 (diff)
add struct fd constructors, get rid of __to_fd()
Make __fdget() et.al. return struct fd directly. New helpers: BORROWED_FD(file) and CLONED_FD(file), for borrowed and cloned file references resp. NOTE: this might need tuning; in particular, inline on __fget_light() is there to keep the code generation same as before - we probably want to keep it inlined in fdget() et.al. (especially so in fdget_pos()), but that needs profiling. Reviewed-by: Christian Brauner <brauner@kernel.org> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'include/linux/file.h')
-rw-r--r--include/linux/file.h33
1 files changed, 11 insertions, 22 deletions
diff --git a/include/linux/file.h b/include/linux/file.h
index eb28469b1c16..aab1caff6713 100644
--- a/include/linux/file.h
+++ b/include/linux/file.h
@@ -53,6 +53,14 @@ static inline bool fd_empty(struct fd f)
}
#define EMPTY_FD (struct fd){0}
+static inline struct fd BORROWED_FD(struct file *f)
+{
+ return (struct fd){(unsigned long)f};
+}
+static inline struct fd CLONED_FD(struct file *f)
+{
+ return (struct fd){(unsigned long)f | FDPUT_FPUT};
+}
static inline void fdput(struct fd fd)
{
@@ -63,30 +71,11 @@ static inline void fdput(struct fd fd)
extern struct file *fget(unsigned int fd);
extern struct file *fget_raw(unsigned int fd);
extern struct file *fget_task(struct task_struct *task, unsigned int fd);
-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 *);
-static inline struct fd __to_fd(unsigned long v)
-{
- return (struct fd){v};
-}
-
-static inline struct fd fdget(unsigned int fd)
-{
- return __to_fd(__fdget(fd));
-}
-
-static inline struct fd fdget_raw(unsigned int fd)
-{
- return __to_fd(__fdget_raw(fd));
-}
-
-static inline struct fd fdget_pos(int fd)
-{
- return __to_fd(__fdget_pos(fd));
-}
+struct fd fdget(unsigned int fd);
+struct fd fdget_raw(unsigned int fd);
+struct fd fdget_pos(unsigned int fd);
static inline void fdput_pos(struct fd f)
{