#include <linux/init.h>
#include <linux/fs.h>
-#include <linux/file.h>
#include <linux/slab.h>
#include <linux/types.h>
#include <linux/fcntl.h>
#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)
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];
}
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) {
/* 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;
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;
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);
state = SkipIt;
return 0;
} else {
- initramfs_write(wfd, victim, count);
+ sys_write(wfd, victim, count);
body_len -= count;
eat(count);
return 1;
}
__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>
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;
}
#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) {
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();
}
return 0;
}
+rootfs_initcall(populate_rootfs);