Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 7 May 2014 17:33:31 +0000 (UTC)
From:      Marcel Moolenaar <marcel@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-user@freebsd.org
Subject:   svn commit: r265579 - user/marcel/mkimg
Message-ID:  <201405071733.s47HXVpf092710@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: marcel
Date: Wed May  7 17:33:31 2014
New Revision: 265579
URL: http://svnweb.freebsd.org/changeset/base/265579

Log:
  Switch to the image API:
  1.  Replace calls to mkimg_set_size() with calls to image_set_size()
  2.  Remove the mkimg_set_size() function
  3.  As above but for mkimg_write() and image_write()
  
  Note that this breaks mkimg(1). The image API has no implementation.
  Hence doing it on my branch :-)

Modified:
  user/marcel/mkimg/apm.c
  user/marcel/mkimg/bsd.c
  user/marcel/mkimg/ebr.c
  user/marcel/mkimg/gpt.c
  user/marcel/mkimg/image.c
  user/marcel/mkimg/image.h
  user/marcel/mkimg/mbr.c
  user/marcel/mkimg/mkimg.c
  user/marcel/mkimg/mkimg.h
  user/marcel/mkimg/pc98.c
  user/marcel/mkimg/scheme.c
  user/marcel/mkimg/scheme.h
  user/marcel/mkimg/vtoc8.c

Modified: user/marcel/mkimg/apm.c
==============================================================================
--- user/marcel/mkimg/apm.c	Wed May  7 17:21:22 2014	(r265578)
+++ user/marcel/mkimg/apm.c	Wed May  7 17:33:31 2014	(r265579)
@@ -35,6 +35,7 @@ __FBSDID("$FreeBSD$");
 #include <string.h>
 #include <unistd.h>
 
+#include "image.h"
 #include "mkimg.h"
 #include "scheme.h"
 
@@ -63,7 +64,7 @@ apm_metadata(u_int where)
 }
 
 static int
-apm_write(int fd, lba_t imgsz, void *bootcode __unused)
+apm_write(lba_t imgsz, void *bootcode __unused)
 {
 	u_char *buf;
 	struct apm_ddr *ddr;
@@ -99,7 +100,7 @@ apm_write(int fd, lba_t imgsz, void *boo
 			strcpy(ent->ent_name, part->label);
 	}
 
-	error = mkimg_write(fd, 0, buf, nparts + 2);
+	error = image_write(0, buf, nparts + 2);
 	free(buf);
 	return (error);
 }

Modified: user/marcel/mkimg/bsd.c
==============================================================================
--- user/marcel/mkimg/bsd.c	Wed May  7 17:21:22 2014	(r265578)
+++ user/marcel/mkimg/bsd.c	Wed May  7 17:33:31 2014	(r265579)
@@ -35,6 +35,7 @@ __FBSDID("$FreeBSD$");
 #include <string.h>
 #include <unistd.h>
 
+#include "image.h"
 #include "mkimg.h"
 #include "scheme.h"
 
@@ -61,7 +62,7 @@ bsd_metadata(u_int where)
 }
 
 static int
