Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/makefs add more msdos stuff.



details:   https://anonhg.NetBSD.org/src/rev/2a73df22ef68
branches:  trunk
changeset: 784335:2a73df22ef68
user:      christos <christos%NetBSD.org@localhost>
date:      Sat Jan 26 00:20:40 2013 +0000

description:
add more msdos stuff.

diffstat:

 usr.sbin/makefs/msdos.c                |  114 ++++++--
 usr.sbin/makefs/msdos.h                |   41 +++
 usr.sbin/makefs/msdos/Makefile.inc     |    7 +-
 usr.sbin/makefs/msdos/msdosfs_denode.c |  379 +++++++++++++++++++++++++++++
 usr.sbin/makefs/msdos/msdosfs_vfsops.c |  429 +++++++++++++++++++++++++++++++++
 usr.sbin/makefs/msdos/msdosfs_vnops.c  |  359 +++++++++++++++++++++++++++
 6 files changed, 1298 insertions(+), 31 deletions(-)

diffs (truncated from 1415 to 300 lines):

diff -r 6edfc56ff4b1 -r 2a73df22ef68 usr.sbin/makefs/msdos.c
--- a/usr.sbin/makefs/msdos.c   Sat Jan 26 00:19:39 2013 +0000
+++ b/usr.sbin/makefs/msdos.c   Sat Jan 26 00:20:40 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: msdos.c,v 1.5 2013/01/24 01:10:47 christos Exp $       */
+/*     $NetBSD: msdos.c,v 1.6 2013/01/26 00:20:40 christos Exp $       */
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(__lint)
-__RCSID("$NetBSD: msdos.c,v 1.5 2013/01/24 01:10:47 christos Exp $");
+__RCSID("$NetBSD: msdos.c,v 1.6 2013/01/26 00:20:40 christos Exp $");
 #endif /* !__lint */
 
 #include <sys/param.h>
@@ -54,10 +54,17 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <dirent.h>
 
+#include <ffs/buf.h>
+#include <fs/msdosfs/denode.h>
 #include "makefs.h"
+#include "msdos.h"
 #include "mkfs_msdos.h"
 
+static int msdos_populate_dir(const char *, struct denode *, fsnode *,
+    fsnode *, fsinfo_t *);
+
 void
 msdos_prep_opts(fsinfo_t *fsopts)
 {
@@ -128,6 +135,14 @@
 msdos_makefs(const char *image, const char *dir, fsnode *root, fsinfo_t *fsopts)
 {
        struct msdos_options *msdos_opt = fsopts->fs_specific;
+       struct vnode vp, rootvp;
+       struct timeval  start;
+       struct msdosfsmount *pmp;
+
+       assert(image != NULL);
+       assert(dir != NULL);
+       assert(root != NULL);
+       assert(fsopts != NULL);
 
        /*
         * XXX: pick up other options from the msdos specific ones?
@@ -135,51 +150,94 @@
         */
        msdos_opt->create_size = MAX(msdos_opt->create_size, fsopts->minsize);
 
+               /* create image */
+       printf("Creating `%s'\n", image);
+       TIMER_START(start);
        if (mkfs_msdos(image, NULL, msdos_opt) == -1)
                return;
-#ifdef notyet
-       struct fs       *superblock;
-       struct timeval  start;
+       TIMER_RESULTS(start, "mkfs_msdos");
+
+       vp.fd = open(image, O_RDWR);
+       vp.fs = msdos_opt;
+       vp.offset = 1;
 
-       assert(image != NULL);
-       assert(dir != NULL);
-       assert(root != NULL);
-       assert(fsopts != NULL);
+       if ((pmp = msdosfs_mount(&vp, 0)) == 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);
 
-               /* validate tree and options */
-       TIMER_START(start);
-       msdos_validate(dir, root, fsopts);
-       TIMER_RESULTS(start, "msdos_validate");
-
        printf("Calculated size of `%s': %lld bytes, %lld inodes\n",
            image, (long long)fsopts->size, (long long)fsopts->inodes);
 
-               /* create image */
-       TIMER_START(start);
-       if (msdos_create_image(image, fsopts) == -1)
-               errx(1, "Image file `%s' not created.", image);
-       TIMER_RESULTS(start, "msdos_create_image");
-
-       fsopts->curinode = ROOTINO;
-
-       if (debug & DEBUG_FS_MAKEFS)
-               putchar('\n');
-
                /* populate image */
        printf("Populating `%s'\n", image);
        TIMER_START(start);
-       if (! msdos_populate_dir(dir, root, fsopts))
-               errx(1, "Image file `%s' not populated.", image);
+       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 (debug & DEBUG_FS_MAKEFS)
+               putchar('\n');
+
                /* ensure no outstanding buffers remain */
        if (debug & DEBUG_FS_MAKEFS)
                bcleanup();
 
        printf("Image `%s' complete\n", image);
-#endif
 }
+
+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)
+                               err(1, "msdosfs_mkdire");
+                       if (!msdos_populate_dir(pbuf, de, cur->child, cur,
+                           fsopts))
+                               err(1, "populate_dir");
+                       continue;
+               } else if (!S_ISREG(cur->type)) {
+                       warnx("skipping non-regular file %s/%s", cur->path,
+                           cur->name);
+                       continue;
+               }
+               if (msdosfs_mkfile(pbuf, dir, cur) == NULL)
+                       err(1, "msdosfs_mkfile");
+       }
+       return 0;
+}
diff -r 6edfc56ff4b1 -r 2a73df22ef68 usr.sbin/makefs/msdos.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.sbin/makefs/msdos.h   Sat Jan 26 00:20:40 2013 +0000
@@ -0,0 +1,41 @@
+/*     $NetBSD: msdos.h,v 1.1 2013/01/26 00:20:40 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.
+ * 3. Neither the name of The NetBSD Foundation nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * 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.
+ */
+
+struct vnode;
+
+struct msdosfsmount *msdosfs_mount(struct vnode *, int);
+int msdosfs_root(struct msdosfsmount *, struct vnode *);
+
+struct denode * msdosfs_mkfile(const char *, struct denode *, fsnode *);
+struct denode *msdosfs_mkdire(const char *, struct denode *, fsnode *);
diff -r 6edfc56ff4b1 -r 2a73df22ef68 usr.sbin/makefs/msdos/Makefile.inc
--- a/usr.sbin/makefs/msdos/Makefile.inc        Sat Jan 26 00:19:39 2013 +0000
+++ b/usr.sbin/makefs/msdos/Makefile.inc        Sat Jan 26 00:20:40 2013 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile.inc,v 1.3 2013/01/23 22:47:18 christos Exp $
+#      $NetBSD: Makefile.inc,v 1.4 2013/01/26 00:20:40 christos Exp $
 #
 
 MSDOS= ${NETBSDSRCDIR}/sys/fs/msdosfs
