summaryrefslogtreecommitdiff
path: root/include/linux/file.h
diff options
context:
space:
mode:
authorAl Viro <viro@zeniv.linux.org.uk>2012-08-27 19:55:01 -0400
committerAl Viro <viro@zeniv.linux.org.uk>2012-09-26 21:16:32 -0400
commita5b470ba06aa3f96999ede5feba178df6bdb134a (patch)
treebf6d8f14a5524313687f605f7db9f047a2f2009d /include/linux/file.h
parent2a117354b7bdfe13750a64307755e75436fb157a (diff)
new helpers: fdget()/fdput()
Signed-off-bs: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'include/linux/file.h')
-rw-r--r--include/linux/file.h26
1 files changed, 26 insertions, 0 deletions
diff --git a/include/linux/file.h b/include/linux/file.h
index 6eee54aea279..c38bfbff4647 100644
--- a/include/linux/file.h
+++ b/include/linux/file.h
@@ -26,8 +26,34 @@ 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};
+}
+
+static inline struct fd fdget_raw(unsigned int fd)
+{
+ int b;
+ struct file *f = fget_raw_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);