-bsd_write(int fd, lba_t imgsz, void *bootcode)
+bsd_write(lba_t imgsz, void *bootcode)
 {
 	u_char *buf, *p;
 	struct disklabel *d;
@@ -80,7 +81,7 @@ bsd_write(int fd, lba_t imgsz, void *boo
 		memset(buf, 0, BBSIZE);
 
 	imgsz = ncyls * nheads * nsecs;
-	error = mkimg_set_size(fd, imgsz);
+	error = image_set_size(imgsz);
 	if (error)
 		return (error);
 
@@ -113,7 +114,7 @@ bsd_write(int fd, lba_t imgsz, void *boo
 		checksum ^= le16dec(p);
 	le16enc(&d->d_checksum, checksum);
 
-	error = mkimg_write(fd, 0, buf, BBSIZE / secsz);
+	error = image_write(0, buf, BBSIZE / secsz);
 	free(buf);
 	return (error);
 }

Modified: user/marcel/mkimg/ebr.c
==============================================================================
--- user/marcel/mkimg/ebr.c	Wed May  7 17:21:22 2014	(r265578)
+++ user/marcel/mkimg/ebr.c	Wed May  7 17:33:31 2014	(r265579)
@@ -35,6 +35,7 @@ __FBSDID("$FreeBSD$");
 #include <string.h>
 #include <unistd.h>
 
+#include "image.h"
 #include "mkimg.h"
 #include "scheme.h"
 
@@ -67,7 +68,7 @@ ebr_chs(u_char *cyl, u_char *hd, u_char 
 }
 
 static int
-ebr_write(int fd, lba_t imgsz __unused, void *bootcode __unused)
+ebr_write(lba_t imgsz __unused, void *bootcode __unused)
 {
 	u_char *ebr;
 	struct dos_partition *dp;
@@ -104,7 +105,7 @@ ebr_write(int fd, lba_t imgsz __unused, 
 			le32enc(&dp->dp_size, next->size + nsecs);
 		}
 
-		error = mkimg_write(fd, block, ebr, 1);
+		error = image_write(block, ebr, 1);
 		if (error)
 			break;
 

Modified: user/marcel/mkimg/gpt.c
==============================================================================
--- user/marcel/mkimg/gpt.c	Wed May  7 17:21:22 2014	(r265578)
+++ user/marcel/mkimg/gpt.c	Wed May  7 17:33:31 2014	(r265579)
@@ -39,6 +39,7 @@ __FBSDID("$FreeBSD$");
 #include <unistd.h>
 #include <uuid.h>
 
+#include "image.h"
 #include "mkimg.h"
 #include "scheme.h"
 
@@ -166,7 +167,7 @@ gpt_metadata(u_int where)
 }
 
 static int
-gpt_write_pmbr(int fd, lba_t blks, void *bootcode)
+gpt_write_pmbr(lba_t blks, void *bootcode)
 {
 	u_char *pmbr;
 	uint32_t secs;
@@ -190,7 +191,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 = mkimg_write(fd, 0, pmbr, 1);
+	error = image_write(0, pmbr, 1);
 	free(pmbr);
 	return (error);
 }
@@ -226,8 +227,7 @@ gpt_mktbl(u_int tblsz)
 }
 
 static int
-gpt_write_hdr(int fd, struct gpt_hdr *hdr, uint64_t self, uint64_t alt,
-    uint64_t tbl)
+gpt_write_hdr(struct gpt_hdr *hdr, uint64_t self, uint64_t alt, uint64_t tbl)
 {
 	uint32_t crc;
 
@@ -237,11 +237,11 @@ 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 (mkimg_write(fd, self, hdr, 1));
+	return (image_write(self, hdr, 1));
 }
 
 static int
-gpt_write(int fd, lba_t imgsz, void *bootcode)
+gpt_write(lba_t imgsz, void *bootcode)
 {
 	uuid_t uuid;
 	struct gpt_ent *tbl;
@@ -251,7 +251,7 @@ gpt_write(int fd, lba_t imgsz, void *boo
 	int error;
 
 	/* PMBR */
-	error = gpt_write_pmbr(fd, imgsz, bootcode);
+	error = gpt_write_pmbr(imgsz, bootcode);
 	if (error)
 		return (error);
 
@@ -260,10 +260,10 @@ gpt_write(int fd, lba_t imgsz, void *boo
 	tbl = gpt_mktbl(tblsz);
 	if (tbl == NULL)
 		return (errno);
-	error = mkimg_write(fd, 2, tbl, tblsz);
+	error = image_write(2, tbl, tblsz);
 	if (error)
 		goto out;
-	error = mkimg_write(fd, imgsz - (tblsz + 1), tbl, tblsz);
+	error = image_write(imgsz - (tblsz + 1), tbl, tblsz);
 	if (error)
 		goto out;
 
@@ -285,9 +285,9 @@ gpt_write(int fd, lba_t imgsz, void *boo
 	le32enc(&hdr->hdr_entsz, sizeof(struct gpt_ent));
 	crc = crc32(tbl, nparts * sizeof(struct gpt_ent));
 	le32enc(&hdr->hdr_crc_table, crc);
-	error = gpt_write_hdr(fd, hdr, 1, imgsz - 1, 2);
+	error = gpt_write_hdr(hdr, 1, imgsz - 1, 2);
 	if (!error)
-		error = gpt_write_hdr(fd, hdr, imgsz - 1, 1, imgsz - tblsz - 1);
+		error = gpt_write_hdr(hdr, imgsz - 1, 1, imgsz - tblsz - 1);
 	free(hdr);
 
  out:

Modified: user/marcel/mkimg/image.c
==============================================================================
--- user/marcel/mkimg/image.c	Wed May  7 17:21:22 2014	(r265578)
+++ user/marcel/mkimg/image.c	Wed May  7 17:33:31 2014	(r265579)
@@ -33,8 +33,8 @@ __FBSDID("$FreeBSD$");
 #include <stdlib.h>
 #include <unistd.h>
 
-#include "mkimg.h"
 #include "image.h"
+#include "mkimg.h"
 
 #define	BUFFER_SIZE	(1024*1024)
 

Modified: user/marcel/mkimg/image.h
==============================================================================
--- user/marcel/mkimg/image.h	Wed May  7 17:21:22 2014	(r265578)
+++ user/marcel/mkimg/image.h	Wed May  7 17:33:31 2014	(r265579)
@@ -29,6 +29,8 @@
 #ifndef _MKIMG_IMAGE_H_
 #define	_MKIMG_IMAGE_H_
 
+typedef int64_t lba_t;
+
 int image_copyin(lba_t blk, int fd, uint64_t *sizep);
 int image_set_size(lba_t blk);
 int image_write(lba_t blk, void *buf, ssize_t len);

Modified: user/marcel/mkimg/mbr.c
==============================================================================
--- user/marcel/mkimg/mbr.c	Wed May  7 17:21:22 2014	(r265578)
+++ user/marcel/mkimg/mbr.c	Wed May  7 17:33:31 2014	(r265579)
@@ -35,6 +35,7 @@ __FBSDID("$FreeBSD$");
 #include <string.h>
 #include <unistd.h>
 
+#include "image.h"
 #include "mkimg.h"
 #include "scheme.h"
 
@@ -68,7 +69,7 @@ mbr_chs(u_char *cyl, u_char *hd, u_char 
 }
 
 static int
-mbr_write(int fd, lba_t imgsz __unused, void *bootcode)
+mbr_write(lba_t imgsz __unused, void *bootcode)
 {
 	u_char *mbr;
 	struct dos_partition *dpbase, *dp;
@@ -96,7 +97,7 @@ mbr_write(int fd, lba_t imgsz __unused, 
 		le32enc(&dp->dp_start, part->block);
 		le32enc(&dp->dp_size, part->size);
 	}
-	error = mkimg_write(fd, 0, mbr, 1);
+	error = image_write(0, mbr, 1);
 	free(mbr);
 	return (error);
 }

Modified: user/marcel/mkimg/mkimg.c
==============================================================================
--- user/marcel/mkimg/mkimg.c	Wed May  7 17:21:22 2014	(r265578)
+++ user/marcel/mkimg/mkimg.c	Wed May  7 17:33:31 2014	(r265579)
@@ -42,6 +42,7 @@ __FBSDID("$FreeBSD$");
 #include <sysexits.h>
 #include <unistd.h>
 
+#include "image.h"
 #include "mkimg.h"
 #include "scheme.h"
 
@@ -316,28 +317,6 @@ fdcopy(int src, lba_t sblk, int dst, lba
 	return (errno);
 }
 
-int
-mkimg_set_size(int fd, lba_t blk)
-{
-
-	if (ftruncate(fd, blk * secsz) == -1)
-		return (errno);
-	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 ofd, int bfd)
 {
@@ -401,7 +380,7 @@ mkimg(int ofd, int bfd)
 	}
 
 	block = scheme_metadata(SCHEME_META_IMG_END, block);
-	error = (scheme_write(ofd, block));
+	error = (scheme_write(block));
 }
 
 int

Modified: user/marcel/mkimg/mkimg.h
==============================================================================
--- user/marcel/mkimg/mkimg.h	Wed May  7 17:21:22 2014	(r265578)
+++ user/marcel/mkimg/mkimg.h	Wed May  7 17:33:31 2014	(r265579)
@@ -31,8 +31,6 @@
 
 #include <sys/queue.h>
 
-typedef int64_t	lba_t;
-
 struct part {
 	STAILQ_ENTRY(part) link;
 	char	*alias;		/* Partition type alias. */
@@ -67,7 +65,4 @@ round_block(lba_t n)
 	return ((n + b - 1) & ~(b - 1));
 }
 
-int mkimg_set_size(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 17:21:22 2014	(r265578)
+++ user/marcel/mkimg/pc98.c	Wed May  7 17:33:31 2014	(r265579)
@@ -35,6 +35,7 @@ __FBSDID("$FreeBSD$");
 #include <string.h>
 #include <unistd.h>
 
+#include "image.h"
 #include "mkimg.h"
 #include "scheme.h"
 
@@ -77,7 +78,7 @@ pc98_chs(u_short *cyl, u_char *hd, u_cha
 }
 
 static int
-pc98_write(int fd, lba_t imgsz __unused, void *bootcode)
+pc98_write(lba_t imgsz __unused, void *bootcode)
 {
 	struct part *part;
 	struct pc98_partition *dpbase, *dp;
@@ -106,7 +107,7 @@ pc98_write(int fd, lba_t imgsz __unused,
 		if (part->label != NULL)
 			memcpy(dp->dp_name, part->label, strlen(part->label));
 	}
-	error = mkimg_write(fd, 0, buf, PC98_BOOTCODESZ / secsz);
+	error = image_write(0, buf, PC98_BOOTCODESZ / secsz);
 	free(buf);
 	return (error);
 }

Modified: user/marcel/mkimg/scheme.c
==============================================================================
--- user/marcel/mkimg/scheme.c	Wed May  7 17:21:22 2014	(r265578)
+++ user/marcel/mkimg/scheme.c	Wed May  7 17:33:31 2014	(r265579)
@@ -38,6 +38,7 @@ __FBSDID("$FreeBSD$");
 #include <string.h>
 #include <unistd.h>
 
+#include "image.h"
 #include "mkimg.h"
 #include "scheme.h"
 
@@ -181,7 +182,7 @@ scheme_metadata(u_int where, lba_t start
 }
 
 int
-scheme_write(int fd, lba_t end)
+scheme_write(lba_t end)
 {
 	u_int cylsz;
 	int error;
@@ -189,8 +190,8 @@ scheme_write(int fd, lba_t end)
 	cylsz = nsecs * nheads;
 	ncyls = (end + cylsz - 1) / cylsz;
 
-	error = mkimg_set_size(fd, end);
+	error = image_set_size(end);
 	if (!error)
-		error = scheme->write(fd, end, bootcode);
+		error = scheme->write(end, bootcode);
 	return (error);
 }

Modified: user/marcel/mkimg/scheme.h
==============================================================================
--- user/marcel/mkimg/scheme.h	Wed May  7 17:21:22 2014	(r265578)
+++ user/marcel/mkimg/scheme.h	Wed May  7 17:33:31 2014	(r265579)
@@ -67,7 +67,7 @@ struct mkimg_scheme {
 #define	SCHEME_META_IMG_END	2
 #define	SCHEME_META_PART_BEFORE	3
 #define	SCHEME_META_PART_AFTER	4
-	int		(*write)(int, lba_t, void *);
+	int		(*write)(lba_t, void *);
 	u_int		nparts;
 	u_int		labellen;
 	u_int		bootcode;
@@ -85,6 +85,6 @@ int scheme_check_part(struct part *);
 u_int scheme_max_parts(void);
 u_int scheme_max_secsz(void);
 lba_t scheme_metadata(u_int, lba_t);
-int scheme_write(int, lba_t);
+int scheme_write(lba_t);
 
 #endif /* _MKIMG_SCHEME_H_ */

Modified: user/marcel/mkimg/vtoc8.c
==============================================================================
--- user/marcel/mkimg/vtoc8.c	Wed May  7 17:21:22 2014	(r265578)
+++ user/marcel/mkimg/vtoc8.c	Wed May  7 17:33:31 2014	(r265579)
@@ -36,6 +36,7 @@ __FBSDID("$FreeBSD$");
 #include <string.h>
 #include <unistd.h>
 
+#include "image.h"
 #include "mkimg.h"
 #include "scheme.h"
 
@@ -62,7 +63,7 @@ vtoc8_metadata(u_int where)
 }
 
 static int
-vtoc8_write(int fd, lba_t imgsz, void *bootcode __unused)
+vtoc8_write(lba_t imgsz, void *bootcode __unused)
 {
 	struct vtoc8 vtoc8;
 	struct part *part;
@@ -86,7 +87,7 @@ vtoc8_write(int fd, lba_t imgsz, void *b
 	be16enc(&vtoc8.nsecs, nsecs);
 	be16enc(&vtoc8.magic, VTOC_MAGIC);
 
-	error = mkimg_set_size(fd, imgsz);
+	error = image_set_size(imgsz);
 	if (error)
 		return (error);
 
@@ -105,7 +106,7 @@ vtoc8_write(int fd, lba_t imgsz, void *b
 		sum ^= be16dec(p + ofs);
 	be16enc(&vtoc8.cksum, sum);
 
-	error = mkimg_write(fd, 0, &vtoc8, 1);
+	error = image_write(0, &vtoc8, 1);
 	return (error);
 }
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201405071733.s47HXVpf092710>