Date: Thu, 26 Jun 2014 01:10:53 +0000 (UTC) From: Marcel Moolenaar <marcel@FreeBSD.org> To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r267888 - user/marcel/mkimg Message-ID: <201406260110.s5Q1Aro1052992@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: marcel Date: Thu Jun 26 01:10:53 2014 New Revision: 267888 URL: http://svnweb.freebsd.org/changeset/base/267888 Log: Sync with ^/head. Modified: user/marcel/mkimg/apm.c user/marcel/mkimg/bsd.c user/marcel/mkimg/image.c user/marcel/mkimg/mkimg.1 (contents, props changed) user/marcel/mkimg/scheme.c (contents, props changed) user/marcel/mkimg/vtoc8.c Directory Properties: user/marcel/mkimg/ (props changed) user/marcel/mkimg/Makefile (props changed) user/marcel/mkimg/scheme.h (props changed) Modified: user/marcel/mkimg/apm.c ============================================================================== --- user/marcel/mkimg/apm.c Thu Jun 26 00:31:58 2014 (r267887) +++ user/marcel/mkimg/apm.c Thu Jun 26 01:10:53 2014 (r267888) @@ -86,8 +86,8 @@ apm_write(lba_t imgsz, void *bootcode __ be32enc(&ent->ent_pmblkcnt, nparts + 1); be32enc(&ent->ent_start, 1); be32enc(&ent->ent_size, nparts + 1); - strcpy(ent->ent_type, APM_ENT_TYPE_SELF); - strcpy(ent->ent_name, "Apple"); + strncpy(ent->ent_type, APM_ENT_TYPE_SELF, sizeof(ent->ent_type)); + strncpy(ent->ent_name, "Apple", sizeof(ent->ent_name)); STAILQ_FOREACH(part, &partlist, link) { ent = (void *)(buf + (part->index + 2) * secsz); @@ -95,9 +95,11 @@ apm_write(lba_t imgsz, void *bootcode __ be32enc(&ent->ent_pmblkcnt, nparts + 1); be32enc(&ent->ent_start, part->block); be32enc(&ent->ent_size, part->size); - strcpy(ent->ent_type, ALIAS_TYPE2PTR(part->type)); + strncpy(ent->ent_type, ALIAS_TYPE2PTR(part->type), + sizeof(ent->ent_type)); if (part->label != NULL) - strcpy(ent->ent_name, part->label); + strncpy(ent->ent_name, part->label, + sizeof(ent->ent_name)); } error = image_write(0, buf, nparts + 2); Modified: user/marcel/mkimg/bsd.c ============================================================================== --- user/marcel/mkimg/bsd.c Thu Jun 26 00:31:58 2014 (r267887) +++ user/marcel/mkimg/bsd.c Thu Jun 26 01:10:53 2014 (r267888) @@ -80,10 +80,12 @@ bsd_write(lba_t imgsz, void *bootcode) } else memset(buf, 0, BBSIZE); - imgsz = ncyls * nheads * nsecs; + imgsz = (lba_t)ncyls * nheads * nsecs; error = image_set_size(imgsz); - if (error) + if (error) { + free(buf); return (error); + } d = (void *)(buf + secsz); le32enc(&d->d_magic, DISKMAGIC); Modified: user/marcel/mkimg/image.c ============================================================================== --- user/marcel/mkimg/image.c Thu Jun 26 00:31:58 2014 (r267887) +++ user/marcel/mkimg/image.c Thu Jun 26 01:10:53 2014 (r267888) @@ -30,6 +30,9 @@ __FBSDID("$FreeBSD$"); #include <sys/types.h> #include <assert.h> #include <errno.h> +#include <limits.h> +#include <paths.h> +#include <stdio.h> #include <stdlib.h> #include <unistd.h> @@ -38,7 +41,7 @@ __FBSDID("$FreeBSD$"); #define BUFFER_SIZE (1024*1024) -static char image_tmpfile[] = "/tmp/mkimg-XXXXXX"; +static char image_tmpfile[PATH_MAX]; static int image_fd = -1; static lba_t image_size; @@ -98,11 +101,11 @@ image_copyout(int fd) ofs = lseek(fd, 0L, SEEK_CUR); + if (lseek(image_fd, 0, SEEK_SET) != 0) + return (errno); buffer = malloc(BUFFER_SIZE); if (buffer == NULL) return (errno); - if (lseek(image_fd, 0, SEEK_SET) != 0) - return (errno); error = 0; while (1) { rdsz = read(image_fd, buffer, BUFFER_SIZE); @@ -119,8 +122,12 @@ image_copyout(int fd) } } free(buffer); + if (error) + return (error); ofs = lseek(fd, 0L, SEEK_CUR); - ftruncate(fd, ofs); + if (ofs == -1) + return (errno); + error = (ftruncate(fd, ofs) == -1) ? errno : 0; return (error); } @@ -157,9 +164,14 @@ image_write(lba_t blk, void *buf, ssize_ int image_init(void) { + const char *tmpdir; if (atexit(cleanup) == -1) return (errno); + if ((tmpdir = getenv("TMPDIR")) == NULL || *tmpdir == '\0') + tmpdir = _PATH_TMP; + snprintf(image_tmpfile, sizeof(image_tmpfile), "%s/mkimg-XXXXXX", + tmpdir); image_fd = mkstemp(image_tmpfile); if (image_fd == -1) return (errno); Modified: user/marcel/mkimg/mkimg.1 ============================================================================== --- user/marcel/mkimg/mkimg.1 Thu Jun 26 00:31:58 2014 (r267887) +++ user/marcel/mkimg/mkimg.1 Thu Jun 26 01:10:53 2014 (r267888) @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd March 27, 2014 +.Dd May 22, 2014 .Dt MKIMG 1 .Os .Sh NAME @@ -115,6 +115,12 @@ For a complete list of supported partiti format, or for a detailed description of how to specify partitions, run the .Nm utility without any arguments. +.Sh ENVIRONMENT +.Bl -tag -width "TMPDIR" -compact +.It Ev TMPDIR +Directory to put temporary files in; default is +.Pa /tmp . +.El .Sh EXAMPLES To create a bootable disk image that is partitioned using the GPT scheme and containing a root file system that was previously created using Modified: user/marcel/mkimg/scheme.c ============================================================================== --- user/marcel/mkimg/scheme.c Thu Jun 26 00:31:58 2014 (r267887) +++ user/marcel/mkimg/scheme.c Thu Jun 26 01:10:53 2014 (r267888) @@ -103,14 +103,12 @@ int scheme_bootcode(int fd) { struct stat sb; - int error; if (scheme->bootcode == 0) return (ENXIO); - error = fstat(fd, &sb); - if (error) - return (error); + if (fstat(fd, &sb) == -1) + return (errno); if (sb.st_size > scheme->bootcode) return (EFBIG); Modified: user/marcel/mkimg/vtoc8.c ============================================================================== --- user/marcel/mkimg/vtoc8.c Thu Jun 26 00:31:58 2014 (r267887) +++ user/marcel/mkimg/vtoc8.c Thu Jun 26 01:10:53 2014 (r267888) @@ -71,7 +71,7 @@ vtoc8_write(lba_t imgsz, void *bootcode int error, n; uint16_t ofs, sum; - imgsz = ncyls * nheads * nsecs; + imgsz = (lba_t)ncyls * nheads * nsecs; memset(&vtoc8, 0, sizeof(vtoc8)); sprintf(vtoc8.ascii, "FreeBSD%lldM",
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201406260110.s5Q1Aro1052992>