Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sbin/fsck_udf Initial commit of the fsck_udf(8) utility that...
details: https://anonhg.NetBSD.org/src/rev/c8d9cc2ed1f6
branches: trunk
changeset: 364683:c8d9cc2ed1f6
user: reinoud <reinoud%NetBSD.org@localhost>
date: Wed Apr 06 13:35:50 2022 +0000
description:
Initial commit of the fsck_udf(8) utility that checks and repairs UDF
filesystems on optical media as well as on disc images, harddisc partitions
and wedges.
diffstat:
sbin/fsck_udf/Makefile | 23 +
sbin/fsck_udf/fsck_udf.8 | 115 +
sbin/fsck_udf/main.c | 4468 ++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 4606 insertions(+), 0 deletions(-)
diffs (truncated from 4618 to 300 lines):
diff -r 874c61bce213 -r c8d9cc2ed1f6 sbin/fsck_udf/Makefile
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sbin/fsck_udf/Makefile Wed Apr 06 13:35:50 2022 +0000
@@ -0,0 +1,23 @@
+# $NetBSD: Makefile,v 1.1 2022/04/06 13:35:50 reinoud Exp $
+
+.include <bsd.own.mk>
+
+PROG= fsck_udf
+MAN= fsck_udf.8
+SRCS= main.c udf_core.c \
+ udf_osta.c fattr.c fsutil.c
+
+FSCK= ${NETBSDSRCDIR}/sbin/fsck
+NEWFS= ${NETBSDSRCDIR}/sbin/newfs_udf
+MOUNT= ${NETBSDSRCDIR}/sbin/mount
+KUDF= ${NETBSDSRCDIR}/sys/fs/udf
+CPPFLAGS+= -I${FSCK} -I${KUDF} -I${NEWFS} -I${NETBSDSRCDIR}/sys
+.PATH: ${FSCK} ${NEWFS} ${MOUNT} ${KUDF}
+
+DPADD+=${LIBUTIL}
+LDADD+=-lutil -lprop
+
+CWARNFLAGS.clang+= -Wno-error=address-of-packed-member
+CWARNFLAGS.gcc+= ${GCC_NO_ADDR_OF_PACKED_MEMBER}
+
+.include <bsd.prog.mk>
diff -r 874c61bce213 -r c8d9cc2ed1f6 sbin/fsck_udf/fsck_udf.8
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sbin/fsck_udf/fsck_udf.8 Wed Apr 06 13:35:50 2022 +0000
@@ -0,0 +1,115 @@
+.\" $NetBSD: fsck_udf.8,v 1.1 2022/04/06 13:35:50 reinoud Exp $
+.\"
+.\" Copyright (C) 2022 Reinoud Zandijk
+.\" Based on fsck_msdos(8) by
+.\" Copyright (C) 1995 Wolfgang Solfrank
+.\" Copyright (c) 1995 Martin Husemann
+.\"
+.\" 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 AUTHORS ``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 AUTHORS 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.
+.\"
+.\"
+.Dd February 6, 2022
+.Dt FSCK_UDF 8
+.Os
+.Sh NAME
+.Nm fsck_udf
+.Nd Universal Disk Format filesystem consistency checker
+.Sh SYNOPSIS
+.Nm
+.Fl p
+.Op Fl fH
+.Ar filesystem ...
+.Nm
+.Op Fl sSynfH
+.Ar filesystem ...
+.Sh DESCRIPTION
+The
+.Nm
+utility verifies and repairs
+.Tn Universal Disk Format
+filesystems (more commonly known as
+.Tn UDF
+filesystems).
+.Pp
+The first form of
+.Nm
+preens the specified filesystems.
+It is normally started by
+.Xr fsck 8
+run from
+.Pa /etc/rc
+during automatic reboot, when an UDF filesystem is detected.
+When preening file systems,
+.Nm
+will fix common inconsistencies non-interactively.
+If more serious problems are found,
+.Nm
+does not try to fix them, indicates that it was not
+successful, and exits.
+.Pp
+The second form of
+.Nm
+checks the specified file systems and tries to repair all
+detected inconsistencies, requesting confirmation before
+making any changes.
+.Pp
+The options are as follows:
+.Bl -tag -width XXXoptions
+.It Fl f
+Force detailed checking even when file system is marked closed.
+.It Fl n
+Causes
+.Nm
+to assume no as the answer to all operator
+questions.
+.It Fl p
+Preen the specified filesystems.
+.It Fl y
+Causes
+.Nm
+to assume yes as the answer to all operator questions.
+.It Fl s Ar session
+Select session
+.Ar session
+to be checked on recordable media. This allows older sessions
+of the file system on recordable media to be recovered.
+.It Fl S
+Causes
+.Nm
+to scan for older VAT tables on recordable media. This allows older snapshots
+of the file system on recordable media to be recovered.
+.It Fl H
+Enables heuristic repair options repairing known corruptions in the wild
+caused by bugs.
+.El
+.Sh SEE ALSO
+.Xr fsck 8 ,
+.Xr fsck_ffs 8 ,
+.Xr mount_udf 8
+.Sh HISTORY
+A
+.Nm
+utility appeared in
+.Nx 10.0 .
+.Sh BUGS
+.Nm
+is still under construction. Not all possible reparations are implemented.
+
diff -r 874c61bce213 -r c8d9cc2ed1f6 sbin/fsck_udf/main.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sbin/fsck_udf/main.c Wed Apr 06 13:35:50 2022 +0000
@@ -0,0 +1,4468 @@
+/* $NetBSD: main.c,v 1.1 2022/04/06 13:35:50 reinoud Exp $ */
+
+/*
+ * Copyright (c) 2022 Reinoud Zandijk
+ * All rights reserved.
+ *
+ * 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 AUTHOR ``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 AUTHOR 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.
+ *
+ */
+
+
+/*
+ * Note to reader:
+ *
+ * fsck_udf uses the common udf_core.c file with newfs and makefs. It does use
+ * some of the layout structure values but not all.
+ */
+
+
+#include <sys/cdefs.h>
+#ifndef lint
+__RCSID("$NetBSD: main.c,v 1.1 2022/04/06 13:35:50 reinoud Exp $");
+#endif /* not lint */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stddef.h>
+#include <dirent.h>
+#include <inttypes.h>
+#include <stdint.h>
+#include <string.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <util.h>
+#include <time.h>
+#include <tzfile.h>
+#include <math.h>
+#include <assert.h>
+#include <err.h>
+
+#if !HAVE_NBTOOL_CONFIG_H
+#define _EXPOSE_MMC
+#include <sys/cdio.h>
+#else
+#include "udf/cdio_mmc_structs.h"
+#endif
+
+#include <sys/ioctl.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#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 "fsutil.h"
+#include "exitvalues.h"
+#include "udf_core.h"
+
+/* Identifying myself */
+#define IMPL_NAME "*NetBSD fsck_udf 10.0"
+#define APP_VERSION_MAIN 0
+#define APP_VERSION_SUB 5
+
+/* allocation walker actions */
+#define AD_LOAD_FILE (1<<0)
+#define AD_SAVE_FILE (1<<1)
+#define AD_CHECK_FIDS (1<<2)
+#define AD_ADJUST_FIDS (1<<3)
+#define AD_GATHER_STATS (1<<4)
+#define AD_CHECK_USED (1<<5)
+#define AD_MARK_AS_USED (1<<6)
+#define AD_FIND_OVERLAP_PAIR (1<<7)
+
+struct udf_fsck_file_stats {
+ uint64_t inf_len;
+ uint64_t obj_size;
+ uint64_t logblks_rec;
+};
+
+
+struct udf_fsck_fid_context {
+ uint64_t fid_offset;
+ uint64_t data_left;
+};
+
+
+/* basic node administration for passes */
+#define FSCK_NODE_FLAG_HARDLINK (1<< 0) /* hardlink, for accounting */
+#define FSCK_NODE_FLAG_DIRECTORY (1<< 1) /* is a normal directory */
+#define FSCK_NODE_FLAG_HAS_STREAM_DIR (1<< 2) /* has a stream directory */
+#define FSCK_NODE_FLAG_STREAM_ENTRY (1<< 3) /* is a stream file */
+#define FSCK_NODE_FLAG_STREAM_DIR (1<< 4) /* is a stream directory */
+#define FSCK_NODE_FLAG_OK(f) (((f) >> 5) == 0)
+
+#define FSCK_NODE_FLAG_KEEP (1<< 5) /* don't discard */
+#define FSCK_NODE_FLAG_DIRTY (1<< 6) /* descriptor needs writeout */
+#define FSCK_NODE_FLAG_REPAIRDIR (1<< 7) /* repair bad FID entries */
+#define FSCK_NODE_FLAG_NEW_UNIQUE_ID (1<< 8) /* repair bad FID entries */
+#define FSCK_NODE_FLAG_COPY_PARENT_ID (1<< 9) /* repair bad FID entries */
+#define FSCK_NODE_FLAG_WIPE_STREAM_DIR (1<<10) /* wipe stream directory */
+#define FSCK_NODE_FLAG_NOTFOUND (1<<11) /* FID pointing to garbage */
+#define FSCK_NODE_FLAG_PAR_NOT_FOUND (1<<12) /* parent node not found! */
+#define FSCK_NODE_FLAG_OVERLAP (1<<13) /* node has overlaps */
+
+#define FSCK_NODE_FLAG_STREAM (FSCK_NODE_FLAG_STREAM_ENTRY | FSCK_NODE_FLAG_STREAM_DIR)
+
+
+#define HASH_HASHBITS 5
+#define HASH_HASHSIZE (1 << HASH_HASHBITS)
+#define HASH_HASHMASK (HASH_HASHSIZE - 1)
+
+/* fsck node for accounting checks */
+struct udf_fsck_node {
+ struct udf_fsck_node *parent;
+ char *fname;
+
+ struct long_ad loc;
+ struct long_ad streamdir_loc;
+ int fsck_flags;
+
+ int link_count;
+ int found_link_count;
+ uint64_t unique_id;
+
+ struct udf_fsck_file_stats declared;
+ struct udf_fsck_file_stats found;
+
Home |
Main Index |
Thread Index |
Old Index