2017-11-26 03:00:33 +01:00
|
|
|
/*-
|
2023-05-10 17:40:58 +02:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2017-11-26 03:00:33 +01:00
|
|
|
*
|
2002-07-01 03:45:03 +02: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.
|
|
|
|
*/
|
|
|
|
|
2002-08-23 01:35:35 +02:00
|
|
|
#ifndef __LIBUFS_H__
|
|
|
|
#define __LIBUFS_H__
|
|
|
|
|
2023-11-17 23:10:29 +01:00
|
|
|
/*
|
|
|
|
* Various disk controllers require their buffers to be aligned to the size
|
|
|
|
* of a cache line. The LIBUFS_BUFALIGN defines the required alignment size.
|
|
|
|
* The alignment must be a power of 2.
|
|
|
|
*/
|
|
|
|
#define LIBUFS_BUFALIGN 128
|
|
|
|
|
2002-07-01 03:45:03 +02:00
|
|
|
/*
|
|
|
|
* libufs structures.
|
|
|
|
*/
|
2018-11-13 22:40:56 +01:00
|
|
|
union dinodep {
|
|
|
|
struct ufs1_dinode *dp1;
|
|
|
|
struct ufs2_dinode *dp2;
|
|
|
|
};
|
2002-07-01 03:45:03 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* userland ufs disk.
|
|
|
|
*/
|
|
|
|
struct uufsd {
|
|
|
|
union {
|
2020-06-23 23:17:13 +02:00
|
|
|
struct fs d_fs; /* filesystem information */
|
2023-11-17 23:10:29 +01:00
|
|
|
char d_sb[SBLOCKSIZE]; /* superblock as buffer */
|
|
|
|
} d_sbunion __aligned(LIBUFS_BUFALIGN);
|
2003-01-19 02:31:26 +01:00
|
|
|
union {
|
2020-06-23 23:17:13 +02:00
|
|
|
struct cg d_cg; /* cylinder group */
|
|
|
|
char d_buf[MAXBSIZE]; /* cylinder group storage */
|
2023-11-17 23:10:29 +01:00
|
|
|
} d_cgunion __aligned(LIBUFS_BUFALIGN);
|
|
|
|
union {
|
|
|
|
union dinodep d_ino[1]; /* inode block */
|
|
|
|
char d_inos[MAXBSIZE]; /* inode block as buffer */
|
|
|
|
} d_inosunion __aligned(LIBUFS_BUFALIGN);
|
|
|
|
const char *d_name; /* disk name */
|
2020-06-23 23:17:13 +02:00
|
|
|
const char *d_error; /* human readable disk error */
|
2023-11-17 23:10:29 +01:00
|
|
|
ufs2_daddr_t d_sblock; /* superblock location */
|
|
|
|
struct fs_summary_info *d_si; /* Superblock summary info */
|
|
|
|
union dinodep d_dp; /* pointer to currently active inode */
|
|
|
|
ino_t d_inomin; /* low ino */
|
|
|
|
ino_t d_inomax; /* high ino */
|
2022-07-31 07:44:01 +02:00
|
|
|
off_t d_sblockloc; /* where to look for the superblock */
|
2023-11-17 23:10:29 +01:00
|
|
|
int64_t d_bsize; /* device bsize */
|
|
|
|
int64_t d_lookupflags; /* flags to superblock lookup */
|
|
|
|
int64_t d_mine; /* internal flags */
|
|
|
|
int32_t d_ccg; /* current cylinder group */
|
|
|
|
int32_t d_ufs; /* decimal UFS version */
|
|
|
|
int32_t d_fd; /* raw device file descriptor */
|
|
|
|
int32_t d_lcg; /* last cylinder group (in d_cg) */
|
|
|
|
};
|
|
|
|
#define d_inos d_inosunion.d_inos
|
2002-07-01 03:45:03 +02:00
|
|
|
#define d_fs d_sbunion.d_fs
|
2003-01-19 02:31:26 +01:00
|
|
|
#define d_cg d_cgunion.d_cg
|
2002-07-01 03:45:03 +02:00
|
|
|
|
2011-02-12 13:46:00 +01:00
|
|
|
/*
|
|
|
|
* libufs macros (internal, non-exported).
|
|
|
|
*/
|
|
|
|
#ifdef _LIBUFS
|
2023-11-17 23:10:29 +01:00
|
|
|
/*
|
|
|
|
* Ensure that the buffer is aligned to the I/O subsystem requirements.
|
|
|
|
*/
|
|
|
|
#define BUF_MALLOC(newbufpp, data, size) { \
|
|
|
|
if (data != NULL && (((intptr_t)data) & (LIBUFS_BUFALIGN - 1)) == 0) \
|
|
|
|
*newbufpp = (void *)data; \
|
|
|
|
else \
|
|
|
|
*newbufpp = aligned_alloc(LIBUFS_BUFALIGN, size); \
|
|
|
|
}
|
2011-02-12 13:46:00 +01:00
|
|
|
/*
|
|
|
|
* 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-23 01:35:35 +02:00
|
|
|
__BEGIN_DECLS
|
|
|
|
|
2002-07-01 03:45:03 +02:00
|
|
|
/*
|
|
|
|
* libufs prototypes.
|
|
|
|
*/
|
|
|
|
|
2018-01-26 01:58:32 +01: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);
|
Move the ability to search for alternate UFS superblocks from fsck_ffs(8)
into ffs_sbsearch() to allow use by other parts of the system.
Historically only fsck_ffs(8), the UFS filesystem checker, had code
to track down and use alternate UFS superblocks. Since fsdb(8) used
much of the fsck_ffs(8) implementation it had some ability to track
down alternate superblocks.
This change extracts the code to track down alternate superblocks
from fsck_ffs(8) and puts it into a new function ffs_sbsearch() in
sys/ufs/ffs/ffs_subr.c. Like ffs_sbget() and ffs_sbput() also found
in ffs_subr.c, these functions can be used directly by the kernel
subsystems. Additionally they are exported to the UFS library,
libufs(8) so that they can be used by user-level programs. The new
functions added to libufs(8) are sbfind(3) that is an alternative
to sbread(3) and sbsearch(3) that is an alternative to sbget(3).
See their manual pages for further details.
The utilities that have been changed to search for superblocks are
dumpfs(8), fsdb(8), ffsinfo(8), and fsck_ffs(8). Also, the prtblknos(8)
tool found in tools/diag/prtblknos searches for superblocks.
The UFS specific mount code uses the superblock search interface
when mounting the root filesystem and when the administrator doing
a mount(8) command specifies the force flag (-f). The standalone UFS
boot code (found in stand/libsa/ufs.c) uses the superblock search
code in the hope of being able to get the system up and running so
that fsck_ffs(8) can be used to get the filesystem cleaned up.
The following utilities have not been changed to search for
superblocks: clri(8), tunefs(8), snapinfo(8), fstyp(8), quot(8),
dump(8), fsirand(8), growfs(8), quotacheck(8), gjournal(8), and
glabel(8). When these utilities fail, they do report the cause of
the failure. The one exception is the tasting code used to try and
figure what a given disk contains. The tasting code will remain
silent so as not to put out a slew of messages as it trying to taste
every new mass storage device that shows up.
Reviewed by: kib
Reviewed by: Warner Losh
Tested by: Peter Holm
Differential Revision: https://reviews.freebsd.org/D36053
Sponsored by: The FreeBSD Foundation
2022-08-13 21:41:53 +02:00
|
|
|
int ffs_sbsearch(void *, struct fs **, int, char *,
|
|
|
|
int (*)(void *, off_t, void **, int));
|
2018-01-26 01:58:32 +01:00
|
|
|
void ffs_setblock(struct fs *, u_char *, ufs1_daddr_t);
|
2022-07-31 07:44:01 +02:00
|
|
|
int ffs_sbget(void *, struct fs **, off_t, int, char *,
|
2018-01-26 01:58:32 +01:00
|
|
|
int (*)(void *, off_t, void **, int));
|
|
|
|
int ffs_sbput(void *, struct fs *, off_t,
|
|
|
|
int (*)(void *, off_t, void *, int));
|
2018-12-11 23:14:37 +01:00
|
|
|
void ffs_update_dinode_ckhash(struct fs *, struct ufs2_dinode *);
|
|
|
|
int ffs_verify_dinode_ckhash(struct fs *, struct ufs2_dinode *);
|
2018-01-26 01:58:32 +01:00
|
|
|
|
2002-07-01 03:45:03 +02: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 19:02:37 +01:00
|
|
|
int berase(struct uufsd *, ufs2_daddr_t, ufs2_daddr_t);
|
2002-07-01 03:45:03 +02:00
|
|
|
|
2003-01-19 02:31:26 +01:00
|
|
|
/*
|
|
|
|
* cgroup.c
|
|
|
|
*/
|
2010-04-24 09:05:35 +02:00
|
|
|
ufs2_daddr_t cgballoc(struct uufsd *);
|
|
|
|
int cgbfree(struct uufsd *, ufs2_daddr_t, long);
|
|
|
|
ino_t cgialloc(struct uufsd *);
|
2020-09-20 00:48:30 +02:00
|
|
|
int cgget(int, struct fs *, int, struct cg *);
|
|
|
|
int cgput(int, struct fs *, struct cg *);
|
2003-01-19 02:31:26 +01:00
|
|
|
int cgread(struct uufsd *);
|
|
|
|
int cgread1(struct uufsd *, int);
|
2010-04-24 09:05:35 +02:00
|
|
|
int cgwrite(struct uufsd *);
|
2006-10-31 22:21:48 +01:00
|
|
|
int cgwrite1(struct uufsd *, int);
|
2003-01-19 02:31:26 +01:00
|
|
|
|
2002-07-01 03:45:03 +02:00
|
|
|
/*
|
|
|
|
* inode.c
|
|
|
|
*/
|
2018-11-13 22:40:56 +01:00
|
|
|
int getinode(struct uufsd *, union dinodep *, ino_t);
|
|
|
|
int putinode(struct uufsd *);
|
2002-07-01 03:45:03 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* sblock.c
|
|
|
|
*/
|
|
|
|
int sbread(struct uufsd *);
|
Move the ability to search for alternate UFS superblocks from fsck_ffs(8)
into ffs_sbsearch() to allow use by other parts of the system.
Historically only fsck_ffs(8), the UFS filesystem checker, had code
to track down and use alternate UFS superblocks. Since fsdb(8) used
much of the fsck_ffs(8) implementation it had some ability to track
down alternate superblocks.
This change extracts the code to track down alternate superblocks
from fsck_ffs(8) and puts it into a new function ffs_sbsearch() in
sys/ufs/ffs/ffs_subr.c. Like ffs_sbget() and ffs_sbput() also found
in ffs_subr.c, these functions can be used directly by the kernel
subsystems. Additionally they are exported to the UFS library,
libufs(8) so that they can be used by user-level programs. The new
functions added to libufs(8) are sbfind(3) that is an alternative
to sbread(3) and sbsearch(3) that is an alternative to sbget(3).
See their manual pages for further details.
The utilities that have been changed to search for superblocks are
dumpfs(8), fsdb(8), ffsinfo(8), and fsck_ffs(8). Also, the prtblknos(8)
tool found in tools/diag/prtblknos searches for superblocks.
The UFS specific mount code uses the superblock search interface
when mounting the root filesystem and when the administrator doing
a mount(8) command specifies the force flag (-f). The standalone UFS
boot code (found in stand/libsa/ufs.c) uses the superblock search
code in the hope of being able to get the system up and running so
that fsck_ffs(8) can be used to get the filesystem cleaned up.
The following utilities have not been changed to search for
superblocks: clri(8), tunefs(8), snapinfo(8), fstyp(8), quot(8),
dump(8), fsirand(8), growfs(8), quotacheck(8), gjournal(8), and
glabel(8). When these utilities fail, they do report the cause of
the failure. The one exception is the tasting code used to try and
figure what a given disk contains. The tasting code will remain
silent so as not to put out a slew of messages as it trying to taste
every new mass storage device that shows up.
Reviewed by: kib
Reviewed by: Warner Losh
Tested by: Peter Holm
Differential Revision: https://reviews.freebsd.org/D36053
Sponsored by: The FreeBSD Foundation
2022-08-13 21:41:53 +02:00
|
|
|
int sbfind(struct uufsd *, int);
|
2002-07-01 03:45:03 +02:00
|
|
|
int sbwrite(struct uufsd *, int);
|
2018-01-26 01:58:32 +01:00
|
|
|
/* low level superblock read/write functions */
|
2022-07-31 07:44:01 +02:00
|
|
|
int sbget(int, struct fs **, off_t, int);
|
Move the ability to search for alternate UFS superblocks from fsck_ffs(8)
into ffs_sbsearch() to allow use by other parts of the system.
Historically only fsck_ffs(8), the UFS filesystem checker, had code
to track down and use alternate UFS superblocks. Since fsdb(8) used
much of the fsck_ffs(8) implementation it had some ability to track
down alternate superblocks.
This change extracts the code to track down alternate superblocks
from fsck_ffs(8) and puts it into a new function ffs_sbsearch() in
sys/ufs/ffs/ffs_subr.c. Like ffs_sbget() and ffs_sbput() also found
in ffs_subr.c, these functions can be used directly by the kernel
subsystems. Additionally they are exported to the UFS library,
libufs(8) so that they can be used by user-level programs. The new
functions added to libufs(8) are sbfind(3) that is an alternative
to sbread(3) and sbsearch(3) that is an alternative to sbget(3).
See their manual pages for further details.
The utilities that have been changed to search for superblocks are
dumpfs(8), fsdb(8), ffsinfo(8), and fsck_ffs(8). Also, the prtblknos(8)
tool found in tools/diag/prtblknos searches for superblocks.
The UFS specific mount code uses the superblock search interface
when mounting the root filesystem and when the administrator doing
a mount(8) command specifies the force flag (-f). The standalone UFS
boot code (found in stand/libsa/ufs.c) uses the superblock search
code in the hope of being able to get the system up and running so
that fsck_ffs(8) can be used to get the filesystem cleaned up.
The following utilities have not been changed to search for
superblocks: clri(8), tunefs(8), snapinfo(8), fstyp(8), quot(8),
dump(8), fsirand(8), growfs(8), quotacheck(8), gjournal(8), and
glabel(8). When these utilities fail, they do report the cause of
the failure. The one exception is the tasting code used to try and
figure what a given disk contains. The tasting code will remain
silent so as not to put out a slew of messages as it trying to taste
every new mass storage device that shows up.
Reviewed by: kib
Reviewed by: Warner Losh
Tested by: Peter Holm
Differential Revision: https://reviews.freebsd.org/D36053
Sponsored by: The FreeBSD Foundation
2022-08-13 21:41:53 +02:00
|
|
|
int sbsearch(int, struct fs **, int);
|
2018-01-26 01:58:32 +01:00
|
|
|
int sbput(int, struct fs *, int);
|
2002-07-01 03:45:03 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* type.c
|
|
|
|
*/
|
|
|
|
int ufs_disk_close(struct uufsd *);
|
|
|
|
int ufs_disk_fillout(struct uufsd *, const char *);
|
2003-01-23 22:32:56 +01:00
|
|
|
int ufs_disk_fillout_blank(struct uufsd *, const char *);
|
2003-01-30 00:19:46 +01:00
|
|
|
int ufs_disk_write(struct uufsd *);
|
2002-08-23 01:35:35 +02:00
|
|
|
|
2017-09-22 14:45:15 +02:00
|
|
|
/*
|
|
|
|
* crc32c.c
|
|
|
|
*/
|
|
|
|
uint32_t calculate_crc32c(uint32_t, const void *, size_t);
|
|
|
|
|
2002-08-23 01:35:35 +02:00
|
|
|
__END_DECLS
|
|
|
|
|
|
|
|
#endif /* __LIBUFS_H__ */
|