From 09062f13dbe16990490a1a87c79ba6b9ea5d4752 Mon Sep 17 00:00:00 2001 From: Al Viro Date: Mon, 27 Aug 2012 19:55:01 -0400 Subject: [PATCH] new helpers: fdget()/fdput() Signed-off-bs: Al Viro --- include/linux/file.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/include/linux/file.h b/include/linux/file.h index 6eee54aea279..45f10bbc3fc7 100644 --- a/include/linux/file.h +++ b/include/linux/file.h @@ -26,8 +26,27 @@ static inline void fput_light(struct file *file, int fput_needed) fput(file); } +struct fd { + struct file *file; + int need_put; +}; + +static inline void fdput(struct fd fd) +{ + if (fd.need_put) + fput(fd.file); +} + extern struct file *fget(unsigned int fd); extern struct file *fget_light(unsigned int fd, int *fput_needed); + +static inline struct fd fdget(unsigned int fd) +{ + int b; + struct file *f = fget_light(fd, &b); + return (struct fd){f,b}; +} + extern struct file *fget_raw(unsigned int fd); extern struct file *fget_raw_light(unsigned int fd, int *fput_needed); extern int f_dupfd(unsigned int from, struct file *file, unsigned flags); -- 2.39.5