what is "unpack_to_rootfs()" unpacking, and where is it putting it?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



  i'm perusing the code in init/initramfs.c, and i'm trying to figure
out how that initial initramfs image becomes the new root filesystem.
(i could follow the code but, as you'll see, it's really pretty
depressingly ugly, so if anyone can clarify what follows, i'd be
eternally grateful.)

  from init/initramfs.c, we have the code that (allegedly) takes the
compressed cpio archive that is the initramfs, and turns it into the
new root filesystem:

... snip ...
static int __init populate_rootfs(void)
{
        char *err = unpack_to_rootfs(__initramfs_start,
                         __initramfs_end - __initramfs_start, 0);
... snip ...

  ok, that tells me that the unpack_to_rootfs() routine is responsible
for taking the gzipped cpio image in the interval [__initramfs_start,
__initramfs_end) and turning it into the new root filesystem.  that
seems obvious enough.  but look at unpack_to_rootfs():

static char * __init unpack_to_rootfs(char *buf, unsigned len, int
check_only)
{
... snip ...
                this_header = 0;
                insize = len;
                inbuf = buf;
                inptr = 0;
                outcnt = 0;             /* bytes in output buffer */
                bytes_out = 0;
                crc = (ulg)0xffffffffL; /* shift register contents */
                makecrc();
                gunzip();
... snip ...

  this code is particularly ugly because this file includes the source
file lib/inflate.c, then promptly uses a plethora of global variables
to get things done.  yeesh.

  in any event, all i want to do is clarify what happens here -- when
unpack_to_rootfs() is called with an address and length of ...
something, what is the final result?

  as i read it, an initramfs image is *always* a gzipped cpio image,
so i'm *assuming* that the responsibility of unpack_to_rootfs() is to
uncompress, then un-cpio that image.  is that it?  does it do anything
else?  can it handle other formats?  and where exactly is that cpio
extraction step done?  or am i misreading something here?  because i'm
assuming that, once unpack_to_rootfs() runs, i will have the contents
of that initramfs image as my new root filesystem.  if i don't, then
i'm confused.

rday
--

========================================================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry:
    Have classroom, will lecture.

http://crashcourse.ca                          Waterloo, Ontario, CANADA
========================================================================

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at http://kernelnewbies.org/FAQ


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux