]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blobdiff - fs/open.c
drm/nouveau/i2c: Disable i2c bus access after ->fini()
[mirror_ubuntu-bionic-kernel.git] / fs / open.c
index 7ea118471dce59996ae3d3d9b9e3b9d156baffba..0ad0459576a152ea7ef291ccc8a1998e018d9ba6 100644 (file)
--- a/fs/open.c
+++ b/fs/open.c
@@ -34,6 +34,9 @@
 
 #include "internal.h"
 
+#define CREATE_TRACE_POINTS
+#include <trace/events/fs.h>
+
 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
        struct file *filp)
 {
@@ -64,6 +67,7 @@ int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
        inode_unlock(dentry->d_inode);
        return ret;
 }
+EXPORT_SYMBOL_GPL(do_truncate);
 
 long vfs_truncate(const struct path *path, loff_t length)
 {
@@ -691,6 +695,7 @@ int open_check_o_direct(struct file *f)
        }
        return 0;
 }
+EXPORT_SYMBOL_GPL(open_check_o_direct);
 
 static int do_dentry_open(struct file *f,
                          struct inode *inode,
@@ -716,6 +721,12 @@ static int do_dentry_open(struct file *f,
                return 0;
        }
 
+       /* Any file opened for execve()/uselib() has to be a regular file. */
+       if (unlikely(f->f_flags & FMODE_EXEC && !S_ISREG(inode->i_mode))) {
+               error = -EACCES;
+               goto cleanup_file;
+       }
+
        if (f->f_mode & FMODE_WRITE && !special_file(inode->i_mode)) {
                error = get_write_access(inode);
                if (unlikely(error))
@@ -1063,6 +1074,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
                } else {
                        fsnotify_open(f);
                        fd_install(fd, f);
+                       trace_do_sys_open(tmp->name, flags, mode);
                }
        }
        putname(tmp);
@@ -1206,3 +1218,21 @@ int nonseekable_open(struct inode *inode, struct file *filp)
 }
 
 EXPORT_SYMBOL(nonseekable_open);
+
+/*
+ * stream_open is used by subsystems that want stream-like file descriptors.
+ * Such file descriptors are not seekable and don't have notion of position
+ * (file.f_pos is always 0). Contrary to file descriptors of other regular
+ * files, .read() and .write() can run simultaneously.
+ *
+ * stream_open never fails and is marked to return int so that it could be
+ * directly used as file_operations.open .
+ */
+int stream_open(struct inode *inode, struct file *filp)
+{
+       filp->f_mode &= ~(FMODE_LSEEK | FMODE_PREAD | FMODE_PWRITE | FMODE_ATOMIC_POS);
+       filp->f_mode |= FMODE_STREAM;
+       return 0;
+}
+
+EXPORT_SYMBOL(stream_open);