Date: Wed, 7 May 2014 14:20:59 +0000 (UTC) From: Marcel Moolenaar <marcel@FreeBSD.org> To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r265547 - user/marcel/mkimg Message-ID: <201405071420.s47EKxPA006894@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: marcel Date: Wed May 7 14:20:58 2014 New Revision: 265547 URL: http://svnweb.freebsd.org/changeset/base/265547 Log: Merge ^/head/usr.bin/mkimg@265546 Modified: user/marcel/mkimg/apm.c user/marcel/mkimg/bsd.c user/marcel/mkimg/ebr.c user/marcel/mkimg/gpt.c user/marcel/mkimg/mbr.c user/marcel/mkimg/mkimg.c (contents, props changed) user/marcel/mkimg/mkimg.h user/marcel/mkimg/pc98.c user/marcel/mkimg/vtoc8.c Directory Properties: user/marcel/mkimg/ (props changed) Modified: user/marcel/mkimg/apm.c ============================================================================== --- user/marcel/mkimg/apm.c Wed May 7 13:53:38 2014 (r265546) +++ user/marcel/mkimg/apm.c Wed May 7 14:20:58 2014 (r265547) @@ -38,8 +38,13 @@ __FBSDID("$FreeBSD$"); #include "mkimg.h" #include "scheme.h" +#ifndef APM_ENT_TYPE_FREEBSD_NANDFS +#define APM_ENT_TYPE_FREEBSD_NANDFS "FreeBSD-nandfs" +#endif + static struct mkimg_alias apm_aliases[] = { { ALIAS_FREEBSD, ALIAS_PTR2TYPE(APM_ENT_TYPE_FREEBSD) }, + { ALIAS_FREEBSD_BOOT, ALIAS_PTR2TYPE(APM_ENT_TYPE_APPLE_BOOT) }, { ALIAS_FREEBSD_NANDFS, ALIAS_PTR2TYPE(APM_ENT_TYPE_FREEBSD_NANDFS) }, { ALIAS_FREEBSD_SWAP, ALIAS_PTR2TYPE(APM_ENT_TYPE_FREEBSD_SWAP) }, { ALIAS_FREEBSD_UFS, ALIAS_PTR2TYPE(APM_ENT_TYPE_FREEBSD_UFS) }, @@ -58,13 +63,12 @@ apm_metadata(u_int where) } static int -apm_write(int fd __unused, lba_t imgsz __unused, void *bootcode __unused) +apm_write(int fd, lba_t imgsz, void *bootcode __unused) { u_char *buf; struct apm_ddr *ddr; struct apm_ent *ent; struct part *part; - ssize_t nbytes; int error; buf = calloc(nparts + 2, secsz); @@ -95,12 +99,7 @@ apm_write(int fd __unused, lba_t imgsz _ strcpy(ent->ent_name, part->label); } - error = mkimg_seek(fd, 0); - if (error == 0) { - nbytes = (nparts + 2) * secsz; - if (write(fd, buf, nbytes) != nbytes) - error = errno; - } + error = mkimg_write(fd, 0, buf, nparts + 2); free(buf); return (error); } Modified: user/marcel/mkimg/bsd.c ============================================================================== --- user/marcel/mkimg/bsd.c Wed May 7 13:53:38 2014 (r265546) +++ user/marcel/mkimg/bsd.c Wed May 7 14:20:58 2014 (r265547) @@ -38,6 +38,10 @@ __FBSDID("$FreeBSD$"); #include "mkimg.h" #include "scheme.h" +#ifndef FS_NANDFS +#define FS_NANDFS 30 +#endif + static struct mkimg_alias bsd_aliases[] = { { ALIAS_FREEBSD_NANDFS, ALIAS_INT2TYPE(FS_NANDFS) }, { ALIAS_FREEBSD_SWAP, ALIAS_INT2TYPE(FS_SWAP) }, @@ -107,11 +111,7 @@ bsd_write(int fd, lba_t imgsz, void *boo checksum ^= le16dec(p); le16enc(&d->d_checksum, checksum); - error = mkimg_seek(fd, 0); - if (error == 0) { - if (write(fd, buf, BBSIZE) != BBSIZE) - error = errno; - } + error = mkimg_write(fd, 0, buf, BBSIZE / secsz); free(buf); return (error); } Modified: user/marcel/mkimg/ebr.c ============================================================================== --- user/marcel/mkimg/ebr.c Wed May 7 13:53:38 2014 (r265546) +++ user/marcel/mkimg/ebr.c Wed May 7 14:20:58 2014 (r265547) @@ -38,6 +38,10 @@ __FBSDID("$FreeBSD$"); #include "mkimg.h" #include "scheme.h" +#ifndef DOSPTYP_FAT32 +#define DOSPTYP_FAT32 0x0b +#endif + static struct mkimg_alias ebr_aliases[] = { { ALIAS_FAT32, ALIAS_INT2TYPE(DOSPTYP_FAT32) }, { ALIAS_FREEBSD, ALIAS_INT2TYPE(DOSPTYP_386BSD) }, @@ -100,11 +104,7 @@ ebr_write(int fd, lba_t imgsz __unused, le32enc(&dp->dp_size, next->size + nsecs); } - error = mkimg_seek(fd, block); - if (error == 0) { - if (write(fd, ebr, secsz) != (ssize_t)secsz) - error = errno; - } + error = mkimg_write(fd, block, ebr, 1); if (error) break; Modified: user/marcel/mkimg/gpt.c ============================================================================== --- user/marcel/mkimg/gpt.c Wed May 7 13:53:38 2014 (r265546) +++ user/marcel/mkimg/gpt.c Wed May 7 14:20:58 2014 (r265547) @@ -42,6 +42,11 @@ __FBSDID("$FreeBSD$"); #include "mkimg.h" #include "scheme.h" +#ifndef GPT_ENT_TYPE_FREEBSD_NANDFS +#define GPT_ENT_TYPE_FREEBSD_NANDFS \ + {0x74ba7dd9,0xa689,0x11e1,0xbd,0x04,{0x00,0xe0,0x81,0x28,0x6a,0xcf}} +#endif + static uuid_t gpt_uuid_efi = GPT_ENT_TYPE_EFI; static uuid_t gpt_uuid_freebsd = GPT_ENT_TYPE_FREEBSD; static uuid_t gpt_uuid_freebsd_boot = GPT_ENT_TYPE_FREEBSD_BOOT; @@ -123,6 +128,21 @@ crc32(const void *buf, size_t sz) return (crc ^ ~0U); } +static void +gpt_uuid_enc(void *buf, const uuid_t *uuid) +{ + uint8_t *p = buf; + int i; + + le32enc(p, uuid->time_low); + le16enc(p + 4, uuid->time_mid); + le16enc(p + 6, uuid->time_hi_and_version); + p[8] = uuid->clock_seq_hi_and_reserved; + p[9] = uuid->clock_seq_low; + for (i = 0; i < _UUID_NODE_LEN; i++) + p[10 + i] = uuid->node[i]; +} + static u_int gpt_tblsz(void) { @@ -146,19 +166,6 @@ gpt_metadata(u_int where) } static int -gpt_filewrite(int fd, lba_t blk, void *buf, ssize_t bufsz) -{ - int error; - - error = mkimg_seek(fd, blk); - if (error == 0) { - if (write(fd, buf, bufsz) != bufsz) - error = errno; - } - return (error); -} - -static int gpt_write_pmbr(int fd, lba_t blks, void *bootcode) { u_char *pmbr; @@ -183,7 +190,7 @@ gpt_write_pmbr(int fd, lba_t blks, void le32enc(pmbr + DOSPARTOFF + 8, 1); le32enc(pmbr + DOSPARTOFF + 12, secs); le16enc(pmbr + DOSMAGICOFFSET, DOSMAGIC); - error = gpt_filewrite(fd, 0, pmbr, secsz); + error = mkimg_write(fd, 0, pmbr, 1); free(pmbr); return (error); } @@ -202,9 +209,9 @@ gpt_mktbl(u_int tblsz) STAILQ_FOREACH(part, &partlist, link) { ent = tbl + part->index; - uuid_enc_le(&ent->ent_type, ALIAS_TYPE2PTR(part->type)); + gpt_uuid_enc(&ent->ent_type, ALIAS_TYPE2PTR(part->type)); uuidgen(&uuid, 1); - uuid_enc_le(&ent->ent_uuid, &uuid); + gpt_uuid_enc(&ent->ent_uuid, &uuid); le64enc(&ent->ent_lba_start, part->block); le64enc(&ent->ent_lba_end, part->block + part->size - 1); if (part->label != NULL) { @@ -230,7 +237,7 @@ gpt_write_hdr(int fd, struct gpt_hdr *hd hdr->hdr_crc_self = 0; crc = crc32(hdr, offsetof(struct gpt_hdr, padding)); le64enc(&hdr->hdr_crc_self, crc); - return (gpt_filewrite(fd, self, hdr, secsz)); + return (mkimg_write(fd, self, hdr, 1)); } static int @@ -253,10 +260,10 @@ gpt_write(int fd, lba_t imgsz, void *boo tbl = gpt_mktbl(tblsz); if (tbl == NULL) return (errno); - error = gpt_filewrite(fd, 2, tbl, tblsz * secsz); + error = mkimg_write(fd, 2, tbl, tblsz); if (error) goto out; - error = gpt_filewrite(fd, imgsz - (tblsz + 1), tbl, tblsz * secsz); + error = mkimg_write(fd, imgsz - (tblsz + 1), tbl, tblsz); if (error) goto out; @@ -273,7 +280,7 @@ gpt_write(int fd, lba_t imgsz, void *boo le64enc(&hdr->hdr_lba_start, 2 + tblsz); le64enc(&hdr->hdr_lba_end, imgsz - tblsz - 2); uuidgen(&uuid, 1); - uuid_enc_le(&hdr->hdr_uuid, &uuid); + gpt_uuid_enc(&hdr->hdr_uuid, &uuid); le32enc(&hdr->hdr_entries, nparts); le32enc(&hdr->hdr_entsz, sizeof(struct gpt_ent)); crc = crc32(tbl, nparts * sizeof(struct gpt_ent)); Modified: user/marcel/mkimg/mbr.c ============================================================================== --- user/marcel/mkimg/mbr.c Wed May 7 13:53:38 2014 (r265546) +++ user/marcel/mkimg/mbr.c Wed May 7 14:20:58 2014 (r265547) @@ -38,6 +38,10 @@ __FBSDID("$FreeBSD$"); #include "mkimg.h" #include "scheme.h" +#ifndef DOSPTYP_FAT32 +#define DOSPTYP_FAT32 0x0b +#endif + static struct mkimg_alias mbr_aliases[] = { { ALIAS_EBR, ALIAS_INT2TYPE(DOSPTYP_EXT) }, { ALIAS_FAT32, ALIAS_INT2TYPE(DOSPTYP_FAT32) }, @@ -92,11 +96,7 @@ mbr_write(int fd, lba_t imgsz __unused, le32enc(&dp->dp_start, part->block); le32enc(&dp->dp_size, part->size); } - error = mkimg_seek(fd, 0); - if (error == 0) { - if (write(fd, mbr, secsz) != (ssize_t)secsz) - error = errno; - } + error = mkimg_write(fd, 0, mbr, 1); free(mbr); return (error); } Modified: user/marcel/mkimg/mkimg.c ============================================================================== --- user/marcel/mkimg/mkimg.c Wed May 7 13:53:38 2014 (r265546) +++ user/marcel/mkimg/mkimg.c Wed May 7 14:20:58 2014 (r265547) @@ -302,7 +302,7 @@ fdcopy(int src, int dst, uint64_t *count return (errno); } -int +static int mkimg_seek(int fd, lba_t blk) { off_t off; @@ -313,6 +313,19 @@ mkimg_seek(int fd, lba_t blk) return (0); } +int +mkimg_write(int fd, lba_t blk, void *buf, ssize_t len) +{ + + blk *= secsz; + if (lseek(fd, blk, SEEK_SET) != blk) + return (errno); + len *= secsz; + if (write(fd, buf, len) != len) + return (errno); + return (0); +} + static void mkimg(int bfd) { Modified: user/marcel/mkimg/mkimg.h ============================================================================== --- user/marcel/mkimg/mkimg.h Wed May 7 13:53:38 2014 (r265546) +++ user/marcel/mkimg/mkimg.h Wed May 7 14:20:58 2014 (r265547) @@ -67,6 +67,6 @@ round_block(lba_t n) return ((n + b - 1) & ~(b - 1)); } -int mkimg_seek(int fd, lba_t blk); +int mkimg_write(int fd, lba_t blk, void *buf, ssize_t len); #endif /* _MKIMG_MKIMG_H_ */ Modified: user/marcel/mkimg/pc98.c ============================================================================== --- user/marcel/mkimg/pc98.c Wed May 7 13:53:38 2014 (r265546) +++ user/marcel/mkimg/pc98.c Wed May 7 14:20:58 2014 (r265547) @@ -38,6 +38,19 @@ __FBSDID("$FreeBSD$"); #include "mkimg.h" #include "scheme.h" +#ifndef PC98_MAGIC +#define PC98_MAGIC 0xaa55 +#endif +#ifndef PC98_MAGICOFS +#define PC98_MAGICOFS 510 +#endif +#ifndef PC98_NPARTS +#define PC98_NPARTS 16 +#endif +#ifndef PC98_PTYP_386BSD +#define PC98_PTYP_386BSD 0xc494 +#endif + #define PC98_BOOTCODESZ 8192 static struct mkimg_alias pc98_aliases[] = { @@ -93,11 +106,7 @@ pc98_write(int fd, lba_t imgsz __unused, if (part->label != NULL) memcpy(dp->dp_name, part->label, strlen(part->label)); } - error = mkimg_seek(fd, 0); - if (error == 0) { - if (write(fd, buf, PC98_BOOTCODESZ) != PC98_BOOTCODESZ) - error = errno; - } + error = mkimg_write(fd, 0, buf, PC98_BOOTCODESZ / secsz); free(buf); return (error); } Modified: user/marcel/mkimg/vtoc8.c ============================================================================== --- user/marcel/mkimg/vtoc8.c Wed May 7 13:53:38 2014 (r265546) +++ user/marcel/mkimg/vtoc8.c Wed May 7 14:20:58 2014 (r265547) @@ -39,6 +39,10 @@ __FBSDID("$FreeBSD$"); #include "mkimg.h" #include "scheme.h" +#ifndef VTOC_TAG_FREEBSD_NANDFS +#define VTOC_TAG_FREEBSD_NANDFS 0x0905 +#endif + static struct mkimg_alias vtoc8_aliases[] = { { ALIAS_FREEBSD_NANDFS, ALIAS_INT2TYPE(VTOC_TAG_FREEBSD_NANDFS) }, { ALIAS_FREEBSD_SWAP, ALIAS_INT2TYPE(VTOC_TAG_FREEBSD_SWAP) }, @@ -99,11 +103,7 @@ vtoc8_write(int fd, lba_t imgsz, void *b sum ^= be16dec(p + ofs); be16enc(&vtoc8.cksum, sum); - error = mkimg_seek(fd, 0); - if (error == 0) { - if (write(fd, &vtoc8, sizeof(vtoc8)) != sizeof(vtoc8)) - error = errno; - } + error = mkimg_write(fd, 0, &vtoc8, 1); return (error); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201405071420.s47EKxPA006894>