浏览代码

new helpers: fdget()/fdput()

Signed-off-bs: Al Viro <viro@zeniv.linux.org.uk>
Al Viro 13 年之前
父节点
当前提交
a5b470ba06
共有 1 个文件被更改,包括 26 次插入0 次删除
  1. 26 0
      include/linux/file.h

+ 26 - 0
include/linux/file.h

@@ -26,8 +26,34 @@ static inline void fput_light(struct file *file, int fput_needed)
 		fput(file);
 		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(unsigned int fd);
 extern struct file *fget_light(unsigned int fd, int *fput_needed);
 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(unsigned int fd);
 extern struct file *fget_raw_light(unsigned int fd, int *fput_needed);
 extern struct file *fget_raw_light(unsigned int fd, int *fput_needed);
 extern int f_dupfd(unsigned int from, struct file *file, unsigned flags);
 extern int f_dupfd(unsigned int from, struct file *file, unsigned flags);