Module Name: src Committed By: jakllsch Date: Mon May 17 23:09:52 UTC 2010
Modified Files: src/sys/dev/dkwedge: dkwedge_gpt.c Log Message: Use wput_utf8() to improve conversion of UTF-16 GPT partition names to UTF-8. Drop static CRC32 function in favor of the one from libkern. To generate a diff of this commit: cvs rdiff -u -r1.11 -r1.12 src/sys/dev/dkwedge/dkwedge_gpt.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/dev/dkwedge/dkwedge_gpt.c diff -u src/sys/dev/dkwedge/dkwedge_gpt.c:1.11 src/sys/dev/dkwedge/dkwedge_gpt.c:1.12 --- src/sys/dev/dkwedge/dkwedge_gpt.c:1.11 Mon Jan 25 14:51:03 2010 +++ src/sys/dev/dkwedge/dkwedge_gpt.c Mon May 17 23:09:52 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: dkwedge_gpt.c,v 1.11 2010/01/25 14:51:03 mlelstv Exp $ */ +/* $NetBSD: dkwedge_gpt.c,v 1.12 2010/05/17 23:09:52 jakllsch Exp $ */ /*- * Copyright (c) 2004 The NetBSD Foundation, Inc. @@ -34,7 +34,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: dkwedge_gpt.c,v 1.11 2010/01/25 14:51:03 mlelstv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: dkwedge_gpt.c,v 1.12 2010/05/17 23:09:52 jakllsch Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -47,6 +47,9 @@ #include <sys/disklabel_gpt.h> #include <sys/uuid.h> +/* UTF-8 encoding stuff */ +#include <fs/unicode.h> + /* * GUID to dkw_ptype mapping information. * @@ -86,29 +89,6 @@ return (DKW_PTYPE_UNKNOWN); } -static const uint32_t gpt_crc_tab[16] = { - 0x00000000U, 0x1db71064U, 0x3b6e20c8U, 0x26d930acU, - 0x76dc4190U, 0x6b6b51f4U, 0x4db26158U, 0x5005713cU, - 0xedb88320U, 0xf00f9344U, 0xd6d6a3e8U, 0xcb61b38cU, - 0x9b64c2b0U, 0x86d3d2d4U, 0xa00ae278U, 0xbdbdf21cU -}; - -static uint32_t -gpt_crc32(const void *vbuf, size_t len) -{ - const uint8_t *buf = vbuf; - uint32_t crc; - - crc = 0xffffffffU; - while (len--) { - crc ^= *buf++; - crc = (crc >> 4) ^ gpt_crc_tab[crc & 0xf]; - crc = (crc >> 4) ^ gpt_crc_tab[crc & 0xf]; - } - - return (crc ^ 0xffffffffU); -} - static int gpt_verify_header_crc(struct gpt_hdr *hdr) { @@ -117,7 +97,7 @@ crc = hdr->hdr_crc_self; hdr->hdr_crc_self = 0; - rv = le32toh(crc) == gpt_crc32(hdr, le32toh(hdr->hdr_size)); + rv = le32toh(crc) == crc32(0, (void *)hdr, le32toh(hdr->hdr_size)); hdr->hdr_crc_self = crc; return (rv); @@ -138,6 +118,8 @@ uint32_t gpe_crc; int error; u_int i; + size_t r, n; + uint8_t *c; secsize = DEV_BSIZE << pdk->dk_blkshift; buf = malloc(secsize, M_DEVBUF, M_WAITOK); @@ -224,7 +206,7 @@ goto out; } - if (gpt_crc32(buf, entries * entsz) != gpe_crc) { + if (crc32(0, buf, entries * entsz) != gpe_crc) { /* XXX Should check alternate location. */ aprint_error("%s: bad GPT partition array CRC\n", pdk->dk_name); @@ -268,12 +250,15 @@ if (ent->ent_name[0] == 0x0000) strcpy(dkw.dkw_wname, ent_guid_str); else { + c = dkw.dkw_wname; + r = sizeof(dkw.dkw_wname) - 1; for (j = 0; ent->ent_name[j] != 0x0000; j++) { - /* XXX UTF-16 -> UTF-8 */ - dkw.dkw_wname[j] = - le16toh(ent->ent_name[j]) & 0xff; + n = wput_utf8(c, r, le16toh(ent->ent_name[j])); + if (n == 0) + break; + c += n; r -= n; } - dkw.dkw_wname[j] = '\0'; + *c = '\0'; } /*