diff options
author | Shao Miller <sha0.miller@gmail.com> | 2012-10-26 02:14:28 -0400 |
---|---|---|
committer | Shao Miller <sha0.miller@gmail.com> | 2012-11-03 01:08:37 -0400 |
commit | 28b3a9d4d7eb932b827122f3e641ce14fb2cbd03 (patch) | |
tree | dbdb0e3e81191cff04be52d69091ce5bd4122344 | |
parent | fb3e1a576ca0243c37786bfd81cc9600d589db45 (diff) | |
download | syslinux-28b3a9d4d7eb932b827122f3e641ce14fb2cbd03.tar.gz syslinux-28b3a9d4d7eb932b827122f3e641ce14fb2cbd03.tar.xz syslinux-28b3a9d4d7eb932b827122f3e641ce14fb2cbd03.zip |
initramfs chain handling: Accounting fixes for padding, etc.
Signed-off-by: Shao Miller <sha0.miller@gmail.com>
-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)) { |