Source-Changes-HG archive

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

[src/trunk]: src/sbin/newfs_udf Initial split up for making newfs_udf(8) rout...



details:   https://anonhg.NetBSD.org/src/rev/2eddd7454504
branches:  trunk
changeset: 788696:2eddd7454504
user:      reinoud <reinoud%NetBSD.org@localhost>
date:      Thu Jul 18 12:44:21 2013 +0000

description:
Initial split up for making newfs_udf(8) routines suitable for makefs_udf(8)

diffstat:

 sbin/newfs_udf/Makefile    |    4 +-
 sbin/newfs_udf/newfs_udf.c |  813 +------------------------------------------
 sbin/newfs_udf/newfs_udf.h |   68 +++
 sbin/newfs_udf/udf_write.c |  819 +++++++++++++++++++++++++++++++++++++++++++++
 sbin/newfs_udf/udf_write.h |   42 ++
 5 files changed, 962 insertions(+), 784 deletions(-)

diffs (truncated from 1861 to 300 lines):

diff -r c346b3b5d0a7 -r 2eddd7454504 sbin/newfs_udf/Makefile
--- a/sbin/newfs_udf/Makefile   Thu Jul 18 12:42:24 2013 +0000
+++ b/sbin/newfs_udf/Makefile   Thu Jul 18 12:44:21 2013 +0000
@@ -1,10 +1,10 @@
-# $NetBSD: Makefile,v 1.3 2009/04/11 07:58:13 lukem Exp $
+# $NetBSD: Makefile,v 1.4 2013/07/18 12:44:21 reinoud Exp $
 
 .include <bsd.own.mk>
 
 PROG=  newfs_udf
 MAN=   newfs_udf.8
-SRCS=  newfs_udf.c udf_create.c udf_osta.c fattr.c
+SRCS=  newfs_udf.c udf_create.c udf_write.c udf_osta.c fattr.c
 
 MOUNT=  ${NETBSDSRCDIR}/sbin/mount
 KUDF=  ${NETBSDSRCDIR}/sys/fs/udf
diff -r c346b3b5d0a7 -r 2eddd7454504 sbin/newfs_udf/newfs_udf.c
--- a/sbin/newfs_udf/newfs_udf.c        Thu Jul 18 12:42:24 2013 +0000
+++ b/sbin/newfs_udf/newfs_udf.c        Thu Jul 18 12:44:21 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: newfs_udf.c,v 1.13 2013/07/02 14:59:01 reinoud Exp $ */
+/* $NetBSD: newfs_udf.c,v 1.14 2013/07/18 12:44:21 reinoud Exp $ */
 
 /*
  * Copyright (c) 2006, 2008, 2013 Reinoud Zandijk
@@ -65,25 +65,23 @@
 
 #include "mountprog.h"
 #include "udf_create.h"
-
-/* general settings */
-#define UDF_512_TRACK  0       /* NOT recommended */
-#define UDF_META_PERC  20      /* picked */
-
+#include "udf_write.h"
+#include "newfs_udf.h"
 
 /* prototypes */
 int newfs_udf(int argc, char **argv);
 static void usage(void) __attribute__((__noreturn__));
 
-int udf_derive_format(int req_en, int req_dis, int force);
-int udf_proces_names(void);
-int udf_do_newfs(void);
 
-/* Identifying myself */
-#define APP_NAME               "*NetBSD newfs"
-#define APP_VERSION_MAIN       0
-#define APP_VERSION_SUB                3
-#define IMPL_NAME              "*NetBSD userland UDF"
+/* queue for temporary storage of sectors to be written out */
+struct wrsect {
+       uint32_t  sectornr;
+       uint8_t  *sector_data;
+       TAILQ_ENTRY(wrsect) next;
+};
+
+/* write queue and track blocking skew */
+TAILQ_HEAD(wrsect_list, wrsect) write_queue;
 
 
 /* global variables describing disc and format requests */
@@ -102,29 +100,13 @@
 float   meta_fract = (float) UDF_META_PERC / 100.0;
 
 
-/* shared structure between udf_create.c users */
-struct udf_create_context context;
-struct udf_disclayout     layout;
-
-
-/* queue for temporary storage of sectors to be written out */
-struct wrsect {
-       uint32_t  sectornr;
-       uint8_t  *sector_data;
-       TAILQ_ENTRY(wrsect) next;
-};
-
-/* write queue and track blocking skew */
-TAILQ_HEAD(wrsect_list, wrsect) write_queue;
-
-
 /* --------------------------------------------------------------------- */
 
 /*
  * write queue implementation
  */
 
