[Midnightbsd-cvs] src [10467] trunk/usr.sbin/makefs: sync with freebsd
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Wed Jun 6 20:10:34 EDT 2018
Revision: 10467
http://svnweb.midnightbsd.org/src/?rev=10467
Author: laffer1
Date: 2018-06-06 20:10:33 -0400 (Wed, 06 Jun 2018)
Log Message:
-----------
sync with freebsd
Modified Paths:
--------------
trunk/usr.sbin/makefs/Makefile
trunk/usr.sbin/makefs/cd9660/Makefile.inc
trunk/usr.sbin/makefs/cd9660/cd9660_archimedes.c
trunk/usr.sbin/makefs/cd9660/cd9660_archimedes.h
trunk/usr.sbin/makefs/cd9660/cd9660_conversion.c
trunk/usr.sbin/makefs/cd9660/cd9660_debug.c
trunk/usr.sbin/makefs/cd9660/cd9660_eltorito.c
trunk/usr.sbin/makefs/cd9660/cd9660_eltorito.h
trunk/usr.sbin/makefs/cd9660/cd9660_strings.c
trunk/usr.sbin/makefs/cd9660/cd9660_write.c
trunk/usr.sbin/makefs/cd9660/iso9660_rrip.c
trunk/usr.sbin/makefs/cd9660/iso9660_rrip.h
trunk/usr.sbin/makefs/cd9660.c
trunk/usr.sbin/makefs/cd9660.h
trunk/usr.sbin/makefs/ffs/Makefile.inc
trunk/usr.sbin/makefs/ffs/buf.c
trunk/usr.sbin/makefs/ffs/buf.h
trunk/usr.sbin/makefs/ffs/ffs_alloc.c
trunk/usr.sbin/makefs/ffs/ffs_balloc.c
trunk/usr.sbin/makefs/ffs/ffs_bswap.c
trunk/usr.sbin/makefs/ffs/ffs_extern.h
trunk/usr.sbin/makefs/ffs/ffs_subr.c
trunk/usr.sbin/makefs/ffs/mkfs.c
trunk/usr.sbin/makefs/ffs/newfs_extern.h
trunk/usr.sbin/makefs/ffs/ufs_bmap.c
trunk/usr.sbin/makefs/ffs/ufs_bswap.h
trunk/usr.sbin/makefs/ffs/ufs_inode.h
trunk/usr.sbin/makefs/ffs.c
trunk/usr.sbin/makefs/ffs.h
trunk/usr.sbin/makefs/getid.c
trunk/usr.sbin/makefs/makefs.8
trunk/usr.sbin/makefs/makefs.c
trunk/usr.sbin/makefs/makefs.h
trunk/usr.sbin/makefs/walk.c
Added Paths:
-----------
trunk/usr.sbin/makefs/mtree.c
trunk/usr.sbin/makefs/tests/
trunk/usr.sbin/makefs/tests/Makefile
trunk/usr.sbin/makefs/tests/makefs_cd9660_tests.sh
trunk/usr.sbin/makefs/tests/makefs_ffs_tests.sh
trunk/usr.sbin/makefs/tests/makefs_tests_common.sh
Property Changed:
----------------
trunk/usr.sbin/makefs/cd9660/Makefile.inc
trunk/usr.sbin/makefs/ffs/Makefile.inc
trunk/usr.sbin/makefs/makefs.8
Modified: trunk/usr.sbin/makefs/Makefile
===================================================================
--- trunk/usr.sbin/makefs/Makefile 2018-06-07 00:04:57 UTC (rev 10466)
+++ trunk/usr.sbin/makefs/Makefile 2018-06-07 00:10:33 UTC (rev 10467)
@@ -1,12 +1,15 @@
-# $FreeBSD: src/usr.sbin/makefs/Makefile,v 1.2.2.2 2011/07/26 14:41:54 marius Exp $
+# $MidnightBSD$
+# $FreeBSD: stable/10/usr.sbin/makefs/Makefile 290586 2015-11-09 07:56:06Z ngie $
+.include <bsd.own.mk>
+
PROG= makefs
CFLAGS+=-I${.CURDIR}
SRCS= cd9660.c ffs.c \
- getid.c \
makefs.c \
+ mtree.c \
walk.c
MAN= makefs.8
@@ -14,16 +17,32 @@
.include "${.CURDIR}/cd9660/Makefile.inc"
.include "${.CURDIR}/ffs/Makefile.inc"
-.include "${.CURDIR}/compat/Makefile.inc"
CFLAGS+=-DHAVE_STRUCT_STAT_ST_FLAGS=1
CFLAGS+=-DHAVE_STRUCT_STAT_ST_GEN=1
-.PATH: ${.CURDIR}/../mtree
-CFLAGS+=-I${.CURDIR}/../mtree
-SRCS+= misc.c spec.c
+.PATH: ${.CURDIR}/../../contrib/mtree
+CFLAGS+=-I${.CURDIR}/../../contrib/mtree
+SRCS+= getid.c misc.c spec.c
+.PATH: ${.CURDIR}/../../contrib/mknod
+CFLAGS+=-I${.CURDIR}/../../contrib/mknod
+SRCS+= pack_dev.c
+
.PATH: ${.CURDIR}/../../sys/ufs/ffs
SRCS+= ffs_tables.c
+CFLAGS+= -I${.CURDIR}/../../lib/libnetbsd
+LIBNETBSDDIR= ${.OBJDIR}/../../lib/libnetbsd
+LIBNETBSD= ${LIBNETBSDDIR}/libnetbsd.a
+DPADD+= ${LIBNETBSD}
+LDADD+= ${LIBNETBSD}
+
+DPADD+= ${LIBSBUF} ${LIBUTIL}
+LDADD+= -lsbuf -lutil
+
+.if ${MK_TESTS} != "no"
+SUBDIR+= tests
+.endif
+
.include <bsd.prog.mk>
Modified: trunk/usr.sbin/makefs/cd9660/Makefile.inc
===================================================================
--- trunk/usr.sbin/makefs/cd9660/Makefile.inc 2018-06-07 00:04:57 UTC (rev 10466)
+++ trunk/usr.sbin/makefs/cd9660/Makefile.inc 2018-06-07 00:10:33 UTC (rev 10467)
@@ -1,5 +1,5 @@
-# $FreeBSD: src/usr.sbin/makefs/cd9660/Makefile.inc,v 1.1.4.2 2011/07/26 14:41:54 marius Exp $
-#
+# $MidnightBSD$
+# $FreeBSD: stable/10/usr.sbin/makefs/cd9660/Makefile.inc 214921 2010-11-07 16:05:04Z cognet $
.PATH: ${.CURDIR}/cd9660 ${.CURDIR}/../../sys/fs/cd9660/
Property changes on: trunk/usr.sbin/makefs/cd9660/Makefile.inc
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/usr.sbin/makefs/cd9660/cd9660_archimedes.c
===================================================================
--- trunk/usr.sbin/makefs/cd9660/cd9660_archimedes.c 2018-06-07 00:04:57 UTC (rev 10466)
+++ trunk/usr.sbin/makefs/cd9660/cd9660_archimedes.c 2018-06-07 00:10:33 UTC (rev 10467)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/* $NetBSD: cd9660_archimedes.c,v 1.1 2009/01/10 22:06:29 bjh21 Exp $ */
/*-
@@ -38,7 +39,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/usr.sbin/makefs/cd9660/cd9660_archimedes.c,v 1.1.4.2 2011/07/26 14:41:54 marius Exp $");
+__FBSDID("$FreeBSD: stable/10/usr.sbin/makefs/cd9660/cd9660_archimedes.c 214921 2010-11-07 16:05:04Z cognet $");
#include <assert.h>
#include <stdint.h>
Modified: trunk/usr.sbin/makefs/cd9660/cd9660_archimedes.h
===================================================================
--- trunk/usr.sbin/makefs/cd9660/cd9660_archimedes.h 2018-06-07 00:04:57 UTC (rev 10466)
+++ trunk/usr.sbin/makefs/cd9660/cd9660_archimedes.h 2018-06-07 00:10:33 UTC (rev 10467)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/* $NetBSD: cd9660_archimedes.h,v 1.1 2009/01/10 22:06:29 bjh21 Exp $ */
/*-
@@ -29,7 +30,7 @@
/*
* cd9660_archimedes.c - support for RISC OS "ARCHIMEDES" extension
*
- * $FreeBSD: src/usr.sbin/makefs/cd9660/cd9660_archimedes.h,v 1.1.4.2 2011/07/26 14:41:54 marius Exp $
+ * $FreeBSD: stable/10/usr.sbin/makefs/cd9660/cd9660_archimedes.h 214921 2010-11-07 16:05:04Z cognet $
*/
struct ISO_ARCHIMEDES {
Modified: trunk/usr.sbin/makefs/cd9660/cd9660_conversion.c
===================================================================
--- trunk/usr.sbin/makefs/cd9660/cd9660_conversion.c 2018-06-07 00:04:57 UTC (rev 10466)
+++ trunk/usr.sbin/makefs/cd9660/cd9660_conversion.c 2018-06-07 00:10:33 UTC (rev 10467)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/* $NetBSD: cd9660_conversion.c,v 1.4 2007/03/14 14:11:17 christos Exp $ */
/*
@@ -34,7 +35,7 @@
#include "cd9660.h"
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/usr.sbin/makefs/cd9660/cd9660_conversion.c,v 1.1.4.3 2011/08/13 13:15:38 marius Exp $");
+__FBSDID("$FreeBSD: stable/10/usr.sbin/makefs/cd9660/cd9660_conversion.c 224762 2011-08-10 19:12:21Z marius $");
static char cd9660_compute_gm_offset(time_t);
Modified: trunk/usr.sbin/makefs/cd9660/cd9660_debug.c
===================================================================
--- trunk/usr.sbin/makefs/cd9660/cd9660_debug.c 2018-06-07 00:04:57 UTC (rev 10466)
+++ trunk/usr.sbin/makefs/cd9660/cd9660_debug.c 2018-06-07 00:10:33 UTC (rev 10467)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/* $NetBSD: cd9660_debug.c,v 1.11 2010/10/27 18:51:35 christos Exp $ */
/*
@@ -33,7 +34,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/usr.sbin/makefs/cd9660/cd9660_debug.c,v 1.1.4.2 2011/07/26 14:41:54 marius Exp $");
+__FBSDID("$FreeBSD: stable/10/usr.sbin/makefs/cd9660/cd9660_debug.c 214921 2010-11-07 16:05:04Z cognet $");
#include <sys/param.h>
#include <sys/mount.h>
Modified: trunk/usr.sbin/makefs/cd9660/cd9660_eltorito.c
===================================================================
--- trunk/usr.sbin/makefs/cd9660/cd9660_eltorito.c 2018-06-07 00:04:57 UTC (rev 10466)
+++ trunk/usr.sbin/makefs/cd9660/cd9660_eltorito.c 2018-06-07 00:10:33 UTC (rev 10467)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/* $NetBSD: cd9660_eltorito.c,v 1.17 2011/06/23 02:35:56 enami Exp $ */
/*
@@ -36,7 +37,7 @@
#include "cd9660_eltorito.h"
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/usr.sbin/makefs/cd9660/cd9660_eltorito.c,v 1.5.4.3 2011/08/13 13:15:38 marius Exp $");
+__FBSDID("$FreeBSD: stable/10/usr.sbin/makefs/cd9660/cd9660_eltorito.c 233783 2012-04-02 16:26:32Z andreast $");
#ifdef DEBUG
#define ELTORITO_DPRINTF(__x) printf __x
@@ -538,9 +539,19 @@
off_t sector_start, off_t nsectors, off_t sector_size,
const char *part_name, const char *part_type)
{
- uint32_t apm32;
+ uint32_t apm32, part_status;
uint16_t apm16;
+ /* See Apple Tech Note 1189 for the details about the pmPartStatus
+ * flags.
+ * Below the flags which are default:
+ * - IsValid 0x01
+ * - IsAllocated 0x02
+ * - IsReadable 0x10
+ * - IsWritable 0x20
+ */
+ part_status = 0x01 | 0x02 | 0x10 | 0x20;
+
if (fseeko(fd, (off_t)(idx + 1) * sector_size, SEEK_SET) == -1)
err(1, "fseeko");
@@ -562,7 +573,18 @@
fwrite(part_name, strlen(part_name) + 1, 1, fd);
fseek(fd, 32 - strlen(part_name) - 1, SEEK_CUR);
fwrite(part_type, strlen(part_type) + 1, 1, fd);
+ fseek(fd, 32 - strlen(part_type) - 1, SEEK_CUR);
+ apm32 = 0;
+ /* pmLgDataStart */
+ fwrite(&apm32, sizeof(apm32), 1, fd);
+ /* pmDataCnt */
+ apm32 = htobe32(nsectors);
+ fwrite(&apm32, sizeof(apm32), 1, fd);
+ /* pmPartStatus */
+ apm32 = htobe32(part_status);
+ fwrite(&apm32, sizeof(apm32), 1, fd);
+
return 0;
}
@@ -589,7 +611,7 @@
e->entry_type);
}
/*
- * It doesnt matter which one gets written
+ * It doesn't matter which one gets written
* since they are the same size
*/
fwrite(&(e->entry_data.VE), 1, 32, fd);
@@ -666,12 +688,6 @@
cd9660_write_apm_partition_entry(fd, 0, total_parts, 1,
total_parts, 512, "Apple", "Apple_partition_map");
- /* Write ISO9660 descriptor, enclosing the whole disk */
- cd9660_write_apm_partition_entry(fd, 1, total_parts, 0,
- diskStructure.totalSectors *
- (diskStructure.sectorSize / 512), 512, "ISO9660",
- "CD_ROM_Mode_1");
-
/* Write all partition entries */
apm_partitions = 0;
TAILQ_FOREACH(t, &diskStructure.boot_images, image_list) {
@@ -679,11 +695,16 @@
continue;
cd9660_write_apm_partition_entry(fd,
- 2 + apm_partitions++, total_parts,
+ 1 + apm_partitions++, total_parts,
t->sector * (diskStructure.sectorSize / 512),
t->num_sectors * (diskStructure.sectorSize / 512),
512, "CD Boot", "Apple_Bootstrap");
}
+ /* Write ISO9660 descriptor, enclosing the whole disk */
+ cd9660_write_apm_partition_entry(fd, 2 + apm_partitions,
+ total_parts, 0, diskStructure.totalSectors *
+ (diskStructure.sectorSize / 512), 512, "ISO9660",
+ "CD_ROM_Mode_1");
}
return 0;
Modified: trunk/usr.sbin/makefs/cd9660/cd9660_eltorito.h
===================================================================
--- trunk/usr.sbin/makefs/cd9660/cd9660_eltorito.h 2018-06-07 00:04:57 UTC (rev 10466)
+++ trunk/usr.sbin/makefs/cd9660/cd9660_eltorito.h 2018-06-07 00:10:33 UTC (rev 10467)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/* $NetBSD: cd9660_eltorito.h,v 1.5 2009/07/04 14:31:38 ahoka Exp $ */
/*
@@ -31,7 +32,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
- * $FreeBSD: src/usr.sbin/makefs/cd9660/cd9660_eltorito.h,v 1.1.4.2 2011/07/26 14:41:54 marius Exp $
+ * $FreeBSD: stable/10/usr.sbin/makefs/cd9660/cd9660_eltorito.h 214921 2010-11-07 16:05:04Z cognet $
*/
#ifndef _CD9660_ELTORITO_H_
Modified: trunk/usr.sbin/makefs/cd9660/cd9660_strings.c
===================================================================
--- trunk/usr.sbin/makefs/cd9660/cd9660_strings.c 2018-06-07 00:04:57 UTC (rev 10466)
+++ trunk/usr.sbin/makefs/cd9660/cd9660_strings.c 2018-06-07 00:10:33 UTC (rev 10467)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/* $NetBSD: cd9660_strings.c,v 1.4 2007/01/16 17:32:05 hubertf Exp $ */
/*
@@ -35,7 +36,7 @@
#include <sys/mount.h>
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/usr.sbin/makefs/cd9660/cd9660_strings.c,v 1.3.4.2 2011/07/26 14:41:54 marius Exp $");
+__FBSDID("$FreeBSD: stable/10/usr.sbin/makefs/cd9660/cd9660_strings.c 219956 2011-03-24 12:35:59Z bapt $");
#include <sys/param.h>
#include <ctype.h>
Modified: trunk/usr.sbin/makefs/cd9660/cd9660_write.c
===================================================================
--- trunk/usr.sbin/makefs/cd9660/cd9660_write.c 2018-06-07 00:04:57 UTC (rev 10466)
+++ trunk/usr.sbin/makefs/cd9660/cd9660_write.c 2018-06-07 00:10:33 UTC (rev 10467)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/* $NetBSD: cd9660_write.c,v 1.14 2011/01/04 09:48:21 wiz Exp $ */
/*
@@ -36,7 +37,7 @@
#include "iso9660_rrip.h"
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/usr.sbin/makefs/cd9660/cd9660_write.c,v 1.2.4.3 2011/08/13 13:15:38 marius Exp $");
+__FBSDID("$FreeBSD: stable/10/usr.sbin/makefs/cd9660/cd9660_write.c 290587 2015-11-09 08:03:15Z ngie $");
static int cd9660_write_volume_descriptors(FILE *);
static int cd9660_write_path_table(FILE *, off_t, int);
@@ -165,7 +166,7 @@
diskStructure.pathTableLength);
unsigned char *buffer;
unsigned char *buffer_head;
- int len;
+ int len, ret;
path_table_entry temp_entry;
cd9660node *ptcur;
@@ -213,8 +214,10 @@
ptcur = ptcur->ptnext;
}
- return cd9660_write_filedata(fd, sector, buffer_head,
+ ret = cd9660_write_filedata(fd, sector, buffer_head,
path_table_sectors);
+ free(buffer_head);
+ return ret;
}
@@ -294,19 +297,21 @@
INODE_WARNX(("%s: writing inode %d blocks at %" PRIu32,
__func__, (int)inode->st.st_ino, inode->ino));
inode->flags |= FI_WRITTEN;
- cd9660_compute_full_filename(writenode,
- temp_file_name, 0);
+ if (writenode->node->contents == NULL)
+ cd9660_compute_full_filename(writenode,
+ temp_file_name);
ret = cd9660_copy_file(fd, writenode->fileDataSector,
- temp_file_name);
+ (writenode->node->contents != NULL) ?
+ writenode->node->contents : temp_file_name);
if (ret == 0)
goto out;
}
} else {
/*
- * Here is a new revelation that ECMA didnt explain
+ * Here is a new revelation that ECMA didn't explain
* (at least not well).
* ALL . and .. records store the name "\0" and "\1"
- * resepctively. So, for each directory, we have to
+ * respectively. So, for each directory, we have to
* make a new node.
*
* This is where it gets kinda messy, since we have to
Modified: trunk/usr.sbin/makefs/cd9660/iso9660_rrip.c
===================================================================
--- trunk/usr.sbin/makefs/cd9660/iso9660_rrip.c 2018-06-07 00:04:57 UTC (rev 10466)
+++ trunk/usr.sbin/makefs/cd9660/iso9660_rrip.c 2018-06-07 00:10:33 UTC (rev 10467)
@@ -1,4 +1,5 @@
-/* $NetBSD: iso9660_rrip.c,v 1.10 2011/05/29 17:07:58 tsutsui Exp $ */
+/* $MidnightBSD$ */
+/* $NetBSD: iso9660_rrip.c,v 1.14 2014/05/30 13:14:47 martin Exp $ */
/*
* Copyright (c) 2005 Daniel Watt, Walter Deignan, Ryan Gabrys, Alan
@@ -42,7 +43,7 @@
#include <stdio.h>
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/usr.sbin/makefs/cd9660/iso9660_rrip.c,v 1.1.4.3 2011/08/13 13:15:38 marius Exp $");
+__FBSDID("$FreeBSD: stable/10/usr.sbin/makefs/cd9660/iso9660_rrip.c 290591 2015-11-09 09:03:24Z ngie $");
static void cd9660_rrip_initialize_inode(cd9660node *);
static int cd9660_susp_handle_continuation(cd9660node *);
@@ -298,7 +299,7 @@
* CE: is added for us where needed
* ST: not sure if it is even required, but if so, should be
* handled by the CE code
- * PD: isnt needed (though might be added for testing)
+ * PD: isn't needed (though might be added for testing)
* SP: is stored ONLY on the . record of the root directory
* ES: not sure
*/
@@ -419,9 +420,9 @@
}
else if ((node->node != NULL) &&
((strlen(node->node->name) !=
- (int)node->isoDirRecord->name_len[0]) ||
+ (uint8_t)node->isoDirRecord->name_len[0]) ||
(memcmp(node->node->name,node->isoDirRecord->name,
- (int) node->isoDirRecord->name_len[0]) != 0))) {
+ (uint8_t)node->isoDirRecord->name_len[0]) != 0))) {
cd9660_rrip_NM(node);
}
@@ -634,7 +635,7 @@
int
cd9660node_rrip_px(struct ISO_SUSP_ATTRIBUTES *v, fsnode *pxinfo)
{
- v->attr.rr_entry.PX.h.length[0] = 36;
+ v->attr.rr_entry.PX.h.length[0] = 44;
v->attr.rr_entry.PX.h.version[0] = 1;
cd9660_bothendian_dword(pxinfo->inode->st.st_mode,
v->attr.rr_entry.PX.mode);
@@ -644,8 +645,9 @@
v->attr.rr_entry.PX.uid);
cd9660_bothendian_dword(pxinfo->inode->st.st_gid,
v->attr.rr_entry.PX.gid);
+ cd9660_bothendian_dword(pxinfo->inode->st.st_ino,
+ v->attr.rr_entry.PX.serial);
- /* Ignoring the serial number for now */
return 1;
}
@@ -655,13 +657,14 @@
pn_field->attr.rr_entry.PN.h.length[0] = 20;
pn_field->attr.rr_entry.PN.h.version[0] = 1;
- if (sizeof (fnode->inode->st.st_dev) > 32)
- cd9660_bothendian_dword((uint64_t)fnode->inode->st.st_dev >> 32,
+ if (sizeof (fnode->inode->st.st_rdev) > 4)
+ cd9660_bothendian_dword(
+ (uint64_t)fnode->inode->st.st_rdev >> 32,
pn_field->attr.rr_entry.PN.high);
else
cd9660_bothendian_dword(0, pn_field->attr.rr_entry.PN.high);
- cd9660_bothendian_dword(fnode->inode->st.st_dev & 0xffffffff,
+ cd9660_bothendian_dword(fnode->inode->st.st_rdev & 0xffffffff,
pn_field->attr.rr_entry.PN.low);
return 1;
}
@@ -685,7 +688,7 @@
cd9660node_rrip_tf(struct ISO_SUSP_ATTRIBUTES *p, fsnode *_node)
{
p->attr.rr_entry.TF.flags[0] = TF_MODIFY | TF_ACCESS | TF_ATTRIBUTES;
- p->attr.rr_entry.TF.h.length[0] = 4;
+ p->attr.rr_entry.TF.h.length[0] = 5;
p->attr.rr_entry.TF.h.version[0] = 1;
/*
Modified: trunk/usr.sbin/makefs/cd9660/iso9660_rrip.h
===================================================================
--- trunk/usr.sbin/makefs/cd9660/iso9660_rrip.h 2018-06-07 00:04:57 UTC (rev 10466)
+++ trunk/usr.sbin/makefs/cd9660/iso9660_rrip.h 2018-06-07 00:10:33 UTC (rev 10467)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/* $NetBSD: iso9660_rrip.h,v 1.5 2009/01/10 22:06:29 bjh21 Exp $ */
/*
@@ -31,7 +32,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
- * $FreeBSD: src/usr.sbin/makefs/cd9660/iso9660_rrip.h,v 1.1.4.2 2011/07/26 14:41:54 marius Exp $
+ * $FreeBSD: stable/10/usr.sbin/makefs/cd9660/iso9660_rrip.h 264936 2014-04-25 21:20:22Z marius $
*/
#ifndef __ISO9660_RRIP_H__
#define __ISO9660_RRIP_H__
@@ -103,7 +104,7 @@
u_char links [ISODCL(13,20)];
u_char uid [ISODCL(21,28)];
u_char gid [ISODCL(29,36)];
- u_char serial [ISODCL(37,44)];/* Not used */
+ u_char serial [ISODCL(37,44)];
} ISO_RRIP_PX;
typedef struct {
Modified: trunk/usr.sbin/makefs/cd9660.c
===================================================================
--- trunk/usr.sbin/makefs/cd9660.c 2018-06-07 00:04:57 UTC (rev 10466)
+++ trunk/usr.sbin/makefs/cd9660.c 2018-06-07 00:10:33 UTC (rev 10467)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/* $NetBSD: cd9660.c,v 1.31 2011/08/06 23:25:19 christos Exp $ */
/*
@@ -96,7 +97,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/usr.sbin/makefs/cd9660.c,v 1.2.4.5 2011/08/29 20:00:57 mm Exp $");
+__FBSDID("$FreeBSD: stable/10/usr.sbin/makefs/cd9660.c 316198 2017-03-30 02:02:48Z sevan $");
#include <string.h>
#include <ctype.h>
@@ -163,7 +164,7 @@
/*
- * Allocate and initalize a cd9660node
+ * Allocate and initialize a cd9660node
* @returns struct cd9660node * Pointer to new node, or NULL on error
*/
static cd9660node *
@@ -230,7 +231,7 @@
memset(diskStructure.primaryDescriptor.abstract_file_id, 0x20,37);
memset(diskStructure.primaryDescriptor.bibliographic_file_id, 0x20,37);
- strcpy(diskStructure.primaryDescriptor.system_id,"NetBSD");
+ strcpy(diskStructure.primaryDescriptor.system_id, "FreeBSD");
cd9660_defaults_set = 1;
@@ -296,8 +297,8 @@
int rv;
/* Set up allowed options - integer options ONLY */
option_t cd9660_options[] = {
- { "l", &diskStructure.isoLevel, 1, 3, "ISO Level" },
- { "isolevel", &diskStructure.isoLevel, 1, 3, "ISO Level" },
+ { "l", &diskStructure.isoLevel, 1, 2, "ISO Level" },
+ { "isolevel", &diskStructure.isoLevel, 1, 2, "ISO Level" },
{ "verbose", &diskStructure.verbose_level, 0, 2,
"Turns on verbose output" },
{ "v", &diskStructure.verbose_level, 0 , 2,
@@ -428,8 +429,7 @@
rv = set_option(cd9660_options, var, val);
}
- if (var)
- free(var);
+ free(var);
return (rv);
}
@@ -472,8 +472,6 @@
return;
}
- diskStructure.rootFilesystemPath = dir;
-
if (diskStructure.verbose_level > 0)
printf("cd9660_makefs: image %s directory %s root %p\n",
image, dir, root);
@@ -623,11 +621,7 @@
cd9660_finalize_PVD(void)
{
time_t tim;
- unsigned char *temp;
- /* Copy the root directory record */
- temp = (unsigned char *) &diskStructure.primaryDescriptor;
-
/* root should be a fixed size of 34 bytes since it has no name */
memcpy(diskStructure.primaryDescriptor.root_directory_record,
diskStructure.rootNode->dot_record->isoDirRecord, 34);
@@ -687,7 +681,8 @@
cd9660_set_date(diskStructure.primaryDescriptor.expiration_date, now);
*/
- memset(diskStructure.primaryDescriptor.expiration_date, '0' ,17);
+ memset(diskStructure.primaryDescriptor.expiration_date, '0', 16);
+ diskStructure.primaryDescriptor.expiration_date[16] = 0;
cd9660_time_8426(
(unsigned char *)diskStructure.primaryDescriptor.effective_date,
tim);
@@ -1053,7 +1048,7 @@
cd9660_rename_filename(cd9660node *iter, int num, int delete_chars)
{
int i = 0;
- int numbts, dot, semi, digit, digits, temp, powers, multiplier, count;
+ int numbts, digit, digits, temp, powers, count;
char *naming;
int maxlength;
char *tmp;
@@ -1061,6 +1056,7 @@
if (diskStructure.verbose_level > 0)
printf("Rename_filename called\n");
+ assert(1 <= diskStructure.isoLevel && diskStructure.isoLevel <= 2);
/* TODO : A LOT of chanes regarding 8.3 filenames */
if (diskStructure.isoLevel == 1)
maxlength = 8;
@@ -1071,11 +1067,10 @@
tmp = malloc(ISO_FILENAME_MAXLENGTH_WITH_PADDING);
- while (i < num) {
+ while (i < num && iter) {
powers = 1;
count = 0;
digits = 1;
- multiplier = 1;
while (((int)(i / powers) ) >= 10) {
digits++;
powers = powers * 10;
@@ -1090,15 +1085,9 @@
}
*/
- dot = -1;
- semi = -1;
while (count < maxlength) {
- if (*naming == '.')
- dot = count;
- else if (*naming == ';') {
- semi = count;
+ if (*naming == ';')
break;
- }
naming++;
count++;
}
@@ -1529,7 +1518,6 @@
cd9660node *last = dirNode;
int pathTableSize = 0; /* computed as we go */
int counter = 1; /* root gets a count of 0 */
- int parentRecNum = 0; /* root's parent is '0' */
TAILQ_HEAD(cd9660_pt_head, ptq_entry) pt_head;
TAILQ_INIT(&pt_head);
@@ -1559,10 +1547,6 @@
}
last = dirNode;
- parentRecNum = 1;
- if (dirNode->parent != 0)
- parentRecNum = dirNode->parent->ptnumber;
-
/* Push children onto queue */
TAILQ_FOREACH(cn, &dirNode->cn_children, cn_next_child) {
/*
@@ -1584,24 +1568,15 @@
}
void
-cd9660_compute_full_filename(cd9660node *node, char *buf, int level)
+cd9660_compute_full_filename(cd9660node *node, char *buf)
{
- cd9660node *parent;
+ int len;
- parent = (node->rr_real_parent == NULL ?
- node->parent : node->rr_real_parent);
- if (parent != NULL) {
- cd9660_compute_full_filename(parent, buf, level + 1);
- strcat(buf, node->node->name);
- } else {
- /* We are at the root */
- strcat(buf, diskStructure.rootFilesystemPath);
- if (buf[strlen(buf) - 1] == '/')
- buf[strlen(buf) - 1] = '\0';
- }
-
- if (level != 0)
- strcat(buf, "/");
+ len = CD9660MAXPATH + 1;
+ len = snprintf(buf, len, "%s/%s/%s", node->node->root,
+ node->node->path, node->node->name);
+ if (len > CD9660MAXPATH)
+ errx(1, "Pathname too long.");
}
/* NEW filename conversion method */
@@ -1757,6 +1732,7 @@
static int
cd9660_convert_filename(const char *oldname, char *newname, int is_file)
{
+ assert(1 <= diskStructure.isoLevel && diskStructure.isoLevel <= 2);
/* NEW */
cd9660_filename_conversion_functor conversion_function = 0;
if (diskStructure.isoLevel == 1)
Modified: trunk/usr.sbin/makefs/cd9660.h
===================================================================
--- trunk/usr.sbin/makefs/cd9660.h 2018-06-07 00:04:57 UTC (rev 10466)
+++ trunk/usr.sbin/makefs/cd9660.h 2018-06-07 00:10:33 UTC (rev 10467)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/* $NetBSD: cd9660.h,v 1.17 2011/06/23 02:35:56 enami Exp $ */
/*
@@ -31,7 +32,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
- * $FreeBSD: src/usr.sbin/makefs/cd9660.h,v 1.2.4.3 2011/08/13 13:15:38 marius Exp $
+ * $FreeBSD: stable/10/usr.sbin/makefs/cd9660.h 230795 2012-01-31 00:32:37Z jkim $
*/
#ifndef _MAKEFS_CD9660_H
@@ -244,8 +245,6 @@
cd9660node *rootNode;
- const char *rootFilesystemPath;
-
/* Important sector numbers here */
/* primaryDescriptor.type_l_path_table*/
int64_t primaryBigEndianTableSector;
@@ -345,7 +344,7 @@
int cd9660_write_image(const char *image);
int cd9660_copy_file(FILE *, off_t, const char *);
-void cd9660_compute_full_filename(cd9660node *, char *, int);
+void cd9660_compute_full_filename(cd9660node *, char *);
int cd9660_compute_record_size(cd9660node *);
/* Debugging functions */
Modified: trunk/usr.sbin/makefs/ffs/Makefile.inc
===================================================================
--- trunk/usr.sbin/makefs/ffs/Makefile.inc 2018-06-07 00:04:57 UTC (rev 10466)
+++ trunk/usr.sbin/makefs/ffs/Makefile.inc 2018-06-07 00:10:33 UTC (rev 10467)
@@ -1,4 +1,5 @@
-# $FreeBSD: src/usr.sbin/makefs/ffs/Makefile.inc,v 1.1 2010/11/07 16:05:04 cognet Exp $
+# $MidnightBSD$
+# $FreeBSD: stable/10/usr.sbin/makefs/ffs/Makefile.inc 214921 2010-11-07 16:05:04Z cognet $
#
.PATH: ${.CURDIR}/ffs ${.CURDIR}/../../sys/ufs/ffs
Property changes on: trunk/usr.sbin/makefs/ffs/Makefile.inc
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/usr.sbin/makefs/ffs/buf.c
===================================================================
--- trunk/usr.sbin/makefs/ffs/buf.c 2018-06-07 00:04:57 UTC (rev 10466)
+++ trunk/usr.sbin/makefs/ffs/buf.c 2018-06-07 00:10:33 UTC (rev 10467)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/* $NetBSD: buf.c,v 1.12 2004/06/20 22:20:18 jmc Exp $ */
/*
@@ -36,7 +37,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/usr.sbin/makefs/ffs/buf.c,v 1.2 2010/11/07 16:05:04 cognet Exp $");
+__FBSDID("$FreeBSD: stable/10/usr.sbin/makefs/ffs/buf.c 214921 2010-11-07 16:05:04Z cognet $");
#include <sys/param.h>
#include <sys/time.h>
Modified: trunk/usr.sbin/makefs/ffs/buf.h
===================================================================
--- trunk/usr.sbin/makefs/ffs/buf.h 2018-06-07 00:04:57 UTC (rev 10466)
+++ trunk/usr.sbin/makefs/ffs/buf.h 2018-06-07 00:10:33 UTC (rev 10467)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/* $NetBSD: buf.h,v 1.2 2001/11/02 03:12:49 lukem Exp $ */
/*
@@ -34,7 +35,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
- * $FreeBSD: src/usr.sbin/makefs/ffs/buf.h,v 1.1 2008/12/19 18:47:46 sam Exp $
+ * $FreeBSD: stable/10/usr.sbin/makefs/ffs/buf.h 186334 2008-12-19 18:45:43Z sam $
*/
#ifndef _FFS_BUF_H
Modified: trunk/usr.sbin/makefs/ffs/ffs_alloc.c
===================================================================
--- trunk/usr.sbin/makefs/ffs/ffs_alloc.c 2018-06-07 00:04:57 UTC (rev 10466)
+++ trunk/usr.sbin/makefs/ffs/ffs_alloc.c 2018-06-07 00:10:33 UTC (rev 10467)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/* $NetBSD: ffs_alloc.c,v 1.14 2004/06/20 22:20:18 jmc Exp $ */
/* From: NetBSD: ffs_alloc.c,v 1.50 2001/09/06 02:16:01 lukem Exp */
@@ -42,12 +43,13 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/usr.sbin/makefs/ffs/ffs_alloc.c,v 1.2 2010/11/07 16:05:04 cognet Exp $");
+__FBSDID("$FreeBSD: stable/10/usr.sbin/makefs/ffs/ffs_alloc.c 241015 2012-09-27 23:31:19Z mdf $");
#include <sys/param.h>
#include <sys/time.h>
#include <errno.h>
+#include <stdint.h>
#include "makefs.h"
@@ -439,8 +441,8 @@
}
cg = dtog(fs, bno);
if (bno >= fs->fs_size) {
- warnx("bad block %lld, ino %llu", (long long)bno,
- (unsigned long long)ip->i_number);
+ warnx("bad block %lld, ino %ju", (long long)bno,
+ (uintmax_t)ip->i_number);
return;
}
error = bread(ip->i_fd, ip->i_fs, fsbtodb(fs, cgtod(fs, cg)),
Modified: trunk/usr.sbin/makefs/ffs/ffs_balloc.c
===================================================================
--- trunk/usr.sbin/makefs/ffs/ffs_balloc.c 2018-06-07 00:04:57 UTC (rev 10466)
+++ trunk/usr.sbin/makefs/ffs/ffs_balloc.c 2018-06-07 00:10:33 UTC (rev 10467)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/* $NetBSD: ffs_balloc.c,v 1.13 2004/06/20 22:20:18 jmc Exp $ */
/* From NetBSD: ffs_balloc.c,v 1.25 2001/08/08 08:36:36 lukem Exp */
@@ -33,7 +34,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/usr.sbin/makefs/ffs/ffs_balloc.c,v 1.1 2008/12/19 18:47:46 sam Exp $");
+__FBSDID("$FreeBSD: stable/10/usr.sbin/makefs/ffs/ffs_balloc.c 186334 2008-12-19 18:45:43Z sam $");
#include <sys/param.h>
#include <sys/time.h>
Modified: trunk/usr.sbin/makefs/ffs/ffs_bswap.c
===================================================================
--- trunk/usr.sbin/makefs/ffs/ffs_bswap.c 2018-06-07 00:04:57 UTC (rev 10466)
+++ trunk/usr.sbin/makefs/ffs/ffs_bswap.c 2018-06-07 00:10:33 UTC (rev 10467)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/* $NetBSD: ffs_bswap.c,v 1.28 2004/05/25 14:54:59 hannken Exp $ */
/*
@@ -31,7 +32,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/usr.sbin/makefs/ffs/ffs_bswap.c,v 1.6 2011/06/16 23:40:10 mckusick Exp $");
+__FBSDID("$FreeBSD: stable/10/usr.sbin/makefs/ffs/ffs_bswap.c 301784 2016-06-10 14:13:24Z ngie $");
#include <sys/param.h>
#if defined(_KERNEL)
@@ -67,7 +68,7 @@
void
ffs_sb_swap(struct fs *o, struct fs *n)
{
- int i;
+ size_t i;
u_int32_t *o32, *n32;
/*
@@ -97,7 +98,7 @@
n->fs_csaddr = bswap64(o->fs_csaddr);
n->fs_pendingblocks = bswap64(o->fs_pendingblocks);
n->fs_pendinginodes = bswap32(o->fs_pendinginodes);
-
+
/* These fields overlap with the second half of the
* historic FS_42POSTBLFMT postbl table
*/
@@ -135,7 +136,8 @@
n->di_mtimensec = bswap32(o->di_mtimensec);
n->di_ctime = bswap32(o->di_ctime);
n->di_ctimensec = bswap32(o->di_ctimensec);
- memcpy(n->di_db, o->di_db, (NDADDR + NIADDR) * sizeof(u_int32_t));
+ memcpy(n->di_db, o->di_db, sizeof(n->di_db));
+ memcpy(n->di_ib, o->di_ib, sizeof(n->di_ib));
n->di_flags = bswap32(o->di_flags);
n->di_blocks = bswap32(o->di_blocks);
n->di_gen = bswap32(o->di_gen);
@@ -165,15 +167,17 @@
n->di_kernflags = bswap32(o->di_kernflags);
n->di_flags = bswap32(o->di_flags);
n->di_extsize = bswap32(o->di_extsize);
- memcpy(n->di_extb, o->di_extb, (NXADDR + NDADDR + NIADDR) * 8);
+ memcpy(n->di_extb, o->di_extb, sizeof(n->di_extb));
+ memcpy(n->di_db, o->di_db, sizeof(n->di_db));
+ memcpy(n->di_ib, o->di_ib, sizeof(n->di_ib));
}
void
ffs_csum_swap(struct csum *o, struct csum *n, int size)
{
- int i;
+ size_t i;
u_int32_t *oint, *nint;
-
+
oint = (u_int32_t*)o;
nint = (u_int32_t*)n;
Modified: trunk/usr.sbin/makefs/ffs/ffs_extern.h
===================================================================
--- trunk/usr.sbin/makefs/ffs/ffs_extern.h 2018-06-07 00:04:57 UTC (rev 10466)
+++ trunk/usr.sbin/makefs/ffs/ffs_extern.h 2018-06-07 00:10:33 UTC (rev 10467)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/* $NetBSD: ffs_extern.h,v 1.6 2003/08/07 11:25:33 agc Exp $ */
/* From: NetBSD: ffs_extern.h,v 1.19 2001/08/17 02:18:48 lukem Exp */
@@ -30,11 +31,13 @@
* SUCH DAMAGE.
*
* @(#)ffs_extern.h 8.6 (Berkeley) 3/30/95
- * $FreeBSD: src/usr.sbin/makefs/ffs/ffs_extern.h,v 1.1 2008/12/19 18:47:46 sam Exp $
+ * $FreeBSD: stable/10/usr.sbin/makefs/ffs/ffs_extern.h 239359 2012-08-17 17:45:27Z mjg $
*/
#include "ffs/buf.h"
+struct inode;
+
/*
* Structure used to pass around logical block paths generated by
* ufs_getlbns and used by truncate and bmap code.
@@ -42,12 +45,10 @@
struct indir {
daddr_t in_lbn; /* Logical block number. */
int in_off; /* Offset in buffer. */
- int in_exists; /* Flag if the block exists. */
};
/* ffs.c */
-void panic(const char *, ...)
- __attribute__((__noreturn__,__format__(__printf__,1,2)));
+_Noreturn void panic(const char *, ...) __printflike(1, 2);
/* ffs_alloc.c */
int ffs_alloc(struct inode *, daddr_t, daddr_t, int, daddr_t *);
Modified: trunk/usr.sbin/makefs/ffs/ffs_subr.c
===================================================================
--- trunk/usr.sbin/makefs/ffs/ffs_subr.c 2018-06-07 00:04:57 UTC (rev 10466)
+++ trunk/usr.sbin/makefs/ffs/ffs_subr.c 2018-06-07 00:10:33 UTC (rev 10467)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/* $NetBSD: ffs_subr.c,v 1.32 2003/12/30 12:33:24 pk Exp $ */
/*
@@ -32,17 +33,15 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/usr.sbin/makefs/ffs/ffs_subr.c,v 1.4 2011/06/16 23:40:10 mckusick Exp $");
+__FBSDID("$FreeBSD: stable/10/usr.sbin/makefs/ffs/ffs_subr.c 228990 2011-12-30 10:58:14Z uqs $");
#include <sys/param.h>
#include <ufs/ufs/dinode.h>
#include <ufs/ffs/fs.h>
+#include "ffs/ffs_extern.h"
#include "ffs/ufs_bswap.h"
-void panic __P((const char *, ...))
- __attribute__((__noreturn__,__format__(__printf__,1,2)));
-
/*
* Update the frsum fields to reflect addition or deletion
* of some frags.
@@ -80,8 +79,8 @@
* block operations
*
* check if a block is available
- * returns true if all the correponding bits in the free map are 1
- * returns false if any corresponding bit in the free map is 0
+ * returns true if all the corresponding bits in the free map are 1
+ * returns false if any corresponding bit in the free map is 0
*/
int
ffs_isblock(fs, cp, h)
Modified: trunk/usr.sbin/makefs/ffs/mkfs.c
===================================================================
--- trunk/usr.sbin/makefs/ffs/mkfs.c 2018-06-07 00:04:57 UTC (rev 10466)
+++ trunk/usr.sbin/makefs/ffs/mkfs.c 2018-06-07 00:10:33 UTC (rev 10467)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/* $NetBSD: mkfs.c,v 1.20 2004/06/24 22:30:13 lukem Exp $ */
/*
@@ -39,7 +40,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/usr.sbin/makefs/ffs/mkfs.c,v 1.3 2011/10/09 16:22:31 nwhitehorn Exp $");
+__FBSDID("$FreeBSD: stable/10/usr.sbin/makefs/ffs/mkfs.c 290599 2015-11-09 09:28:34Z ngie $");
#include <sys/param.h>
#include <sys/time.h>
@@ -248,15 +249,16 @@
exit(21);
}
sblock.fs_fsbtodb = ilog2(sblock.fs_fsize / sectorsize);
- sblock.fs_size = fssize = dbtofsb(&sblock, fssize);
+ sblock.fs_size = sblock.fs_providersize = fssize =
+ dbtofsb(&sblock, fssize);
if (Oflag <= 1) {
sblock.fs_magic = FS_UFS1_MAGIC;
sblock.fs_sblockloc = SBLOCK_UFS1;
- sblock.fs_nindir = sblock.fs_bsize / sizeof(int32_t);
+ sblock.fs_nindir = sblock.fs_bsize / sizeof(ufs1_daddr_t);
sblock.fs_inopb = sblock.fs_bsize / sizeof(struct ufs1_dinode);
sblock.fs_maxsymlinklen = ((NDADDR + NIADDR) *
- sizeof (int32_t));
+ sizeof (ufs1_daddr_t));
sblock.fs_old_inodefmt = FS_44INODEFMT;
sblock.fs_old_cgoffset = 0;
sblock.fs_old_cgmask = 0xffffffff;
@@ -272,15 +274,11 @@
sblock.fs_old_nrpos = 1;
} else {
sblock.fs_magic = FS_UFS2_MAGIC;
-#if 0 /* XXX makefs is used for small filesystems. */
sblock.fs_sblockloc = SBLOCK_UFS2;
-#else
- sblock.fs_sblockloc = SBLOCK_UFS1;
-#endif
- sblock.fs_nindir = sblock.fs_bsize / sizeof(int64_t);
+ sblock.fs_nindir = sblock.fs_bsize / sizeof(ufs2_daddr_t);
sblock.fs_inopb = sblock.fs_bsize / sizeof(struct ufs2_dinode);
sblock.fs_maxsymlinklen = ((NDADDR + NIADDR) *
- sizeof (int64_t));
+ sizeof (ufs2_daddr_t));
}
sblock.fs_sblkno =
Modified: trunk/usr.sbin/makefs/ffs/newfs_extern.h
===================================================================
--- trunk/usr.sbin/makefs/ffs/newfs_extern.h 2018-06-07 00:04:57 UTC (rev 10466)
+++ trunk/usr.sbin/makefs/ffs/newfs_extern.h 2018-06-07 00:10:33 UTC (rev 10467)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/* $NetBSD: newfs_extern.h,v 1.2 2004/06/24 22:30:13 lukem Exp $ */
/* From: NetBSD: extern.h,v 1.3 2000/12/01 12:03:27 simonb Exp $ */
@@ -29,7 +30,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
- * $FreeBSD: src/usr.sbin/makefs/ffs/newfs_extern.h,v 1.1 2008/12/19 18:47:46 sam Exp $
+ * $FreeBSD: stable/10/usr.sbin/makefs/ffs/newfs_extern.h 186334 2008-12-19 18:45:43Z sam $
*/
/* prototypes */
Modified: trunk/usr.sbin/makefs/ffs/ufs_bmap.c
===================================================================
--- trunk/usr.sbin/makefs/ffs/ufs_bmap.c 2018-06-07 00:04:57 UTC (rev 10466)
+++ trunk/usr.sbin/makefs/ffs/ufs_bmap.c 2018-06-07 00:10:33 UTC (rev 10467)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/* $NetBSD: ufs_bmap.c,v 1.14 2004/06/20 22:20:18 jmc Exp $ */
/* From: NetBSD: ufs_bmap.c,v 1.14 2001/11/08 05:00:51 chs Exp */
@@ -38,7 +39,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/usr.sbin/makefs/ffs/ufs_bmap.c,v 1.1 2008/12/19 18:47:46 sam Exp $");
+__FBSDID("$FreeBSD: stable/10/usr.sbin/makefs/ffs/ufs_bmap.c 239359 2012-08-17 17:45:27Z mjg $");
#include <sys/param.h>
#include <sys/time.h>
@@ -117,7 +118,6 @@
*/
ap->in_lbn = metalbn;
ap->in_off = off = NIADDR - i;
- ap->in_exists = 0;
ap++;
for (++numlevels; i <= NIADDR; i++) {
/* If searching for a meta-data block, quit when found. */
@@ -131,7 +131,6 @@
++numlevels;
ap->in_lbn = metalbn;
ap->in_off = off;
- ap->in_exists = 0;
++ap;
metalbn -= -1 + (off << lbc);
Modified: trunk/usr.sbin/makefs/ffs/ufs_bswap.h
===================================================================
--- trunk/usr.sbin/makefs/ffs/ufs_bswap.h 2018-06-07 00:04:57 UTC (rev 10466)
+++ trunk/usr.sbin/makefs/ffs/ufs_bswap.h 2018-06-07 00:10:33 UTC (rev 10467)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/* $NetBSD: ufs_bswap.h,v 1.13 2003/10/05 17:48:50 bouyer Exp $ */
/*
@@ -28,7 +29,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
- * $FreeBSD: src/usr.sbin/makefs/ffs/ufs_bswap.h,v 1.2 2009/02/26 20:59:05 ed Exp $
+ * $FreeBSD: stable/10/usr.sbin/makefs/ffs/ufs_bswap.h 253675 2013-07-26 14:22:03Z marius $
*/
#ifndef _UFS_UFS_BSWAP_H_
@@ -40,6 +41,8 @@
#include <sys/endian.h>
+#include "makefs.h"
+
/* Macros to access UFS flags */
#ifdef FFS_EI
#define UFS_MPNEEDSWAP(mp) (VFSTOUFS(mp)->um_flags & UFS_NEEDSWAP)
Modified: trunk/usr.sbin/makefs/ffs/ufs_inode.h
===================================================================
--- trunk/usr.sbin/makefs/ffs/ufs_inode.h 2018-06-07 00:04:57 UTC (rev 10466)
+++ trunk/usr.sbin/makefs/ffs/ufs_inode.h 2018-06-07 00:10:33 UTC (rev 10467)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/* $NetBSD: ufs_inode.h,v 1.3 2003/08/07 11:25:34 agc Exp $ */
/* From: NetBSD: inode.h,v 1.27 2001/12/18 10:57:23 fvdl Exp $ */
@@ -35,7 +36,7 @@
* SUCH DAMAGE.
*
* @(#)inode.h 8.9 (Berkeley) 5/14/95
- * $FreeBSD: src/usr.sbin/makefs/ffs/ufs_inode.h,v 1.1 2008/12/19 18:47:46 sam Exp $
+ * $FreeBSD: stable/10/usr.sbin/makefs/ffs/ufs_inode.h 186334 2008-12-19 18:45:43Z sam $
*/
union dinode {
Modified: trunk/usr.sbin/makefs/ffs.c
===================================================================
--- trunk/usr.sbin/makefs/ffs.c 2018-06-07 00:04:57 UTC (rev 10466)
+++ trunk/usr.sbin/makefs/ffs.c 2018-06-07 00:10:33 UTC (rev 10467)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/* $NetBSD: ffs.c,v 1.44 2009/04/28 22:49:26 joerg Exp $ */
/*
@@ -66,7 +67,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/usr.sbin/makefs/ffs.c,v 1.6 2011/10/09 16:22:31 nwhitehorn Exp $");
+__FBSDID("$FreeBSD: stable/10/usr.sbin/makefs/ffs.c 290589 2015-11-09 08:59:55Z ngie $");
#include <sys/param.h>
@@ -145,7 +146,7 @@
int sectorsize; /* XXX: for buf.c::getblk() */
- /* publically visible functions */
+ /* publicly visible functions */
void
ffs_prep_opts(fsinfo_t *fsopts)
@@ -191,7 +192,7 @@
"bytes per inode" },
{ "minfree", &ffs_opts->minfree, 0, 99,
"minfree" },
- { "maxbpf", &ffs_opts->maxbpg, 1, INT_MAX,
+ { "maxbpg", &ffs_opts->maxbpg, 1, INT_MAX,
"max blocks per file in a cg" },
{ "avgfilesize", &ffs_opts->avgfilesize,1, INT_MAX,
"expected average file size" },
@@ -410,6 +411,10 @@
/* round up to the next block */
fsopts->size = roundup(fsopts->size, ffs_opts->bsize);
+ /* round up to requested block size, if any */
+ if (fsopts->roundup > 0)
+ fsopts->size = roundup(fsopts->size, fsopts->roundup);
+
/* calculate density if necessary */
if (ffs_opts->density == -1)
ffs_opts->density = fsopts->size / fsopts->inodes + 1;
@@ -493,14 +498,26 @@
bufsize = sfs.f_iosize;
#endif
bufrem = fsopts->size;
- if (debug & DEBUG_FS_CREATE_IMAGE)
- printf(
- "zero-ing image `%s', %lld sectors, using %d byte chunks\n",
- image, (long long)bufrem, bufsize);
- if ((buf = calloc(1, bufsize)) == NULL) {
- warn("Can't create buffer for sector");
- return (-1);
+ if (fsopts->sparse) {
+ if (ftruncate(fsopts->fd, bufrem) == -1) {
+ warn("sparse option disabled.\n");
+ fsopts->sparse = 0;
+ }
}
+ if (fsopts->sparse) {
+ /* File truncated at bufrem. Remaining is 0 */
+ bufrem = 0;
+ buf = NULL;
+ } else {
+ if (debug & DEBUG_FS_CREATE_IMAGE)
+ printf("zero-ing image `%s', %lld sectors, "
+ "using %d byte chunks\n", image, (long long)bufrem,
+ bufsize);
+ if ((buf = calloc(1, bufsize)) == NULL) {
+ warn("Can't create buffer for sector");
+ return (-1);
+ }
+ }
while (bufrem > 0) {
i = write(fsopts->fd, buf, MIN(bufsize, bufrem));
if (i == -1) {
@@ -511,7 +528,8 @@
}
bufrem -= i;
}
- free(buf);
+ if (buf)
+ free(buf);
/* make the file system */
if (debug & DEBUG_FS_CREATE_IMAGE)
@@ -780,8 +798,8 @@
cur->inode->flags |= FI_WRITTEN;
if (cur->contents == NULL) {
- if (snprintf(path, sizeof(path), "%s/%s", dir,
- cur->name) >= sizeof(path))
+ if (snprintf(path, sizeof(path), "%s/%s/%s", cur->root,
+ cur->path, cur->name) >= (int)sizeof(path))
errx(1, "Pathname too long.");
}
Modified: trunk/usr.sbin/makefs/ffs.h
===================================================================
--- trunk/usr.sbin/makefs/ffs.h 2018-06-07 00:04:57 UTC (rev 10466)
+++ trunk/usr.sbin/makefs/ffs.h 2018-06-07 00:10:33 UTC (rev 10467)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/* $NetBSD: ffs.h,v 1.1 2004/12/20 20:51:42 jmc Exp $ */
/*
@@ -34,7 +35,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
- * $FreeBSD: src/usr.sbin/makefs/ffs.h,v 1.2 2011/10/09 16:22:31 nwhitehorn Exp $
+ * $FreeBSD: stable/10/usr.sbin/makefs/ffs.h 226169 2011-10-09 16:22:31Z nwhitehorn $
*/
#ifndef _FFS_H
Modified: trunk/usr.sbin/makefs/getid.c
===================================================================
--- trunk/usr.sbin/makefs/getid.c 2018-06-07 00:04:57 UTC (rev 10466)
+++ trunk/usr.sbin/makefs/getid.c 2018-06-07 00:10:33 UTC (rev 10467)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/* $NetBSD: getid.c,v 1.5 2004/06/20 22:20:18 jmc Exp $ */
/* from: NetBSD: getpwent.c,v 1.48 2000/10/03 03:22:26 enami Exp */
/* from: NetBSD: getgrent.c,v 1.41 2002/01/12 23:51:30 lukem Exp */
Modified: trunk/usr.sbin/makefs/makefs.8
===================================================================
--- trunk/usr.sbin/makefs/makefs.8 2018-06-07 00:04:57 UTC (rev 10466)
+++ trunk/usr.sbin/makefs/makefs.8 2018-06-07 00:10:33 UTC (rev 10467)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
.\" $NetBSD: makefs.8,v 1.32 2009/01/20 20:47:25 bjh21 Exp $
.\"
.\" Copyright (c) 2001-2003 Wasabi Systems, Inc.
@@ -33,31 +34,33 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.\" $FreeBSD: src/usr.sbin/makefs/makefs.8,v 1.1.2.4 2011/07/26 14:41:54 marius Exp $
+.\" $FreeBSD: stable/10/usr.sbin/makefs/makefs.8 316800 2017-04-14 00:15:34Z brooks $
.\"
-.Dd January 10, 2009
+.Dd April 6, 2017
.Dt MAKEFS 8
.Os
.Sh NAME
.Nm makefs
-.Nd create a file system image from a directory tree
+.Nd create a file system image from a directory tree or a mtree manifest
.Sh SYNOPSIS
.Nm
-.Op Fl x
-.Op Fl B Ar byte-order
+.Op Fl DxZ
+.Op Fl B Ar endian
.Op Fl b Ar free-blocks
.Op Fl d Ar debug-mask
-.Op Fl F Ar specfile
+.Op Fl F Ar mtree-specfile
.Op Fl f Ar free-files
.Op Fl M Ar minimum-size
.Op Fl m Ar maximum-size
.Op Fl N Ar userdb-dir
.Op Fl o Ar fs-options
+.Op Fl R Ar roundup-size
.Op Fl S Ar sector-size
.Op Fl s Ar image-size
.Op Fl t Ar fs-type
.Ar image-file
-.Ar directory
+.Ar directory | manifest
+.Op Ar extra-directory ...
.Sh DESCRIPTION
The utility
.Nm
@@ -64,14 +67,25 @@
creates a file system image into
.Ar image-file
from the directory tree
-.Ar directory .
+.Ar directory
+or from the mtree manifest
+.Ar manifest .
+If any optional directory trees are passed in the
+.Ar extra-directory
+arguments, then the directory tree of each argument will be merged
+into the
+.Ar directory
+or
+.Ar manifest
+first before creating
+.Ar image-file .
No special devices or privileges are required to perform this task.
.Pp
The options are as follows:
.Bl -tag -width flag
-.It Fl B Ar byte-order
+.It Fl B Ar endian
Set the byte order of the image to
-.Ar byte-order .
+.Ar endian .
Valid byte orders are
.Ql 4321 ,
.Ql big ,
@@ -94,18 +108,28 @@
suffix may be provided to indicate that
.Ar free-blocks
indicates a percentage of the calculated image size.
+.It Fl D
+Treat duplicate paths in an mtree manifest as warnings not error.
.It Fl d Ar debug-mask
Enable various levels of debugging, depending upon which bits are
set in
.Ar debug-mask .
XXX: document these
-.It Fl F Ar specfile
+.It Fl F Ar mtree-specfile
+.Em This is almost certainly not the option you are looking for.
+To create an image from a list of files in an mtree format manifest,
+specify it as the last argument on the commandline, not as a the
+argument to
+.Fl F .
+.Pp
Use
-.Ar specfile
+.Ar mtree-specfile
as an
.Xr mtree 8
.Sq specfile
specification.
+This option has no effect when the image is created from a mtree manifest
+rather than a directory.
.Pp
If a specfile entry exists in the underlying file system, its
permissions and modification time will be used unless specifically
@@ -130,8 +154,7 @@
.Sy uname
or
.Sy uid ,
-.Sy device
-(in the case of block or character devices), and
+and
.Sy link
(in the case of symbolic links).
If
@@ -158,13 +181,13 @@
.Ar maximum-size .
An error will be raised if the target file system needs to be larger
than this to accommodate the provided directory tree.
-.It Fl N Ar dbdir
+.It Fl N Ar userdb-dir
Use the user database text file
.Pa master.passwd
and group database text file
.Pa group
from
-.Ar dbdir ,
+.Ar userdb-dir ,
rather than using the results from the system's
.Xr getpwnam 3
and
@@ -175,6 +198,19 @@
.Ar fs-options
is a comma separated list of options.
Valid file system specific options are detailed below.
+.It Fl p
+Deprecated.
+See the
+.Fl Z
+flag.
+.It Fl R Ar roundup-size
+Round the image up to
+.Ar roundup-size .
+.Ar roundup-size
+should be a multiple of the file system block size.
+This option only applies to the
+.Sy ffs
+file system type.
.It Fl S Ar sector-size
Set the file system sector size to
.Ar sector-size .
@@ -196,6 +232,10 @@
.El
.It Fl x
Exclude file system nodes not explicitly listed in the specfile.
+.It Fl Z
+Create a sparse file for
+.Sy ffs .
+This is useful for virtual machine images.
.El
.Pp
Where sizes are specified, a decimal number of bytes is expected.
@@ -238,6 +278,8 @@
Bytes per inode.
.It Sy fsize
Fragment size.
+.It Sy label
+Label name of the image.
.It Sy maxbpg
Maximum blocks per file in a cylinder group.
.It Sy minfree
@@ -268,10 +310,10 @@
.It Sy allow-deep-trees
Allow the directory structure to exceed the maximum specified in
the spec.
-.\" .It Sy allow-illegal-chars
-.\" Unknown
-.\" .It Sy allow-lowercase
-.\" Unknown
+.It Sy allow-illegal-chars
+Allow illegal characters in filenames. This option is not implemented.
+.It Sy allow-lowercase
+Allow lowercase characters in filenames. This option is not implemented.
.It Sy allow-max-name
Allow 37 instead of 33 characters for filenames by omitting the
version id.
@@ -285,6 +327,8 @@
extension to encode
.Tn RISC OS
metadata.
+.It Sy bootimagedir
+Boot image directory. This option is not implemented.
.It Sy chrp-boot
Write an MBR partition table to the image to allow older CHRP hardware to
boot.
@@ -305,8 +349,18 @@
Load a generic boot image into the first 32K of the cd9660 image.
.It Sy hard-disk-boot
Boot image is a hard disk image.
+.It Sy isolevel
+An integer representing the ISO 9660 interchange level where
+.Dq level
+is either
+.Ql 1
+or
+.Ql 2 .
+.Dq level
+.Ql 3
+is not implemented.
.It Sy keep-bad-images
-Don't throw away images whose write was aborted due to an error.
+Do not discard images whose write was aborted due to an error.
For debugging purposes.
.It Sy label
Label name of the image.
@@ -318,8 +372,8 @@
ElTorito image.
.It Sy no-trailing-padding
Do not pad the image (apparently Linux needs the padding).
-.\" .It Sy omit-trailing-period
-.\" Unknown
+.It Sy omit-trailing-period
+Omit trailing periods in filenames.
.It Sy preparer
Preparer ID of the image.
.It Sy publisher
@@ -326,10 +380,13 @@
Publisher ID of the image.
.It Sy rockridge
Use RockRidge extensions (for longer filenames, etc.).
+.It Sy verbose
+Turns on verbose output.
.It Sy volumeid
Volume set identifier of the image.
.El
.Sh SEE ALSO
+.Xr mtree 5 ,
.Xr mtree 8 ,
.Xr newfs 8
.Sh HISTORY
@@ -338,9 +395,8 @@
utility appeared in
.Nx 1.6 .
.Sh AUTHORS
-.An Luke Mewburn
-.Aq lukem at NetBSD.org
-(original program)
+.An Luke Mewburn Aq Mt lukem at NetBSD.org
+(original program),
.An Daniel Watt ,
.An Walter Deignan ,
.An Ryan Gabrys ,
Property changes on: trunk/usr.sbin/makefs/makefs.8
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/usr.sbin/makefs/makefs.c
===================================================================
--- trunk/usr.sbin/makefs/makefs.c 2018-06-07 00:04:57 UTC (rev 10466)
+++ trunk/usr.sbin/makefs/makefs.c 2018-06-07 00:10:33 UTC (rev 10467)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/* $NetBSD: makefs.c,v 1.26 2006/10/22 21:11:56 christos Exp $ */
/*
@@ -36,8 +37,10 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/usr.sbin/makefs/makefs.c,v 1.1.2.2 2011/07/26 14:41:54 marius Exp $");
+__FBSDID("$FreeBSD: stable/10/usr.sbin/makefs/makefs.c 293025 2016-01-01 00:36:59Z ngie $");
+#include <sys/types.h>
+#include <sys/stat.h>
#include <assert.h>
#include <ctype.h>
#include <errno.h>
@@ -45,6 +48,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <time.h>
#include <unistd.h>
#include "makefs.h"
@@ -70,6 +74,7 @@
};
u_int debug;
+int dupsok;
struct timespec start_time;
static fstype_t *get_fstype(const char *);
@@ -79,11 +84,13 @@
int
main(int argc, char *argv[])
{
+ struct stat sb;
struct timeval start;
fstype_t *fstype;
fsinfo_t fsoptions;
fsnode *root;
- int ch, len;
+ int ch, i, len;
+ char *subtree;
char *specfile;
setprogname(argv[0]);
@@ -107,7 +114,7 @@
start_time.tv_sec = start.tv_sec;
start_time.tv_nsec = start.tv_usec * 1000;
- while ((ch = getopt(argc, argv, "B:b:d:f:F:M:m:N:o:s:S:t:x")) != -1) {
+ while ((ch = getopt(argc, argv, "B:b:Dd:f:F:M:m:N:o:pR:s:S:t:xZ")) != -1) {
switch (ch) {
case 'B':
@@ -143,6 +150,10 @@
}
break;
+ case 'D':
+ dupsok = 1;
+ break;
+
case 'd':
debug = strtoll(optarg, NULL, 0);
break;
@@ -194,7 +205,17 @@
}
break;
}
+ case 'p':
+ /* Deprecated in favor of 'Z' */
+ fsoptions.sparse = 1;
+ break;
+ case 'R':
+ /* Round image size up to specified block size */
+ fsoptions.roundup =
+ strsuftoll("roundup-size", optarg, 0, LLONG_MAX);
+ break;
+
case 's':
fsoptions.minsize = fsoptions.maxsize =
strsuftoll("size", optarg, 1LL, LLONG_MAX);
@@ -220,6 +241,11 @@
fsoptions.onlyspec = 1;
break;
+ case 'Z':
+ /* Superscedes 'p' for compatibility with NetBSD makefs(8) */
+ fsoptions.sparse = 1;
+ break;
+
case '?':
default:
usage();
@@ -236,7 +262,7 @@
argc -= optind;
argv += optind;
- if (argc != 2)
+ if (argc < 2)
usage();
/* -x must be accompanied by -F */
@@ -243,26 +269,58 @@
if (fsoptions.onlyspec != 0 && specfile == NULL)
errx(1, "-x requires -F mtree-specfile.");
- /* walk the tree */
- TIMER_START(start);
- root = walk_dir(argv[1], NULL);
- TIMER_RESULTS(start, "walk_dir");
+ /* Accept '-' as meaning "read from standard input". */
+ if (strcmp(argv[1], "-") == 0)
+ sb.st_mode = S_IFREG;
+ else {
+ if (stat(argv[1], &sb) == -1)
+ err(1, "Can't stat `%s'", argv[1]);
+ }
+ switch (sb.st_mode & S_IFMT) {
+ case S_IFDIR: /* walk the tree */
+ subtree = argv[1];
+ TIMER_START(start);
+ root = walk_dir(subtree, ".", NULL, NULL);
+ TIMER_RESULTS(start, "walk_dir");
+ break;
+ case S_IFREG: /* read the manifest file */
+ subtree = ".";
+ TIMER_START(start);
+ root = read_mtree(argv[1], NULL);
+ TIMER_RESULTS(start, "manifest");
+ break;
+ default:
+ errx(1, "%s: not a file or directory", argv[1]);
+ /* NOTREACHED */
+ }
+
+ /* append extra directory */
+ for (i = 2; i < argc; i++) {
+ if (stat(argv[i], &sb) == -1)
+ err(1, "Can't stat `%s'", argv[i]);
+ if (!S_ISDIR(sb.st_mode))
+ errx(1, "%s: not a directory", argv[i]);
+ TIMER_START(start);
+ root = walk_dir(argv[i], ".", NULL, root);
+ TIMER_RESULTS(start, "walk_dir2");
+ }
+
if (specfile) { /* apply a specfile */
TIMER_START(start);
- apply_specfile(specfile, argv[1], root, fsoptions.onlyspec);
+ apply_specfile(specfile, subtree, root, fsoptions.onlyspec);
TIMER_RESULTS(start, "apply_specfile");
}
if (debug & DEBUG_DUMP_FSNODES) {
- printf("\nparent: %s\n", argv[1]);
- dump_fsnodes(".", root);
+ printf("\nparent: %s\n", subtree);
+ dump_fsnodes(root);
putchar('\n');
}
/* build the file system */
TIMER_START(start);
- fstype->make_fs(argv[0], argv[1], root, &fsoptions);
+ fstype->make_fs(argv[0], subtree, root, &fsoptions);
TIMER_RESULTS(start, "make_fs");
free_fsnodes(root);
@@ -308,9 +366,9 @@
prog = getprogname();
fprintf(stderr,
"usage: %s [-t fs-type] [-o fs-options] [-d debug-mask] [-B endian]\n"
-"\t[-S sector-size] [-M minimum-size] [-m maximum-size] [-s image-size]\n"
-"\t[-b free-blocks] [-f free-files] [-F mtree-specfile] [-x]\n"
-"\t[-N userdb-dir] image-file directory\n",
+"\t[-S sector-size] [-M minimum-size] [-m maximum-size] [-R roundup-size]\n"
+"\t[-s image-size] [-b free-blocks] [-f free-files] [-F mtree-specfile]\n"
+"\t[-xZ] [-N userdb-dir] image-file directory | manifest [extra-directory ...]\n",
prog);
exit(1);
}
Modified: trunk/usr.sbin/makefs/makefs.h
===================================================================
--- trunk/usr.sbin/makefs/makefs.h 2018-06-07 00:04:57 UTC (rev 10466)
+++ trunk/usr.sbin/makefs/makefs.h 2018-06-07 00:10:33 UTC (rev 10467)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/* $NetBSD: makefs.h,v 1.20 2008/12/28 21:51:46 christos Exp $ */
/*
@@ -34,7 +35,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
- * $FreeBSD: src/usr.sbin/makefs/makefs.h,v 1.3 2011/06/19 18:34:49 marcel Exp $
+ * $FreeBSD: stable/10/usr.sbin/makefs/makefs.h 290589 2015-11-09 08:59:55Z ngie $
*/
#ifndef _MAKEFS_H
@@ -94,6 +95,8 @@
fsinode *inode; /* actual inode data */
char *symlink; /* symlink target */
char *contents; /* file to provide contents */
+ const char *root; /* root path */
+ char *path; /* directory name */
char *name; /* file name */
int flags; /* misc flags */
} fsnode;
@@ -127,6 +130,8 @@
int freeblockpc; /* free block % */
int needswap; /* non-zero if byte swapping needed */
int sectorsize; /* sector size */
+ int sparse; /* sparse image, don't fill it with zeros */
+ off_t roundup; /* round image size up to this value */
void *fs_specific; /* File system specific additions. */
} fsinfo_t;
@@ -147,11 +152,11 @@
void apply_specfile(const char *, const char *, fsnode *, int);
-void dump_fsnodes(const char *, fsnode *);
+void dump_fsnodes(fsnode *);
const char * inode_type(mode_t);
fsnode * read_mtree(const char *, fsnode *);
int set_option(option_t *, const char *, const char *);
-fsnode * walk_dir(const char *, fsnode *);
+fsnode * walk_dir(const char *, const char *, fsnode *, fsnode *);
void free_fsnodes(fsnode *);
void ffs_prep_opts(fsinfo_t *);
@@ -166,6 +171,7 @@
extern u_int debug;
+extern int dupsok;
extern struct timespec start_time;
/*
@@ -276,22 +282,6 @@
struct fs;
void ffs_fragacct_swap(struct fs *, int, int32_t [], int, int);
-/*
- * Declarations for compat routines.
- */
-long long strsuftoll(const char *, const char *, long long, long long);
-long long strsuftollx(const char *, const char *,
- long long, long long, char *, size_t);
+fsinode *link_check(fsinode *);
-struct passwd;
-int uid_from_user(const char *, uid_t *);
-int pwcache_userdb(int (*)(int), void (*)(void),
- struct passwd * (*)(const char *), struct passwd * (*)(uid_t));
-struct group;
-int gid_from_group(const char *, gid_t *);
-int pwcache_groupdb(int (*)(int), void (*)(void),
- struct group * (*)(const char *), struct group * (*)(gid_t));
-
-int setup_getid(const char *dir);
-
#endif /* _MAKEFS_H */
Added: trunk/usr.sbin/makefs/mtree.c
===================================================================
--- trunk/usr.sbin/makefs/mtree.c (rev 0)
+++ trunk/usr.sbin/makefs/mtree.c 2018-06-07 00:10:33 UTC (rev 10467)
@@ -0,0 +1,1122 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2011 Marcel Moolenaar
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/usr.sbin/makefs/mtree.c 300459 2016-05-23 05:21:55Z truckman $");
+
+#include <sys/param.h>
+#include <sys/queue.h>
+#include <sys/sbuf.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <assert.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <grp.h>
+#include <inttypes.h>
+#include <pwd.h>
+#include <stdarg.h>
+#include <stdbool.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+#include <unistd.h>
+
+#include "makefs.h"
+
+#define IS_DOT(nm) ((nm)[0] == '.' && (nm)[1] == '\0')
+#define IS_DOTDOT(nm) ((nm)[0] == '.' && (nm)[1] == '.' && (nm)[2] == '\0')
+
+struct mtree_fileinfo {
+ SLIST_ENTRY(mtree_fileinfo) next;
+ FILE *fp;
+ const char *name;
+ u_int line;
+};
+
+/* Global state used while parsing. */
+static SLIST_HEAD(, mtree_fileinfo) mtree_fileinfo =
+ SLIST_HEAD_INITIALIZER(mtree_fileinfo);
+static fsnode *mtree_root;
+static fsnode *mtree_current;
+static fsnode mtree_global;
+static fsinode mtree_global_inode;
+static u_int errors, warnings;
+
+static void mtree_error(const char *, ...) __printflike(1, 2);
+static void mtree_warning(const char *, ...) __printflike(1, 2);
+
+static int
+mtree_file_push(const char *name, FILE *fp)
+{
+ struct mtree_fileinfo *fi;
+
+ fi = malloc(sizeof(*fi));
+ if (fi == NULL)
+ return (ENOMEM);
+
+ if (strcmp(name, "-") == 0)
+ fi->name = strdup("(stdin)");
+ else
+ fi->name = strdup(name);
+ if (fi->name == NULL) {
+ free(fi);
+ return (ENOMEM);
+ }
+
+ fi->fp = fp;
+ fi->line = 0;
+
+ SLIST_INSERT_HEAD(&mtree_fileinfo, fi, next);
+ return (0);
+}
+
+static void
+mtree_print(const char *msgtype, const char *fmt, va_list ap)
+{
+ struct mtree_fileinfo *fi;
+
+ if (msgtype != NULL) {
+ fi = SLIST_FIRST(&mtree_fileinfo);
+ if (fi != NULL)
+ fprintf(stderr, "%s:%u: ", fi->name, fi->line);
+ fprintf(stderr, "%s: ", msgtype);
+ }
+ vfprintf(stderr, fmt, ap);
+}
+
+static void
+mtree_error(const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ mtree_print("error", fmt, ap);
+ va_end(ap);
+
+ errors++;
+ fputc('\n', stderr);
+}
+
+static void
+mtree_warning(const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ mtree_print("warning", fmt, ap);
+ va_end(ap);
+
+ warnings++;
+ fputc('\n', stderr);
+}
+
+#ifndef MAKEFS_MAX_TREE_DEPTH
+# define MAKEFS_MAX_TREE_DEPTH (MAXPATHLEN/2)
+#endif
+
+/* construct path to node->name */
+static char *
+mtree_file_path(fsnode *node)
+{
+ fsnode *pnode;
+ struct sbuf *sb;
+ char *res, *rp[MAKEFS_MAX_TREE_DEPTH];
+ int depth;
+
+ depth = 0;
+ rp[depth] = node->name;
+ for (pnode = node->parent; pnode && depth < MAKEFS_MAX_TREE_DEPTH - 1;
+ pnode = pnode->parent) {
+ if (strcmp(pnode->name, ".") == 0)
+ break;
+ rp[++depth] = pnode->name;
+ }
+
+ sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND);
+ if (sb == NULL) {
+ errno = ENOMEM;
+ return (NULL);
+ }
+ while (depth > 0) {
+ sbuf_cat(sb, rp[depth--]);
+ sbuf_putc(sb, '/');
+ }
+ sbuf_cat(sb, rp[depth]);
+ sbuf_finish(sb);
+ res = strdup(sbuf_data(sb));
+ sbuf_delete(sb);
+ if (res == NULL)
+ errno = ENOMEM;
+ return res;
+
+}
+
+/* mtree_resolve() sets errno to indicate why NULL was returned. */
+static char *
+mtree_resolve(const char *spec, int *istemp)
+{
+ struct sbuf *sb;
+ char *res, *var;
+ const char *base, *p, *v;
+ size_t len;
+ int c, error, quoted, subst;
+
+ len = strlen(spec);
+ if (len == 0) {
+ errno = EINVAL;
+ return (NULL);
+ }
+
+ c = (len > 1) ? (spec[0] == spec[len - 1]) ? spec[0] : 0 : 0;
+ *istemp = (c == '`') ? 1 : 0;
+ subst = (c == '`' || c == '"') ? 1 : 0;
+ quoted = (subst || c == '\'') ? 1 : 0;
+
+ if (!subst) {
+ res = strdup(spec + quoted);
+ if (res != NULL && quoted)
+ res[len - 2] = '\0';
+ return (res);
+ }
+
+ sb = sbuf_new_auto();
+ if (sb == NULL) {
+ errno = ENOMEM;
+ return (NULL);
+ }
+
+ base = spec + 1;
+ len -= 2;
+ error = 0;
+ while (len > 0) {
+ p = strchr(base, '$');
+ if (p == NULL) {
+ sbuf_bcat(sb, base, len);
+ base += len;
+ len = 0;
+ continue;
+ }
+ /* The following is safe. spec always starts with a quote. */
+ if (p[-1] == '\\')
+ p--;
+ if (base != p) {
+ sbuf_bcat(sb, base, p - base);
+ len -= p - base;
+ base = p;
+ }
+ if (*p == '\\') {
+ sbuf_putc(sb, '$');
+ base += 2;
+ len -= 2;
+ continue;
+ }
+ /* Skip the '$'. */
+ base++;
+ len--;
+ /* Handle ${X} vs $X. */
+ v = base;
+ if (*base == '{') {
+ p = strchr(v, '}');
+ if (p == NULL)
+ p = v;
+ } else
+ p = v;
+ len -= (p + 1) - base;
+ base = p + 1;
+
+ if (v == p) {
+ sbuf_putc(sb, *v);
+ continue;
+ }
+
+ error = ENOMEM;
+ var = calloc(p - v, 1);
+ if (var == NULL)
+ break;
+
+ memcpy(var, v + 1, p - v - 1);
+ if (strcmp(var, ".CURDIR") == 0) {
+ res = getcwd(NULL, 0);
+ if (res == NULL)
+ break;
+ } else if (strcmp(var, ".PROG") == 0) {
+ res = strdup(getprogname());
+ if (res == NULL)
+ break;
+ } else {
+ v = getenv(var);
+ if (v != NULL) {
+ res = strdup(v);
+ if (res == NULL)
+ break;
+ } else
+ res = NULL;
+ }
+ error = 0;
+
+ if (res != NULL) {
+ sbuf_cat(sb, res);
+ free(res);
+ }
+ free(var);
+ }
+
+ sbuf_finish(sb);
+ res = (error == 0) ? strdup(sbuf_data(sb)) : NULL;
+ sbuf_delete(sb);
+ if (res == NULL)
+ errno = ENOMEM;
+ return (res);
+}
+
+static int
+skip_over(FILE *fp, const char *cs)
+{
+ int c;
+
+ c = getc(fp);
+ while (c != EOF && strchr(cs, c) != NULL)
+ c = getc(fp);
+ if (c != EOF) {
+ ungetc(c, fp);
+ return (0);
+ }
+ return (ferror(fp) ? errno : -1);
+}
+
+static int
+skip_to(FILE *fp, const char *cs)
+{
+ int c;
+
+ c = getc(fp);
+ while (c != EOF && strchr(cs, c) == NULL)
+ c = getc(fp);
+ if (c != EOF) {
+ ungetc(c, fp);
+ return (0);
+ }
+ return (ferror(fp) ? errno : -1);
+}
+
+static int
+read_word(FILE *fp, char *buf, size_t bufsz)
+{
+ struct mtree_fileinfo *fi;
+ size_t idx, qidx;
+ int c, done, error, esc, qlvl;
+
+ if (bufsz == 0)
+ return (EINVAL);
+
+ done = 0;
+ esc = 0;
+ idx = 0;
+ qidx = -1;
+ qlvl = 0;
+ do {
+ c = getc(fp);
+ switch (c) {
+ case EOF:
+ buf[idx] = '\0';
+ error = ferror(fp) ? errno : -1;
+ if (error == -1)
+ mtree_error("unexpected end of file");
+ return (error);
+ case '\\':
+ esc++;
+ if (esc == 1)
+ continue;
+ break;
+ case '`':
+ case '\'':
+ case '"':
+ if (esc)
+ break;
+ if (qlvl == 0) {
+ qlvl++;
+ qidx = idx;
+ } else if (c == buf[qidx]) {
+ qlvl--;
+ if (qlvl > 0) {
+ do {
+ qidx--;
+ } while (buf[qidx] != '`' &&
+ buf[qidx] != '\'' &&
+ buf[qidx] != '"');
+ } else
+ qidx = -1;
+ } else {
+ qlvl++;
+ qidx = idx;
+ }
+ break;
+ case ' ':
+ case '\t':
+ case '\n':
+ if (!esc && qlvl == 0) {
+ ungetc(c, fp);
+ c = '\0';
+ done = 1;
+ break;
+ }
+ if (c == '\n') {
+ /*
+ * We going to eat the newline ourselves.
+ */
+ if (qlvl > 0)
+ mtree_warning("quoted word straddles "
+ "onto next line.");
+ fi = SLIST_FIRST(&mtree_fileinfo);
+ fi->line++;
+ }
+ break;
+ case 'a':
+ if (esc)
+ c = '\a';
+ break;
+ case 'b':
+ if (esc)
+ c = '\b';
+ break;
+ case 'f':
+ if (esc)
+ c = '\f';
+ break;
+ case 'n':
+ if (esc)
+ c = '\n';
+ break;
+ case 'r':
+ if (esc)
+ c = '\r';
+ break;
+ case 't':
+ if (esc)
+ c = '\t';
+ break;
+ case 'v':
+ if (esc)
+ c = '\v';
+ break;
+ }
+ buf[idx++] = c;
+ esc = 0;
+ } while (idx < bufsz && !done);
+
+ if (idx >= bufsz) {
+ mtree_error("word too long to fit buffer (max %zu characters)",
+ bufsz);
+ skip_to(fp, " \t\n");
+ }
+ return (0);
+}
+
+static fsnode *
+create_node(const char *name, u_int type, fsnode *parent, fsnode *global)
+{
+ fsnode *n;
+
+ n = calloc(1, sizeof(*n));
+ if (n == NULL)
+ return (NULL);
+
+ n->name = strdup(name);
+ if (n->name == NULL) {
+ free(n);
+ return (NULL);
+ }
+
+ n->type = (type == 0) ? global->type : type;
+ n->parent = parent;
+
+ n->inode = calloc(1, sizeof(*n->inode));
+ if (n->inode == NULL) {
+ free(n->name);
+ free(n);
+ return (NULL);
+ }
+
+ /* Assign global options/defaults. */
+ bcopy(global->inode, n->inode, sizeof(*n->inode));
+ n->inode->st.st_mode = (n->inode->st.st_mode & ~S_IFMT) | n->type;
+
+ if (n->type == S_IFLNK)
+ n->symlink = global->symlink;
+ else if (n->type == S_IFREG)
+ n->contents = global->contents;
+
+ return (n);
+}
+
+static void
+destroy_node(fsnode *n)
+{
+
+ assert(n != NULL);
+ assert(n->name != NULL);
+ assert(n->inode != NULL);
+
+ free(n->inode);
+ free(n->name);
+ free(n);
+}
+
+static int
+read_number(const char *tok, u_int base, intmax_t *res, intmax_t min,
+ intmax_t max)
+{
+ char *end;
+ intmax_t val;
+
+ val = strtoimax(tok, &end, base);
+ if (end == tok || end[0] != '\0')
+ return (EINVAL);
+ if (val < min || val > max)
+ return (EDOM);
+ *res = val;
+ return (0);
+}
+
+static int
+read_mtree_keywords(FILE *fp, fsnode *node)
+{
+ char keyword[PATH_MAX];
+ char *name, *p, *value;
+ gid_t gid;
+ uid_t uid;
+ struct stat *st, sb;
+ intmax_t num;
+ u_long flset, flclr;
+ int error, istemp, type;
+
+ st = &node->inode->st;
+ do {
+ error = skip_over(fp, " \t");
+ if (error)
+ break;
+
+ error = read_word(fp, keyword, sizeof(keyword));
+ if (error)
+ break;
+
+ if (keyword[0] == '\0')
+ break;
+
+ value = strchr(keyword, '=');
+ if (value != NULL)
+ *value++ = '\0';
+
+ /*
+ * We use EINVAL, ENOATTR, ENOSYS and ENXIO to signal
+ * certain conditions:
+ * EINVAL - Value provided for a keyword that does
+ * not take a value. The value is ignored.
+ * ENOATTR - Value missing for a keyword that needs
+ * a value. The keyword is ignored.
+ * ENOSYS - Unsupported keyword encountered. The
+ * keyword is ignored.
+ * ENXIO - Value provided for a keyword that does
+ * not take a value. The value is ignored.
+ */
+ switch (keyword[0]) {
+ case 'c':
+ if (strcmp(keyword, "contents") == 0) {
+ if (value == NULL) {
+ error = ENOATTR;
+ break;
+ }
+ node->contents = strdup(value);
+ } else
+ error = ENOSYS;
+ break;
+ case 'f':
+ if (strcmp(keyword, "flags") == 0) {
+ if (value == NULL) {
+ error = ENOATTR;
+ break;
+ }
+ flset = flclr = 0;
+ if (!strtofflags(&value, &flset, &flclr)) {
+ st->st_flags &= ~flclr;
+ st->st_flags |= flset;
+ } else
+ error = errno;
+ } else
+ error = ENOSYS;
+ break;
+ case 'g':
+ if (strcmp(keyword, "gid") == 0) {
+ if (value == NULL) {
+ error = ENOATTR;
+ break;
+ }
+ error = read_number(value, 10, &num,
+ 0, UINT_MAX);
+ if (!error)
+ st->st_gid = num;
+ } else if (strcmp(keyword, "gname") == 0) {
+ if (value == NULL) {
+ error = ENOATTR;
+ break;
+ }
+ if (gid_from_group(value, &gid) == 0)
+ st->st_gid = gid;
+ else
+ error = EINVAL;
+ } else
+ error = ENOSYS;
+ break;
+ case 'l':
+ if (strcmp(keyword, "link") == 0) {
+ if (value == NULL) {
+ error = ENOATTR;
+ break;
+ }
+ node->symlink = strdup(value);
+ } else
+ error = ENOSYS;
+ break;
+ case 'm':
+ if (strcmp(keyword, "mode") == 0) {
+ if (value == NULL) {
+ error = ENOATTR;
+ break;
+ }
+ if (value[0] >= '0' && value[0] <= '9') {
+ error = read_number(value, 8, &num,
+ 0, 07777);
+ if (!error) {
+ st->st_mode &= S_IFMT;
+ st->st_mode |= num;
+ }
+ } else {
+ /* Symbolic mode not supported. */
+ error = EINVAL;
+ break;
+ }
+ } else
+ error = ENOSYS;
+ break;
+ case 'o':
+ if (strcmp(keyword, "optional") == 0) {
+ if (value != NULL)
+ error = ENXIO;
+ node->flags |= FSNODE_F_OPTIONAL;
+ } else
+ error = ENOSYS;
+ break;
+ case 's':
+ if (strcmp(keyword, "size") == 0) {
+ if (value == NULL) {
+ error = ENOATTR;
+ break;
+ }
+ error = read_number(value, 10, &num,
+ 0, INTMAX_MAX);
+ if (!error)
+ st->st_size = num;
+ } else
+ error = ENOSYS;
+ break;
+ case 't':
+ if (strcmp(keyword, "time") == 0) {
+ if (value == NULL) {
+ error = ENOATTR;
+ break;
+ }
+ p = strchr(value, '.');
+ if (p != NULL)
+ *p++ = '\0';
+ error = read_number(value, 10, &num, 0,
+ INTMAX_MAX);
+ if (error)
+ break;
+ st->st_atime = num;
+ st->st_ctime = num;
+ st->st_mtime = num;
+ error = read_number(p, 10, &num, 0,
+ INTMAX_MAX);
+ if (error)
+ break;
+ if (num != 0)
+ error = EINVAL;
+ } else if (strcmp(keyword, "type") == 0) {
+ if (value == NULL) {
+ error = ENOATTR;
+ break;
+ }
+ if (strcmp(value, "dir") == 0)
+ node->type = S_IFDIR;
+ else if (strcmp(value, "file") == 0)
+ node->type = S_IFREG;
+ else if (strcmp(value, "link") == 0)
+ node->type = S_IFLNK;
+ else
+ error = EINVAL;
+ } else
+ error = ENOSYS;
+ break;
+ case 'u':
+ if (strcmp(keyword, "uid") == 0) {
+ if (value == NULL) {
+ error = ENOATTR;
+ break;
+ }
+ error = read_number(value, 10, &num,
+ 0, UINT_MAX);
+ if (!error)
+ st->st_uid = num;
+ } else if (strcmp(keyword, "uname") == 0) {
+ if (value == NULL) {
+ error = ENOATTR;
+ break;
+ }
+ if (uid_from_user(value, &uid) == 0)
+ st->st_uid = uid;
+ else
+ error = EINVAL;
+ } else
+ error = ENOSYS;
+ break;
+ default:
+ error = ENOSYS;
+ break;
+ }
+
+ switch (error) {
+ case EINVAL:
+ mtree_error("%s: invalid value '%s'", keyword, value);
+ break;
+ case ENOATTR:
+ mtree_error("%s: keyword needs a value", keyword);
+ break;
+ case ENOSYS:
+ mtree_warning("%s: unsupported keyword", keyword);
+ break;
+ case ENXIO:
+ mtree_error("%s: keyword does not take a value",
+ keyword);
+ break;
+ }
+ } while (1);
+
+ if (error)
+ return (error);
+
+ st->st_mode = (st->st_mode & ~S_IFMT) | node->type;
+
+ /* Nothing more to do for the global defaults. */
+ if (node->name == NULL)
+ return (0);
+
+ /*
+ * Be intelligent about the file type.
+ */
+ if (node->contents != NULL) {
+ if (node->symlink != NULL) {
+ mtree_error("%s: both link and contents keywords "
+ "defined", node->name);
+ return (0);
+ }
+ type = S_IFREG;
+ } else if (node->type != 0) {
+ type = node->type;
+ if (type == S_IFREG) {
+ /* the named path is the default contents */
+ node->contents = mtree_file_path(node);
+ }
+ } else
+ type = (node->symlink != NULL) ? S_IFLNK : S_IFDIR;
+
+ if (node->type == 0)
+ node->type = type;
+
+ if (node->type != type) {
+ mtree_error("%s: file type and defined keywords to not match",
+ node->name);
+ return (0);
+ }
+
+ st->st_mode = (st->st_mode & ~S_IFMT) | node->type;
+
+ if (node->contents == NULL)
+ return (0);
+
+ name = mtree_resolve(node->contents, &istemp);
+ if (name == NULL)
+ return (errno);
+
+ if (stat(name, &sb) != 0) {
+ mtree_error("%s: contents file '%s' not found", node->name,
+ name);
+ free(name);
+ return (0);
+ }
+
+ /*
+ * Check for hardlinks. If the contents key is used, then the check
+ * will only trigger if the contents file is a link even if it is used
+ * by more than one file
+ */
+ if (sb.st_nlink > 1) {
+ fsinode *curino;
+
+ st->st_ino = sb.st_ino;
+ st->st_dev = sb.st_dev;
+ curino = link_check(node->inode);
+ if (curino != NULL) {
+ free(node->inode);
+ node->inode = curino;
+ node->inode->nlink++;
+ }
+ }
+
+ free(node->contents);
+ node->contents = name;
+ st->st_size = sb.st_size;
+ return (0);
+}
+
+static int
+read_mtree_command(FILE *fp)
+{
+ char cmd[10];
+ int error;
+
+ error = read_word(fp, cmd, sizeof(cmd));
+ if (error)
+ goto out;
+
+ error = read_mtree_keywords(fp, &mtree_global);
+
+ out:
+ skip_to(fp, "\n");
+ (void)getc(fp);
+ return (error);
+}
+
+static int
+read_mtree_spec1(FILE *fp, bool def, const char *name)
+{
+ fsnode *last, *node, *parent;
+ u_int type;
+ int error;
+
+ assert(name[0] != '\0');
+
+ /*
+ * Treat '..' specially, because it only changes our current
+ * directory. We don't create a node for it. We simply ignore
+ * any keywords that may appear on the line as well.
+ * Going up a directory is a little non-obvious. A directory
+ * node has a corresponding '.' child. The parent of '.' is
+ * not the '.' node of the parent directory, but the directory
+ * node within the parent to which the child relates. However,
+ * going up a directory means we need to find the '.' node to
+ * which the directoy node is linked. This we can do via the
+ * first * pointer, because '.' is always the first entry in a
+ * directory.
+ */
+ if (IS_DOTDOT(name)) {
+ /* This deals with NULL pointers as well. */
+ if (mtree_current == mtree_root) {
+ mtree_warning("ignoring .. in root directory");
+ return (0);
+ }
+
+ node = mtree_current;
+
+ assert(node != NULL);
+ assert(IS_DOT(node->name));
+ assert(node->first == node);
+
+ /* Get the corresponding directory node in the parent. */
+ node = mtree_current->parent;
+
+ assert(node != NULL);
+ assert(!IS_DOT(node->name));
+
+ node = node->first;
+
+ assert(node != NULL);
+ assert(IS_DOT(node->name));
+ assert(node->first == node);
+
+ mtree_current = node;
+ return (0);
+ }
+
+ /*
+ * If we don't have a current directory and the first specification
+ * (either implicit or defined) is not '.', then we need to create
+ * a '.' node first (using a recursive call).
+ */
+ if (!IS_DOT(name) && mtree_current == NULL) {
+ error = read_mtree_spec1(fp, false, ".");
+ if (error)
+ return (error);
+ }
+
+ /*
+ * Lookup the name in the current directory (if we have a current
+ * directory) to make sure we do not create multiple nodes for the
+ * same component. For non-definitions, if we find a node with the
+ * same name, simply change the current directory. For definitions
+ * more happens.
+ */
+ last = NULL;
+ node = mtree_current;
+ while (node != NULL) {
+ assert(node->first == mtree_current);
+
+ if (strcmp(name, node->name) == 0) {
+ if (def == true) {
+ if (!dupsok)
+ mtree_error(
+ "duplicate definition of %s",
+ name);
+ else
+ mtree_warning(
+ "duplicate definition of %s",
+ name);
+ return (0);
+ }
+
+ if (node->type != S_IFDIR) {
+ mtree_error("%s is not a directory", name);
+ return (0);
+ }
+
+ assert(!IS_DOT(name));
+
+ node = node->child;
+
+ assert(node != NULL);
+ assert(IS_DOT(node->name));
+
+ mtree_current = node;
+ return (0);
+ }
+
+ last = node;
+ node = last->next;
+ }
+
+ parent = (mtree_current != NULL) ? mtree_current->parent : NULL;
+ type = (def == false || IS_DOT(name)) ? S_IFDIR : 0;
+ node = create_node(name, type, parent, &mtree_global);
+ if (node == NULL)
+ return (ENOMEM);
+
+ if (def == true) {
+ error = read_mtree_keywords(fp, node);
+ if (error) {
+ destroy_node(node);
+ return (error);
+ }
+ }
+
+ node->first = (mtree_current != NULL) ? mtree_current : node;
+
+ if (last != NULL)
+ last->next = node;
+
+ if (node->type != S_IFDIR)
+ return (0);
+
+ if (!IS_DOT(node->name)) {
+ parent = node;
+ node = create_node(".", S_IFDIR, parent, parent);
+ if (node == NULL) {
+ last->next = NULL;
+ destroy_node(parent);
+ return (ENOMEM);
+ }
+ parent->child = node;
+ node->first = node;
+ }
+
+ assert(node != NULL);
+ assert(IS_DOT(node->name));
+ assert(node->first == node);
+
+ mtree_current = node;
+ if (mtree_root == NULL)
+ mtree_root = node;
+
+ return (0);
+}
+
+static int
+read_mtree_spec(FILE *fp)
+{
+ char pathspec[PATH_MAX];
+ char *cp;
+ int error;
+
+ error = read_word(fp, pathspec, sizeof(pathspec));
+ if (error)
+ goto out;
+
+ cp = strchr(pathspec, '/');
+ if (cp != NULL) {
+ /* Absolute pathname */
+ mtree_current = mtree_root;
+
+ do {
+ *cp++ = '\0';
+
+ /* Disallow '..' as a component. */
+ if (IS_DOTDOT(pathspec)) {
+ mtree_error("absolute path cannot contain "
+ ".. component");
+ goto out;
+ }
+
+ /* Ignore multiple adjacent slashes and '.'. */
+ if (pathspec[0] != '\0' && !IS_DOT(pathspec))
+ error = read_mtree_spec1(fp, false, pathspec);
+ memmove(pathspec, cp, strlen(cp) + 1);
+ cp = strchr(pathspec, '/');
+ } while (!error && cp != NULL);
+
+ /* Disallow '.' and '..' as the last component. */
+ if (!error && (IS_DOT(pathspec) || IS_DOTDOT(pathspec))) {
+ mtree_error("absolute path cannot contain . or .. "
+ "components");
+ goto out;
+ }
+ }
+
+ /* Ignore absolute specfications that end with a slash. */
+ if (!error && pathspec[0] != '\0')
+ error = read_mtree_spec1(fp, true, pathspec);
+
+ out:
+ skip_to(fp, "\n");
+ (void)getc(fp);
+ return (error);
+}
+
+fsnode *
+read_mtree(const char *fname, fsnode *node)
+{
+ struct mtree_fileinfo *fi;
+ FILE *fp;
+ int c, error;
+
+ /* We do not yet support nesting... */
+ assert(node == NULL);
+
+ if (strcmp(fname, "-") == 0)
+ fp = stdin;
+ else {
+ fp = fopen(fname, "r");
+ if (fp == NULL)
+ err(1, "Can't open `%s'", fname);
+ }
+
+ error = mtree_file_push(fname, fp);
+ if (error)
+ goto out;
+
+ bzero(&mtree_global, sizeof(mtree_global));
+ bzero(&mtree_global_inode, sizeof(mtree_global_inode));
+ mtree_global.inode = &mtree_global_inode;
+ mtree_global_inode.nlink = 1;
+ mtree_global_inode.st.st_nlink = 1;
+ mtree_global_inode.st.st_atime = mtree_global_inode.st.st_ctime =
+ mtree_global_inode.st.st_mtime = time(NULL);
+ errors = warnings = 0;
+
+ setgroupent(1);
+ setpassent(1);
+
+ mtree_root = node;
+ mtree_current = node;
+ do {
+ /* Start of a new line... */
+ fi = SLIST_FIRST(&mtree_fileinfo);
+ fi->line++;
+
+ error = skip_over(fp, " \t");
+ if (error)
+ break;
+
+ c = getc(fp);
+ if (c == EOF) {
+ error = ferror(fp) ? errno : -1;
+ break;
+ }
+
+ switch (c) {
+ case '\n': /* empty line */
+ error = 0;
+ break;
+ case '#': /* comment -- skip to end of line. */
+ error = skip_to(fp, "\n");
+ if (!error)
+ (void)getc(fp);
+ break;
+ case '/': /* special commands */
+ error = read_mtree_command(fp);
+ break;
+ default: /* specification */
+ ungetc(c, fp);
+ error = read_mtree_spec(fp);
+ break;
+ }
+ } while (!error);
+
+ endpwent();
+ endgrent();
+
+ if (error <= 0 && (errors || warnings)) {
+ warnx("%u error(s) and %u warning(s) in mtree manifest",
+ errors, warnings);
+ if (errors)
+ exit(1);
+ }
+
+ out:
+ if (error > 0)
+ errc(1, error, "Error reading mtree file");
+
+ if (fp != stdin)
+ fclose(fp);
+
+ if (mtree_root != NULL)
+ return (mtree_root);
+
+ /* Handle empty specifications. */
+ node = create_node(".", S_IFDIR, NULL, &mtree_global);
+ node->first = node;
+ return (node);
+}
Property changes on: trunk/usr.sbin/makefs/mtree.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/usr.sbin/makefs/tests/Makefile
===================================================================
--- trunk/usr.sbin/makefs/tests/Makefile (rev 0)
+++ trunk/usr.sbin/makefs/tests/Makefile 2018-06-07 00:10:33 UTC (rev 10467)
@@ -0,0 +1,20 @@
+# $MidnightBSD$
+# $FreeBSD: stable/10/usr.sbin/makefs/tests/Makefile 296788 2016-03-13 01:20:20Z ngie $
+
+TESTSDIR= ${TESTSBASE}/usr.sbin/makefs
+
+ATF_TESTS_SH+= makefs_cd9660_tests
+ATF_TESTS_SH+= makefs_ffs_tests
+
+BINDIR= ${TESTSDIR}
+
+SCRIPTS+= makefs_tests_common.sh
+SCRIPTSNAME_makefs_tests_common.sh= makefs_tests_common.sh
+
+TEST_METADATA.makefs_cd9660_tests+= required_files="/sbin/mount_cd9660"
+
+.for t in ${ATF_TESTS_SH}
+TEST_METADATA.$t+= required_user="root"
+.endfor
+
+.include <bsd.test.mk>
Property changes on: trunk/usr.sbin/makefs/tests/Makefile
___________________________________________________________________
Added: mnbsd:nokeywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/usr.sbin/makefs/tests/makefs_cd9660_tests.sh
===================================================================
--- trunk/usr.sbin/makefs/tests/makefs_cd9660_tests.sh (rev 0)
+++ trunk/usr.sbin/makefs/tests/makefs_cd9660_tests.sh 2018-06-07 00:10:33 UTC (rev 10467)
@@ -0,0 +1,373 @@
+#
+# Copyright 2015 EMC Corp.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+# $FreeBSD: stable/10/usr.sbin/makefs/tests/makefs_cd9660_tests.sh 290594 2015-11-09 09:20:01Z ngie $
+#
+
+# A note on specs:
+# - A copy of the ISO-9660 spec can be found here:
+# http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-119.pdf
+# - Any references to `rockridge` are referring to the `Rock Ridge` extensions
+# of the ISO-9660 spec. A copy of the draft `IEEE-P1282` spec can be found
+# here:
+# http://www.ymi.com/ymi/sites/default/files/pdf/Rockridge.pdf
+
+MAKEFS="makefs -t cd9660"
+MOUNT="mount_cd9660"
+
+. "$(dirname "$0")/makefs_tests_common.sh"
+
+common_cleanup()
+{
+ if ! test_md_device=$(cat $TEST_MD_DEVICE_FILE); then
+ echo "$TEST_MD_DEVICE_FILE could not be opened; has an md(4) device been attached?"
+ return
+ fi
+
+ umount -f /dev/$test_md_device || :
+ mdconfig -d -u $test_md_device || :
+}
+
+check_base_iso9660_image_contents()
+{
+ # Symlinks are treated like files when rockridge support isn't
+ # specified
+ check_image_contents "$@" -X c
+
+ atf_check -e empty -o empty -s exit:0 test -L $TEST_INPUTS_DIR/c
+ atf_check -e empty -o empty -s exit:0 test -f $TEST_MOUNT_DIR/c
+}
+
+atf_test_case D_flag cleanup
+D_flag_body()
+{
+ atf_skip "makefs crashes with SIGBUS with dupe mtree entries; see FreeBSD bug # 192839"
+
+ create_test_inputs
+
+ atf_check -e empty -o save:$TEST_SPEC_FILE -s exit:0 \
+ mtree -cp $TEST_INPUTS_DIR
+ atf_check -e empty -o not-empty -s exit:0 \
+ $MAKEFS -F $TEST_SPEC_FILE -M 1m $TEST_IMAGE $TEST_INPUTS_DIR
+
+ atf_check -e empty -o empty -s exit:0 \
+ cp $TEST_SPEC_FILE spec2.mtree
+ atf_check -e empty -o save:dupe_$TEST_SPEC_FILE -s exit:0 \
+ cat $TEST_SPEC_FILE spec2.mtree
+
+ atf_check -e empty -o not-empty -s not-exit:0 \
+ $MAKEFS -F dupe_$TEST_SPEC_FILE -M 1m $TEST_IMAGE $TEST_INPUTS_DIR
+ atf_check -e empty -o not-empty -s exit:0 \
+ $MAKEFS -D -F dupe_$TEST_SPEC_FILE -M 1m $TEST_IMAGE $TEST_INPUTS_DIR
+}
+D_flag_cleanup()
+{
+ common_cleanup
+}
+
+atf_test_case F_flag cleanup
+F_flag_body()
+{
+ create_test_inputs
+
+ atf_check -e empty -o save:$TEST_SPEC_FILE -s exit:0 \
+ mtree -cp $TEST_INPUTS_DIR
+
+ atf_check -e empty -o empty -s exit:0 \
+ $MAKEFS -F $TEST_SPEC_FILE -M 1m $TEST_IMAGE $TEST_INPUTS_DIR
+
+ mount_image
+ check_base_iso9660_image_contents
+}
+F_flag_cleanup()
+{
+ common_cleanup
+}
+
+atf_test_case from_mtree_spec_file cleanup
+from_mtree_spec_file_body()
+{
+ create_test_inputs
+
+ atf_check -e empty -o save:$TEST_SPEC_FILE -s exit:0 \
+ mtree -c -k "$DEFAULT_MTREE_KEYWORDS" -p $TEST_INPUTS_DIR
+ cd $TEST_INPUTS_DIR
+ atf_check -e empty -o empty -s exit:0 \
+ $MAKEFS $TEST_IMAGE $TEST_SPEC_FILE
+ cd -
+
+ mount_image
+ check_base_iso9660_image_contents
+}
+from_mtree_spec_file_cleanup()
+{
+ common_cleanup
+}
+
+atf_test_case from_multiple_dirs cleanup
+from_multiple_dirs_body()
+{
+ test_inputs_dir2=$TMPDIR/inputs2
+
+ create_test_inputs
+
+ atf_check -e empty -o empty -s exit:0 mkdir -p $test_inputs_dir2
+ atf_check -e empty -o empty -s exit:0 \
+ touch $test_inputs_dir2/multiple_dirs_test_file
+
+ atf_check -e empty -o empty -s exit:0 \
+ $MAKEFS $TEST_IMAGE $TEST_INPUTS_DIR $test_inputs_dir2
+
+ mount_image
+ check_base_iso9660_image_contents -d $test_inputs_dir2
+}
+from_multiple_dirs_cleanup()
+{
+ common_cleanup
+}
+
+atf_test_case from_single_dir cleanup
+from_single_dir_body()
+{
+ create_test_inputs
+
+ atf_check -e empty -o empty -s exit:0 \
+ $MAKEFS $TEST_IMAGE $TEST_INPUTS_DIR
+
+ mount_image
+ check_base_iso9660_image_contents
+}
+from_single_dir_cleanup()
+{
+ common_cleanup
+}
+
+atf_test_case o_flag_allow_deep_trees cleanup
+o_flag_allow_deep_trees_body()
+{
+ create_test_inputs
+
+ # Make sure the "more than 8 levels deep" requirement is met.
+ atf_check -e empty -o empty -s exit:0 \
+ mkdir -p $TEST_INPUTS_DIR/a/b/c/d/e/f/g/h/i/j
+
+ atf_check -e empty -o empty -s exit:0 \
+ $MAKEFS -o allow-deep-trees $TEST_IMAGE $TEST_INPUTS_DIR
+
+ mount_image
+ check_base_iso9660_image_contents
+}
+o_flag_allow_deep_trees_cleanup()
+{
+ common_cleanup
+}
+
+atf_test_case o_flag_allow_max_name cleanup
+o_flag_allow_max_name_body()
+{
+ atf_expect_fail "-o allow-max-name doesn't appear to be implemented on FreeBSD's copy of makefs [yet]"
+
+ create_test_inputs
+
+ long_path=$TEST_INPUTS_DIR/$(jot -s '' -b 0 37)
+
+ # Make sure the "37 char name" limit requirement is met.
+ atf_check -e empty -o empty -s exit:0 touch $long_path
+
+ atf_check -e empty -o empty -s exit:0 \
+ $MAKEFS -o allow-max-name $TEST_IMAGE $TEST_INPUTS_DIR
+
+ mount_image
+ check_base_iso9660_image_contents
+}
+o_flag_allow_max_name_cleanup()
+{
+ common_cleanup
+}
+
+atf_test_case o_flag_isolevel_1 cleanup
+o_flag_isolevel_1_body()
+{
+ atf_expect_fail "this testcase needs work; the filenames generated seem incorrect/corrupt"
+
+ create_test_inputs
+
+ atf_check -e empty -o empty -s exit:0 \
+ $MAKEFS -o isolevel=1 $TEST_IMAGE $TEST_INPUTS_DIR
+
+ mount_image
+ check_base_iso9660_image_contents
+}
+o_flag_isolevel_1_cleanup()
+{
+ common_cleanup
+}
+
+atf_test_case o_flag_isolevel_2 cleanup
+o_flag_isolevel_2_body()
+{
+ create_test_inputs
+
+ atf_check -e empty -o empty -s exit:0 \
+ $MAKEFS -o isolevel=2 $TEST_IMAGE $TEST_INPUTS_DIR
+
+ mount_image
+ check_base_iso9660_image_contents
+}
+o_flag_isolevel_2_cleanup()
+{
+ common_cleanup
+}
+
+atf_test_case o_flag_isolevel_3 cleanup
+o_flag_isolevel_3_body()
+{
+ create_test_inputs
+
+ # XXX: isolevel=3 isn't implemented yet. See FreeBSD bug # 203645
+ if true; then
+ atf_check -e match:'makefs: ISO Level 3 is greater than 2\.' -o empty -s not-exit:0 \
+ $MAKEFS -o isolevel=3 $TEST_IMAGE $TEST_INPUTS_DIR
+ else
+ atf_check -e empty -o empty -s exit:0 \
+ $MAKEFS -o isolevel=3 $TEST_IMAGE $TEST_INPUTS_DIR
+ mount_image
+ check_base_iso9660_image_contents
+ fi
+}
+o_flag_isolevel_3_cleanup()
+{
+ common_cleanup
+}
+
+atf_test_case o_flag_preparer
+o_flag_preparer_body()
+{
+ create_test_dirs
+
+ preparer='My Very First ISO'
+ preparer_uppercase="$(echo $preparer | tr '[[:lower:]]' '[[:upper:]]')"
+
+ atf_check -e empty -o empty -s exit:0 touch $TEST_INPUTS_DIR/dummy_file
+ atf_check -e empty -o empty -s exit:0 \
+ $MAKEFS -o preparer="$preparer" $TEST_IMAGE $TEST_INPUTS_DIR
+ atf_check -e empty -o match:"$preparer_uppercase" -s exit:0 \
+ strings $TEST_IMAGE
+}
+
+atf_test_case o_flag_publisher
+o_flag_publisher_body()
+{
+ create_test_dirs
+
+ publisher='My Super Awesome Publishing Company LTD'
+ publisher_uppercase="$(echo $publisher | tr '[[:lower:]]' '[[:upper:]]')"
+
+ atf_check -e empty -o empty -s exit:0 touch $TEST_INPUTS_DIR/dummy_file
+ atf_check -e empty -o empty -s exit:0 \
+ $MAKEFS -o publisher="$publisher" $TEST_IMAGE $TEST_INPUTS_DIR
+ atf_check -e empty -o match:"$publisher_uppercase" -s exit:0 \
+ strings $TEST_IMAGE
+}
+
+atf_test_case o_flag_rockridge cleanup
+o_flag_rockridge_body()
+{
+ create_test_dirs
+
+ # Make sure the "more than 8 levels deep" requirement is met.
+ atf_check -e empty -o empty -s exit:0 \
+ mkdir -p $TEST_INPUTS_DIR/a/b/c/d/e/f/g/h/i/j
+
+ # Make sure the "pathname larger than 255 chars" requirement is met.
+ #
+ # $long_path's needs to be nested in a directory, as creating it
+ # outright as a 256 char filename via touch will fail with ENAMETOOLONG
+ long_path=$TEST_INPUTS_DIR/$(jot -s '/' -b "$(jot -s '' -b 0 64)" 4)
+ atf_check -e empty -o empty -s exit:0 mkdir -p "$(dirname $long_path)"
+ atf_check -e empty -o empty -s exit:0 touch "$long_path"
+
+ atf_check -e empty -o empty -s exit:0 \
+ $MAKEFS -o rockridge $TEST_IMAGE $TEST_INPUTS_DIR
+
+ mount_image
+ check_image_contents -X .rr_moved
+
+ # .rr_moved is a special directory created when you have deep directory
+ # trees with rock ridge extensions on
+ atf_check -e empty -o empty -s exit:0 \
+ test -d $TEST_MOUNT_DIR/.rr_moved
+}
+o_flag_rockridge_cleanup()
+{
+ common_cleanup
+}
+
+atf_test_case o_flag_rockridge_dev_nodes cleanup
+o_flag_rockridge_dev_nodes_head()
+{
+ atf_set "descr" "Functional tests to ensure that dev nodes are handled properly with rockridge extensions (NetBSD kern/48852; FreeBSD bug 203648)"
+}
+o_flag_rockridge_dev_nodes_body()
+{
+ create_test_dirs
+
+ (tar -cvf - -C /dev null && touch .tar_ok) | \
+ atf_check -e not-empty -o empty -s exit:0 tar -xvf - -C "$TEST_INPUTS_DIR"
+
+ atf_check -e empty -o empty -s exit:0 test -c $TEST_INPUTS_DIR/null
+ atf_check -e empty -o empty -s exit:0 test -f .tar_ok
+
+ atf_check -e empty -o empty -s exit:0 \
+ $MAKEFS -o rockridge $TEST_IMAGE $TEST_INPUTS_DIR
+
+ mount_image
+ check_image_contents
+}
+o_flag_rockridge_dev_nodes_cleanup()
+{
+ common_cleanup
+}
+
+atf_init_test_cases()
+{
+ atf_add_test_case D_flag
+ atf_add_test_case F_flag
+
+ atf_add_test_case from_mtree_spec_file
+ atf_add_test_case from_multiple_dirs
+ atf_add_test_case from_single_dir
+
+ atf_add_test_case o_flag_allow_deep_trees
+ atf_add_test_case o_flag_allow_max_name
+ atf_add_test_case o_flag_isolevel_1
+ atf_add_test_case o_flag_isolevel_2
+ atf_add_test_case o_flag_isolevel_3
+ atf_add_test_case o_flag_preparer
+ atf_add_test_case o_flag_publisher
+ atf_add_test_case o_flag_rockridge
+ atf_add_test_case o_flag_rockridge_dev_nodes
+}
Property changes on: trunk/usr.sbin/makefs/tests/makefs_cd9660_tests.sh
___________________________________________________________________
Added: mnbsd:nokeywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/usr.sbin/makefs/tests/makefs_ffs_tests.sh
===================================================================
--- trunk/usr.sbin/makefs/tests/makefs_ffs_tests.sh (rev 0)
+++ trunk/usr.sbin/makefs/tests/makefs_ffs_tests.sh 2018-06-07 00:10:33 UTC (rev 10467)
@@ -0,0 +1,237 @@
+#
+# Copyright 2015 EMC Corp.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+# $FreeBSD: stable/10/usr.sbin/makefs/tests/makefs_ffs_tests.sh 321820 2017-07-31 21:52:08Z asomers $
+#
+
+MAKEFS="makefs -t ffs"
+MOUNT="mount"
+
+. "$(dirname "$0")/makefs_tests_common.sh"
+
+TEST_TUNEFS_OUTPUT=$TMPDIR/tunefs.output
+
+common_cleanup()
+{
+ if ! test_md_device=$(cat $TEST_MD_DEVICE_FILE); then
+ echo "$TEST_MD_DEVICE_FILE could not be opened; has an md(4) device been attached?"
+ return
+ fi
+
+ umount -f /dev/$test_md_device || :
+ mdconfig -d -u $test_md_device || :
+}
+
+check_ffs_image_contents()
+{
+ atf_check -e save:$TEST_TUNEFS_OUTPUT -o empty -s exit:0 \
+ tunefs -p /dev/$(cat $TEST_MD_DEVICE_FILE)
+
+ check_image_contents "$@"
+}
+
+atf_test_case D_flag cleanup
+D_flag_body()
+{
+ atf_skip "makefs crashes with SIGBUS with dupe mtree entries; see FreeBSD bug # 192839"
+
+ create_test_inputs
+
+ atf_check -e empty -o save:$TEST_SPEC_FILE -s exit:0 \
+ mtree -cp $TEST_INPUTS_DIR
+ atf_check -e empty -o not-empty -s exit:0 \
+ $MAKEFS -F $TEST_SPEC_FILE -M 1m $TEST_IMAGE $TEST_INPUTS_DIR
+
+ atf_check -e empty -o empty -s exit:0 \
+ cp $TEST_SPEC_FILE spec2.mtree
+ atf_check -e empty -o save:dupe_$TEST_SPEC_FILE -s exit:0 \
+ cat $TEST_SPEC_FILE spec2.mtree
+
+ atf_check -e empty -o not-empty -s not-exit:0 \
+ $MAKEFS -F dupe_$TEST_SPEC_FILE -M 1m $TEST_IMAGE $TEST_INPUTS_DIR
+ atf_check -e empty -o not-empty -s exit:0 \
+ $MAKEFS -D -F dupe_$TEST_SPEC_FILE -M 1m $TEST_IMAGE $TEST_INPUTS_DIR
+}
+D_flag_cleanup()
+{
+ common_cleanup
+}
+
+atf_test_case F_flag cleanup
+F_flag_body()
+{
+ create_test_inputs
+
+ atf_check -e empty -o save:$TEST_SPEC_FILE -s exit:0 \
+ mtree -cp $TEST_INPUTS_DIR
+
+ atf_check -e empty -o not-empty -s exit:0 \
+ $MAKEFS -F $TEST_SPEC_FILE -M 1m $TEST_IMAGE $TEST_INPUTS_DIR
+
+ mount_image
+ check_ffs_image_contents
+}
+F_flag_cleanup()
+{
+ common_cleanup
+}
+
+atf_test_case from_mtree_spec_file cleanup
+from_mtree_spec_file_body()
+{
+ create_test_inputs
+
+ atf_check -e empty -o save:$TEST_SPEC_FILE -s exit:0 \
+ mtree -c -k "$DEFAULT_MTREE_KEYWORDS" -p $TEST_INPUTS_DIR
+
+ cd $TEST_INPUTS_DIR
+ atf_check -e empty -o not-empty -s exit:0 \
+ $MAKEFS $TEST_IMAGE $TEST_SPEC_FILE
+ cd -
+
+ mount_image
+ check_ffs_image_contents
+}
+from_mtree_spec_file_cleanup()
+{
+ common_cleanup
+}
+
+atf_test_case from_multiple_dirs cleanup
+from_multiple_dirs_body()
+{
+ test_inputs_dir2=$TMPDIR/inputs2
+
+ create_test_inputs
+
+ atf_check -e empty -o empty -s exit:0 mkdir -p $test_inputs_dir2
+ atf_check -e empty -o empty -s exit:0 \
+ touch $test_inputs_dir2/multiple_dirs_test_file
+
+ atf_check -e empty -o not-empty -s exit:0 \
+ $MAKEFS $TEST_IMAGE $TEST_INPUTS_DIR $test_inputs_dir2
+
+ mount_image
+ check_image_contents -d $test_inputs_dir2
+}
+from_multiple_dirs_cleanup()
+{
+ common_cleanup
+}
+
+atf_test_case from_single_dir cleanup
+from_single_dir_body()
+{
+ create_test_inputs
+
+ atf_check -e empty -o not-empty -s exit:0 \
+ $MAKEFS -M 1m $TEST_IMAGE $TEST_INPUTS_DIR
+
+ mount_image
+ check_ffs_image_contents
+}
+from_single_dir_cleanup()
+{
+ common_cleanup
+}
+
+atf_test_case o_flag_version_1 cleanup
+o_flag_version_1_body()
+{
+ ffs_version=1
+
+ platform=$(uname)
+ case "$platform" in
+ FreeBSD)
+ ffs_label=UFS${ffs_version}
+ ;;
+ NetBSD)
+ ffs_label=FFSv${ffs_version}
+ ;;
+ *)
+ atf_skip "Unsupported platform"
+ ;;
+ esac
+
+ create_test_inputs
+
+ atf_check -e empty -o not-empty -s exit:0 \
+ $MAKEFS -M 1m -o version=$ffs_version $TEST_IMAGE $TEST_INPUTS_DIR
+
+ mount_image
+ atf_check -e ignore -o match:"$ffs_label" dumpfs $TEST_MOUNT_DIR
+ check_ffs_image_contents
+}
+o_flag_version_1_cleanup()
+{
+ common_cleanup
+}
+
+atf_test_case o_flag_version_2 cleanup
+o_flag_version_2_body()
+{
+ ffs_version=2
+
+ platform=$(uname)
+ case "$platform" in
+ FreeBSD)
+ ffs_label=UFS${ffs_version}
+ ;;
+ NetBSD)
+ ffs_label=FFSv${ffs_version}
+ ;;
+ *)
+ atf_skip "Unsupported platform"
+ ;;
+ esac
+
+ create_test_inputs
+
+ atf_check -e empty -o not-empty -s exit:0 \
+ $MAKEFS -M 1m -o version=$ffs_version $TEST_IMAGE $TEST_INPUTS_DIR
+
+ mount_image
+ atf_check -e ignore -o match:"$ffs_label" dumpfs $TEST_MOUNT_DIR
+ check_ffs_image_contents
+}
+o_flag_version_2_cleanup()
+{
+ common_cleanup
+}
+
+atf_init_test_cases()
+{
+
+ atf_add_test_case D_flag
+ atf_add_test_case F_flag
+
+ atf_add_test_case from_mtree_spec_file
+ atf_add_test_case from_multiple_dirs
+ atf_add_test_case from_single_dir
+
+ atf_add_test_case o_flag_version_1
+ atf_add_test_case o_flag_version_2
+}
Property changes on: trunk/usr.sbin/makefs/tests/makefs_ffs_tests.sh
___________________________________________________________________
Added: mnbsd:nokeywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/usr.sbin/makefs/tests/makefs_tests_common.sh
===================================================================
--- trunk/usr.sbin/makefs/tests/makefs_tests_common.sh (rev 0)
+++ trunk/usr.sbin/makefs/tests/makefs_tests_common.sh 2018-06-07 00:10:33 UTC (rev 10467)
@@ -0,0 +1,152 @@
+#
+# Copyright 2015 EMC Corp.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+# $FreeBSD: stable/10/usr.sbin/makefs/tests/makefs_tests_common.sh 290594 2015-11-09 09:20:01Z ngie $
+#
+
+KB=1024
+: ${TMPDIR=/tmp}
+# TODO: add mtree `time` support; get a lot of errors like this right now when
+# passing generating disk images with keyword mtree support, like:
+#
+# `[...]/mtree.spec:8: error: time: invalid value '1446458503'`
+#
+#DEFAULT_MTREE_KEYWORDS="type,mode,gid,uid,size,link,time"
+DEFAULT_MTREE_KEYWORDS="type,mode,gid,uid,size,link"
+TEST_IMAGE="$TMPDIR/test.img"
+TEST_INPUTS_DIR="$TMPDIR/inputs"
+TEST_MD_DEVICE_FILE="$TMPDIR/md.output"
+TEST_MOUNT_DIR="$TMPDIR/mnt"
+TEST_SPEC_FILE="$TMPDIR/mtree.spec"
+
+check_image_contents()
+{
+ local directories=$TEST_INPUTS_DIR
+ local excludes mtree_excludes_arg mtree_file
+ local mtree_keywords="$DEFAULT_MTREE_KEYWORDS"
+
+ while getopts "d:f:m:X:" flag; do
+ case "$flag" in
+ d)
+ directories="$directories $OPTARG"
+ ;;
+ f)
+ mtree_file=$OPTARG
+ ;;
+ m)
+ mtree_keywords=$OPTARG
+ ;;
+ X)
+ excludes="$excludes $OPTARG"
+ ;;
+ *)
+ echo "usage: check_image_contents [-d directory ...] [-f mtree-file] [-m mtree-keywords] [-X exclude]"
+ atf_fail "unhandled option: $flag"
+ ;;
+ esac
+ done
+
+ if [ -n "$excludes" ]; then
+ echo "$excludes" | tr ' ' '\n' > excludes.txt
+ mtree_excludes_arg="-X excludes.txt"
+ fi
+
+ if [ -z "$mtree_file" ]; then
+ mtree_file=input_spec.mtree
+ for directory in $directories; do
+ mtree -c -k $mtree_keywords -p $directory $mtree_excludes_arg
+ done > $mtree_file
+ fi
+
+ echo "<---- Input spec BEGIN ---->"
+ cat $mtree_file
+ echo "<---- Input spec END ---->"
+ atf_check -e empty -o empty -s exit:0 \
+ mtree -UW -f $mtree_file \
+ -p $TEST_MOUNT_DIR \
+ $mtree_excludes_arg
+}
+
+create_test_dirs()
+{
+ atf_check -e empty -s exit:0 mkdir -m 0777 -p $TEST_MOUNT_DIR
+ atf_check -e empty -s exit:0 mkdir -m 0777 -p $TEST_INPUTS_DIR
+}
+
+create_test_inputs()
+{
+ create_test_dirs
+
+ cd $TEST_INPUTS_DIR
+
+ atf_check -e empty -s exit:0 mkdir -m 0755 -p a/b/1
+ atf_check -e empty -s exit:0 ln -s a/b c
+ atf_check -e empty -s exit:0 touch d
+ atf_check -e empty -s exit:0 ln d e
+ atf_check -e empty -s exit:0 touch .f
+ atf_check -e empty -s exit:0 mkdir .g
+ # XXX: fifos on the filesystem don't match fifos created by makefs for
+ # some odd reason.
+ #atf_check -e empty -s exit:0 mkfifo h
+ atf_check -e ignore -s exit:0 dd if=/dev/zero of=i count=1000 bs=1
+ atf_check -e empty -s exit:0 touch klmn
+ atf_check -e empty -s exit:0 touch opqr
+ atf_check -e empty -s exit:0 touch stuv
+ atf_check -e empty -s exit:0 install -m 0755 /dev/null wxyz
+ atf_check -e empty -s exit:0 touch 0b00000001
+ atf_check -e empty -s exit:0 touch 0b00000010
+ atf_check -e empty -s exit:0 touch 0b00000011
+ atf_check -e empty -s exit:0 touch 0b00000100
+ atf_check -e empty -s exit:0 touch 0b00000101
+ atf_check -e empty -s exit:0 touch 0b00000110
+ atf_check -e empty -s exit:0 touch 0b00000111
+ atf_check -e empty -s exit:0 touch 0b00001000
+ atf_check -e empty -s exit:0 touch 0b00001001
+ atf_check -e empty -s exit:0 touch 0b00001010
+ atf_check -e empty -s exit:0 touch 0b00001011
+ atf_check -e empty -s exit:0 touch 0b00001100
+ atf_check -e empty -s exit:0 touch 0b00001101
+ atf_check -e empty -s exit:0 touch 0b00001110
+
+ for filesize in 1 512 $(( 2 * $KB )) $(( 10 * $KB )) $(( 512 * $KB )); \
+ do
+ atf_check -e ignore -o empty -s exit:0 \
+ dd if=/dev/zero of=${filesize}.file bs=1 \
+ count=1 oseek=${filesize} conv=sparse
+ files="${files} ${filesize}.file"
+ done
+
+ cd -
+}
+
+mount_image()
+{
+ atf_check -e empty -o save:$TEST_MD_DEVICE_FILE -s exit:0 \
+ mdconfig -a -f $TEST_IMAGE
+ atf_check -e empty -o empty -s exit:0 \
+ $MOUNT /dev/$(cat $TEST_MD_DEVICE_FILE) $TEST_MOUNT_DIR
+}
+
Property changes on: trunk/usr.sbin/makefs/tests/makefs_tests_common.sh
___________________________________________________________________
Added: mnbsd:nokeywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Modified: trunk/usr.sbin/makefs/walk.c
===================================================================
--- trunk/usr.sbin/makefs/walk.c 2018-06-07 00:04:57 UTC (rev 10466)
+++ trunk/usr.sbin/makefs/walk.c 2018-06-07 00:10:33 UTC (rev 10467)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/* $NetBSD: walk.c,v 1.24 2008/12/28 21:51:46 christos Exp $ */
/*
@@ -37,7 +38,7 @@
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/usr.sbin/makefs/walk.c,v 1.1.2.2 2011/07/26 14:41:54 marius Exp $");
+__FBSDID("$FreeBSD: stable/10/usr.sbin/makefs/walk.c 250407 2013-05-09 14:43:36Z brooks $");
#include <sys/param.h>
@@ -57,40 +58,69 @@
static void apply_specdir(const char *, NODE *, fsnode *, int);
static void apply_specentry(const char *, NODE *, fsnode *);
-static fsnode *create_fsnode(const char *, struct stat *);
-static fsinode *link_check(fsinode *);
+static fsnode *create_fsnode(const char *, const char *, const char *,
+ struct stat *);
/*
* walk_dir --
- * build a tree of fsnodes from `dir', with a parent fsnode of `parent'
- * (which may be NULL for the root of the tree).
+ * build a tree of fsnodes from `root' and `dir', with a parent
+ * fsnode of `parent' (which may be NULL for the root of the tree).
+ * append the tree to a fsnode of `join' if it is not NULL.
* each "level" is a directory, with the "." entry guaranteed to be
* at the start of the list, and without ".." entries.
*/
fsnode *
-walk_dir(const char *dir, fsnode *parent)
+walk_dir(const char *root, const char *dir, fsnode *parent, fsnode *join)
{
- fsnode *first, *cur, *prev;
+ fsnode *first, *cur, *prev, *last;
DIR *dirp;
struct dirent *dent;
char path[MAXPATHLEN + 1];
struct stat stbuf;
+ char *name, *rp;
+ int dot, len;
+ assert(root != NULL);
assert(dir != NULL);
+ len = snprintf(path, sizeof(path), "%s/%s", root, dir);
+ if (len >= (int)sizeof(path))
+ errx(1, "Pathname too long.");
if (debug & DEBUG_WALK_DIR)
- printf("walk_dir: %s %p\n", dir, parent);
- if ((dirp = opendir(dir)) == NULL)
- err(1, "Can't opendir `%s'", dir);
- first = prev = NULL;
+ printf("walk_dir: %s %p\n", path, parent);
+ if ((dirp = opendir(path)) == NULL)
+ err(1, "Can't opendir `%s'", path);
+ rp = path + strlen(root) + 1;
+ if (join != NULL) {
+ first = cur = join;
+ while (cur->next != NULL)
+ cur = cur->next;
+ prev = cur;
+ } else
+ first = prev = NULL;
+ last = prev;
while ((dent = readdir(dirp)) != NULL) {
- if (strcmp(dent->d_name, "..") == 0)
- continue;
+ name = dent->d_name;
+ dot = 0;
+ if (name[0] == '.')
+ switch (name[1]) {
+ case '\0': /* "." */
+ if (join != NULL)
+ continue;
+ dot = 1;
+ break;
+ case '.': /* ".." */
+ if (name[2] == '\0')
+ continue;
+ /* FALLTHROUGH */
+ default:
+ dot = 0;
+ }
if (debug & DEBUG_WALK_DIR_NODE)
- printf("scanning %s/%s\n", dir, dent->d_name);
- if (snprintf(path, sizeof(path), "%s/%s", dir, dent->d_name)
- >= sizeof(path))
+ printf("scanning %s/%s/%s\n", root, dir, name);
+ if (snprintf(path + len, sizeof(path) - len, "/%s", name) >=
+ (int)sizeof(path) - len)
errx(1, "Pathname too long.");
if (lstat(path, &stbuf) == -1)
err(1, "Can't lstat `%s'", path);
@@ -102,14 +132,42 @@
}
#endif
- cur = create_fsnode(dent->d_name, &stbuf);
+ if (join != NULL) {
+ cur = join->next;
+ for (;;) {
+ if (cur == NULL || strcmp(cur->name, name) == 0)
+ break;
+ if (cur == last) {
+ cur = NULL;
+ break;
+ }
+ cur = cur->next;
+ }
+ if (cur != NULL) {
+ if (S_ISDIR(cur->type) &&
+ S_ISDIR(stbuf.st_mode)) {
+ if (debug & DEBUG_WALK_DIR_NODE)
+ printf("merging %s with %p\n",
+ path, cur->child);
+ cur->child = walk_dir(root, rp, cur,
+ cur->child);
+ continue;
+ }
+ errx(1, "Can't merge %s `%s' with existing %s",
+ inode_type(stbuf.st_mode), path,
+ inode_type(cur->type));
+ }
+ }
+
+ cur = create_fsnode(root, dir, name, &stbuf);
cur->parent = parent;
- if (strcmp(dent->d_name, ".") == 0) {
+ if (dot) {
/* ensure "." is at the start of the list */
cur->next = first;
first = cur;
if (! prev)
prev = cur;
+ cur->first = first;
} else { /* not "." */
if (prev)
prev->next = cur;
@@ -116,8 +174,9 @@
prev = cur;
if (!first)
first = cur;
+ cur->first = first;
if (S_ISDIR(cur->type)) {
- cur->child = walk_dir(path, cur);
+ cur->child = walk_dir(root, rp, cur, NULL);
continue;
}
}
@@ -147,22 +206,27 @@
err(1, "Memory allocation error");
}
}
- for (cur = first; cur != NULL; cur = cur->next)
- cur->first = first;
+ assert(first != NULL);
+ if (join == NULL)
+ for (cur = first->next; cur != NULL; cur = cur->next)
+ cur->first = first;
if (closedir(dirp) == -1)
- err(1, "Can't closedir `%s'", dir);
+ err(1, "Can't closedir `%s/%s'", root, dir);
return (first);
}
static fsnode *
-create_fsnode(const char *name, struct stat *stbuf)
+create_fsnode(const char *root, const char *path, const char *name,
+ struct stat *stbuf)
{
fsnode *cur;
if ((cur = calloc(1, sizeof(fsnode))) == NULL ||
+ (cur->path = strdup(path)) == NULL ||
(cur->name = strdup(name)) == NULL ||
(cur->inode = calloc(1, sizeof(fsinode))) == NULL)
err(1, "Memory allocation error");
+ cur->root = root;
cur->type = stbuf->st_mode & S_IFMT;
cur->inode->nlink = 1;
cur->inode->st = *stbuf;
@@ -172,7 +236,7 @@
/*
* free_fsnodes --
* Removes node from tree and frees it and all of
- * its decendents.
+ * its descendants.
*/
void
free_fsnodes(fsnode *node)
@@ -211,6 +275,7 @@
free(cur->inode);
if (cur->symlink)
free(cur->symlink);
+ free(cur->path);
free(cur->name);
free(cur);
}
@@ -240,7 +305,7 @@
if ((fp = fopen(specfile, "r")) == NULL)
err(1, "Can't open `%s'", specfile);
TIMER_START(start);
- root = mtree_readspec(fp);
+ root = spec(fp);
TIMER_RESULTS(start, "spec");
if (fclose(fp) == EOF)
err(1, "Can't close `%s'", specfile);
@@ -256,33 +321,6 @@
}
-static u_int
-nodetoino(u_int type)
-{
-
- switch (type) {
- case F_BLOCK:
- return S_IFBLK;
- case F_CHAR:
- return S_IFCHR;
- case F_DIR:
- return S_IFDIR;
- case F_FIFO:
- return S_IFIFO;
- case F_FILE:
- return S_IFREG;
- case F_LINK:
- return S_IFLNK;
- case F_SOCK:
- return S_IFSOCK;
- default:
- printf("unknown type %d", type);
- abort();
- }
- /* NOTREACHED */
-}
-
-
static void
apply_specdir(const char *dir, NODE *specnode, fsnode *dirnode, int speconly)
{
@@ -388,7 +426,8 @@
stbuf.st_mtimensec = stbuf.st_atimensec =
stbuf.st_ctimensec = start_time.tv_nsec;
#endif
- curfsnode = create_fsnode(curnode->name, &stbuf);
+ curfsnode = create_fsnode(".", ".", curnode->name,
+ &stbuf);
curfsnode->parent = dirnode->parent;
curfsnode->first = dirnode;
curfsnode->next = dirnode->next;
@@ -395,7 +434,8 @@
dirnode->next = curfsnode;
if (curfsnode->type == S_IFDIR) {
/* for dirs, make "." entry as well */
- curfsnode->child = create_fsnode(".", &stbuf);
+ curfsnode->child = create_fsnode(".", ".", ".",
+ &stbuf);
curfsnode->child->parent = curfsnode;
curfsnode->child->first = curfsnode->child;
}
@@ -503,19 +543,18 @@
/*
* dump_fsnodes --
- * dump the fsnodes from `cur', based in the directory `dir'
+ * dump the fsnodes from `cur'
*/
void
-dump_fsnodes(const char *dir, fsnode *root)
+dump_fsnodes(fsnode *root)
{
fsnode *cur;
char path[MAXPATHLEN + 1];
- assert (dir != NULL);
- printf("dump_fsnodes: %s %p\n", dir, root);
+ printf("dump_fsnodes: %s %p\n", root->path, root);
for (cur = root; cur != NULL; cur = cur->next) {
- if (snprintf(path, sizeof(path), "%s/%s", dir, cur->name)
- >= sizeof(path))
+ if (snprintf(path, sizeof(path), "%s/%s", cur->path,
+ cur->name) >= (int)sizeof(path))
errx(1, "Pathname too long.");
if (debug & DEBUG_DUMP_FSNODES_VERBOSE)
@@ -534,10 +573,10 @@
if (cur->child) {
assert (cur->type == S_IFDIR);
- dump_fsnodes(path, cur->child);
+ dump_fsnodes(cur->child);
}
}
- printf("dump_fsnodes: finished %s\n", dir);
+ printf("dump_fsnodes: finished %s/%s\n", root->path, root->name);
}
@@ -578,7 +617,7 @@
/* This was borrowed from du.c and tweaked to keep an fsnode
* pointer instead. -- dbj at netbsd.org
*/
-static fsinode *
+fsinode *
link_check(fsinode *entry)
{
static struct entry {
More information about the Midnightbsd-cvs
mailing list