[syslinux] [syslinux:master] isohybrid: Function to write UTF-16LE strings

Geert Stappers stappers at stappers.nl
Mon Jun 23 21:19:03 PDT 2014


Op 2014-06-23 om 20:09 schreef syslinux-bot for H. Peter Anvin:
> Commit-ID:  f9dad5340bcefe34d860e991e8743be01a4d6c3c
> Gitweb:     http://www.syslinux.org/commit/f9dad5340bcefe34d860e991e8743be01a4d6c3c
> Author:     H. Peter Anvin <hpa op zytor.com>
> AuthorDate: Mon, 23 Jun 2014 20:06:51 -0700
> Committer:  H. Peter Anvin <hpa op zytor.com>
> CommitDate: Mon, 23 Jun 2014 20:06:51 -0700
> 
> isohybrid: Function to write UTF-16LE strings
> 
> Rather than open-coding the content of UTF-16LE strings, just add a
> simple function to convert ASCII (only) strings to UTF-16LE.
> 
> Signed-off-by: H. Peter Anvin <hpa op zytor.com>
> 
> ---
>  utils/isohybrid.c | 28 +++++++++++++++++++---------
>  1 file changed, 19 insertions(+), 9 deletions(-)
> 
> diff --git a/utils/isohybrid.c b/utils/isohybrid.c
> index 0011b78..e308a82 100644
> --- a/utils/isohybrid.c
> +++ b/utils/isohybrid.c
> @@ -593,7 +593,7 @@ read_mbr_template(char *path, uint8_t *mbr)
>          err(1, "could not open MBR template file `%s'", path);
>      clearerr(fp);
>      ret = fread(mbr, 1, MBRSIZE, fp);
> -    if (ferror(fp))
> +    if (ferror(fp) || ret != MBRSIZE)
>          err(1, "error while reading MBR template file `%s'", path);
>      fclose(fp);
>  }

Shouldn't that be in a separate commit?


> @@ -786,6 +786,21 @@ reverse_uuid(uuid_t uuid)
>  	t = p[6]; p[6] = p[7]; p[7] = t;
>  }
>  
> +static uint16_t *
> +ascii_to_utf16le(uint16_t *dst, const char *src)
> +{
> +    uint8_t *p = (uint8_t *)dst;
> +    char c;
> +
> +    do {
> +	c = *src++;
> +	*p++ = c;
> +	*p++ = 0;
> +    } while (c);
> +
> +    return (uint16_t *)p;
> +}
> +
>  void
>  initialise_gpt(uint8_t *gpt, uint32_t current, uint32_t alternate, int primary)
>  {
> @@ -793,11 +808,6 @@ initialise_gpt(uint8_t *gpt, uint32_t current, uint32_t alternate, int primary)
>      struct gpt_part_header *part;
>      int hole = 0;
>      int gptsize = 128 / 4 + 2;
> -    char part_name_iso[] = {'I', 0, 'S', 0, 'O', 0, 'H', 0, 'y', 0,
> -                            'b', 0, 'r', 0, 'i', 0, 'd', 0, ' ', 0,
> -                            'I', 0, 'S', 0, 'O', 0,   0, 0};
> -    char part_name_bootimg[]= {'I', 0, 'S', 0, 'O', 0, 'H', 0, 'y', 0,
> -                               'b', 0, 'r', 0, 'i', 0, 'd', 0,   0, 0};
>  
>      if (mac_lba) {
>  	/* 2048 bytes per partition, plus round to 2048 boundary */
> @@ -842,7 +852,7 @@ initialise_gpt(uint8_t *gpt, uint32_t current, uint32_t alternate, int primary)
>      memcpy(part->partTypeGUID, basic_partition, sizeof(uuid_t));
>      part->firstLBA = lendian_64(0);
>      part->lastLBA = lendian_64(psize - 1);
> -    memcpy(part->name, part_name_iso, 28);
> +    ascii_to_utf16le(part->name, "ISOHybrid ISO");
>  
>      gpt += sizeof(struct gpt_part_header);
>      part++;
> @@ -851,7 +861,7 @@ initialise_gpt(uint8_t *gpt, uint32_t current, uint32_t alternate, int primary)
>      memcpy(part->partTypeGUID, basic_partition, sizeof(uuid_t));
>      part->firstLBA = lendian_64(efi_lba * 4);
>      part->lastLBA = lendian_64(part->firstLBA + efi_count - 1);
> -    memcpy(part->name, part_name_bootimg, 20);
> +    ascii_to_utf16le(part->name, "ISOHybrid");
>  
>      gpt += sizeof(struct gpt_part_header);
>  
> @@ -864,7 +874,7 @@ initialise_gpt(uint8_t *gpt, uint32_t current, uint32_t alternate, int primary)
>  	memcpy(part->partTypeGUID, hfs_partition, sizeof(uuid_t));
>  	part->firstLBA = lendian_64(mac_lba * 4);
>  	part->lastLBA = lendian_64(part->firstLBA + mac_count - 1);
> -	memcpy(part->name, part_name_bootimg, 20);
> +	ascii_to_utf16le(part->name, "ISOHybrid");
>  
>  	part--;
>      }
> _______________________________________________
> Syslinux-commits mailing list
> Syslinux-commits op zytor.com
> http://www.zytor.com/mailman/listinfo/syslinux-commits

-- 
Groeten
Geert Stappers
-- 
Leven en laten leven


More information about the Syslinux mailing list