xref: /freebsd/lib/libufs/sbread.3 (revision 1165fc9a526630487a1feb63daef65c5aee1a583)
1.\" Author:	Juli Mallett <jmallett@FreeBSD.org>
2.\" Date:	June 04, 2003
3.\" Description:
4.\" 	Manual page for libufs functions:
5.\"		sbget(3)
6.\"		sbput(3)
7.\"		sbread(3)
8.\"		sbwrite(3)
9.\"
10.\" This file is in the public domain.
11.\"
12.\" $FreeBSD$
13.\"
14.Dd September 2, 2020
15.Dt SBREAD 3
16.Os
17.Sh NAME
18.Nm sbget , sbput , sbread , sbwrite
19.Nd read and write superblocks of a UFS file system
20.Sh LIBRARY
21.Lb libufs
22.Sh SYNOPSIS
23.In sys/param.h
24.In sys/mount.h
25.In ufs/ufs/ufsmount.h
26.In ufs/ufs/dinode.h
27.In ufs/ffs/fs.h
28.In libufs.h
29.Ft int
30.Fn sbget "int devfd" "struct fs **fsp" "off_t sblockloc" "int flags"
31.Ft int
32.Fn sbput "int devfd" "struct fs *fs" "int numaltwrite"
33.Ft int
34.Fn sbread "struct uufsd *disk"
35.Ft int
36.Fn sbwrite "struct uufsd *disk" "int all"
37.Sh DESCRIPTION
38The
39.Fn sbget
40and
41.Fn sbread
42functions provide superblock reads for
43.Xr libufs 3
44consumers.
45The
46.Fn sbput
47and
48.Fn sbwrite
49functions provide superblock writes for
50.Xr libufs 3
51consumers.
52.Pp
53The
54.Fn sbget
55function first allocates a buffer to hold the superblock.
56Using the
57.Va devfd
58file descriptor that references the filesystem disk,
59.Fn sbget
60reads the superblock located at the byte offset specified by
61.Va sblockloc
62into the allocated buffer.
63The value
64.Cm UFS_STDSB
65may be specified for
66.Va sblockloc
67to request that the standard location for the superblock be read.
68Flags are specified by
69.Em or Ns 'ing
70the following values:
71.Pp
72.Bl -tag -width UFS_NOHASHFAIL
73.It Cm UFS_NOHASHFAIL
74Will note if the check hash is wrong but will still return the superblock.
75.It Cm UFS_NOMSG
76Indicates that superblock inconsistency error messages should not be printed.
77.It Cm UFS_NOCSUM
78Causes only the superblock itself to be returned, but does not read in any auxiliary data structures like the cylinder group summary information.
79.El
80.Pp
81If successful,
82.Fn sbget
83returns a pointer to the buffer containing the superblock in
84.Va fsp .
85The
86.Fn sbget
87function is safe to use in threaded applications.
88.Pp
89The
90.Fn sbput
91function writes the superblock specified by
92.Va fs
93to the location from which it was read on the disk referenced by the
94.Va devfd
95file descriptor.
96Additionally, the
97.Fn sbput
98function will update the first
99.Va numaltwrite
100alternate superblock locations.
101To update all the alternate superblocks,
102specify a
103.Va numaltwrite
104value of
105.Va fs->fs_ncg .
106The
107.Fn sbput
108function is safe to use in threaded applications.
109Note that the
110.Fn sbput
111function needs to be called only if the superblock has been
112modified and the on-disk copy needs to be updated.
113.Pp
114The
115.Fn sbread
116function reads the standard filesystem superblock into the
117.Va d_sb ,
118structure embedded in the given user-land UFS disk structure.
119.Pp
120The
121.Fn sbwrite
122function writes the superblock from the
123.Va d_sb ,
124structure embedded in the given user-land UFS disk structure
125to the location from which it was read.
126Additionally, the
127.Fn sbwrite
128function will write to all the alternate superblock locations if the
129.Fa all
130value is non-zero.
131.Sh RETURN VALUES
132.Rv -std sbread sbwrite
133The
134.Fn sbget
135and
136.Fn sbput
137functions return the value 0 if successful;
138otherwise they return one of the errors described below.
139.Sh ERRORS
140The errors returned by
141.Fn sbget
142and
143.Fn sbread
144include any of the errors specified for the library function
145.Xr bread 3 .
146Additionally, they may follow the
147.Xr libufs 3
148error methodologies in situations where no usable superblock could be
149found.
150.Pp
151The errors returned by
152.Fn sbput
153and
154.Fn sbwrite
155include any of the errors specified for the library function
156.Xr bwrite 3 .
157.Sh SEE ALSO
158.Xr bread 3 ,
159.Xr bwrite 3 ,
160.Xr libufs 3
161.Sh HISTORY
162These functions first appeared as part of
163.Xr libufs 3
164in
165.Fx 5.0 .
166.Sh AUTHORS
167.An Juli Mallett Aq Mt jmallett@FreeBSD.org
168.An Marshall Kirk McKusick Aq Mt mckusick@FreeBSD.org
169