Source-Changes-HG archive

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

[src/trunk]: src/sbin/newfs_udf Adjust newfs_udf to be sharing code with the ...



details:   https://anonhg.NetBSD.org/src/rev/1b40e1f75d30
branches:  trunk
changeset: 789049:1b40e1f75d30
user:      reinoud <reinoud%NetBSD.org@localhost>
date:      Mon Aug 05 14:11:30 2013 +0000

description:
Adjust newfs_udf to be sharing code with the new `makefs -t udf' to be
comitted.

diffstat:

 sbin/newfs_udf/newfs_udf.8  |    9 +-
 sbin/newfs_udf/newfs_udf.c  |   24 +-
 sbin/newfs_udf/udf_create.c |  660 +++++++++++++++++++++++++++++++++++++------
 sbin/newfs_udf/udf_create.h |   39 ++-
 sbin/newfs_udf/udf_write.c  |  145 +++++++--
 sbin/newfs_udf/udf_write.h  |    5 +
 sbin/newfs_udf/unicode.h    |  161 ++++++++++
 7 files changed, 893 insertions(+), 150 deletions(-)

diffs (truncated from 1663 to 300 lines):

diff -r 1c8cc5943019 -r 1b40e1f75d30 sbin/newfs_udf/newfs_udf.8
--- a/sbin/newfs_udf/newfs_udf.8        Mon Aug 05 13:38:35 2013 +0000
+++ b/sbin/newfs_udf/newfs_udf.8        Mon Aug 05 14:11:30 2013 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: newfs_udf.8,v 1.12 2013/07/20 21:39:58 wiz Exp $
+.\" $NetBSD: newfs_udf.8,v 1.13 2013/08/05 14:11:30 reinoud Exp $
 .\"
 .\" Copyright (c) 2008 Reinoud Zandijk
 .\" All rights reserved.
@@ -26,7 +26,7 @@
 .\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 .\"
 .\"
-.Dd July 2, 2013
+.Dd August 2, 2013
 .Dt NEWFS_UDF 8
 .Os
 .Sh NAME
@@ -40,6 +40,7 @@
 .Op Fl p Ar percentage
 .Op Fl S Ar sectorsize
 .Op Fl s Ar size
+.Op Fl B Ar blockingsize
 .Op Fl t Ar gmtoff
 .Op Fl V Ar max_udf
 .Op Fl v Ar min_udf
@@ -84,6 +85,10 @@
 .It Fl s Ar size
 For image files, set the file size to the humanized size
 .Ar size .
+.It Fl B Ar blockingsize
+When creating image files, specify the blocking size or packetsize of the media
+to
+.Ar blockingsize .
 .It Fl t Ar gmtoff
 Use the specified
 .Ar gmtoff
diff -r 1c8cc5943019 -r 1b40e1f75d30 sbin/newfs_udf/newfs_udf.c
--- a/sbin/newfs_udf/newfs_udf.c        Mon Aug 05 13:38:35 2013 +0000
+++ b/sbin/newfs_udf/newfs_udf.c        Mon Aug 05 14:11:30 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: newfs_udf.c,v 1.14 2013/07/18 12:44:21 reinoud Exp $ */
+/* $NetBSD: newfs_udf.c,v 1.15 2013/08/05 14:11:30 reinoud Exp $ */
 
 /*
  * Copyright (c) 2006, 2008, 2013 Reinoud Zandijk
@@ -94,6 +94,7 @@
 int     media_accesstype;              /* derived from current mmc cap  */
 int     check_surface;                 /* for rewritables               */
 int     imagefile_secsize;             /* for files                     */
+int     emul_packetsize;               /* for discs and files           */
 
 int     wrtrack_skew;
 int     meta_perc = UDF_META_PERC;
@@ -289,8 +290,9 @@
                sectors = size / secsize;
        } else {
                /*
-                * disc partition support; note we can't use DIOCGPART in userland so
-                * get disc label and use the stat info to get the partition number.
+                * disc partition support; note we can't use DIOCGPART in
+                * userland so get disc label and use the stat info to get the
+                * partition number.
                 */
                if (ioctl(fd, DIOCGDINFO, &disklab) == -1) {
                        /* failed to get disclabel! */
@@ -303,9 +305,10 @@
                partnr = DISKPART(st.st_rdev);
                dp = &disklab.d_partitions[partnr];
 
-               /* TODO problem with last_possible_lba on resizable VND; request */
+               /* TODO problem with last_possible_lba on resizable VND */
                if (dp->p_size == 0) {
-                       perror("faulty disklabel partition returned, check label\n");
+                       perror("faulty disklabel partition returned, "
+                               "check label\n");
                        return EIO;
                }
 
@@ -363,7 +366,7 @@
        ti->flags = MMC_TRACKINFO_LRA_VALID | MMC_TRACKINFO_NWA_VALID;
 
        ti->track_start    = 0;
-       ti->packet_size    = 1;
+       ti->packet_size    = emul_packetsize;
 
        /* TODO support for resizable vnd */
        ti->track_size    = di->last_possible_lba;
@@ -722,6 +725,7 @@
        check_surface = 0;
        setsize       = 0;
        imagefile_secsize = 512;        /* minimum allowed sector size */
+       emul_packetsize   = 32;         /* reasonable default */
 
        srandom((unsigned long) time(NULL));
        udf_init_create_context();
@@ -740,7 +744,7 @@
        context.gmtoff = tm->tm_gmtoff;
 
        /* process options */
-       while ((ch = getopt(argc, argv, "cFL:Mp:P:s:S:t:v:V:")) != -1) {
+       while ((ch = getopt(argc, argv, "cFL:Mp:P:s:S:B:t:v:V:")) != -1) {
                switch (ch) {
                case 'c' :
                        check_surface = 1;
@@ -802,6 +806,12 @@
                        imagefile_secsize = a_num(optarg, "secsize");
                        imagefile_secsize = MAX(512, imagefile_secsize);
                        break;
+               case 'B' :
+                       emul_packetsize = a_num(optarg,
+                               "blockingnr, packetsize");
+                       emul_packetsize = MAX(emul_packetsize, 1);
+                       emul_packetsize = MIN(emul_packetsize, 32);
+                       break;
                case 't' :
                        /* time zone overide */
                        context.gmtoff = a_num(optarg, "gmtoff");
diff -r 1c8cc5943019 -r 1b40e1f75d30 sbin/newfs_udf/udf_create.c
--- a/sbin/newfs_udf/udf_create.c       Mon Aug 05 13:38:35 2013 +0000
+++ b/sbin/newfs_udf/udf_create.c       Mon Aug 05 14:11:30 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: udf_create.c,v 1.17 2009/12/23 09:13:21 mbalmer Exp $ */
+/* $NetBSD: udf_create.c,v 1.18 2013/08/05 14:11:30 reinoud Exp $ */
 
 /*
  * Copyright (c) 2006, 2008 Reinoud Zandijk
@@ -28,11 +28,12 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: udf_create.c,v 1.17 2009/12/23 09:13:21 mbalmer Exp $");
+__RCSID("$NetBSD: udf_create.c,v 1.18 2013/08/05 14:11:30 reinoud Exp $");
 #endif /* not lint */
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <stddef.h>
 #include <string.h>
 #include <errno.h>
 #include <time.h>
@@ -40,6 +41,7 @@
 #include <err.h>
 #include <sys/types.h>
 #include <sys/param.h>
+#include "unicode.h"
 #include "udf_create.h"
 
 
@@ -49,6 +51,10 @@
 #  endif
 #endif
 
+/*
+ * NOTE that there is some overlap between this code and the udf kernel fs.
+ * This is intentially though it might better be factored out one day.
+ */
 
 void
 udf_init_create_context(void)
@@ -82,6 +88,11 @@
 
        context.num_files       = 0;
        context.num_directories = 0;
+
+       context.data_part          = 0;
+       context.metadata_part      = 0;
+       context.metadata_alloc_pos = 0;
+       context.data_alloc_pos     = 0;
 }
 
 
@@ -178,7 +189,7 @@
 
        /* all non sequential media needs an unallocated space bitmap */
        layout.alloc_bitmap_dscr_size = 0;
-       if ((format_flags & FORMAT_SEQUENTIAL) == 0) {
+       if ((format_flags & (FORMAT_SEQUENTIAL | FORMAT_READONLY)) == 0) {
                bytes = udf_space_bitmap_len(layout.part_size_lba);
                layout.alloc_bitmap_dscr_size = udf_bytes_to_sectors(bytes);
 
@@ -208,7 +219,7 @@
         * not updated sporadically
         */
 
-       if ((format_flags & FORMAT_SEQUENTIAL) == 0) {
+       if ((format_flags & (FORMAT_SEQUENTIAL | FORMAT_READONLY)) == 0) {
 #ifdef DEBUG
                printf("Lost %d slack sectors at start\n", UDF_ROUNDUP(
                        first_lba - wrtrack_skew, align_blockingnr) -
@@ -218,8 +229,10 @@
                                first_lba - wrtrack_skew, align_blockingnr));
 #endif
 
-               first_lba = UDF_ROUNDUP( first_lba - wrtrack_skew, align_blockingnr);
-               last_lba  = UDF_ROUNDDOWN(last_lba - wrtrack_skew, align_blockingnr);
+               first_lba = UDF_ROUNDUP( first_lba - wrtrack_skew,
+                               align_blockingnr);
+               last_lba  = UDF_ROUNDDOWN(last_lba - wrtrack_skew,
+                               align_blockingnr);
        }
 
        if ((format_flags & FORMAT_SPARABLE) == 0)
@@ -335,11 +348,13 @@
 #endif
 
        kbsize = (uint64_t) last_lba * sector_size;
-       printf("Total space on this medium approx. %"PRIu64" KiB, %"PRIu64" MiB\n",
+       printf("Total space on this medium approx. "
+                       "%"PRIu64" KiB, %"PRIu64" MiB\n",
                        kbsize/1024, kbsize/(1024*1024));
-       kbsize = (uint64_t) (layout.part_size_lba - layout.alloc_bitmap_dscr_size
+       kbsize = (uint64_t)(layout.part_size_lba - layout.alloc_bitmap_dscr_size
                - layout.meta_bitmap_dscr_size) * sector_size;
-       printf("Free space on this volume approx.  %"PRIu64" KiB, %"PRIu64" MiB\n\n",
+       printf("Free space on this volume approx.  "
+                       "%"PRIu64" KiB, %"PRIu64" MiB\n\n",
                        kbsize/1024, kbsize/(1024*1024));
 
        return 0;
@@ -520,8 +535,8 @@
 
 
 /*
- * Fill in timestamp structure based on clock_gettime(). Time is reported back as a time_t
- * accompanied with a nano second field.
+ * Fill in timestamp structure based on clock_gettime(). Time is reported back
+ * as a time_t accompanied with a nano second field.
  *
  * The husec, usec and csec could be relaxed in type.
  */
@@ -557,13 +572,17 @@
        csec   =  husec / 100;                          /* only 0-99 in csec  */
        husec -=   csec * 100;                          /* only 0-99 in husec */
 
+       /* in rare cases there is overflow in csec */
+       csec  = MIN(99, csec);
+       husec = MIN(99, husec);
+       usec  = MIN(99, usec);
+
        timestamp->centisec     = csec;
        timestamp->hund_usec    = husec;
        timestamp->usec         = usec;
 }
 
 
-
 void
 udf_set_timestamp_now(struct timestamp *timestamp)
 {
@@ -574,6 +593,38 @@
 }
 
 
+/* some code copied from sys/fs/udf */
+
+static void
+udf_set_timestamp(struct timestamp *timestamp, time_t value)
+{
+       struct timespec t;
+
+       memset(&t, 0, sizeof(struct timespec));
+       t.tv_sec  = value;
+       t.tv_nsec = 0;
+       udf_timespec_to_timestamp(&t, timestamp);
+}
+
+
+static uint32_t
+unix_mode_to_udf_perm(mode_t mode)
+{
+       uint32_t perm;
+       
+       perm  = ((mode & S_IRWXO)     );
+       perm |= ((mode & S_IRWXG) << 2);
+       perm |= ((mode & S_IRWXU) << 4);
+       perm |= ((mode & S_IWOTH) << 3);
+       perm |= ((mode & S_IWGRP) << 5);
+       perm |= ((mode & S_IWUSR) << 7);
+
+       return perm;
+}
+
+/* end of copied code */
+
+
 int
 udf_create_primaryd(void)
 {
@@ -1242,7 +1293,7 @@
        uint8_t *bpos;
        uint32_t cnt, bit;
 
-       /* make not on space used on underlying partition */
+       /* account for space used on underlying partition */
        context.part_free[partnr] -= blocks;
 #ifdef DEBUG
        printf("mark allocated : partnr %d, start_lb %d for %d blocks\n",
@@ -1256,6 +1307,10 @@
        case UDF_VTOP_TYPE_PHYS:



Home | Main Index | Thread Index | Old Index