@@ -6,6 +6,7 @@
 
 .PATH: ${.CURDIR}/msdos ${MSDOS} ${MSDOS_NEWFS}
 
-CPPFLAGS+= -DMSDOS_EI -I${MSDOS} -I${MSDOS_NEWFS}
+CPPFLAGS+= -DMSDOS_EI -I${MSDOS} -I${MSDOS_NEWFS} -I${NETBSDSRCDIR}/sys
 
-SRCS+= mkfs_msdos.c
+SRCS+= mkfs_msdos.c msdosfs_fat.c msdosfs_conv.c msdosfs_vfsops.c
+SRCS+= msdosfs_lookup.c msdosfs_denode.c msdosfs_vnops.c
diff -r 6edfc56ff4b1 -r 2a73df22ef68 usr.sbin/makefs/msdos/msdosfs_denode.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.sbin/makefs/msdos/msdosfs_denode.c    Sat Jan 26 00:20:40 2013 +0000
@@ -0,0 +1,379 @@
+/*     $NetBSD: msdosfs_denode.c,v 1.1 2013/01/26 00:20:40 christos Exp $      */
+
+/*-
+ * Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank.
+ * Copyright (C) 1994, 1995, 1997 TooLs GmbH.
+ * All rights reserved.
+ * Original code by Paul Popelka (paulp%uts.amdahl.com@localhost) (see below).
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by TooLs GmbH.
+ * 4. The name of TooLs GmbH may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``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 TOOLS GMBH 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.
+ */
+/*
+ * Written by Paul Popelka (paulp%uts.amdahl.com@localhost)
+ *
+ * You can do anything you want with this software, just don't say you wrote
+ * it, and don't remove this notice.
+ *
+ * This software is provided "as is".
+ *
+ * The author supplies this software to be publicly redistributed on the
+ * understanding that the author is not responsible for the correct
+ * functioning of this software in any circumstances and is not liable for
+ * any damages caused by this software.
+ *
+ * October 1992
+ */
+
+#if HAVE_NBTOOL_CONFIG_H
+#include "nbtool_config.h"
+#endif
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: msdosfs_denode.c,v 1.1 2013/01/26 00:20:40 christos Exp $");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/mount.h>
+#include <sys/malloc.h>



Home | Main Index | Thread Index | Old Index