Abstract the use of ftruncate(2) behind mkimg_set_size().
This commit is contained in:
parent
8743dd6a3b
commit
ef21d96a0f
4
bsd.c
4
bsd.c
@ -80,7 +80,9 @@ bsd_write(int fd, lba_t imgsz, void *bootcode)
|
||||
memset(buf, 0, BBSIZE);
|
||||
|
||||
imgsz = ncyls * nheads * nsecs;
|
||||
ftruncate(fd, imgsz * secsz);
|
||||
error = mkimg_set_size(fd, imgsz);
|
||||
if (error)
|
||||
return (error);
|
||||
|
||||
d = (void *)(buf + secsz);
|
||||
le32enc(&d->d_magic, DISKMAGIC);
|
||||
|
9
mkimg.c
9
mkimg.c
@ -316,6 +316,15 @@ fdcopy(int src, lba_t sblk, int dst, lba_t dblk, uint64_t *count)
|
||||
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)
|
||||
{
|
||||
|
1
mkimg.h
1
mkimg.h
@ -67,6 +67,7 @@ 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_ */
|
||||
|
7
scheme.c
7
scheme.c
@ -189,9 +189,8 @@ scheme_write(int fd, lba_t end)
|
||||
cylsz = nsecs * nheads;
|
||||
ncyls = (end + cylsz - 1) / cylsz;
|
||||
|
||||
if (ftruncate(fd, end * secsz) == -1)
|
||||
return (errno);
|
||||
|
||||
error = scheme->write(fd, end, bootcode);
|
||||
error = mkimg_set_size(fd, end);
|
||||
if (!error)
|
||||
error = scheme->write(fd, end, bootcode);
|
||||
return (error);
|
||||
}
|
||||
|
4
vtoc8.c
4
vtoc8.c
@ -86,7 +86,9 @@ vtoc8_write(int fd, lba_t imgsz, void *bootcode __unused)
|
||||
be16enc(&vtoc8.nsecs, nsecs);
|
||||
be16enc(&vtoc8.magic, VTOC_MAGIC);
|
||||
|
||||
ftruncate(fd, imgsz * secsz);
|
||||
error = mkimg_set_size(fd, imgsz);
|
||||
if (error)
|
||||
return (error);
|
||||
|
||||
be32enc(&vtoc8.map[VTOC_RAW_PART].nblks, imgsz);
|
||||
STAILQ_FOREACH(part, &partlist, link) {
|
||||
|
Loading…
Reference in New Issue
Block a user