]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blame - arch/um/kernel/initrd.c
uml: rename os_{read_write}_file_k back to os_{read_write}_file
[mirror_ubuntu-hirsute-kernel.git] / arch / um / kernel / initrd.c
CommitLineData
9b67a3c4
JD
1/*
2 * Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
4 */
5
6#include "linux/init.h"
7#include "linux/bootmem.h"
8#include "linux/initrd.h"
9#include "asm/types.h"
9b67a3c4
JD
10#include "kern_util.h"
11#include "initrd.h"
12#include "init.h"
13#include "os.h"
14
15/* Changed by uml_initrd_setup, which is a setup */
16static char *initrd __initdata = NULL;
17
18static int __init read_initrd(void)
19{
20 void *area;
21 long long size;
22 int err;
23
dc764e50
JD
24 if(initrd == NULL)
25 return 0;
26
9b67a3c4 27 err = os_file_size(initrd, &size);
dc764e50
JD
28 if(err)
29 return 0;
30
9b67a3c4 31 area = alloc_bootmem(size);
dc764e50
JD
32 if(area == NULL)
33 return 0;
34
35 if(load_initrd(initrd, area, size) == -1)
36 return 0;
37
9b67a3c4
JD
38 initrd_start = (unsigned long) area;
39 initrd_end = initrd_start + size;
40 return 0;
41}
42
43__uml_postsetup(read_initrd);
44
45static int __init uml_initrd_setup(char *line, int *add)
46{
47 initrd = line;
48 return 0;
49}
50
51__uml_setup("initrd=", uml_initrd_setup,
52"initrd=<initrd image>\n"
53" This is used to boot UML from an initrd image. The argument is the\n"
54" name of the file containing the image.\n\n"
55);
56
57int load_initrd(char *filename, void *buf, int size)
58{
59 int fd, n;
60
61 fd = os_open_file(filename, of_read(OPENFLAGS()), 0);
62 if(fd < 0){
63 printk("Opening '%s' failed - err = %d\n", filename, -fd);
dc764e50 64 return -1;
9b67a3c4 65 }
a6ea4cce 66 n = os_read_file(fd, buf, size);
9b67a3c4
JD
67 if(n != size){
68 printk("Read of %d bytes from '%s' failed, err = %d\n", size,
69 filename, -n);
dc764e50 70 return -1;
9b67a3c4
JD
71 }
72
73 os_close_file(fd);
dc764e50 74 return 0;
9b67a3c4 75}