Thu May 27 06:54:45 2021 UTC ()
add bi-endian support to the libsa ufs reader and enable it in efiboot.

ffs frontends to "ufs.c" now also define ufs_dinode_swap, ufs_indp_swap,
and FS_MAGIC (moved from ufs.c #if segments.)  these are used to call
the right (32/64 bit) ffsv1/v2 version.

ufs.c 'struct file' gains f_swapped member.  accessors for d_magic,
d_reclen, and d_ino are introduced (they need to be swapped.)  sfter
reading an inode from disk, read_inode() may call ufs_dinode_swap().
indirect block number and caches may be swapped.

error handling in ffs_find_superblock() is cleaned up.  (size is slightly
reduced on some ports with this part.)

defaults for new defines added to ufs.c.  (XXX: we build ufs.c but i think
all the consumers don't use it, and we can stop building it.)

LFS support is not included.

add a cut-down copy of ffs_bswap.c from the kernel.

also enable bi-endian disklabel support in efiboot.

most ports build and sizes compared for platforms that don't enable this
code and all but one saw reduced code size.  booted several platforms with
new boot code.


(mrg)
diff -r1.94 -r1.95 src/sys/lib/libsa/Makefile
diff -r0 -r1.1 src/sys/lib/libsa/ffs_bswap.c
diff -r1.7 -r1.8 src/sys/lib/libsa/ffsv1.c
diff -r1.7 -r1.8 src/sys/lib/libsa/ffsv2.c
diff -r1.14 -r1.15 src/sys/lib/libsa/lfsv1.c
diff -r1.14 -r1.15 src/sys/lib/libsa/lfsv2.c
diff -r1.79 -r1.80 src/sys/lib/libsa/ufs.c
diff -r1.10 -r1.11 src/sys/lib/libsa/ufs.h
diff -r1.20 -r1.21 src/sys/stand/efiboot/Makefile.efiboot
diff -r1.24 -r1.25 src/sys/stand/efiboot/version

cvs diff -r1.94 -r1.95 src/sys/lib/libsa/Makefile (expand / switch to unified diff)

--- src/sys/lib/libsa/Makefile 2021/05/17 08:50:36 1.94
+++ src/sys/lib/libsa/Makefile 2021/05/27 06:54:44 1.95
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1# $NetBSD: Makefile,v 1.94 2021/05/17 08:50:36 mrg Exp $ 1# $NetBSD: Makefile,v 1.95 2021/05/27 06:54:44 mrg Exp $
2 2
3LIB= sa 3LIB= sa
4LIBISPRIVATE?= yes 4LIBISPRIVATE?= yes
5 5
6SA_USE_CREAD?= no # Read compressed kernels 6SA_USE_CREAD?= no # Read compressed kernels
7SA_INCLUDE_NET?= yes # Netboot via TFTP, NFS 7SA_INCLUDE_NET?= yes # Netboot via TFTP, NFS
8SA_USE_LOADFILE?= no # Generic executable loading support 8SA_USE_LOADFILE?= no # Generic executable loading support
9SA_ENABLE_LS_OP?= no # Filesystems ls operation 9SA_ENABLE_LS_OP?= no # Filesystems ls operation
10SA_ENABLE_BIENDIAN?= no # Biendian support 10SA_ENABLE_BIENDIAN?= no # Biendian support
11 # (currently only for loadfile_elf*) 11 # (currently only for loadfile_elf*)
12 12
13#DEBUGCPPFLAGS= -DBOOTP_DEBUG -DNETIF_DEBUG -DETHER_DEBUG -DNFS_DEBUG -DRPC_DEBUG -DRARP_DEBUG -DARP_DEBUG -DNET_DEBUG -DDEBUG -DPARANOID 13#DEBUGCPPFLAGS= -DBOOTP_DEBUG -DNETIF_DEBUG -DETHER_DEBUG -DNFS_DEBUG -DRPC_DEBUG -DRARP_DEBUG -DARP_DEBUG -DNET_DEBUG -DDEBUG -DPARANOID
14CPPFLAGS= -I${SADIR} ${SACPPFLAGS} ${SAMISCCPPFLAGS} \ 14CPPFLAGS= -I${SADIR} ${SACPPFLAGS} ${SAMISCCPPFLAGS} \
@@ -70,27 +70,27 @@ SRCS+= arp.c ether.c ether_sprintf.c ip_ @@ -70,27 +70,27 @@ SRCS+= arp.c ether.c ether_sprintf.c ip_
70 70
71# network info services: 71# network info services:
72SRCS+= bootp.c rarp.c bootparam.c 72SRCS+= bootp.c rarp.c bootparam.c
73 73
74# boot filesystems 74# boot filesystems
75SRCS+= nfs.c tftp.c 75SRCS+= nfs.c tftp.c
76.endif 76.endif
77 77
78.if (${SA_ENABLE_BIENDIAN} == "yes") 78.if (${SA_ENABLE_BIENDIAN} == "yes")
79CPPFLAGS+= -DLIBSA_BIENDIAN_SUPPORT 79CPPFLAGS+= -DLIBSA_BIENDIAN_SUPPORT
80SRCS+= byteorder.c 80SRCS+= byteorder.c
81.endif 81.endif
82 82
83SRCS+= ffsv1.c ffsv2.c 83SRCS+= ffsv1.c ffsv2.c ffs_bswap.c
84SRCS+= lfsv1.c lfsv2.c 84SRCS+= lfsv1.c lfsv2.c
85SRCS+= cd9660.c 85SRCS+= cd9660.c
86SRCS+= ustarfs.c 86SRCS+= ustarfs.c
87SRCS+= dosfs.c 87SRCS+= dosfs.c
88SRCS+= ext2fs.c 88SRCS+= ext2fs.c
89SRCS+= minixfs3.c 89SRCS+= minixfs3.c
90SRCS+= fnmatch.c 90SRCS+= fnmatch.c
91# for historic compatibility ufs == ffsv1 91# for historic compatibility ufs == ffsv1
92SRCS+= ufs.c 92SRCS+= ufs.c
93 93
94.include <bsd.lib.mk> 94.include <bsd.lib.mk>
95 95
96lib${LIB}.o:: ${OBJS:O} __buildstdlib 96lib${LIB}.o:: ${OBJS:O} __buildstdlib

File Added: src/sys/lib/libsa/ffs_bswap.c
/*	$NetBSD: ffs_bswap.c,v 1.1 2021/05/27 06:54:44 mrg Exp $	*/

/*
 * Copyright (c) 1998 Manuel Bouyer.
 *
 * 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.
 *
 */

/*
 * This copy is a minimal version for libsa and it's ufs.c.  The unused
 * functions are removed, and additional swapping is performed on the
 * di_extb, di_db, and di_ib arrays.
 */

#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ffs_bswap.c,v 1.1 2021/05/27 06:54:44 mrg Exp $");

#include <sys/param.h>
#include <lib/libkern/libkern.h>

#include <ufs/ufs/dinode.h>
#include <ufs/ufs/quota.h>
#include <ufs/ufs/ufs_bswap.h>
#include <ufs/ffs/fs.h>
#include <ufs/ffs/ffs_extern.h>

static void
libsa_ffs_csumtotal_swap(const struct csum_total *o, struct csum_total *n)
{
	n->cs_ndir = bswap64(o->cs_ndir);
	n->cs_nbfree = bswap64(o->cs_nbfree);
	n->cs_nifree = bswap64(o->cs_nifree);
	n->cs_nffree = bswap64(o->cs_nffree);
}

void
ffs_sb_swap(const struct fs *o, struct fs *n)
{
	size_t i;
	const u_int32_t *o32;
	u_int32_t *n32;

	/*
	 * In order to avoid a lot of lines, as the first N fields (52)
	 * of the superblock up to fs_fmod are u_int32_t, we just loop
	 * here to convert them.
	 */
	o32 = (const u_int32_t *)o;
	n32 = (u_int32_t *)n;
	for (i = 0; i < offsetof(struct fs, fs_fmod) / sizeof(u_int32_t); i++)
		n32[i] = bswap32(o32[i]);

	n->fs_swuid = bswap64(o->fs_swuid);
	n->fs_cgrotor = bswap32(o->fs_cgrotor); /* Unused */
	n->fs_old_cpc = bswap32(o->fs_old_cpc);

	/* These fields overlap with a possible location for the
	 * historic FS_DYNAMICPOSTBLFMT postbl table, and with the
	 * first half of the historic FS_42POSTBLFMT postbl table.
	 */
	n->fs_maxbsize = bswap32(o->fs_maxbsize);
	/* XXX journal */
	n->fs_quota_magic = bswap32(o->fs_quota_magic);
	for (i = 0; i < MAXQUOTAS; i++)
		n->fs_quotafile[i] = bswap64(o->fs_quotafile[i]);
	n->fs_sblockloc = bswap64(o->fs_sblockloc);
	libsa_ffs_csumtotal_swap(&o->fs_cstotal, &n->fs_cstotal);
	n->fs_time = bswap64(o->fs_time);
	n->fs_size = bswap64(o->fs_size);
	n->fs_dsize = bswap64(o->fs_dsize);
	n->fs_csaddr = bswap64(o->fs_csaddr);
	n->fs_pendingblocks = bswap64(o->fs_pendingblocks);
	n->fs_pendinginodes = bswap32(o->fs_pendinginodes);

	/* These fields overlap with the second half of the
	 * historic FS_42POSTBLFMT postbl table
	 */
	for (i = 0; i < FSMAXSNAP; i++)
		n->fs_snapinum[i] = bswap32(o->fs_snapinum[i]);
	n->fs_avgfilesize = bswap32(o->fs_avgfilesize);
	n->fs_avgfpdir = bswap32(o->fs_avgfpdir);
	/* fs_sparecon[28] - ignore for now */
	n->fs_flags = bswap32(o->fs_flags);
	n->fs_contigsumsize = bswap32(o->fs_contigsumsize);
	n->fs_maxsymlinklen = bswap32(o->fs_maxsymlinklen);
	n->fs_old_inodefmt = bswap32(o->fs_old_inodefmt);
	n->fs_maxfilesize = bswap64(o->fs_maxfilesize);
	n->fs_qbmask = bswap64(o->fs_qbmask);
	n->fs_qfmask = bswap64(o->fs_qfmask);
	n->fs_state = bswap32(o->fs_state);
	n->fs_old_postblformat = bswap32(o->fs_old_postblformat);
	n->fs_old_nrpos = bswap32(o->fs_old_nrpos);
	n->fs_old_postbloff = bswap32(o->fs_old_postbloff);
	n->fs_old_rotbloff = bswap32(o->fs_old_rotbloff);

	n->fs_magic = bswap32(o->fs_magic);
}

void
ffs_dinode1_swap(struct ufs1_dinode *o, struct ufs1_dinode *n)
{
	size_t i;

	n->di_mode = bswap16(o->di_mode);
	n->di_nlink = bswap16(o->di_nlink);
	n->di_oldids[0] = bswap16(o->di_oldids[0]);
	n->di_oldids[1] = bswap16(o->di_oldids[1]);
	n->di_size = bswap64(o->di_size);
	n->di_atime = bswap32(o->di_atime);
	n->di_atimensec = bswap32(o->di_atimensec);
	n->di_mtime = bswap32(o->di_mtime);
	n->di_mtimensec = bswap32(o->di_mtimensec);
	n->di_ctime = bswap32(o->di_ctime);
	n->di_ctimensec = bswap32(o->di_ctimensec);
	/* Swap these here, unlike kernel version .*/
	for (i = 0; i < UFS_NDADDR; i++)
		n->di_db[i] = bswap32(o->di_db[i]);
	for (i = 0; i < UFS_NIADDR; i++)
		n->di_ib[i] = bswap32(o->di_ib[i]);
	n->di_flags = bswap32(o->di_flags);
	n->di_blocks = bswap32(o->di_blocks);
	n->di_gen = bswap32(o->di_gen);
	n->di_uid = bswap32(o->di_uid);
	n->di_gid = bswap32(o->di_gid);
}

void
ffs_dinode2_swap(struct ufs2_dinode *o, struct ufs2_dinode *n)
{
	size_t i;

	n->di_mode = bswap16(o->di_mode);
	n->di_nlink = bswap16(o->di_nlink);
	n->di_uid = bswap32(o->di_uid);
	n->di_gid = bswap32(o->di_gid);
	n->di_blksize = bswap32(o->di_blksize);
	n->di_size = bswap64(o->di_size);
	n->di_blocks = bswap64(o->di_blocks);
	n->di_atime = bswap64(o->di_atime);
	n->di_atimensec = bswap32(o->di_atimensec);
	n->di_mtime = bswap64(o->di_mtime);
	n->di_mtimensec = bswap32(o->di_mtimensec);
	n->di_ctime = bswap64(o->di_ctime);
	n->di_ctimensec = bswap32(o->di_ctimensec);
	n->di_birthtime = bswap64(o->di_birthtime);
	n->di_birthnsec = bswap32(o->di_birthnsec);
	n->di_gen = bswap32(o->di_gen);
	n->di_kernflags = bswap32(o->di_kernflags);
	n->di_flags = bswap32(o->di_flags);
	n->di_extsize = bswap32(o->di_extsize);
	/* Swap these here, unlike kernel version .*/
	for (i = 0; i < UFS_NXADDR; i++)
		n->di_extb[i] = bswap64(o->di_extb[i]);
	for (i = 0; i < UFS_NDADDR; i++)
		n->di_db[i] = bswap64(o->di_db[i]);
	for (i = 0; i < UFS_NIADDR; i++)
		n->di_ib[i] = bswap64(o->di_ib[i]);
}

cvs diff -r1.7 -r1.8 src/sys/lib/libsa/ffsv1.c (expand / switch to unified diff)

--- src/sys/lib/libsa/ffsv1.c 2019/06/24 13:58:24 1.7
+++ src/sys/lib/libsa/ffsv1.c 2021/05/27 06:54:44 1.8
@@ -1,22 +1,26 @@ @@ -1,22 +1,26 @@
1/* $NetBSD: ffsv1.c,v 1.7 2019/06/24 13:58:24 pgoyette Exp $ */ 1/* $NetBSD: ffsv1.c,v 1.8 2021/05/27 06:54:44 mrg Exp $ */
2 2
3#define LIBSA_FFSv1 3#define LIBSA_FFSv1
4 4
5#define ufs_open ffsv1_open 5#define ufs_open ffsv1_open
6#define ufs_close ffsv1_close 6#define ufs_close ffsv1_close
7#define ufs_read ffsv1_read 7#define ufs_read ffsv1_read
8#define ufs_write ffsv1_write 8#define ufs_write ffsv1_write
9#define ufs_seek ffsv1_seek 9#define ufs_seek ffsv1_seek
10#define ufs_stat ffsv1_stat 10#define ufs_stat ffsv1_stat
11#if defined(LIBSA_ENABLE_LS_OP) 11#if defined(LIBSA_ENABLE_LS_OP)
12#define ufs_ls ffsv1_ls 12#define ufs_ls ffsv1_ls
13#endif 13#endif
14 14
15#define ufs_dinode ufs1_dinode 15#define ufs_dinode ufs1_dinode
 16#define ufs_dinode_swap ffs_dinode1_swap
 17#define ufs_indp_swap bswap32
16#define indp_t int32_t 18#define indp_t int32_t
17 19
 20#define FS_MAGIC FS_UFS1_MAGIC
 21
18#if 0 22#if 0
19#define FSMOD "wapbl/ufs/ffs" 23#define FSMOD "wapbl/ufs/ffs"
20#endif 24#endif
21 25
22#include "ufs.c" 26#include "ufs.c"

cvs diff -r1.7 -r1.8 src/sys/lib/libsa/ffsv2.c (expand / switch to unified diff)

--- src/sys/lib/libsa/ffsv2.c 2019/06/24 13:58:24 1.7
+++ src/sys/lib/libsa/ffsv2.c 2021/05/27 06:54:44 1.8
@@ -1,22 +1,26 @@ @@ -1,22 +1,26 @@
1/* $NetBSD: ffsv2.c,v 1.7 2019/06/24 13:58:24 pgoyette Exp $ */ 1/* $NetBSD: ffsv2.c,v 1.8 2021/05/27 06:54:44 mrg Exp $ */
2 2
3#define LIBSA_FFSv2 3#define LIBSA_FFSv2
4 4
5#define ufs_open ffsv2_open 5#define ufs_open ffsv2_open
6#define ufs_close ffsv2_close 6#define ufs_close ffsv2_close
7#define ufs_read ffsv2_read 7#define ufs_read ffsv2_read
8#define ufs_write ffsv2_write 8#define ufs_write ffsv2_write
9#define ufs_seek ffsv2_seek 9#define ufs_seek ffsv2_seek
10#define ufs_stat ffsv2_stat 10#define ufs_stat ffsv2_stat
11#if defined(LIBSA_ENABLE_LS_OP) 11#if defined(LIBSA_ENABLE_LS_OP)
12#define ufs_ls ffsv2_ls 12#define ufs_ls ffsv2_ls
13#endif 13#endif
14 14
15#define ufs_dinode ufs2_dinode 15#define ufs_dinode ufs2_dinode
 16#define ufs_dinode_swap ffs_dinode2_swap
 17#define ufs_indp_swap bswap64
16#define indp_t int64_t 18#define indp_t int64_t
17 19
 20#define FS_MAGIC FS_UFS2_MAGIC
 21
18#if 0 22#if 0
19#define FSMOD "wapbl/ufs/ffs" 23#define FSMOD "wapbl/ufs/ffs"
20#endif 24#endif
21 25
22#include "ufs.c" 26#include "ufs.c"

cvs diff -r1.14 -r1.15 src/sys/lib/libsa/lfsv1.c (expand / switch to unified diff)

--- src/sys/lib/libsa/lfsv1.c 2015/08/12 18:28:01 1.14
+++ src/sys/lib/libsa/lfsv1.c 2021/05/27 06:54:44 1.15
@@ -1,30 +1,32 @@ @@ -1,30 +1,32 @@
1/* $NetBSD: lfsv1.c,v 1.14 2015/08/12 18:28:01 dholland Exp $ */ 1/* $NetBSD: lfsv1.c,v 1.15 2021/05/27 06:54:44 mrg Exp $ */
2 2
3#define LIBSA_LFS 3#define LIBSA_LFS
4#define REQUIRED_LFS_VERSION 1 4#define REQUIRED_LFS_VERSION 1
5 5
6#define ufs_open lfsv1_open 6#define ufs_open lfsv1_open
7#define ufs_close lfsv1_close 7#define ufs_close lfsv1_close
8#define ufs_read lfsv1_read 8#define ufs_read lfsv1_read
9#define ufs_write lfsv1_write 9#define ufs_write lfsv1_write
10#define ufs_seek lfsv1_seek 10#define ufs_seek lfsv1_seek
11#define ufs_stat lfsv1_stat 11#define ufs_stat lfsv1_stat
12#if defined(LIBSA_ENABLE_LS_OP) 12#if defined(LIBSA_ENABLE_LS_OP)
13#define ufs_ls lfsv1_ls 13#define ufs_ls lfsv1_ls
14#endif 14#endif
15 15
16#define ufs_dinode lfs32_dinode 16#define ufs_dinode lfs32_dinode
17 17
18#define fs_bsize lfs_dlfs_u.u_32.dlfs_ibsize 18#define fs_bsize lfs_dlfs_u.u_32.dlfs_ibsize
19 19
20#define INOPBx(fs) LFS_INOPB(fs) 20#define INOPBx(fs) LFS_INOPB(fs)
21 21
22#define UFS_NINDIR LFS_NINDIR 22#define UFS_NINDIR LFS_NINDIR
23#define ufs_blkoff(a, b) lfs_blkoff((a), (b)) 23#define ufs_blkoff(a, b) lfs_blkoff((a), (b))
24#define ufs_lblkno(a, b) lfs_lblkno((a), (b)) 24#define ufs_lblkno(a, b) lfs_lblkno((a), (b))
25#define dblksize(a, b, c) lfs_dblksize((a), (b), (c)) 25#define dblksize(a, b, c) lfs_dblksize((a), (b), (c))
26#define FSBTODB(fs, daddr) (daddr) /* LFSv1 uses sectors for addresses */ 26#define FSBTODB(fs, daddr) (daddr) /* LFSv1 uses sectors for addresses */
27 27
 28#define FS_MAGIC LFS_MAGIC
 29
28#define FSMOD "lfs" 30#define FSMOD "lfs"
29 31
30#include "lib/libsa/ufs.c" 32#include "lib/libsa/ufs.c"

cvs diff -r1.14 -r1.15 src/sys/lib/libsa/lfsv2.c (expand / switch to unified diff)

--- src/sys/lib/libsa/lfsv2.c 2015/08/12 18:28:01 1.14
+++ src/sys/lib/libsa/lfsv2.c 2021/05/27 06:54:44 1.15
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: lfsv2.c,v 1.14 2015/08/12 18:28:01 dholland Exp $ */ 1/* $NetBSD: lfsv2.c,v 1.15 2021/05/27 06:54:44 mrg Exp $ */
2 2
3#define LIBSA_LFS 3#define LIBSA_LFS
4#define REQUIRED_LFS_VERSION 2 4#define REQUIRED_LFS_VERSION 2
5 5
6#define ufs_open lfsv2_open 6#define ufs_open lfsv2_open
7#define ufs_close lfsv2_close 7#define ufs_close lfsv2_close
8#define ufs_read lfsv2_read 8#define ufs_read lfsv2_read
9#define ufs_write lfsv2_write 9#define ufs_write lfsv2_write
10#define ufs_seek lfsv2_seek 10#define ufs_seek lfsv2_seek
11#define ufs_stat lfsv2_stat 11#define ufs_stat lfsv2_stat
12#if defined(LIBSA_ENABLE_LS_OP) 12#if defined(LIBSA_ENABLE_LS_OP)
13#define ufs_ls lfsv2_ls 13#define ufs_ls lfsv2_ls
14#endif 14#endif
@@ -19,16 +19,18 @@ @@ -19,16 +19,18 @@
19 19
20#ifdef LFS_IFILE_FRAG_ADDRESSING /* XXX see sys/ufs/lfs/ -- not tested */ 20#ifdef LFS_IFILE_FRAG_ADDRESSING /* XXX see sys/ufs/lfs/ -- not tested */
21#define INOPBx(fs) LFS_INOPF(fs) 21#define INOPBx(fs) LFS_INOPF(fs)
22#else 22#else
23#define INOPBx(fs) LFS_INOPB(fs) 23#define INOPBx(fs) LFS_INOPB(fs)
24#endif 24#endif
25 25
26#define UFS_NINDIR LFS_NINDIR 26#define UFS_NINDIR LFS_NINDIR
27#define ufs_blkoff(a, b) lfs_blkoff((a), (b)) 27#define ufs_blkoff(a, b) lfs_blkoff((a), (b))
28#define ufs_lblkno(a, b) lfs_lblkno((a), (b)) 28#define ufs_lblkno(a, b) lfs_lblkno((a), (b))
29#define dblksize(a, b, c) lfs_dblksize((a), (b), (c)) 29#define dblksize(a, b, c) lfs_dblksize((a), (b), (c))
30#define FSBTODB(a, b) LFS_FSBTODB((a), (b)) 30#define FSBTODB(a, b) LFS_FSBTODB((a), (b))
31 31
 32#define FS_MAGIC LFS_MAGIC
 33
32#define FSMOD "lfs" 34#define FSMOD "lfs"
33 35
34#include "lib/libsa/ufs.c" 36#include "lib/libsa/ufs.c"

cvs diff -r1.79 -r1.80 src/sys/lib/libsa/ufs.c (expand / switch to unified diff)

--- src/sys/lib/libsa/ufs.c 2021/05/12 08:45:28 1.79
+++ src/sys/lib/libsa/ufs.c 2021/05/27 06:54:44 1.80
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: ufs.c,v 1.79 2021/05/12 08:45:28 mrg Exp $ */ 1/* $NetBSD: ufs.c,v 1.80 2021/05/27 06:54:44 mrg Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1993 4 * Copyright (c) 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to Berkeley by 7 * This code is derived from software contributed to Berkeley by
8 * The Mach Operating System project at Carnegie-Mellon University. 8 * The Mach Operating System project at Carnegie-Mellon University.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -90,91 +90,100 @@ @@ -90,91 +90,100 @@
90/* If this file is compiled by itself, build ufs (aka ffsv1) support */ 90/* If this file is compiled by itself, build ufs (aka ffsv1) support */
91#if !defined(LIBSA_FFSv2) && !defined(LIBSA_LFS) 91#if !defined(LIBSA_FFSv2) && !defined(LIBSA_LFS)
92#define LIBSA_FFSv1 92#define LIBSA_FFSv1
93#endif 93#endif
94 94
95#if defined(LIBSA_FS_SINGLECOMPONENT) && !defined(LIBSA_NO_FS_SYMLINK) 95#if defined(LIBSA_FS_SINGLECOMPONENT) && !defined(LIBSA_NO_FS_SYMLINK)
96#define LIBSA_NO_FS_SYMLINK 96#define LIBSA_NO_FS_SYMLINK
97#endif 97#endif
98#if defined(COMPAT_UFS) && defined(LIBSA_NO_COMPAT_UFS) 98#if defined(COMPAT_UFS) && defined(LIBSA_NO_COMPAT_UFS)
99#undef COMPAT_UFS 99#undef COMPAT_UFS
100#endif 100#endif
101 101
102#ifdef LIBSA_LFS 102#ifdef LIBSA_LFS
 103/* Do not (yet) support FFS_EI on LFS. */
 104#undef LIBSA_FFS_EI
103/* 105/*
104 * In-core LFS superblock - just the on-disk one. 106 * In-core LFS superblock - just the on-disk one.
105 */ 107 */
106struct salfs { 108struct salfs {
107 union { 109 union {
108 struct dlfs u_32; 110 struct dlfs u_32;
109 struct dlfs64 u_64; 111 struct dlfs64 u_64;
110 } lfs_dlfs_u; 112 } lfs_dlfs_u;
111 unsigned lfs_is64 : 1, 113 unsigned lfs_is64 : 1,
112 lfs_dobyteswap : 1, 114 lfs_dobyteswap : 1,
113 lfs_hasolddirfmt : 1; 115 lfs_hasolddirfmt : 1;
114}; 116};
115/* Get lfs accessors that use struct salfs. */ 117/* Get lfs accessors that use struct salfs. */
116#define STRUCT_LFS struct salfs 118#define STRUCT_LFS struct salfs
117#include <ufs/lfs/lfs_accessors.h> 119#include <ufs/lfs/lfs_accessors.h>
118 120
119/* override this to avoid a mess with the dinode accessors */ 121/* override this to avoid a mess with the dinode accessors */
120#define lfs_dino_getsize(fs, dp) ((dp)->di_size) 122#define lfs_dino_getsize(fs, dp) ((dp)->di_size)
121 123
122typedef struct salfs FS; 124typedef struct salfs FS;
123#define fs_magic lfs_dlfs_u.u_32.dlfs_magic 125#define fs_magic lfs_dlfs_u.u_32.dlfs_magic
124#define fs_maxsymlinklen lfs_dlfs_u.u_32.dlfs_maxsymlinklen 126#define fs_maxsymlinklen lfs_dlfs_u.u_32.dlfs_maxsymlinklen
125#define lfs_version lfs_dlfs_u.u_32.dlfs_version 127#define lfs_version lfs_dlfs_u.u_32.dlfs_version
126 128
127#define FS_MAGIC LFS_MAGIC 
128#define SBLOCKSIZE LFS_SBPAD 129#define SBLOCKSIZE LFS_SBPAD
129#define SBLOCKOFFSET LFS_LABELPAD 130#define SBLOCKOFFSET LFS_LABELPAD
130#else 131#else
131/* NB ufs2 doesn't use the common superblock code... */ 132/* NB ufs2 doesn't use the common superblock code... */
132typedef struct fs FS; 133typedef struct fs FS;
133#define FS_MAGIC FS_UFS1_MAGIC 
134#define SBLOCKOFFSET SBLOCK_UFS1 134#define SBLOCKOFFSET SBLOCK_UFS1
135#endif 135#endif
136 136
137#if defined(LIBSA_NO_TWIDDLE) 137#if defined(LIBSA_NO_TWIDDLE)
138#define twiddle() 138#define twiddle()
139#endif 139#endif
140 140
141#undef cgstart 141#undef cgstart
142#if defined(LIBSA_FFSv2) 142#if defined(LIBSA_FFSv2)
143#define cgstart(fc, c) cgstart_ufs2((fs), (c)) 143#define cgstart(fc, c) cgstart_ufs2((fs), (c))
144#else 144#else
145#define cgstart(fc, c) cgstart_ufs1((fs), (c)) 145#define cgstart(fc, c) cgstart_ufs1((fs), (c))
146#endif 146#endif
147 147
148#ifndef ufs_dinode 148#ifndef ufs_dinode
149#define ufs_dinode ufs1_dinode 149#define ufs_dinode ufs1_dinode
150#endif 150#endif
151#ifndef indp_t 151#ifndef indp_t
152#define indp_t int32_t 152#define indp_t int32_t
153#endif 153#endif
154typedef uint32_t ino32_t; 154typedef uint32_t ino32_t;
155 155
156#ifndef FSBTODB 156#ifndef FSBTODB
157#define FSBTODB(fs, indp) FFS_FSBTODB(fs, indp) 157#define FSBTODB(fs, indp) FFS_FSBTODB(fs, indp)
158#endif 158#endif
 159#ifndef FS_MAGIC
 160#define FS_MAGIC FS_UFS1_MAGIC
 161#endif
159#ifndef UFS_NINDIR 162#ifndef UFS_NINDIR
160#define UFS_NINDIR FFS_NINDIR 163#define UFS_NINDIR FFS_NINDIR
161#endif 164#endif
162#ifndef ufs_blkoff 165#ifndef ufs_blkoff
163#define ufs_blkoff ffs_blkoff 166#define ufs_blkoff ffs_blkoff
164#endif 167#endif
165#ifndef ufs_lblkno 168#ifndef ufs_lblkno
166#define ufs_lblkno ffs_lblkno 169#define ufs_lblkno ffs_lblkno
167#endif 170#endif
 171#ifndef ufs_dinode_swap
 172#define ufs_dinode_swap ffs_dinode1_swap
 173#endif
 174#ifndef ufs_indp_swap
 175#define ufs_indp_swap bswap32
 176#endif
168 177
169/* 178/*
170 * To avoid having a lot of filesystem-block sized buffers lurking (which 179 * To avoid having a lot of filesystem-block sized buffers lurking (which
171 * could be 32k) we only keep a few entries of the indirect block map. 180 * could be 32k) we only keep a few entries of the indirect block map.
172 * With 8k blocks, 2^8 blocks is ~500k so we reread the indirect block 181 * With 8k blocks, 2^8 blocks is ~500k so we reread the indirect block
173 * ~13 times pulling in a 6M kernel. 182 * ~13 times pulling in a 6M kernel.
174 * The cache size must be smaller than the smallest filesystem block, 183 * The cache size must be smaller than the smallest filesystem block,
175 * so LN2_IND_CACHE_SZ <= 9 (UFS2 and 4k blocks). 184 * so LN2_IND_CACHE_SZ <= 9 (UFS2 and 4k blocks).
176 */ 185 */
177#define LN2_IND_CACHE_SZ 6 186#define LN2_IND_CACHE_SZ 6
178#define IND_CACHE_SZ (1 << LN2_IND_CACHE_SZ) 187#define IND_CACHE_SZ (1 << LN2_IND_CACHE_SZ)
179#define IND_CACHE_MASK (IND_CACHE_SZ - 1) 188#define IND_CACHE_MASK (IND_CACHE_SZ - 1)
180 189
@@ -182,36 +191,85 @@ typedef uint32_t ino32_t; @@ -182,36 +191,85 @@ typedef uint32_t ino32_t;
182 * In-core open file. 191 * In-core open file.
183 */ 192 */
184struct file { 193struct file {
185 off_t f_seekp; /* seek pointer */ 194 off_t f_seekp; /* seek pointer */
186 FS *f_fs; /* pointer to super-block */ 195 FS *f_fs; /* pointer to super-block */
187 struct ufs_dinode f_di; /* copy of on-disk inode */ 196 struct ufs_dinode f_di; /* copy of on-disk inode */
188 uint f_nishift; /* for blocks in indirect block */ 197 uint f_nishift; /* for blocks in indirect block */
189 indp_t f_ind_cache_block; 198 indp_t f_ind_cache_block;
190 indp_t f_ind_cache[IND_CACHE_SZ]; 199 indp_t f_ind_cache[IND_CACHE_SZ];
191 200
192 char *f_buf; /* buffer for data block */ 201 char *f_buf; /* buffer for data block */
193 size_t f_buf_size; /* size of data block */ 202 size_t f_buf_size; /* size of data block */
194 daddr_t f_buf_blkno; /* block number of data block */ 203 daddr_t f_buf_blkno; /* block number of data block */
 204#if defined(LIBSA_FFS_EI)
 205 bool f_swapped; /* FFS is other endian */
 206#endif
195}; 207};
196 208
197static int read_inode(ino32_t, struct open_file *); 209static int read_inode(ino32_t, struct open_file *);
198static int block_map(struct open_file *, indp_t, indp_t *); 210static int block_map(struct open_file *, indp_t, indp_t *);
199static int buf_read_file(struct open_file *, char **, size_t *); 211static int buf_read_file(struct open_file *, char **, size_t *);
200static int search_directory(const char *, int, struct open_file *, ino32_t *); 212static int search_directory(const char *, int, struct open_file *, ino32_t *);
201#ifdef LIBSA_FFSv1 213#ifdef LIBSA_FFSv1
202static void ffs_oldfscompat(FS *); 214static void ffs_oldfscompat(FS *);
203#endif 215#endif
204 216
 217static __inline__ bool
 218ffs_is_magic(FS *fs)
 219{
 220 return fs->fs_magic == FS_MAGIC;
 221}
 222
 223static __inline__ void
 224ffs_fix_magic_swapped(struct file *fp, FS *fs)
 225{
 226#ifdef LIBSA_FFS_EI
 227 fp->f_swapped = fs->fs_magic == bswap32(FS_MAGIC);
 228 if (fp->f_swapped)
 229{
 230 ffs_sb_swap(fs, fs);
 231}
 232#endif
 233}
 234
 235#ifdef LIBSA_FFS_EI
 236static __inline__ bool
 237ffs_swapped(struct file *fp)
 238{
 239 return fp->f_swapped;
 240}
 241#endif
 242
 243static __inline__ uint16_t
 244ffs_get_reclen(struct file *fp, struct direct *dp)
 245{
 246#ifdef LIBSA_FFS_EI
 247 if (ffs_swapped(fp))
 248 return bswap16(dp->d_reclen);
 249#endif
 250 return dp->d_reclen;
 251}
 252
 253static __inline__ uint32_t
 254ffs_get_ino(struct file *fp, struct direct *dp)
 255{
 256#ifdef LIBSA_FFS_EI
 257 if (ffs_swapped(fp))
 258 return bswap32(dp->d_ino);
 259#endif
 260 return dp->d_ino;
 261}
 262
205 263
206#ifdef LIBSA_LFS 264#ifdef LIBSA_LFS
207/* 265/*
208 * Find an inode's block. Look it up in the ifile. Whee! 266 * Find an inode's block. Look it up in the ifile. Whee!
209 */ 267 */
210static int 268static int
211find_inode_sector(ino32_t inumber, struct open_file *f, daddr_t *isp) 269find_inode_sector(ino32_t inumber, struct open_file *f, daddr_t *isp)
212{ 270{
213 struct file *fp = (struct file *)f->f_fsdata; 271 struct file *fp = (struct file *)f->f_fsdata;
214 FS *fs = fp->f_fs; 272 FS *fs = fp->f_fs;
215 daddr_t ifileent_blkno; 273 daddr_t ifileent_blkno;
216 char *ent_in_buf; 274 char *ent_in_buf;
217 size_t buf_after_ent; 275 size_t buf_after_ent;
@@ -281,26 +339,30 @@ read_inode(ino32_t inumber, struct open_ @@ -281,26 +339,30 @@ read_inode(ino32_t inumber, struct open_
281 return EIO; 339 return EIO;
282 340
283#ifdef LIBSA_LFS 341#ifdef LIBSA_LFS
284 cnt = INOPBx(fs); 342 cnt = INOPBx(fs);
285 dip = (struct ufs_dinode *)buf + (cnt - 1); 343 dip = (struct ufs_dinode *)buf + (cnt - 1);
286 for (; dip->di_inumber != inumber; --dip) { 344 for (; dip->di_inumber != inumber; --dip) {
287 /* kernel code panics, but boot blocks which panic are Bad. */ 345 /* kernel code panics, but boot blocks which panic are Bad. */
288 if (--cnt == 0) 346 if (--cnt == 0)
289 return EINVAL; 347 return EINVAL;
290 } 348 }
291 fp->f_di = *dip; 349 fp->f_di = *dip;
292#else 350#else
293 fp->f_di = ((struct ufs_dinode *)buf)[ino_to_fsbo(fs, inumber)]; 351 fp->f_di = ((struct ufs_dinode *)buf)[ino_to_fsbo(fs, inumber)];
 352#ifdef LIBSA_FFS_EI
 353 if (ffs_swapped(fp))
 354 ufs_dinode_swap(&fp->f_di, &fp->f_di);
 355#endif
294#endif 356#endif
295 357
296 /* 358 /*
297 * Clear out the old buffers 359 * Clear out the old buffers
298 */ 360 */
299 fp->f_ind_cache_block = ~0; 361 fp->f_ind_cache_block = ~0;
300 fp->f_buf_blkno = -1; 362 fp->f_buf_blkno = -1;
301 return rc; 363 return rc;
302} 364}
303 365
304/* 366/*
305 * Given an offset in a file, find the disk block number that 367 * Given an offset in a file, find the disk block number that
306 * contains that block. 368 * contains that block.
@@ -377,35 +439,50 @@ block_map(struct open_file *f, indp_t fi @@ -377,35 +439,50 @@ block_map(struct open_file *f, indp_t fi
377 /* 439 /*
378 * If we were feeling brave, we could work out the number 440 * If we were feeling brave, we could work out the number
379 * of the disk sector and read a single disk sector instead 441 * of the disk sector and read a single disk sector instead
380 * of a filesystem block. 442 * of a filesystem block.
381 * However we don't do this very often anyway... 443 * However we don't do this very often anyway...
382 */ 444 */
383 rc = DEV_STRATEGY(f->f_dev)(f->f_devdata, F_READ, 445 rc = DEV_STRATEGY(f->f_dev)(f->f_devdata, F_READ,
384 FSBTODB(fp->f_fs, ind_block_num), fs->fs_bsize, 446 FSBTODB(fp->f_fs, ind_block_num), fs->fs_bsize,
385 buf, &rsize); 447 buf, &rsize);
386 if (rc) 448 if (rc)
387 return rc; 449 return rc;
388 if (rsize != (size_t)fs->fs_bsize) 450 if (rsize != (size_t)fs->fs_bsize)
389 return EIO; 451 return EIO;
390 ind_block_num = buf[file_block >> level]; 452#ifdef LIBSA_FFS_EI
 453 if (ffs_swapped(fp))
 454 ind_block_num = ufs_indp_swap(buf[file_block >> level]);
 455 else
 456#endif
 457 ind_block_num = buf[file_block >> level];
391 if (level == 0) 458 if (level == 0)
392 break; 459 break;
393 file_block &= (1 << level) - 1; 460 file_block &= (1 << level) - 1;
394 } 461 }
395 462
396 /* Save the part of the block that contains this sector */ 463 /* Save the part of the block that contains this sector */
397 memcpy(fp->f_ind_cache, &buf[file_block & ~IND_CACHE_MASK], 464#if defined(LIBSA_FFS_EI)
398 IND_CACHE_SZ * sizeof fp->f_ind_cache[0]); 465 if (ffs_swapped(fp)) {
 466 size_t i;
 467
 468 for (i = 0; i < IND_CACHE_SZ; i++) {
 469 fp->f_ind_cache[i] = ufs_indp_swap(
 470 buf[(file_block & ~IND_CACHE_MASK) + i]);
 471 }
 472 } else
 473#endif
 474 memcpy(fp->f_ind_cache, &buf[file_block & ~IND_CACHE_MASK],
 475 IND_CACHE_SZ * sizeof fp->f_ind_cache[0]);
399 fp->f_ind_cache_block = ind_cache; 476 fp->f_ind_cache_block = ind_cache;
400 477
401 *disk_block_p = ind_block_num; 478 *disk_block_p = ind_block_num;
402 479
403 return 0; 480 return 0;
404} 481}
405 482
406/* 483/*
407 * Read a portion of a file into an internal buffer. 484 * Read a portion of a file into an internal buffer.
408 * Return the location in the buffer and the amount in the buffer. 485 * Return the location in the buffer and the amount in the buffer.
409 */ 486 */
410static int 487static int
411buf_read_file(struct open_file *f, char **buf_p, size_t *size_p) 488buf_read_file(struct open_file *f, char **buf_p, size_t *size_p)
@@ -477,82 +554,91 @@ search_directory(const char *name, int l @@ -477,82 +554,91 @@ search_directory(const char *name, int l
477 char *buf; 554 char *buf;
478 size_t buf_size; 555 size_t buf_size;
479 int namlen; 556 int namlen;
480 int rc; 557 int rc;
481 558
482 fp->f_seekp = 0; 559 fp->f_seekp = 0;
483 while (fp->f_seekp < (off_t)fp->f_di.di_size) { 560 while (fp->f_seekp < (off_t)fp->f_di.di_size) {
484 rc = buf_read_file(f, &buf, &buf_size); 561 rc = buf_read_file(f, &buf, &buf_size);
485 if (rc) 562 if (rc)
486 return rc; 563 return rc;
487 564
488 dp = (struct direct *)buf; 565 dp = (struct direct *)buf;
489 edp = (struct direct *)(buf + buf_size); 566 edp = (struct direct *)(buf + buf_size);
490 for (;dp < edp; dp = (void *)((char *)dp + dp->d_reclen)) { 567 for (; dp < edp;
491 if (dp->d_reclen <= 0) 568 dp = (void *)((char *)dp + ffs_get_reclen(fp, dp))) {
 569 if (ffs_get_reclen(fp, dp) <= 0)
492 break; 570 break;
493 if (dp->d_ino == (ino32_t)0) 571 if (ffs_get_ino(fp, dp) == (ino32_t)0)
494 continue; 572 continue;
495#if BYTE_ORDER == LITTLE_ENDIAN 573#if BYTE_ORDER == LITTLE_ENDIAN
496 if (fp->f_fs->fs_maxsymlinklen <= 0) 574 if (fp->f_fs->fs_maxsymlinklen <= 0)
497 namlen = dp->d_type; 575 namlen = dp->d_type;
498 else 576 else
499#endif 577#endif
500 namlen = dp->d_namlen; 578 namlen = dp->d_namlen;
501 if (namlen == length && 579 if (namlen == length &&
502 !memcmp(name, dp->d_name, length)) { 580 !memcmp(name, dp->d_name, length)) {
503 /* found entry */ 581 /* found entry */
504 *inumber_p = dp->d_ino; 582 *inumber_p = ffs_get_ino(fp, dp);
505 return 0; 583 return 0;
506 } 584 }
507 } 585 }
508 fp->f_seekp += buf_size; 586 fp->f_seekp += buf_size;
509 } 587 }
510 return ENOENT; 588 return ENOENT;
511} 589}
512 590
513static __inline__ int 591static __inline__ int
514ffs_find_superblock(struct open_file *f, FS *fs) 592ffs_find_superblock(struct open_file *f, FS *fs)
515{ 593{
 594 struct file *fp = (struct file *)f->f_fsdata;
516 int rc; 595 int rc;
517 size_t buf_size; 596 size_t buf_size;
518#ifdef LIBSA_FFSv2 597#ifdef LIBSA_FFSv2
519 static daddr_t sblock_try[] = SBLOCKSEARCH; 598 static daddr_t sblock_try[] = SBLOCKSEARCH;
520 int i; 599 int i;
521 600
522 for (i = 0; sblock_try[i] != -1; i++) { 601 for (i = 0; sblock_try[i] != -1; i++) {
523 rc = DEV_STRATEGY(f->f_dev)(f->f_devdata, F_READ, 602 rc = DEV_STRATEGY(f->f_dev)(f->f_devdata, F_READ,
524 sblock_try[i] / DEV_BSIZE, SBLOCKSIZE, fs, &buf_size); 603 sblock_try[i] / DEV_BSIZE, SBLOCKSIZE, fs, &buf_size);
525 if (rc != 0 || buf_size != SBLOCKSIZE) 604 if (rc)
526 return rc; 605 return rc;
 606 if (buf_size != SBLOCKSIZE)
 607 return EINVAL;
 608 ffs_fix_magic_swapped(fp, fs);
527 if (fs->fs_sblockloc != sblock_try[i]) 609 if (fs->fs_sblockloc != sblock_try[i])
528 /* an alternate superblock - try again */ 610 /* an alternate superblock - try again */
529 continue; 611 continue;
530 if (fs->fs_magic == FS_UFS2_MAGIC) { 612 if (ffs_is_magic(fs))
531 return 0; 613 return 0;
532 } 
533 } 614 }
534 return EINVAL; 615 return EINVAL;
535#else /* LIBSA_FFSv2 */ 616#else /* LIBSA_FFSv2 */
536 rc = DEV_STRATEGY(f->f_dev)(f->f_devdata, F_READ, 617 rc = DEV_STRATEGY(f->f_dev)(f->f_devdata, F_READ,
537 SBLOCKOFFSET / DEV_BSIZE, SBLOCKSIZE, fs, &buf_size); 618 SBLOCKOFFSET / DEV_BSIZE, SBLOCKSIZE, fs, &buf_size);
538 if (rc) 619 if (rc)
539 return rc; 620 return rc;
540 if (buf_size != SBLOCKSIZE || 621 if (buf_size != SBLOCKSIZE)
 622 return EINVAL;
 623 ffs_fix_magic_swapped(fp, fs);
 624
541#ifdef LIBSA_LFS 625#ifdef LIBSA_LFS
542 fs->lfs_version != REQUIRED_LFS_VERSION || 626 if (fs->lfs_version != REQUIRED_LFS_VERSION)
 627 return EINVAL;
543#endif 628#endif
544 fs->fs_magic != FS_MAGIC) 629 if (!ffs_is_magic(fs))
545 return EINVAL; 630 return EINVAL;
 631
546 return 0; 632 return 0;
547#endif /* !LIBSA_FFSv2 */ 633#endif /* !LIBSA_FFSv2 */
548} 634}
549 635
550/* 636/*
551 * Open a file. 637 * Open a file.
552 */ 638 */
553__compactcall int 639__compactcall int
554ufs_open(const char *path, struct open_file *f) 640ufs_open(const char *path, struct open_file *f)
555{ 641{
556#ifndef LIBSA_FS_SINGLECOMPONENT 642#ifndef LIBSA_FS_SINGLECOMPONENT
557 const char *cp, *ncp; 643 const char *cp, *ncp;
558 int c; 644 int c;
@@ -905,48 +991,49 @@ ufs_ls(struct open_file *f, const char * @@ -905,48 +991,49 @@ ufs_ls(struct open_file *f, const char *
905 fp->f_seekp = 0; 991 fp->f_seekp = 0;
906 while (fp->f_seekp < (off_t)fp->f_di.di_size) { 992 while (fp->f_seekp < (off_t)fp->f_di.di_size) {
907 struct direct *dp, *edp; 993 struct direct *dp, *edp;
908 int rc = buf_read_file(f, &buf, &buf_size); 994 int rc = buf_read_file(f, &buf, &buf_size);
909 if (rc) 995 if (rc)
910 goto out; 996 goto out;
911 /* some firmware might use block size larger than DEV_BSIZE */ 997 /* some firmware might use block size larger than DEV_BSIZE */
912 if (buf_size < UFS_DIRBLKSIZ) 998 if (buf_size < UFS_DIRBLKSIZ)
913 goto out; 999 goto out;
914 1000
915 dp = (struct direct *)buf; 1001 dp = (struct direct *)buf;
916 edp = (struct direct *)(buf + buf_size); 1002 edp = (struct direct *)(buf + buf_size);
917 1003
918 for (; dp < edp; dp = (void *)((char *)dp + dp->d_reclen)) { 1004 for (; dp < edp;
 1005 dp = (void *)((char *)dp + ffs_get_reclen(fp, dp))) {
919 const char *t; 1006 const char *t;
920 if (dp->d_ino == 0) 1007 if (ffs_get_ino(fp, dp) == 0)
921 continue; 1008 continue;
922 1009
923 if (dp->d_type >= NELEM(typestr) || 1010 if (dp->d_type >= NELEM(typestr) ||
924 !(t = typestr[dp->d_type])) { 1011 !(t = typestr[dp->d_type])) {
925 /* 1012 /*
926 * This does not handle "old" 1013 * This does not handle "old"
927 * filesystems properly. On little 1014 * filesystems properly. On little
928 * endian machines, we get a bogus 1015 * endian machines, we get a bogus
929 * type name if the namlen matches a 1016 * type name if the namlen matches a
930 * valid type identifier. We could 1017 * valid type identifier. We could
931 * check if we read namlen "0" and 1018 * check if we read namlen "0" and
932 * handle this case specially, if 1019 * handle this case specially, if
933 * there were a pressing need... 1020 * there were a pressing need...
934 */ 1021 */
935 printf("bad dir entry\n"); 1022 printf("bad dir entry\n");
936 goto out; 1023 goto out;
937 } 1024 }
938 lsadd(&names, pattern, dp->d_name, strlen(dp->d_name), 1025 lsadd(&names, pattern, dp->d_name, strlen(dp->d_name),
939 dp->d_ino, t); 1026 ffs_get_ino(fp, dp), t);
940 } 1027 }
941 fp->f_seekp += buf_size; 1028 fp->f_seekp += buf_size;
942 } 1029 }
943 lsprint(names); 1030 lsprint(names);
944out: lsfree(names); 1031out: lsfree(names);
945} 1032}
946#endif /* LIBSA_ENABLE_LS_OP */ 1033#endif /* LIBSA_ENABLE_LS_OP */
947 1034
948#ifdef LIBSA_FFSv1 1035#ifdef LIBSA_FFSv1
949/* 1036/*
950 * Sanity checks for old file systems. 1037 * Sanity checks for old file systems.
951 * 1038 *
952 * XXX - goes away some day. 1039 * XXX - goes away some day.

cvs diff -r1.10 -r1.11 src/sys/lib/libsa/ufs.h (expand / switch to unified diff)

--- src/sys/lib/libsa/ufs.h 2011/12/25 06:09:08 1.10
+++ src/sys/lib/libsa/ufs.h 2021/05/27 06:54:44 1.11
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: ufs.h,v 1.10 2011/12/25 06:09:08 tsutsui Exp $ */ 1/* $NetBSD: ufs.h,v 1.11 2021/05/27 06:54:44 mrg Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1993 4 * Copyright (c) 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -24,13 +24,21 @@ @@ -24,13 +24,21 @@
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE. 29 * SUCH DAMAGE.
30 * 30 *
31 * @(#)ufs.h 8.1 (Berkeley) 6/11/93 31 * @(#)ufs.h 8.1 (Berkeley) 6/11/93
32 */ 32 */
33 33
34FS_DEF(ufs); 34FS_DEF(ufs);
35FS_DEF(ffsv1); 35FS_DEF(ffsv1);
36FS_DEF(ffsv2); 36FS_DEF(ffsv2);
 37
 38/* in libsa's ffs_bswap.c */
 39struct fs;
 40struct ufs1_dinode;
 41struct ufs2_dinode;
 42void ffs_sb_swap(const struct fs *, struct fs *);
 43void ffs_dinode1_swap(struct ufs1_dinode *, struct ufs1_dinode *);
 44void ffs_dinode2_swap(struct ufs2_dinode *, struct ufs2_dinode *);

cvs diff -r1.20 -r1.21 src/sys/stand/efiboot/Makefile.efiboot (expand / switch to unified diff)

--- src/sys/stand/efiboot/Makefile.efiboot 2021/05/04 19:07:19 1.20
+++ src/sys/stand/efiboot/Makefile.efiboot 2021/05/27 06:54:45 1.21
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1# $NetBSD: Makefile.efiboot,v 1.20 2021/05/04 19:07:19 jmcneill Exp $ 1# $NetBSD: Makefile.efiboot,v 1.21 2021/05/27 06:54:45 mrg Exp $
2 2
3S= ${.CURDIR}/../../.. 3S= ${.CURDIR}/../../..
4 4
5NOMAN= # defined 5NOMAN= # defined
6NOPIE= # defined 6NOPIE= # defined
7NOLIBCSANITIZER=# defined 7NOLIBCSANITIZER=# defined
8NOSANITIZER= # defined 8NOSANITIZER= # defined
9NORELRO= # defined 9NORELRO= # defined
10PROG?= boot.efi 10PROG?= boot.efi
11NEWVERSWHAT?= "efiboot" 11NEWVERSWHAT?= "efiboot"
12 12
13EFIDIR= ${S}/external/bsd/gnu-efi/dist 13EFIDIR= ${S}/external/bsd/gnu-efi/dist
14GNUEFIARCH?= ${MACHINE_CPU} 14GNUEFIARCH?= ${MACHINE_CPU}
@@ -70,26 +70,28 @@ CPPFLAGS+= -DPROGRESS_FN=efi_progress @@ -70,26 +70,28 @@ CPPFLAGS+= -DPROGRESS_FN=efi_progress
70CPPFLAGS+= -Wall -Wmissing-prototypes 70CPPFLAGS+= -Wall -Wmissing-prototypes
71CPPFLAGS+= -Wno-pointer-sign 71CPPFLAGS+= -Wno-pointer-sign
72 72
73CPPFLAGS+= -DHEAP_VARIABLE 73CPPFLAGS+= -DHEAP_VARIABLE
74CPPFLAGS+= -DSUPPORT_CD9660 74CPPFLAGS+= -DSUPPORT_CD9660
75CPPFLAGS+= -D"devb2cdb(bno)=(bno)" 75CPPFLAGS+= -D"devb2cdb(bno)=(bno)"
76CPPFLAGS+= -DSUPPORT_DOSFS 76CPPFLAGS+= -DSUPPORT_DOSFS
77#CPPFLAGS+= -DSUPPORT_EXT2FS 77#CPPFLAGS+= -DSUPPORT_EXT2FS
78CPPFLAGS+= -DSUPPORT_BOOTP 78CPPFLAGS+= -DSUPPORT_BOOTP
79CPPFLAGS+= -DSUPPORT_DHCP 79CPPFLAGS+= -DSUPPORT_DHCP
80#CPPFLAGS+= -DSUPPORT_NFS 80#CPPFLAGS+= -DSUPPORT_NFS
81CPPFLAGS+= -DSUPPORT_TFTP 81CPPFLAGS+= -DSUPPORT_TFTP
82CPPFLAGS+= -DLIBSA_ENABLE_LS_OP 82CPPFLAGS+= -DLIBSA_ENABLE_LS_OP
 83CPPFLAGS+= -DLIBSA_FFS_EI
 84CPPFLAGS+= -DLIBSA_DISKLABEL_EI
83 85
84#CPPFLAGS+= -DEFIBOOT_DEBUG 86#CPPFLAGS+= -DEFIBOOT_DEBUG
85#CPPFLAGS+= -DARP_DEBUG 87#CPPFLAGS+= -DARP_DEBUG
86#CPPFLAGS+= -DBOOTP_DEBUG 88#CPPFLAGS+= -DBOOTP_DEBUG
87#CPPFLAGS+= -DNET_DEBUG 89#CPPFLAGS+= -DNET_DEBUG
88#CPPFLAGS+= -DNETIF_DEBUG 90#CPPFLAGS+= -DNETIF_DEBUG
89#CPPFLAGS+= -DNFS_DEBUG 91#CPPFLAGS+= -DNFS_DEBUG
90#CPPFLAGS+= -DRARP_DEBUG 92#CPPFLAGS+= -DRARP_DEBUG
91#CPPFLAGS+= -DRPC_DEBUG 93#CPPFLAGS+= -DRPC_DEBUG
92 94
93# Follow the suit of Makefile.kern.inc; needed for the lfs64 union 95# Follow the suit of Makefile.kern.inc; needed for the lfs64 union
94# accessors -- they don't actually dereference the resulting pointer, 96# accessors -- they don't actually dereference the resulting pointer,
95# just use it for type-checking. 97# just use it for type-checking.

cvs diff -r1.24 -r1.25 src/sys/stand/efiboot/version (expand / switch to unified diff)

--- src/sys/stand/efiboot/version 2021/05/26 09:42:36 1.24
+++ src/sys/stand/efiboot/version 2021/05/27 06:54:45 1.25
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1$NetBSD: version,v 1.24 2021/05/26 09:42:36 mrg Exp $ 1$NetBSD: version,v 1.25 2021/05/27 06:54:45 mrg Exp $
2 2
3NOTE ANY CHANGES YOU MAKE TO THE EFI BOOTLOADER HERE. The format of this 3NOTE ANY CHANGES YOU MAKE TO THE EFI BOOTLOADER HERE. The format of this
4file is important - make sure the entries are appended on end, last item 4file is important - make sure the entries are appended on end, last item
5is taken as the current. 5is taken as the current.
6 6
71.0: Initial version. 71.0: Initial version.
81.1: Add PXE booting support. 81.1: Add PXE booting support.
91.2: Add environment variable support. 91.2: Add environment variable support.
101.3: Add ACPI support. 101.3: Add ACPI support.
111.4: Add bootfile support. 111.4: Add bootfile support.
121.5: EFI runtime support. 121.5: EFI runtime support.
131.6: Add GPT support. 131.6: Add GPT support.
141.7: Add NFS support. 141.7: Add NFS support.
@@ -18,13 +18,14 @@ is taken as the current. @@ -18,13 +18,14 @@ is taken as the current.
181.11: Add full UEFI memory map to /chosen node. 181.11: Add full UEFI memory map to /chosen node.
191.12: Derive ACPI model string from SMBIOS. 191.12: Derive ACPI model string from SMBIOS.
201.13: Add rndseed support. 201.13: Add rndseed support.
211.14: Add EFI RNG support. 211.14: Add EFI RNG support.
221.15: Add module support. 221.15: Add module support.
232.0: Add boot.cfg support. 232.0: Add boot.cfg support.
242.1: Remove efiboot.plist support; support dtoverlay in boot.cfg. 242.1: Remove efiboot.plist support; support dtoverlay in boot.cfg.
252.2: Remove support for storing settings in EFI env vars. 252.2: Remove support for storing settings in EFI env vars.
262.3: EFI RT and GOP support for devicetree mode. 262.3: EFI RT and GOP support for devicetree mode.
272.4: Add ISO9660 support. 272.4: Add ISO9660 support.
282.5: Recognize the EFI system partion as fstype MSDOS. 282.5: Recognize the EFI system partion as fstype MSDOS.
292.6: Disable ACPI support when booting big endian kernels. 292.6: Disable ACPI support when booting big endian kernels.
302.7: Add basic support for booting from RAID1 volumes. 302.7: Add basic support for booting from RAID1 volumes.
 312.8: Add bi-endian disklabel and FFS support.