perf annotate: Fix objdump line parsing offset validation
[linux/fpc-iii.git] / arch / um / kernel / initrd.c
blob55cead809b18baccf804dd89dafec13c37eb0af0
1 /*
2 * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
3 * Licensed under the GPL
4 */
6 #include <linux/init.h>
7 #include <linux/bootmem.h>
8 #include <linux/initrd.h>
9 #include <asm/types.h>
10 #include <init.h>
11 #include <os.h>
13 /* Changed by uml_initrd_setup, which is a setup */
14 static char *initrd __initdata = NULL;
15 static int load_initrd(char *filename, void *buf, int size);
17 static int __init read_initrd(void)
19 void *area;
20 long long size;
21 int err;
23 if (initrd == NULL)
24 return 0;
26 err = os_file_size(initrd, &size);
27 if (err)
28 return 0;
31 * This is necessary because alloc_bootmem craps out if you
32 * ask for no memory.
34 if (size == 0) {
35 printk(KERN_ERR "\"%s\" is a zero-size initrd\n", initrd);
36 return 0;
39 area = alloc_bootmem(size);
40 if (area == NULL)
41 return 0;
43 if (load_initrd(initrd, area, size) == -1)
44 return 0;
46 initrd_start = (unsigned long) area;
47 initrd_end = initrd_start + size;
48 return 0;
51 __uml_postsetup(read_initrd);
53 static int __init uml_initrd_setup(char *line, int *add)
55 initrd = line;
56 return 0;
59 __uml_setup("initrd=", uml_initrd_setup,
60 "initrd=<initrd image>\n"
61 " This is used to boot UML from an initrd image. The argument is the\n"
62 " name of the file containing the image.\n\n"
65 static int load_initrd(char *filename, void *buf, int size)
67 int fd, n;
69 fd = os_open_file(filename, of_read(OPENFLAGS()), 0);
70 if (fd < 0) {
71 printk(KERN_ERR "Opening '%s' failed - err = %d\n", filename,
72 -fd);
73 return -1;
75 n = os_read_file(fd, buf, size);
76 if (n != size) {
77 printk(KERN_ERR "Read of %d bytes from '%s' failed, "
78 "err = %d\n", size,
79 filename, -n);
80 return -1;
83 os_close_file(fd);
84 return 0;