initrd.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 "user_util.h"
  10. #include "kern_util.h"
  11. #include "initrd.h"
  12. #include "init.h"
  13. #include "os.h"
  14. /* Changed by uml_initrd_setup, which is a setup */
  15. static char *initrd __initdata = NULL;
  16. static int __init read_initrd(void)
  17. {
  18. void *area;
  19. long long size;
  20. int err;
  21. if(initrd == NULL) return 0;
  22. err = os_file_size(initrd, &size);
  23. if(err) return 0;
  24. area = alloc_bootmem(size);
  25. if(area == NULL) return 0;
  26. if(load_initrd(initrd, area, size) == -1) return 0;
  27. initrd_start = (unsigned long) area;
  28. initrd_end = initrd_start + size;
  29. return 0;
  30. }
  31. __uml_postsetup(read_initrd);
  32. static int __init uml_initrd_setup(char *line, int *add)
  33. {
  34. initrd = line;
  35. return 0;
  36. }
  37. __uml_setup("initrd=", uml_initrd_setup,
  38. "initrd=<initrd image>\n"
  39. " This is used to boot UML from an initrd image. The argument is the\n"
  40. " name of the file containing the image.\n\n"
  41. );
  42. int load_initrd(char *filename, void *buf, int size)
  43. {
  44. int fd, n;
  45. fd = os_open_file(filename, of_read(OPENFLAGS()), 0);
  46. if(fd < 0){
  47. printk("Opening '%s' failed - err = %d\n", filename, -fd);
  48. return(-1);
  49. }
  50. n = os_read_file(fd, buf, size);
  51. if(n != size){
  52. printk("Read of %d bytes from '%s' failed, err = %d\n", size,
  53. filename, -n);
  54. return(-1);
  55. }
  56. os_close_file(fd);
  57. return(0);
  58. }
  59. /*
  60. * Overrides for Emacs so that we follow Linus's tabbing style.
  61. * Emacs will notice this stuff at the end of the file and automatically
  62. * adjust the settings for this buffer only. This must remain at the end
  63. * of the file.
  64. * ---------------------------------------------------------------------------
  65. * Local variables:
  66. * c-file-style: "linux"
  67. * End:
  68. */