Update to 3.4-final.
[linux-flexiantxendom0-3.2.10.git] / init / initramfs.c
index 1f6d1b7..8216c30 100644 (file)
@@ -1,6 +1,5 @@
 #include <linux/init.h>
 #include <linux/fs.h>
-#include <linux/file.h>
 #include <linux/slab.h>
 #include <linux/types.h>
 #include <linux/fcntl.h>
@@ -9,8 +8,6 @@
 #include <linux/dirent.h>
 #include <linux/syscalls.h>
 #include <linux/utime.h>
-#include <linux/pagemap.h>
-#include <linux/uio.h>
 
 static __initdata char *message;
 static void __init error(char *x)
@@ -25,7 +22,7 @@ static void __init error(char *x)
 
 static __initdata struct hash {
        int ino, minor, major;
-       mode_t mode;
+       umode_t mode;
        struct hash *next;
        char name[N_ALIGN(PATH_MAX)];
 } *head[32];
@@ -38,7 +35,7 @@ static inline int hash(int major, int minor, int ino)
 }
 
 static char __init *find_link(int major, int minor, int ino,
-                             mode_t mode, char *name)
+                             umode_t mode, char *name)
 {
        struct hash **p, *q;
        for (p = head + hash(major, minor, ino); *p; p = &(*p)->next) {
@@ -123,7 +120,7 @@ static __initdata time_t mtime;
 /* cpio header parsing */
 
 static __initdata unsigned long ino, major, minor, nlink;
-static __initdata mode_t mode;
+static __initdata umode_t mode;
 static __initdata unsigned long body_len, name_len;
 static __initdata uid_t uid;
 static __initdata gid_t gid;
@@ -279,7 +276,7 @@ static int __init maybe_link(void)
        return 0;
 }
 
-static void __init clean_path(char *path, mode_t mode)
+static void __init clean_path(char *path, umode_t mode)
 {
        struct stat st;
 
@@ -336,153 +333,10 @@ static int __init do_name(void)
        return 0;
 }
 
-ssize_t initramfs_file_read(struct file *file, const char *buf,
-                           size_t count, loff_t *ppos)
-{
-       struct address_space *mapping = file->f_mapping;
-       struct iovec iov = { .iov_base = (void __user *) buf,
-                            .iov_len = count };
-       struct iov_iter i;
-       long status = 0;
-       loff_t pos = *ppos;
-       ssize_t read = 0;
-
-       iov_iter_init(&i, &iov, 1, count, 0);
-
-       do {
-               struct page *page;
-               pgoff_t index;
-               unsigned long offset;
-               unsigned long bytes;
-               char *data;
-
-               offset = (pos & (PAGE_CACHE_SIZE - 1));
-               index = pos >> PAGE_CACHE_SHIFT;
-               bytes = min_t(unsigned long, PAGE_CACHE_SIZE - offset,
-                             iov_iter_count(&i));
-
-               page = read_mapping_page(mapping, index, NULL);
-               if (IS_ERR(page)) {
-                       status = PTR_ERR(page);
-                       break;
-               }
-
-               data = kmap_atomic(page, KM_USER0);
-               memcpy(i.iov->iov_base + i.iov_offset, data + offset, bytes);
-               kunmap_atomic(data, KM_USER0);
-
-               iov_iter_advance(&i, bytes);
-               pos += bytes;
-               read += bytes;
-       } while (iov_iter_count(&i));
-
-       *ppos = pos;
-
-       return read ? read : status;
-}
-
-ssize_t initramfs_file_write(struct file *file, const char * __user buf,
-                            size_t count, loff_t *ppos)
-{
-       struct address_space *mapping = file->f_mapping;
-       struct iovec iov = { .iov_base = (void __user *) buf,
-                            .iov_len = count };
-       long status = 0;
-       ssize_t written = 0;
-       unsigned int flags = 0;
-       loff_t pos = *ppos;
-       struct iov_iter i;
-
-       iov_iter_init(&i, &iov, 1, count, 0);
-
-       /*
-        * Copies from kernel address space cannot fail (NFSD is a big user).
-        */
-       if (segment_eq(get_fs(), KERNEL_DS))
-               flags |= AOP_FLAG_UNINTERRUPTIBLE;
-
-       mutex_lock(&mapping->host->i_mutex);
-
-       do {
-               struct page *page;
-               pgoff_t index;          /* Pagecache index for current page */
-               unsigned long offset;   /* Offset into pagecache page */
-               unsigned long bytes;    /* Bytes to write to page */
-               size_t copied;          /* Bytes copied from user */
-               void *fsdata;
-               char *data;
-
-               offset = (pos & (PAGE_CACHE_SIZE - 1));
-               index = pos >> PAGE_CACHE_SHIFT;
-               bytes = min_t(unsigned long, PAGE_CACHE_SIZE - offset,
-                                               iov_iter_count(&i));
-
-               status = simple_write_begin(file, mapping, pos, bytes, flags,
-                                               &page, &fsdata);
-               if (unlikely(status))
-                       break;
-               data = kmap_atomic(page, KM_USER0);
-               memcpy(data + offset, i.iov->iov_base + i.iov_offset, bytes);
-               kunmap_atomic(data, KM_USER0);
-               copied = bytes;
-
-               status = simple_write_end(file, mapping, pos, bytes, copied,
-                                               page, fsdata);
-               if (unlikely(status < 0))
-                       break;
-               copied = status;
-
-               iov_iter_advance(&i, copied);
-               pos += copied;
-               written += copied;
-
-       } while (iov_iter_count(&i));
-
-       mutex_unlock(&mapping->host->i_mutex);
-
-       *ppos = pos;
-
-       return written ? written : status;
-}
-
-ssize_t
-initramfs_read(unsigned int fd, const char * buf, size_t count)
-{
-       struct file *file;
-       ssize_t ret = 0;
-
-       file = fget(fd);
-       if (file) {
-               loff_t pos = file->f_pos;
-               ret = initramfs_file_read(file, buf, count, &pos);
-               file->f_pos = pos;
-               fput(file);
-       }
-
-       return ret;
-}
-
-ssize_t
-initramfs_write(unsigned int fd, const char * buf, size_t count)
-{
-       struct file *file;
-       ssize_t ret = 0;
-
-       file = fget(fd);
-       if (file) {
-               loff_t pos = file->f_pos;
-               ret = initramfs_file_write(file, buf, count, &pos);
-               file->f_pos = pos;
-               fput(file);
-       }
-
-       return ret;
-}
-
 static int __init do_copy(void)
 {
        if (count >= body_len) {
-               initramfs_write(wfd, victim, body_len);
+               sys_write(wfd, victim, body_len);
                sys_close(wfd);
                do_utime(vcollected, mtime);
                kfree(vcollected);
@@ -490,7 +344,7 @@ static int __init do_copy(void)
                state = SkipIt;
                return 0;
        } else {
-               initramfs_write(wfd, victim, count);
+               sys_write(wfd, victim, count);
                body_len -= count;
                eat(count);
                return 1;
@@ -629,7 +483,8 @@ static int __init retain_initrd_param(char *str)
 }
 __setup("retain_initrd", retain_initrd_param);
 
-extern char __initramfs_start[], __initramfs_end[];
+extern char __initramfs_start[];
+extern unsigned long __initramfs_size;
 #include <linux/initrd.h>
 #include <linux/kexec.h>
 
@@ -674,7 +529,7 @@ static void __init clean_rootfs(void)
        struct linux_dirent64 *dirp;
        int num;
 
-       fd = sys_open("/", O_RDONLY, 0);
+       fd = sys_open((const char __user __force *) "/", O_RDONLY, 0);
        WARN_ON(fd < 0);
        if (fd < 0)
                return;
@@ -714,10 +569,9 @@ static void __init clean_rootfs(void)
 }
 #endif
 
-int __init populate_rootfs(void)
+static int __init populate_rootfs(void)
 {
-       char *err = unpack_to_rootfs(__initramfs_start,
-                        __initramfs_end - __initramfs_start);
+       char *err = unpack_to_rootfs(__initramfs_start, __initramfs_size);
        if (err)
                panic(err);     /* Failed to decompress INTERNAL initramfs */
        if (initrd_start) {
@@ -731,14 +585,14 @@ int __init populate_rootfs(void)
                        return 0;
                } else {
                        clean_rootfs();
-                       unpack_to_rootfs(__initramfs_start,
-                                __initramfs_end - __initramfs_start);
+                       unpack_to_rootfs(__initramfs_start, __initramfs_size);
                }
                printk(KERN_INFO "rootfs image is not initramfs (%s)"
                                "; looks like an initrd\n", err);
-               fd = sys_open("/initrd.image", O_WRONLY|O_CREAT, 0700);
+               fd = sys_open((const char __user __force *) "/initrd.image",
+                             O_WRONLY|O_CREAT, 0700);
                if (fd >= 0) {
-                       initramfs_write(fd, (char *)initrd_start,
+                       sys_write(fd, (char *)initrd_start,
                                        initrd_end - initrd_start);
                        sys_close(fd);
                        free_initrd();
@@ -754,3 +608,4 @@ int __init populate_rootfs(void)
        }
        return 0;
 }
+rootfs_initcall(populate_rootfs);