Module Name: src Committed By: perseant Date: Wed Jul 3 04:08:47 UTC 2024
Modified Files: src/sys/fs/exfatfs [perseant-exfatfs]: exfatfs.h exfatfs_balloc.h exfatfs_vnops.c Log Message: Use a larger block size for directory writes. Keep better track of buffer pointers to avoid a panic on error. To generate a diff of this commit: cvs rdiff -u -r1.1.2.3 -r1.1.2.4 src/sys/fs/exfatfs/exfatfs.h \ src/sys/fs/exfatfs/exfatfs_vnops.c cvs rdiff -u -r1.1.2.1 -r1.1.2.2 src/sys/fs/exfatfs/exfatfs_balloc.h 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/exfatfs/exfatfs.h diff -u src/sys/fs/exfatfs/exfatfs.h:1.1.2.3 src/sys/fs/exfatfs/exfatfs.h:1.1.2.4 --- src/sys/fs/exfatfs/exfatfs.h:1.1.2.3 Tue Jul 2 20:36:50 2024 +++ src/sys/fs/exfatfs/exfatfs.h Wed Jul 3 04:08:47 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: exfatfs.h,v 1.1.2.3 2024/07/02 20:36:50 perseant Exp $ */ +/* $NetBSD: exfatfs.h,v 1.1.2.4 2024/07/03 04:08:47 perseant Exp $ */ /*- * Copyright (c) 2022, 2024 The NetBSD Foundation, Inc. @@ -219,11 +219,17 @@ struct exfatfs_args { (fs)->xf_SectorsPerClusterShift) #define SECSIZE(fs) (1 << (fs)->xf_BytesPerSectorShift) #define SECMASK(fs) (SECSIZE(fs) - 1) -#define CLUSTERSIZE(fs) (1 << ((fs)->xf_BytesPerSectorShift + \ - (fs)->xf_SectorsPerClusterShift)) + +#define CLUSTERSHIFT(fs) ((fs)->xf_BytesPerSectorShift + \ + (fs)->xf_SectorsPerClusterShift) +#define CLUSTERSIZE(fs) (1 << CLUSTERSHIFT(fs)) #define CLUSTERMASK(fs) (CLUSTERSIZE(fs) - 1) + /* The unit in which I/O is performed */ -#define IOSIZE(fs) MIN(CLUSTERSIZE(fs), MAXPHYS) +#define MAXPSHIFT 16 +#define MAXPSIZE (1 << MAXPSHIFT) /* Must be <= MAXPHYS */ +#define IOSHIFT(fs) MIN(CLUSTERSHIFT(fs), MAXPSHIFT) +#define IOSIZE(fs) MIN(CLUSTERSIZE(fs), MAXPSIZE) #define IOMASK(fs) (IOSIZE(fs) - 1) #define EXFATFS_CLUSTER2HWADDR(fs, clust) (EXFATFS_CLUSTER2FSSEC((fs), \ Index: src/sys/fs/exfatfs/exfatfs_vnops.c diff -u src/sys/fs/exfatfs/exfatfs_vnops.c:1.1.2.3 src/sys/fs/exfatfs/exfatfs_vnops.c:1.1.2.4 --- src/sys/fs/exfatfs/exfatfs_vnops.c:1.1.2.3 Tue Jul 2 20:36:50 2024 +++ src/sys/fs/exfatfs/exfatfs_vnops.c Wed Jul 3 04:08:47 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: exfatfs_vnops.c,v 1.1.2.3 2024/07/02 20:36:50 perseant Exp $ */ +/* $NetBSD: exfatfs_vnops.c,v 1.1.2.4 2024/07/03 04:08:47 perseant Exp $ */ /*- * Copyright (c) 2022 The NetBSD Foundation, Inc. @@ -27,7 +27,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: exfatfs_vnops.c,v 1.1.2.3 2024/07/02 20:36:50 perseant Exp $"); +__KERNEL_RCSID(0, "$NetBSD: exfatfs_vnops.c,v 1.1.2.4 2024/07/03 04:08:47 perseant Exp $"); #include <sys/buf.h> #include <sys/dirent.h> @@ -411,12 +411,12 @@ exfatfs_read(void *v) if (uio->uio_offset >= GET_DSE_VALIDDATALENGTH(xip)) return 0; - lbn = uio->uio_offset >> fs->xf_BytesPerSectorShift; - error = bread(vp, lbn, 1 << fs->xf_BytesPerSectorShift, 0, &bp); + lbn = uio->uio_offset >> IOSHIFT(fs); + error = bread(vp, lbn, IOSIZE(fs), 0, &bp); if (error) goto bad; - off = uio->uio_offset & (SECSIZE(fs) - 1); + off = uio->uio_offset & IOMASK(fs); n = uio->uio_resid - uio->uio_offset; if (uio->uio_offset + uio->uio_resid > GET_DSE_VALIDDATALENGTH(xip)) @@ -2430,7 +2430,7 @@ static int deextend(struct xfinode *xip, /* If pcn is not allocated, allocate it */ allocated = 0; if (pcn == 0 || pcn == 0xFFFFFFFF) { - uint32_t tpcn = opcn; + uint32_t tpcn = opcn + 1; #ifndef ALLOC_SEQUENTIAL mutex_enter(&fs->xf_lock); tpcn = fs->xf_next_cluster; @@ -2446,7 +2446,7 @@ static int deextend(struct xfinode *xip, } #ifndef ALLOC_SEQUENTIAL mutex_enter(&fs->xf_lock); - fs->xf_next_cluster = pcn; + fs->xf_next_cluster = pcn + 1; mutex_exit(&fs->xf_lock); #endif /* !ALLOC_SEQUENTIAL */ allocated = 1; @@ -2483,6 +2483,7 @@ static int deextend(struct xfinode *xip, bwrite(bp); else bdwrite(bp); + bp = NULL; } /* Fill a new directory cluster with zero */ @@ -2518,6 +2519,7 @@ static int deextend(struct xfinode *xip, return error; pcn = ((uint32_t *)bp->b_data)[EXFATFS_FATOFF(pcn)]; brelse(bp, 0); + bp = NULL; } } KASSERT(lcn < newcount); Index: src/sys/fs/exfatfs/exfatfs_balloc.h diff -u src/sys/fs/exfatfs/exfatfs_balloc.h:1.1.2.1 src/sys/fs/exfatfs/exfatfs_balloc.h:1.1.2.2 --- src/sys/fs/exfatfs/exfatfs_balloc.h:1.1.2.1 Tue Jul 2 20:36:50 2024 +++ src/sys/fs/exfatfs/exfatfs_balloc.h Wed Jul 3 04:08:47 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: exfatfs_balloc.h,v 1.1.2.1 2024/07/02 20:36:50 perseant Exp $ */ +/* $NetBSD: exfatfs_balloc.h,v 1.1.2.2 2024/07/03 04:08:47 perseant Exp $ */ /*- * Copyright (c) 2022, 2024 The NetBSD Foundation, Inc. @@ -29,9 +29,7 @@ #ifndef EXFATFS_BALLOC_H_ #define EXFATFS_BALLOC_H_ -/* XXX we need MAXPHYSSHIFT */ -#define MAXPSHIFT 16 -#define MAXPSIZE (1 << MAXPSHIFT) /* Must be <= MAXPHYS */ +#include <fs/exfatfs/exfatfs.h> /* Convert cluster number to disk address and offset */ #define NBBYSHIFT 3 /* 1 << NBBYSHIFT == NBBY == 8 */