initrd.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com)
  3. * Licensed under the GPL
  4. */
  5. #include "linux/init.h"
  6. #include "linux/bootmem.h"
  7. #include "linux/initrd.h"
  8. #include "asm/types.h"
  9. #include "initrd.h"
  10. #include "init.h"
  11. #include "os.h"
  12. /* Changed by uml_initrd_setup, which is a setup */
  13. static char *initrd __initdata = NULL;
  14. static int __init read_initrd(void)
  15. {
  16. void *area;
  17. long long size;
  18. int err;
  19. if(initrd == NULL)
  20. return 0;
  21. err = os_file_size(initrd, &size);
  22. if(err)
  23. return 0;
  24. area = alloc_bootmem(size);
  25. if(area == NULL)
  26. return 0;
  27. if(load_initrd(initrd, area, size) == -1)
  28. return 0;
  29. initrd_start = (unsigned long) area;
  30. initrd_end = initrd_start + size;
  31. return 0;
  32. }
  33. __uml_postsetup(read_initrd);
  34. static int __init uml_initrd_setup(char *line, int *add)
  35. {
  36. initrd = line;
  37. return 0;
  38. }
  39. __uml_setup("initrd=", uml_initrd_setup,
  40. "initrd=<initrd image>\n"
  41. " This is used to boot UML from an initrd image. The argument is the\n"
  42. " name of the file containing the image.\n\n"
  43. );
  44. int load_initrd(char *filename, void *buf, int size)
  45. {
  46. int fd, n;
  47. fd = os_open_file(filename, of_read(OPENFLAGS()), 0);
  48. if(fd < 0){
  49. printk("Opening '%s' failed - err = %d\n", filename, -fd);
  50. return -1;
  51. }
  52. n = os_read_file(fd, buf, size);
  53. if(n != size){
  54. printk("Read of %d bytes from '%s' failed, err = %d\n", size,
  55. filename, -n);
  56. return -1;
  57. }
  58. os_close_file(fd);
  59. return 0;
  60. }