2017-11-26 02:00:33 +00:00
|
|
|
/*-
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
|
|
|
|
*
|
2002-07-01 01:45:03 +00:00
|
|
|
* Copyright (c) 2002 Juli Mallett. All rights reserved.
|
|
|
|
*
|
|
|
|
* This software was written by Juli Mallett <jmallett@FreeBSD.org> for the
|
|
|
|
* FreeBSD project. Redistribution and use in source and binary forms, with
|
|
|
|
* or without modification, are permitted provided that the following
|
|
|
|
* conditions are met:
|
|
|
|
*
|
|
|
|
* 1. Redistribution of source code must retain the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistribution 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.
|
|
|
|
*
|
|
|
|
* $FreeBSD$
|
|
|
|
*/
|
|
|
|
|
2002-08-22 23:35:35 +00:00
|
|
|
#ifndef __LIBUFS_H__
|
|
|
|
#define __LIBUFS_H__
|
|
|
|
|
2002-07-01 01:45:03 +00:00
|
|
|
/*
|
|
|
|
* libufs structures.
|
|
|
|
*/
|
2018-11-13 21:40:56 +00:00
|
|
|
union dinodep {
|
|
|
|
struct ufs1_dinode *dp1;
|
|
|
|
struct ufs2_dinode *dp2;
|
|
|
|
};
|
2002-07-01 01:45:03 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* userland ufs disk.
|
|
|
|
*/
|
|
|
|
struct uufsd {
|
|
|
|
const char *d_name; /* disk name */
|
|
|
|
int d_ufs; /* decimal UFS version */
|
|
|
|
int d_fd; /* raw device file descriptor */
|
|
|
|
long d_bsize; /* device bsize */
|
|
|
|
ufs2_daddr_t d_sblock; /* superblock location */
|
2010-04-24 07:05:35 +00:00
|
|
|
struct csum *d_sbcsum; /* Superblock summary info */
|
2002-07-01 01:45:03 +00:00
|
|
|
caddr_t d_inoblock; /* inode block */
|
Commit the 64-bit inode project.
Extend the ino_t, dev_t, nlink_t types to 64-bit ints. Modify
struct dirent layout to add d_off, increase the size of d_fileno
to 64-bits, increase the size of d_namlen to 16-bits, and change
the required alignment. Increase struct statfs f_mntfromname[] and
f_mntonname[] array length MNAMELEN to 1024.
ABI breakage is mitigated by providing compatibility using versioned
symbols, ingenious use of the existing padding in structures, and
by employing other tricks. Unfortunately, not everything can be
fixed, especially outside the base system. For instance, third-party
APIs which pass struct stat around are broken in backward and
forward incompatible ways.
Kinfo sysctl MIBs ABI is changed in backward-compatible way, but
there is no general mechanism to handle other sysctl MIBS which
return structures where the layout has changed. It was considered
that the breakage is either in the management interfaces, where we
usually allow ABI slip, or is not important.
Struct xvnode changed layout, no compat shims are provided.
For struct xtty, dev_t tty device member was reduced to uint32_t.
It was decided that keeping ABI compat in this case is more useful
than reporting 64-bit dev_t, for the sake of pstat.
Update note: strictly follow the instructions in UPDATING. Build
and install the new kernel with COMPAT_FREEBSD11 option enabled,
then reboot, and only then install new world.
Credits: The 64-bit inode project, also known as ino64, started life
many years ago as a project by Gleb Kurtsou (gleb). Kirk McKusick
(mckusick) then picked up and updated the patch, and acted as a
flag-waver. Feedback, suggestions, and discussions were carried
by Ed Maste (emaste), John Baldwin (jhb), Jilles Tjoelker (jilles),
and Rick Macklem (rmacklem). Kris Moore (kris) performed an initial
ports investigation followed by an exp-run by Antoine Brodin (antoine).
Essential and all-embracing testing was done by Peter Holm (pho).
The heavy lifting of coordinating all these efforts and bringing the
project to completion were done by Konstantin Belousov (kib).
Sponsored by: The FreeBSD Foundation (emaste, kib)
Differential revision: https://reviews.freebsd.org/D10439
2017-05-23 09:29:05 +00:00
|
|
|
uint32_t d_inomin; /* low inode (not ino_t for ABI compat) */
|
|
|
|
uint32_t d_inomax; /* high inode (not ino_t for ABI compat) */
|
2018-11-13 21:40:56 +00:00
|
|
|
union dinodep d_dp; /* pointer to currently active inode */
|
2002-07-01 01:45:03 +00:00
|
|
|
union {
|
|
|
|
struct fs d_fs; /* filesystem information */
|
|
|
|
char d_sb[MAXBSIZE];
|
|
|
|
/* superblock as buffer */
|
|
|
|
} d_sbunion;
|
2003-01-19 01:31:26 +00:00
|
|
|
union {
|
|
|
|
struct cg d_cg; /* cylinder group */
|
|
|
|
char d_buf[MAXBSIZE];
|
|
|
|
/* cylinder group storage */
|
|
|
|
} d_cgunion;
|
|
|
|
int d_ccg; /* current cylinder group */
|
2003-01-19 05:46:23 +00:00
|
|
|
int d_lcg; /* last cylinder group (in d_cg) */
|
2002-10-22 19:25:58 +00:00
|
|
|
const char *d_error; /* human readable disk error */
|
2003-01-19 00:43:17 +00:00
|
|
|
int d_mine; /* internal flags */
|
2002-07-01 01:45:03 +00:00
|
|
|
#define d_fs d_sbunion.d_fs
|
|
|
|
#define d_sb d_sbunion.d_sb
|
2003-01-19 01:31:26 +00:00
|
|
|
#define d_cg d_cgunion.d_cg
|
2002-07-01 01:45:03 +00:00
|
|
|
};
|
|
|
|
|
2011-02-12 12:46:00 +00:00
|
|
|
/*
|
|
|
|
* libufs macros (internal, non-exported).
|
|
|
|
*/
|
|
|
|
#ifdef _LIBUFS
|
|
|
|
/*
|
|
|
|
* Trace steps through libufs, to be used at entry and erroneous return.
|
|
|
|
*/
|
|
|
|
static inline void
|
|
|
|
ERROR(struct uufsd *u, const char *str)
|
|
|
|
{
|
|
|
|
|
|
|
|
#ifdef _LIBUFS_DEBUGGING
|
|
|
|
if (str != NULL) {
|
|
|
|
fprintf(stderr, "libufs: %s", str);
|
|
|
|
if (errno != 0)
|
|
|
|
fprintf(stderr, ": %s", strerror(errno));
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (u != NULL)
|
|
|
|
u->d_error = str;
|
|
|
|
}
|
|
|
|
#endif /* _LIBUFS */
|
|
|
|
|
2002-08-22 23:35:35 +00:00
|
|
|
__BEGIN_DECLS
|
|
|
|
|
2002-07-01 01:45:03 +00:00
|
|
|
/*
|
|
|
|
* libufs prototypes.
|
|
|
|
*/
|
|
|
|
|
2018-01-26 00:58:32 +00:00
|
|
|
/*
|
|
|
|
* ffs_subr.c
|
|
|
|
*/
|
|
|
|
void ffs_clrblock(struct fs *, u_char *, ufs1_daddr_t);
|
|
|
|
void ffs_clusteracct(struct fs *, struct cg *, ufs1_daddr_t, int);
|
|
|
|
void ffs_fragacct(struct fs *, int, int32_t [], int);
|
|
|
|
int ffs_isblock(struct fs *, u_char *, ufs1_daddr_t);
|
|
|
|
int ffs_isfreeblock(struct fs *, u_char *, ufs1_daddr_t);
|
|
|
|
void ffs_setblock(struct fs *, u_char *, ufs1_daddr_t);
|
|
|
|
int ffs_sbget(void *, struct fs **, off_t, char *,
|
|
|
|
int (*)(void *, off_t, void **, int));
|
|
|
|
int ffs_sbput(void *, struct fs *, off_t,
|
|
|
|
int (*)(void *, off_t, void *, int));
|
2018-12-11 22:14:37 +00:00
|
|
|
void ffs_update_dinode_ckhash(struct fs *, struct ufs2_dinode *);
|
|
|
|
int ffs_verify_dinode_ckhash(struct fs *, struct ufs2_dinode *);
|
2018-01-26 00:58:32 +00:00
|
|
|
|
Normally when an attempt is made to mount a UFS/FFS filesystem whose
superblock has a check-hash error, an error message noting the
superblock check-hash failure is printed and the mount fails. The
administrator then runs fsck to repair the filesystem and when
successful, the filesystem can once again be mounted.
This approach fails if the filesystem in question is a root filesystem
from which you are trying to boot. Here, the loader fails when trying
to access the filesystem to get the kernel to boot. So it is necessary
to allow the loader to ignore the superblock check-hash error and make
a best effort to read the kernel. The filesystem may be suffiently
corrupted that the read attempt fails, but there is no harm in trying
since the loader makes no attempt to write to the filesystem.
Once the kernel is loaded and starts to run, it attempts to mount its
root filesystem. Once again, failure means that it breaks to its prompt
to ask where to get its root filesystem. Unless you have an alternate
root filesystem, you are stuck.
Since the root filesystem is initially mounted read-only, it is
safe to make an attempt to mount the root filesystem with the failed
superblock check-hash. Thus, when asked to mount a root filesystem
with a failed superblock check-hash, the kernel prints a warning
message that the root filesystem superblock check-hash needs repair,
but notes that it is ignoring the error and proceeding. It does
mark the filesystem as needing an fsck which prevents it from being
enabled for writing until fsck has been run on it. The net effect
is that the reboot fails to single user, but at least at that point
the administrator has the tools at hand to fix the problem.
Reported by: Rick Macklem (rmacklem@)
Discussed with: Warner Losh (imp@)
Sponsored by: Netflix
2018-12-06 00:09:39 +00:00
|
|
|
/*
|
|
|
|
* Request standard superblock location in ffs_sbget
|
|
|
|
*/
|
|
|
|
#define STDSB -1 /* Fail if check-hash is bad */
|
|
|
|
#define STDSB_NOHASHFAIL -2 /* Ignore check-hash failure */
|
|
|
|
|
2002-07-01 01:45:03 +00:00
|
|
|
/*
|
|
|
|
* block.c
|
|
|
|
*/
|
|
|
|
ssize_t bread(struct uufsd *, ufs2_daddr_t, void *, size_t);
|
|
|
|
ssize_t bwrite(struct uufsd *, ufs2_daddr_t, const void *, size_t);
|
2007-12-16 18:02:37 +00:00
|
|
|
int berase(struct uufsd *, ufs2_daddr_t, ufs2_daddr_t);
|
2002-07-01 01:45:03 +00:00
|
|
|
|
2003-01-19 01:31:26 +00:00
|
|
|
/*
|
|
|
|
* cgroup.c
|
|
|
|
*/
|
2010-04-24 07:05:35 +00:00
|
|
|
ufs2_daddr_t cgballoc(struct uufsd *);
|
|
|
|
int cgbfree(struct uufsd *, ufs2_daddr_t, long);
|
|
|
|
ino_t cgialloc(struct uufsd *);
|
2018-01-17 17:58:24 +00:00
|
|
|
int cgget(struct uufsd *, int, struct cg *);
|
|
|
|
int cgput(struct uufsd *, struct cg *);
|
2003-01-19 01:31:26 +00:00
|
|
|
int cgread(struct uufsd *);
|
|
|
|
int cgread1(struct uufsd *, int);
|
2010-04-24 07:05:35 +00:00
|
|
|
int cgwrite(struct uufsd *);
|
2006-10-31 21:21:48 +00:00
|
|
|
int cgwrite1(struct uufsd *, int);
|
2003-01-19 01:31:26 +00:00
|
|
|
|
2002-07-01 01:45:03 +00:00
|
|
|
/*
|
|
|
|
* inode.c
|
|
|
|
*/
|
2018-11-13 21:40:56 +00:00
|
|
|
int getinode(struct uufsd *, union dinodep *, ino_t);
|
|
|
|
int putinode(struct uufsd *);
|
2002-07-01 01:45:03 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* sblock.c
|
|
|
|
*/
|
|
|
|
int sbread(struct uufsd *);
|
|
|
|
int sbwrite(struct uufsd *, int);
|
2018-01-26 00:58:32 +00:00
|
|
|
/* low level superblock read/write functions */
|
|
|
|
int sbget(int, struct fs **, off_t);
|
|
|
|
int sbput(int, struct fs *, int);
|
2002-07-01 01:45:03 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* type.c
|
|
|
|
*/
|
|
|
|
int ufs_disk_close(struct uufsd *);
|
|
|
|
int ufs_disk_fillout(struct uufsd *, const char *);
|
2003-01-23 21:32:56 +00:00
|
|
|
int ufs_disk_fillout_blank(struct uufsd *, const char *);
|
2003-01-29 23:19:46 +00:00
|
|
|
int ufs_disk_write(struct uufsd *);
|
2002-08-22 23:35:35 +00:00
|
|
|
|
2017-09-22 12:45:15 +00:00
|
|
|
/*
|
|
|
|
* crc32c.c
|
|
|
|
*/
|
|
|
|
uint32_t calculate_crc32c(uint32_t, const void *, size_t);
|
|
|
|
|
2002-08-22 23:35:35 +00:00
|
|
|
__END_DECLS
|
|
|
|
|
|
|
|
#endif /* __LIBUFS_H__ */
|