-static int
+int
 udf_write_sector(void *sector, uint32_t location)
 {
        struct wrsect *pos, *seekpos;
@@ -167,7 +149,7 @@
  * XXX support for growing vnd?
  */
 
-static int
+int
 writeout_write_queue(void)
 {
        struct wrsect *pos;
@@ -357,7 +339,7 @@
 }
 
 
-static int
+int
 udf_update_trackinfo(struct mmc_discinfo *di, struct mmc_trackinfo *ti)
 {
        int error, class;
@@ -447,276 +429,6 @@
 /* --------------------------------------------------------------------- */
 
 static int
-udf_write_dscr_phys(union dscrptr *dscr, uint32_t location,
-       uint32_t sects)
-{
-       uint32_t phys, cnt;
-       uint8_t *bpos;
-       int error;
-
-       dscr->tag.tag_loc = udf_rw32(location);
-       (void) udf_validate_tag_and_crc_sums(dscr);
-
-       for (cnt = 0; cnt < sects; cnt++) {
-               bpos  = (uint8_t *) dscr;
-               bpos += context.sector_size * cnt;
-
-               phys = location + cnt;
-               error = udf_write_sector(bpos, phys);
-               if (error)
-                       return error;
-       }
-       return 0;
-}
-
-
-static int
-udf_write_dscr_virt(union dscrptr *dscr, uint32_t location, uint32_t vpart,
-       uint32_t sects)
-{
-       struct file_entry *fe;
-       struct extfile_entry *efe;
-       struct extattrhdr_desc *extattrhdr;
-       uint32_t phys, cnt;
-       uint8_t *bpos;
-       int error;
-
-       extattrhdr = NULL;
-       if (udf_rw16(dscr->tag.id) == TAGID_FENTRY) {
-               fe = (struct file_entry *) dscr;
-               if (udf_rw32(fe->l_ea) > 0)
-                       extattrhdr = (struct extattrhdr_desc *) fe->data;
-       }
-       if (udf_rw16(dscr->tag.id) == TAGID_EXTFENTRY) {
-               efe = (struct extfile_entry *) dscr;
-               if (udf_rw32(efe->l_ea) > 0)
-                       extattrhdr = (struct extattrhdr_desc *) efe->data;
-       }
-       if (extattrhdr) {
-               extattrhdr->tag.tag_loc = udf_rw32(location);
-               udf_validate_tag_and_crc_sums((union dscrptr *) extattrhdr);
-       }
-
-       dscr->tag.tag_loc = udf_rw32(location);
-       udf_validate_tag_and_crc_sums(dscr);
-
-       for (cnt = 0; cnt < sects; cnt++) {
-               bpos  = (uint8_t *) dscr;
-               bpos += context.sector_size * cnt;
-
-               /* NOTE linear mapping assumed in the ranges used */
-               phys = context.vtop_offset[vpart] + location + cnt;
-
-               error = udf_write_sector(bpos, phys);
-               if (error)
-                       return error;
-       }
-       return 0;
-}
-
-/* --------------------------------------------------------------------- */
-
-/*
- * udf_derive_format derives the format_flags from the disc's mmc_discinfo.
- * The resulting flags uniquely define a disc format. Note there are at least
- * 7 distinct format types defined in UDF.
- */
-
-#define UDF_VERSION(a) \
-       (((a) == 0x100) || ((a) == 0x102) || ((a) == 0x150) || ((a) == 0x200) || \
-        ((a) == 0x201) || ((a) == 0x250) || ((a) == 0x260))
-
-int
-udf_derive_format(int req_enable, int req_disable, int force)
-{
-       /* disc writability, formatted, appendable */
-       if ((mmc_discinfo.mmc_cur & MMC_CAP_RECORDABLE) == 0) {
-               (void)printf("Can't newfs readonly device\n");
-               return EROFS;
-       }
-       if (mmc_discinfo.mmc_cur & MMC_CAP_SEQUENTIAL) {
-               /* sequentials need sessions appended */
-               if (mmc_discinfo.disc_state == MMC_STATE_CLOSED) {
-                       (void)printf("Can't append session to a closed disc\n");
-                       return EROFS;
-               }
-               if ((mmc_discinfo.disc_state != MMC_STATE_EMPTY) && !force) {
-                       (void)printf("Disc not empty! Use -F to force "
-                           "initialisation\n");
-                       return EROFS;
-               }
-       } else {
-               /* check if disc (being) formatted or has been started on */
-               if (mmc_discinfo.disc_state == MMC_STATE_EMPTY) {
-                       (void)printf("Disc is not formatted\n");
-                       return EROFS;
-               }
-       }
-
-       /* determine UDF format */
-       format_flags = 0;
-       if (mmc_discinfo.mmc_cur & MMC_CAP_REWRITABLE) {
-               /* all rewritable media */
-               format_flags |= FORMAT_REWRITABLE;
-               if (context.min_udf >= 0x0250) {
-                       /* standard dictates meta as default */
-                       format_flags |= FORMAT_META;
-               }
-
-               if ((mmc_discinfo.mmc_cur & MMC_CAP_HW_DEFECTFREE) == 0) {
-                       /* sparables for defect management */
-                       if (context.min_udf >= 0x150)
-                               format_flags |= FORMAT_SPARABLE;
-               }
-       } else {
-               /* all once recordable media */
-               format_flags |= FORMAT_WRITEONCE;
-               if (mmc_discinfo.mmc_cur & MMC_CAP_SEQUENTIAL) {
-                       format_flags |= FORMAT_SEQUENTIAL;
-
-                       if (mmc_discinfo.mmc_cur & MMC_CAP_PSEUDOOVERWRITE) {
-                               /* logical overwritable */
-                               format_flags |= FORMAT_LOW;
-                       } else {
-                               /* have to use VAT for overwriting */
-                               format_flags |= FORMAT_VAT;
-                       }
-               } else {
-                       /* rare WORM devices, but BluRay has one, strat4096 */
-                       format_flags |= FORMAT_WORM;
-               }
-       }
-
-       /* enable/disable requests */
-       if (req_disable & FORMAT_META) {
-               format_flags &= ~(FORMAT_META | FORMAT_LOW);
-               req_disable  &= ~FORMAT_META;
-       }
-       if (req_disable || req_enable) {
-               (void)printf("Internal error\n");
-               (void)printf("\tunrecognised enable/disable req.\n");
-               return EIO;
-       }
-       if ((format_flags & FORMAT_VAT) & UDF_512_TRACK)
-               format_flags |= FORMAT_TRACK512;
-
-       /* determine partition/media access type */
-       media_accesstype = UDF_ACCESSTYPE_NOT_SPECIFIED;
-       if (mmc_discinfo.mmc_cur & MMC_CAP_REWRITABLE) {
-               media_accesstype = UDF_ACCESSTYPE_OVERWRITABLE;
-               if (mmc_discinfo.mmc_cur & MMC_CAP_ERASABLE)
-                       media_accesstype = UDF_ACCESSTYPE_REWRITEABLE;
-       } else {
-               /* all once recordable media */
-               media_accesstype = UDF_ACCESSTYPE_WRITE_ONCE;
-       }
-       if (mmc_discinfo.mmc_cur & MMC_CAP_PSEUDOOVERWRITE)
-               media_accesstype = UDF_ACCESSTYPE_PSEUDO_OVERWITE;
-
-       /* adjust minimum version limits */
-       if (format_flags & FORMAT_VAT)
-               context.min_udf = MAX(context.min_udf, 0x0150);
-       if (format_flags & FORMAT_SPARABLE)
-               context.min_udf = MAX(context.min_udf, 0x0150);
-       if (format_flags & FORMAT_META)
-               context.min_udf = MAX(context.min_udf, 0x0250);
-       if (format_flags & FORMAT_LOW)
-               context.min_udf = MAX(context.min_udf, 0x0260);
-
-       /* adjust maximum version limits not to tease or break things */
-       if (!(format_flags & (FORMAT_META | FORMAT_LOW)) &&
-           (context.max_udf > 0x200))
-               context.max_udf = 0x201;
-
-       if ((format_flags & (FORMAT_VAT | FORMAT_SPARABLE)) == 0)
-               if (context.max_udf <= 0x150)
-                       context.min_udf = 0x102;
-



Home | Main Index | Thread Index | Old Index