diff --git a/usr.sbin/makefs/cd9660/Makefile.inc b/usr.sbin/makefs/cd9660/Makefile.inc index be08e8e34cd9..e596309a6243 100644 --- a/usr.sbin/makefs/cd9660/Makefile.inc +++ b/usr.sbin/makefs/cd9660/Makefile.inc @@ -1,8 +1,6 @@ -# - .PATH: ${SRCDIR}/cd9660 CFLAGS+=-I${SRCTOP}/sys/fs/cd9660/ SRCS+= cd9660_strings.c cd9660_debug.c cd9660_eltorito.c \ cd9660_write.c cd9660_conversion.c iso9660_rrip.c cd9660_archimedes.c diff --git a/usr.sbin/makefs/ffs/Makefile.inc b/usr.sbin/makefs/ffs/Makefile.inc index bf62ac8bf926..0db1750ab282 100644 --- a/usr.sbin/makefs/ffs/Makefile.inc +++ b/usr.sbin/makefs/ffs/Makefile.inc @@ -1,10 +1,8 @@ -# - .PATH: ${SRCDIR}/ffs ${SRCTOP}/sys/ufs/ffs SRCS+= ffs_alloc.c ffs_balloc.c ffs_bswap.c ffs_subr.c ufs_bmap.c SRCS+= buf.c mkfs.c # Reach-over source from sys/ufs/ffs SRCS+= ffs_tables.c CWARNFLAGS.ffs_balloc.c+= -Wno-sign-compare diff --git a/usr.sbin/makefs/msdos.c b/usr.sbin/makefs/msdos.c index 07238a9aed63..c310e24c4908 100644 --- a/usr.sbin/makefs/msdos.c +++ b/usr.sbin/makefs/msdos.c @@ -1,271 +1,268 @@ /* $NetBSD: msdos.c,v 1.20 2017/04/14 15:40:35 christos Exp $ */ /*- * Copyright (c) 2013 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Christos Zoulas. * * 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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. */ #if HAVE_NBTOOL_CONFIG_H #include "nbtool_config.h" #endif #include -#if defined(__RCSID) && !defined(__lint) -#endif /* !__lint */ - #include #if !HAVE_NBTOOL_CONFIG_H #include #endif #include #include #include #include #include #include #include #include #include #include #include #include "ffs/buf.h" #include "makefs.h" #include "msdos.h" #include #include #include "msdos/direntry.h" #include #include static int msdos_populate_dir(const char *, struct denode *, fsnode *, fsnode *, fsinfo_t *); struct msdos_options_ex { struct msdos_options options; }; void msdos_prep_opts(fsinfo_t *fsopts) { struct msdos_options_ex *msdos_opt = ecalloc(1, sizeof(*msdos_opt)); const option_t msdos_options[] = { #define AOPT(_opt, _type, _name, _min, _desc) { \ .letter = _opt, \ .name = # _name, \ .type = _min == -1 ? OPT_STRPTR : \ (_min == -2 ? OPT_BOOL : \ (sizeof(_type) == 1 ? OPT_INT8 : \ (sizeof(_type) == 2 ? OPT_INT16 : \ (sizeof(_type) == 4 ? OPT_INT32 : OPT_INT64)))), \ .value = &msdos_opt->options._name, \ .minimum = _min, \ .maximum = sizeof(_type) == 1 ? UINT8_MAX : \ (sizeof(_type) == 2 ? UINT16_MAX : \ (sizeof(_type) == 4 ? UINT32_MAX : INT64_MAX)), \ .desc = _desc, \ }, ALLOPTS #undef AOPT { .name = NULL } }; fsopts->fs_specific = msdos_opt; fsopts->fs_options = copy_opts(msdos_options); } void msdos_cleanup_opts(fsinfo_t *fsopts) { free(fsopts->fs_specific); free(fsopts->fs_options); } int msdos_parse_opts(const char *option, fsinfo_t *fsopts) { struct msdos_options *msdos_opt = fsopts->fs_specific; option_t *msdos_options = fsopts->fs_options; int rv; assert(option != NULL); assert(fsopts != NULL); assert(msdos_opt != NULL); if (debug & DEBUG_FS_PARSE_OPTS) printf("msdos_parse_opts: got `%s'\n", option); rv = set_option(msdos_options, option, NULL, 0); if (rv == -1) return rv; if (strcmp(msdos_options[rv].name, "volume_id") == 0) msdos_opt->volume_id_set = 1; else if (strcmp(msdos_options[rv].name, "media_descriptor") == 0) msdos_opt->media_descriptor_set = 1; else if (strcmp(msdos_options[rv].name, "hidden_sectors") == 0) msdos_opt->hidden_sectors_set = 1; if (stampst.st_ino) { msdos_opt->timestamp_set = 1; msdos_opt->timestamp = stampst.st_mtime; } return 1; } void msdos_makefs(const char *image, const char *dir, fsnode *root, fsinfo_t *fsopts) { struct msdos_options_ex *msdos_opt = fsopts->fs_specific; struct vnode vp, rootvp; struct timeval start; struct msdosfsmount *pmp; uint32_t flags; assert(image != NULL); assert(dir != NULL); assert(root != NULL); assert(fsopts != NULL); fsopts->size = fsopts->maxsize; msdos_opt->options.create_size = MAX(msdos_opt->options.create_size, fsopts->offset + fsopts->size); if (fsopts->offset > 0) msdos_opt->options.offset = fsopts->offset; if (msdos_opt->options.bytes_per_sector == 0) { if (fsopts->sectorsize == -1) fsopts->sectorsize = 512; msdos_opt->options.bytes_per_sector = fsopts->sectorsize; } else if (fsopts->sectorsize == -1) { fsopts->sectorsize = msdos_opt->options.bytes_per_sector; } else if (fsopts->sectorsize != msdos_opt->options.bytes_per_sector) { err(1, "inconsistent sectorsize -S %u" "!= -o bytes_per_sector %u", fsopts->sectorsize, msdos_opt->options.bytes_per_sector); } /* create image */ printf("Creating `%s'\n", image); TIMER_START(start); if (mkfs_msdos(image, NULL, &msdos_opt->options) == -1) return; TIMER_RESULTS(start, "mkfs_msdos"); fsopts->fd = open(image, O_RDWR); vp.fs = fsopts; flags = 0; if ((pmp = msdosfs_mount(&vp)) == NULL) err(1, "msdosfs_mount"); if (msdosfs_root(pmp, &rootvp) != 0) err(1, "msdosfs_root"); if (debug & DEBUG_FS_MAKEFS) printf("msdos_makefs: image %s directory %s root %p\n", image, dir, root); /* populate image */ printf("Populating `%s'\n", image); TIMER_START(start); if (msdos_populate_dir(dir, VTODE(&rootvp), root, root, fsopts) == -1) errx(1, "Image file `%s' not created.", image); TIMER_RESULTS(start, "msdos_populate_dir"); if (msdosfs_fsiflush(pmp) != 0) errx(1, "Unable to update FSInfo block."); if (debug & DEBUG_FS_MAKEFS) putchar('\n'); /* ensure no outstanding buffers remain */ if (debug & DEBUG_FS_MAKEFS) bcleanup(); printf("Image `%s' complete\n", image); } static int msdos_populate_dir(const char *path, struct denode *dir, fsnode *root, fsnode *parent, fsinfo_t *fsopts) { fsnode *cur; char pbuf[MAXPATHLEN]; assert(dir != NULL); assert(root != NULL); assert(fsopts != NULL); for (cur = root->next; cur != NULL; cur = cur->next) { if ((size_t)snprintf(pbuf, sizeof(pbuf), "%s/%s", path, cur->name) >= sizeof(pbuf)) { warnx("path %s too long", pbuf); return -1; } if ((cur->inode->flags & FI_ALLOCATED) == 0) { cur->inode->flags |= FI_ALLOCATED; if (cur != root) { fsopts->curinode++; cur->inode->ino = fsopts->curinode; cur->parent = parent; } } if (cur->inode->flags & FI_WRITTEN) { continue; // hard link } cur->inode->flags |= FI_WRITTEN; if (cur->child) { struct denode *de; if ((de = msdosfs_mkdire(pbuf, dir, cur)) == NULL) { warn("msdosfs_mkdire %s", pbuf); return -1; } if (msdos_populate_dir(pbuf, de, cur->child, cur, fsopts) == -1) { warn("msdos_populate_dir %s", pbuf); return -1; } continue; } else if (!S_ISREG(cur->type)) { warnx("skipping non-regular file %s/%s", cur->path, cur->name); continue; } if (msdosfs_mkfile(cur->contents ? cur->contents : pbuf, dir, cur) == NULL) { warn("msdosfs_mkfile %s", pbuf); return -1; } } return 0; } diff --git a/usr.sbin/makefs/msdos/Makefile.inc b/usr.sbin/makefs/msdos/Makefile.inc index 3fb55c5394fc..78ddc7804b31 100644 --- a/usr.sbin/makefs/msdos/Makefile.inc +++ b/usr.sbin/makefs/msdos/Makefile.inc @@ -1,12 +1,10 @@ -# - MSDOS= ${SRCTOP}/sys/fs/msdosfs MSDOS_NEWFS= ${SRCTOP}/sbin/newfs_msdos .PATH: ${SRCDIR}/msdos ${MSDOS} ${MSDOS_NEWFS} CFLAGS+= -DMAKEFS -I${MSDOS} -I${MSDOS_NEWFS} SRCS+= mkfs_msdos.c SRCS+= msdosfs_conv.c msdosfs_denode.c msdosfs_fat.c msdosfs_lookup.c SRCS+= msdosfs_vnops.c msdosfs_vfsops.c diff --git a/usr.sbin/makefs/tests/makefs_cd9660_tests.sh b/usr.sbin/makefs/tests/makefs_cd9660_tests.sh index 3f9b37abee4c..2fdf47f76a4c 100644 --- a/usr.sbin/makefs/tests/makefs_cd9660_tests.sh +++ b/usr.sbin/makefs/tests/makefs_cd9660_tests.sh @@ -1,397 +1,395 @@ # # 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. -# -# # A note on specs: # - A copy of the ISO-9660 spec can be found here: # https://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 } check_cd9660_support() { kldstat -m cd9660 || \ atf_skip "Requires cd9660 filesystem support to be present in the kernel" } 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 check_cd9660_support 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 - check_cd9660_support 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 check_cd9660_support 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 check_cd9660_support 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 check_cd9660_support 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 check_cd9660_support 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 check_cd9660_support 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 check_cd9660_support 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 check_cd9660_support mount_image check_base_iso9660_image_contents fi } o_flag_isolevel_3_cleanup() { common_cleanup } atf_test_case o_flag_preparer o_flag_preparer_head() { atf_set "require.progs" "strings" } 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_head() { atf_set "require.progs" "strings" } 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 check_cd9660_support 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 check_cd9660_support 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 } diff --git a/usr.sbin/makefs/tests/makefs_ffs_tests.sh b/usr.sbin/makefs/tests/makefs_ffs_tests.sh index fafec4c885fb..2505b2e24d72 100644 --- a/usr.sbin/makefs/tests/makefs_ffs_tests.sh +++ b/usr.sbin/makefs/tests/makefs_ffs_tests.sh @@ -1,260 +1,258 @@ # # 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. -# -# 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 "$@" } # With no -M, -m, or -s options, makefs should autocalculate the image size atf_test_case autocalculate_image_size cleanup autocalculate_image_size_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 } autocalculate_image_size_cleanup() { common_cleanup } 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 -M 1m $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 -M 1m $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 autocalculate_image_size 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 } diff --git a/usr.sbin/makefs/tests/makefs_tests_common.sh b/usr.sbin/makefs/tests/makefs_tests_common.sh index 08f687fa44a4..12c7c7c84fb7 100644 --- a/usr.sbin/makefs/tests/makefs_tests_common.sh +++ b/usr.sbin/makefs/tests/makefs_tests_common.sh @@ -1,145 +1,143 @@ # # 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. -# -# KB=1024 : ${TMPDIR=/tmp} DEFAULT_MTREE_KEYWORDS="type,mode,gid,uid,size,link,time" 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 }