Module Name: src Committed By: martin Date: Sun Mar 13 09:48:32 UTC 2022
Modified Files: src/sys/fs/udf [netbsd-9]: udf_allocation.c udf_subr.c udf_vfsops.c Log Message: Pull up following revision(s), all via patch, requested by reinoud in ticket #1432: sys/fs/udf/udf_vfsops.c: revision 1.83 sys/fs/udf/udf_allocation.c: revision 1.45 sys/fs/udf/udf_subr.c: revision 1.160 sys/fs/udf/udf_subr.c: revision 1.161 While searching the VAT on recordable media, search the last sector too! This fixes Win10 formatted discs from being mounted incorrectly. Make sysctl udf.verbose dependent on UDF_DEBUG instead of DEBUG Fix serious issue with recordable media formatted with Win10. When closing it after modification the VAT was written out corrupted making the disc unreadable anymore on remount. Thanks for ig@ for spotting it in the wild! On freeing a virtual address in the VAT, use the correct value; this might confuse other implementations who can reject the VAT on this. To generate a diff of this commit: cvs rdiff -u -r1.40 -r1.40.4.1 src/sys/fs/udf/udf_allocation.c cvs rdiff -u -r1.146.2.1 -r1.146.2.2 src/sys/fs/udf/udf_subr.c cvs rdiff -u -r1.76 -r1.76.10.1 src/sys/fs/udf/udf_vfsops.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/fs/udf/udf_allocation.c diff -u src/sys/fs/udf/udf_allocation.c:1.40 src/sys/fs/udf/udf_allocation.c:1.40.4.1 --- src/sys/fs/udf/udf_allocation.c:1.40 Sun Oct 14 17:37:40 2018 +++ src/sys/fs/udf/udf_allocation.c Sun Mar 13 09:48:32 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: udf_allocation.c,v 1.40 2018/10/14 17:37:40 jdolecek Exp $ */ +/* $NetBSD: udf_allocation.c,v 1.40.4.1 2022/03/13 09:48:32 martin Exp $ */ /* * Copyright (c) 2006, 2008 Reinoud Zandijk @@ -28,7 +28,7 @@ #include <sys/cdefs.h> #ifndef lint -__KERNEL_RCSID(0, "$NetBSD: udf_allocation.c,v 1.40 2018/10/14 17:37:40 jdolecek Exp $"); +__KERNEL_RCSID(0, "$NetBSD: udf_allocation.c,v 1.40.4.1 2022/03/13 09:48:32 martin Exp $"); #endif /* not lint */ @@ -864,7 +864,7 @@ udf_search_free_vatloc(struct udf_mount } /* mark entry with initialiser just in case */ - lb_map = udf_rw32(0xfffffffe); + lb_map = udf_rw32(0xffffffff); udf_vat_write(ump->vat_node, (uint8_t *) &lb_map, 4, ump->vat_offset + lb_num *4); ump->vat_last_free_lb = lb_num; Index: src/sys/fs/udf/udf_subr.c diff -u src/sys/fs/udf/udf_subr.c:1.146.2.1 src/sys/fs/udf/udf_subr.c:1.146.2.2 --- src/sys/fs/udf/udf_subr.c:1.146.2.1 Sun Mar 13 09:44:33 2022 +++ src/sys/fs/udf/udf_subr.c Sun Mar 13 09:48:32 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: udf_subr.c,v 1.146.2.1 2022/03/13 09:44:33 martin Exp $ */ +/* $NetBSD: udf_subr.c,v 1.146.2.2 2022/03/13 09:48:32 martin Exp $ */ /* * Copyright (c) 2006, 2008 Reinoud Zandijk @@ -29,7 +29,7 @@ #include <sys/cdefs.h> #ifndef lint -__KERNEL_RCSID(0, "$NetBSD: udf_subr.c,v 1.146.2.1 2022/03/13 09:44:33 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: udf_subr.c,v 1.146.2.2 2022/03/13 09:48:32 martin Exp $"); #endif /* not lint */ @@ -2764,10 +2764,11 @@ udf_update_vat_descriptor(struct udf_mou struct icb_tag *icbtag; struct udf_oldvat_tail *oldvat_tl; struct udf_vat *vat; + struct regid *regid; uint64_t unique_id; uint32_t lb_size; uint8_t *raw_vat; - int filetype, error; + int vat_length, impl_use_len, filetype, error; KASSERT(vat_node); KASSERT(lvinfo); @@ -2812,11 +2813,20 @@ udf_update_vat_descriptor(struct udf_mou sizeof(struct udf_oldvat_tail), ump->vat_entries * 4); } else { /* compose the VAT2 header */ + vat_length = sizeof(struct udf_vat); vat = (struct udf_vat *) raw_vat; - memset(vat, 0, sizeof(struct udf_vat)); - vat->header_len = udf_rw16(152); /* as per spec */ - vat->impl_use_len = udf_rw16(0); + error = udf_vat_read(vat_node, raw_vat, vat_length, 0); + if (error) + goto errout; + + impl_use_len = udf_rw16(vat->impl_use_len); + vat_length += impl_use_len; + + error = udf_vat_read(vat_node, raw_vat, vat_length, 0); + if (error) + goto errout; + memmove(vat->logvol_id, ump->logical_vol->logvol_id, 128); vat->prev_vat = udf_rw32(0xffffffff); vat->num_files = lvinfo->num_files; @@ -2825,9 +2835,20 @@ udf_update_vat_descriptor(struct udf_mou vat->min_udf_writever = lvinfo->min_udf_writever; vat->max_udf_writever = lvinfo->max_udf_writever; - error = udf_vat_write(vat_node, raw_vat, - sizeof(struct udf_vat), 0); + if (impl_use_len >= sizeof(struct regid)) { + /* insert our implementation identification */ + memset(vat->data, 0, impl_use_len); + regid = (struct regid *) vat->data; + udf_set_regid(regid, IMPL_NAME); + udf_add_app_regid(ump, regid); + } else { + if (impl_use_len) + memset(vat->data, 0, impl_use_len); + vat->impl_use_len = 0; + } + error = udf_vat_write(vat_node, raw_vat, vat_length, 0); } +errout: free(raw_vat, M_TEMP); return error; /* success! */ @@ -2996,7 +3017,7 @@ udf_check_for_vat(struct udf_node *vat_n /* definition */ vat = (struct udf_vat *) raw_vat; - vat_offset = vat->header_len; + vat_offset = udf_rw16(vat->header_len); vat_entries = (vat_length - vat_offset)/4; assert(lvinfo); @@ -3100,7 +3121,7 @@ udf_search_vat(struct udf_mount *ump, un if (vat_node) vput(vat_node->vnode); vat_loc++; /* walk forward */ - } while (vat_loc < late_vat_loc); + } while (vat_loc <= late_vat_loc); if (accepted_vat_node) break; Index: src/sys/fs/udf/udf_vfsops.c diff -u src/sys/fs/udf/udf_vfsops.c:1.76 src/sys/fs/udf/udf_vfsops.c:1.76.10.1 --- src/sys/fs/udf/udf_vfsops.c:1.76 Sat Jun 24 12:13:16 2017 +++ src/sys/fs/udf/udf_vfsops.c Sun Mar 13 09:48:32 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: udf_vfsops.c,v 1.76 2017/06/24 12:13:16 hannken Exp $ */ +/* $NetBSD: udf_vfsops.c,v 1.76.10.1 2022/03/13 09:48:32 martin Exp $ */ /* * Copyright (c) 2006, 2008 Reinoud Zandijk @@ -28,7 +28,7 @@ #include <sys/cdefs.h> #ifndef lint -__KERNEL_RCSID(0, "$NetBSD: udf_vfsops.c,v 1.76 2017/06/24 12:13:16 hannken Exp $"); +__KERNEL_RCSID(0, "$NetBSD: udf_vfsops.c,v 1.76.10.1 2022/03/13 09:48:32 martin Exp $"); #endif /* not lint */ @@ -191,7 +191,7 @@ udf_modcmd(modcmd_t cmd, void *arg) SYSCTL_DESCR("OSTA Universal File System"), NULL, 0, NULL, 0, CTL_VFS, 24, CTL_EOL); -#ifdef DEBUG +#ifdef UDF_DEBUG sysctl_createv(&udf_sysctl_log, 0, NULL, &node, CTLFLAG_PERMANENT|CTLFLAG_READWRITE, CTLTYPE_INT, "verbose",