Using this wrapper allows us to avoid the in-kernel calls to the
sys_open() syscall. The ksys_ prefix denotes that this function is meant
as a drop-in replacement for the syscall. In particular, it uses the
same calling convention as sys_open().
This patch is part of a series which removes in-kernel calls to syscalls.
On this basis, the syscall entry path can be streamlined. For details, see
http://lkml.kernel.org/r/
20180325162527.GA17492@light.dominikbrodowski.net
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Dominik Brodowski <linux@dominikbrodowski.net>
  */
 SYSCALL_DEFINE2(creat, const char __user *, pathname, umode_t, mode)
 {
-       return sys_open(pathname, O_CREAT | O_WRONLY | O_TRUNC, mode);
+       return ksys_open(pathname, O_CREAT | O_WRONLY | O_TRUNC, mode);
 }
 
 #endif
 
        return __close_fd(current->files, fd);
 }
 
+extern long do_sys_open(int dfd, const char __user *filename, int flags,
+                       umode_t mode);
+
+static inline long ksys_open(const char __user *filename, int flags,
+                            umode_t mode)
+{
+       if (force_o_largefile())
+               flags |= O_LARGEFILE;
+       return do_sys_open(AT_FDCWD, filename, flags, mode);
+}
+
 #endif
 
        va_start(args, fmt);
        vsprintf(buf, fmt, args);
        va_end(args);
-       fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
+       fd = ksys_open("/dev/root", O_RDWR | O_NDELAY, 0);
        if (fd >= 0) {
                sys_ioctl(fd, FDEJECT, 0);
                ksys_close(fd);
        }
        printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
-       fd = sys_open("/dev/console", O_RDWR, 0);
+       fd = ksys_open("/dev/console", O_RDWR, 0);
        if (fd >= 0) {
                sys_ioctl(fd, TCGETS, (long)&termios);
                termios.c_lflag &= ~ICANON;
 
 {
        sys_unshare(CLONE_FS | CLONE_FILES);
        /* stdin/stdout/stderr for /linuxrc */
-       sys_open("/dev/console", O_RDWR, 0);
+       ksys_open("/dev/console", O_RDWR, 0);
        ksys_dup(0);
        ksys_dup(0);
        /* move initrd over / and chdir/chroot in initrd root */
        if (!error)
                printk("okay\n");
        else {
-               int fd = sys_open("/dev/root.old", O_RDWR, 0);
+               int fd = ksys_open("/dev/root.old", O_RDWR, 0);
                if (error == -ENOENT)
                        printk("/initrd does not exist. Ignored.\n");
                else
 
                        partitioned ? "_d" : "", minor,
                        md_setup_args[ent].device_names);
 
-               fd = sys_open(name, 0, 0);
+               fd = ksys_open(name, 0, 0);
                if (fd < 0) {
                        printk(KERN_ERR "md: open failed - cannot start "
                                        "array %s\n", name);
                         * array without it
                         */
                        ksys_close(fd);
-                       fd = sys_open(name, 0, 0);
+                       fd = ksys_open(name, 0, 0);
                        sys_ioctl(fd, BLKRRPART, 0);
                }
                ksys_close(fd);
 
        wait_for_device_probe();
 
-       fd = sys_open("/dev/md0", 0, 0);
+       fd = ksys_open("/dev/md0", 0, 0);
        if (fd >= 0) {
                sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
                ksys_close(fd);
 
        char rotator[4] = { '|' , '/' , '-' , '\\' };
 #endif
 
-       out_fd = sys_open("/dev/ram", O_RDWR, 0);
+       out_fd = ksys_open("/dev/ram", O_RDWR, 0);
        if (out_fd < 0)
                goto out;
 
-       in_fd = sys_open(from, O_RDONLY, 0);
+       in_fd = ksys_open(from, O_RDONLY, 0);
        if (in_fd < 0)
                goto noclose_input;
 
                                goto noclose_input;
                        }
                        change_floppy("disk #%d", disk);
-                       in_fd = sys_open(from, O_RDONLY, 0);
+                       in_fd = ksys_open(from, O_RDONLY, 0);
                        if (in_fd < 0)  {
                                printk("Error opening disk.\n");
                                goto noclose_input;
 
                        int openflags = O_WRONLY|O_CREAT;
                        if (ml != 1)
                                openflags |= O_TRUNC;
-                       wfd = sys_open(collected, openflags, mode);
+                       wfd = ksys_open(collected, openflags, mode);
 
                        if (wfd >= 0) {
                                ksys_fchown(wfd, uid, gid);
        struct linux_dirent64 *dirp;
        int num;
 
-       fd = sys_open("/", O_RDONLY, 0);
+       fd = ksys_open("/", O_RDONLY, 0);
        WARN_ON(fd < 0);
        if (fd < 0)
                return;
                }
                printk(KERN_INFO "rootfs image is not initramfs (%s)"
                                "; looks like an initrd\n", err);
-               fd = sys_open("/initrd.image",
+               fd = ksys_open("/initrd.image",
                              O_WRONLY|O_CREAT, 0700);
                if (fd >= 0) {
                        ssize_t written = xwrite(fd, (char *)initrd_start,
 
        do_basic_setup();
 
        /* Open the /dev/console on the rootfs, this should never fail */
-       if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
+       if (ksys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
                pr_err("Warning: unable to open an initial console.\n");
 
        (void) ksys_dup(0);