Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src Refactor and rewrite of newfs_udf(8) and makefs(8) (-t udf) ...
details: https://anonhg.NetBSD.org/src/rev/874c61bce213
branches: trunk
changeset: 364682:874c61bce213
user: reinoud <reinoud%NetBSD.org@localhost>
date: Wed Apr 06 13:29:15 2022 +0000
description:
Refactor and rewrite of newfs_udf(8) and makefs(8) (-t udf) with a shared
section for fsck_udf(8).
Newfs_udf and makefs support predefined disc image profiles, harddisc
partitions (disklabel and wedges on all generic block devices) and all optical
media types on CD/DVD/BD writers.
Newfs_udf and makefs now also support formatting of UDF 2.50 with a metadata
partition.
diffstat:
sbin/newfs_udf/Makefile | 7 +-
sbin/newfs_udf/newfs_udf.c | 709 +----
sbin/newfs_udf/newfs_udf.h | 37 +-
sbin/newfs_udf/udf_core.c | 5102 ++++++++++++++++++++++++++++++++++++++
sbin/newfs_udf/udf_core.h | 414 +++
sbin/newfs_udf/udf_create.c | 2398 -----------------
sbin/newfs_udf/udf_create.h | 283 --
sbin/newfs_udf/udf_write.c | 908 ------
sbin/newfs_udf/udf_write.h | 54 -
usr.sbin/makefs/makefs.8 | 33 +-
usr.sbin/makefs/udf.c | 594 +--
usr.sbin/makefs/udf/Makefile.inc | 7 +-
12 files changed, 5863 insertions(+), 4683 deletions(-)
diffs (truncated from 11196 to 300 lines):
diff -r 45bdbf6cce1e -r 874c61bce213 sbin/newfs_udf/Makefile
--- a/sbin/newfs_udf/Makefile Wed Apr 06 10:02:55 2022 +0000
+++ b/sbin/newfs_udf/Makefile Wed Apr 06 13:29:15 2022 +0000
@@ -1,10 +1,11 @@
-# $NetBSD: Makefile,v 1.7 2020/09/06 07:20:27 mrg Exp $
+# $NetBSD: Makefile,v 1.8 2022/04/06 13:29:15 reinoud Exp $
.include <bsd.own.mk>
PROG= newfs_udf
MAN= newfs_udf.8
-SRCS= newfs_udf.c udf_create.c udf_write.c udf_osta.c fattr.c
+SRCS= newfs_udf.c udf_core.c \
+ udf_osta.c fattr.c
MOUNT= ${NETBSDSRCDIR}/sbin/mount
KUDF= ${NETBSDSRCDIR}/sys/fs/udf
@@ -12,7 +13,7 @@
.PATH: ${MOUNT} ${KUDF}
DPADD+=${LIBUTIL}
-LDADD+=-lutil
+LDADD+=-lutil -lprop
CWARNFLAGS.clang+= -Wno-error=address-of-packed-member
CWARNFLAGS.gcc+= ${GCC_NO_ADDR_OF_PACKED_MEMBER}
diff -r 45bdbf6cce1e -r 874c61bce213 sbin/newfs_udf/newfs_udf.c
--- a/sbin/newfs_udf/newfs_udf.c Wed Apr 06 10:02:55 2022 +0000
+++ b/sbin/newfs_udf/newfs_udf.c Wed Apr 06 13:29:15 2022 +0000
@@ -1,7 +1,7 @@
-/* $NetBSD: newfs_udf.c,v 1.22 2021/09/19 10:34:07 andvar Exp $ */
+/* $NetBSD: newfs_udf.c,v 1.23 2022/04/06 13:29:15 reinoud Exp $ */
/*
- * Copyright (c) 2006, 2008, 2013 Reinoud Zandijk
+ * Copyright (c) 2006, 2008, 2013, 2021, 2022 Reinoud Zandijk
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -58,568 +58,56 @@
#include <sys/disklabel.h>
#include <sys/dkio.h>
#include <sys/param.h>
-#include <sys/queue.h>
-#include <fs/udf/ecma167-udf.h>
#include <fs/udf/udf_mount.h>
#include "mountprog.h"
-#include "udf_create.h"
-#include "udf_write.h"
+#include "udf_core.h"
#include "newfs_udf.h"
+/* Identifying myself */
+#define IMPL_NAME "*NetBSD newfs_udf 10.0"
+#define APP_VERSION_MAIN 0
+#define APP_VERSION_SUB 5
+
/* prototypes */
int newfs_udf(int argc, char **argv);
static void usage(void) __attribute__((__noreturn__));
-/* queue for temporary storage of sectors to be written out */
-struct wrsect {
- uint64_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 */
-int fd; /* device: file descriptor */
-char *dev; /* device: name */
-struct mmc_discinfo mmc_discinfo; /* device: disc info */
-
char *format_str; /* format: string representation */
-int format_flags; /* format: attribute flags */
-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;
-float meta_fract = (float) UDF_META_PERC / 100.0;
-
-
-/* --------------------------------------------------------------------- */
-
-/*
- * write queue implementation
- */
-
-int
-udf_write_sector(void *sector, uint64_t location)
-{
- struct wrsect *pos, *seekpos;
-
-
- /* search location */
- TAILQ_FOREACH_REVERSE(seekpos, &write_queue, wrsect_list, next) {
- if (seekpos->sectornr <= location)
- break;
- }
- if ((seekpos == NULL) || (seekpos->sectornr != location)) {
- pos = calloc(1, sizeof(struct wrsect));
- if (pos == NULL)
- return errno;
- /* allocate space for copy of sector data */
- pos->sector_data = calloc(1, context.sector_size);
- if (pos->sector_data == NULL) {
- free(pos);
- return errno;
- }
- pos->sectornr = location;
-
- if (seekpos) {
- TAILQ_INSERT_AFTER(&write_queue, seekpos, pos, next);
- } else {
- TAILQ_INSERT_HEAD(&write_queue, pos, next);
- }
- } else {
- pos = seekpos;
- }
- memcpy(pos->sector_data, sector, context.sector_size);
-
- return 0;
-}
-
-
-/*
- * Now all write requests are queued in the TAILQ, write them out to the
- * disc/file image. Special care needs to be taken for devices that are only
- * strict overwritable i.e. only in packet size chunks
- *
- * XXX support for growing vnd?
- */
-
-int
-writeout_write_queue(void)
-{
- struct wrsect *pos;
- uint64_t offset;
- uint64_t line_start, new_line_start;
- uint32_t line_len, line_offset, relpos;
- uint32_t blockingnr;
- uint8_t *linebuf, *adr;
-
- blockingnr = layout.blockingnr;
- line_len = blockingnr * context.sector_size;
- line_offset = wrtrack_skew * context.sector_size;
- linebuf = malloc(line_len);
- if (linebuf == NULL)
- return ENOMEM;
-
- pos = TAILQ_FIRST(&write_queue);
- bzero(linebuf, line_len);
-
- /*
- * Always writing out in whole lines now; this is slightly wastefull
- * on logical overwrite volumes but it reduces complexity and the loss
- * is near zero compared to disc size.
- */
- line_start = (pos->sectornr - wrtrack_skew) / blockingnr;
- TAILQ_FOREACH(pos, &write_queue, next) {
- new_line_start = (pos->sectornr - wrtrack_skew) / blockingnr;
- if (new_line_start != line_start) {
- /* write out */
- offset = (uint64_t) line_start * line_len + line_offset;
-#ifdef DEBUG
- printf("WRITEOUT %08"PRIu64" + %02d -- "
- "[%08"PRIu64"..%08"PRIu64"]\n",
- offset / context.sector_size, blockingnr,
- offset / context.sector_size,
- offset / context.sector_size + blockingnr-1);
-#endif
- if (pwrite(fd, linebuf, line_len, offset) < 0) {
- perror("Writing failed");
- return errno;
- }
- line_start = new_line_start;
- bzero(linebuf, line_len);
- }
-
- relpos = (pos->sectornr - wrtrack_skew) % blockingnr;
- adr = linebuf + relpos * context.sector_size;
- memcpy(adr, pos->sector_data, context.sector_size);
- }
- /* writeout last chunk */
- offset = (uint64_t) line_start * line_len + line_offset;
-#ifdef DEBUG
- printf("WRITEOUT %08"PRIu64" + %02d -- [%08"PRIu64"..%08"PRIu64"]\n",
- offset / context.sector_size, blockingnr,
- offset / context.sector_size,
- offset / context.sector_size + blockingnr-1);
-#endif
- if (pwrite(fd, linebuf, line_len, offset) < 0) {
- perror("Writing failed");
- return errno;
- }
-
- /* success */
- return 0;
-}
-
-/* --------------------------------------------------------------------- */
-
-/*
- * mmc_discinfo and mmc_trackinfo readers modified from origional in udf main
- * code in sys/fs/udf/
- */
-
-#ifdef DEBUG
-static void
-udf_dump_discinfo(struct mmc_discinfo *di)
-{
- char bits[128];
-
- printf("Device/media info :\n");
- printf("\tMMC profile 0x%02x\n", di->mmc_profile);
- printf("\tderived class %d\n", di->mmc_class);
- printf("\tsector size %d\n", di->sector_size);
- printf("\tdisc state %d\n", di->disc_state);
- printf("\tlast ses state %d\n", di->last_session_state);
- printf("\tbg format state %d\n", di->bg_format_state);
- printf("\tfrst track %d\n", di->first_track);
- printf("\tfst on last ses %d\n", di->first_track_last_session);
- printf("\tlst on last ses %d\n", di->last_track_last_session);
- printf("\tlink block penalty %d\n", di->link_block_penalty);
- snprintb(bits, sizeof(bits), MMC_DFLAGS_FLAGBITS, (uint64_t) di->disc_flags);
- printf("\tdisc flags %s\n", bits);
- printf("\tdisc id %x\n", di->disc_id);
- printf("\tdisc barcode %"PRIx64"\n", di->disc_barcode);
-
- printf("\tnum sessions %d\n", di->num_sessions);
- printf("\tnum tracks %d\n", di->num_tracks);
-
- snprintb(bits, sizeof(bits), MMC_CAP_FLAGBITS, di->mmc_cur);
- printf("\tcapabilities cur %s\n", bits);
- snprintb(bits, sizeof(bits), MMC_CAP_FLAGBITS, di->mmc_cap);
- printf("\tcapabilities cap %s\n", bits);
- printf("\n");
- printf("\tlast_possible_lba %d\n", di->last_possible_lba);
- printf("\n");
-}
-#else
-#define udf_dump_discinfo(a);
-#endif
/* --------------------------------------------------------------------- */
static int
-udf_update_discinfo(struct mmc_discinfo *di)
-{
- struct stat st;
- struct disklabel disklab;
- struct partition *dp;
- off_t size, sectors, secsize;
- int partnr, error;
-
- memset(di, 0, sizeof(struct mmc_discinfo));
-
- /* check if we're on a MMC capable device, i.e. CD/DVD */
- error = ioctl(fd, MMCGETDISCINFO, di);
- if (error == 0)
- return 0;
-
- /* (re)fstat the file */
- fstat(fd, &st);
-
- if (S_ISREG(st.st_mode)) {
- /* file support; we pick the minimum sector size allowed */
- size = st.st_size;
- secsize = imagefile_secsize;
- 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.
- */
- if (ioctl(fd, DIOCGDINFO, &disklab) == -1) {
- /* failed to get disclabel! */
- perror("disklabel");
- return errno;
- }
-
- /* get disk partition it refers to */
- fstat(fd, &st);
- partnr = DISKPART(st.st_rdev);
- dp = &disklab.d_partitions[partnr];
-
- /* TODO problem with last_possible_lba on resizable VND */
- if (dp->p_size == 0) {
- perror("faulty disklabel partition returned, "
Home |
Main Index |
Thread Index |
Old Index