diff options
author | Shao Miller <sha0.miller@gmail.com> | 2012-10-26 02:14:28 -0400 |
---|---|---|
committer | Shao Miller <sha0.miller@gmail.com> | 2012-10-30 00:13:50 -0400 |
commit | a6671b7d17293cf3f7fac1083ae16542828987b4 (patch) | |
tree | 75ccaf411d6c829864df89a27035b04c560794c5 /com32 | |
parent | 7a115323a6b136af3ac5ee115a1c4c123eebdddc (diff) | |
download | syslinux-a6671b7d17293cf3f7fac1083ae16542828987b4.tar.gz syslinux-a6671b7d17293cf3f7fac1083ae16542828987b4.tar.xz syslinux-a6671b7d17293cf3f7fac1083ae16542828987b4.zip |
initramfs chain handling: Accounting fixes for padding, etc.multi_initrd
Signed-off-by: Shao Miller <sha0.miller@gmail.com>
Diffstat (limited to 'com32')
-rw-r--r-- | com32/lib/syslinux/initramfs_file.c | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/com32/lib/syslinux/initramfs_file.c b/com32/lib/syslinux/initramfs_file.c index 763eff28..7eb55b5e 100644 --- a/com32/lib/syslinux/initramfs_file.c +++ b/com32/lib/syslinux/initramfs_file.c @@ -65,7 +65,7 @@ static size_t initramfs_mkdirs(const char *filename, void *buffer, const char *p = filename; char *bp = buffer; int len; - size_t bytes = 0; + size_t bytes = 0, hdr_sz; int pad; while ((p = strchr(p, '/'))) { @@ -81,15 +81,17 @@ static size_t initramfs_mkdirs(const char *filename, void *buffer, while ((p = strchr(p, '/'))) { if (p != filename && p[-1] != '/') { len = p - filename; + hdr_sz = ((sizeof(struct cpio_header) + len + 1) + 3) & ~3; bp += sprintf(bp, "070701%08x%08x%08x%08x%08x%08x%08x%08x%08x" "%08x%08x%08x%08x", next_ino++, S_IFDIR | 0755, 0, 0, 1, 0, 0, 0, 1, 0, 1, len + 1, 0); memcpy(bp, filename, len); bp += len; - pad = (-(sizeof(struct cpio_header) + len) & 3) + 1; + pad = hdr_sz - (sizeof(struct cpio_header) + len); memset(bp, 0, pad); bp += pad; } + p++; } } @@ -104,7 +106,7 @@ int initramfs_mknod(struct initramfs *ihead, const char *filename, int do_mkdir, uint16_t mode, size_t len, uint32_t major, uint32_t minor) { - size_t bytes; + size_t bytes, hdr_sz; int namelen = strlen(filename); int pad; char *buffer, *bp; @@ -114,7 +116,8 @@ int initramfs_mknod(struct initramfs *ihead, const char *filename, else bytes = 0; - bytes += ((sizeof(struct cpio_header) + namelen + 1) + 3) & ~3; + hdr_sz = ((sizeof(struct cpio_header) + namelen + 1) + 3) & ~3; + bytes += hdr_sz; bp = buffer = malloc(bytes); if (!buffer) @@ -127,8 +130,8 @@ int initramfs_mknod(struct initramfs *ihead, const char *filename, "%08x%08x%08x%08x", next_ino++, mode, 0, 0, 1, 0, len, 0, 1, major, minor, namelen + 1, 0); memcpy(bp, filename, namelen); - bp += len; - pad = (-(sizeof(struct cpio_header) + namelen) & 3) + 1; + bp += namelen; + pad = hdr_sz - (sizeof(struct cpio_header) + namelen); memset(bp, 0, pad); if (initramfs_add_data(ihead, buffer, bytes, bytes, 4)) { |