ffs_subr.c (a02bd3e38ccefc7c2de92652ebd11d12e53efa85) ffs_subr.c (fb14e73cb4062d7272ce6183d748adedd868906b)
1/*-
2 * SPDX-License-Identifier: BSD-3-Clause
3 *
4 * Copyright (c) 1982, 1986, 1989, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 37 unchanged lines hidden (view full) ---

46#include <ufs/ffs/fs.h>
47
48uint32_t calculate_crc32c(uint32_t, const void *, size_t);
49uint32_t ffs_calc_sbhash(struct fs *);
50struct malloc_type;
51#define UFS_MALLOC(size, type, flags) malloc(size)
52#define UFS_FREE(ptr, type) free(ptr)
53#define UFS_TIME time(NULL)
1/*-
2 * SPDX-License-Identifier: BSD-3-Clause
3 *
4 * Copyright (c) 1982, 1986, 1989, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 37 unchanged lines hidden (view full) ---

46#include <ufs/ffs/fs.h>
47
48uint32_t calculate_crc32c(uint32_t, const void *, size_t);
49uint32_t ffs_calc_sbhash(struct fs *);
50struct malloc_type;
51#define UFS_MALLOC(size, type, flags) malloc(size)
52#define UFS_FREE(ptr, type) free(ptr)
53#define UFS_TIME time(NULL)
54/*
55 * Request standard superblock location in ffs_sbget
56 */
57#define STDSB -1 /* Fail if check-hash is bad */
58#define STDSB_NOHASHFAIL -2 /* Ignore check-hash failure */
54
55#else /* _KERNEL */
56#include <sys/systm.h>
57#include <sys/lock.h>
58#include <sys/malloc.h>
59#include <sys/mount.h>
60#include <sys/vnode.h>
61#include <sys/bio.h>

--- 72 unchanged lines hidden (view full) ---

134 ip->i_nlink = dip2->di_nlink;
135 ip->i_size = dip2->di_size;
136 ip->i_flags = dip2->di_flags;
137 ip->i_gen = dip2->di_gen;
138 ip->i_uid = dip2->di_uid;
139 ip->i_gid = dip2->di_gid;
140 return (0);
141}
59
60#else /* _KERNEL */
61#include <sys/systm.h>
62#include <sys/lock.h>
63#include <sys/malloc.h>
64#include <sys/mount.h>
65#include <sys/vnode.h>
66#include <sys/bio.h>

--- 72 unchanged lines hidden (view full) ---

139 ip->i_nlink = dip2->di_nlink;
140 ip->i_size = dip2->di_size;
141 ip->i_flags = dip2->di_flags;
142 ip->i_gen = dip2->di_gen;
143 ip->i_uid = dip2->di_uid;
144 ip->i_gid = dip2->di_gid;
145 return (0);
146}
142#endif /* KERNEL */
147#endif /* _KERNEL */
143
144/*
145 * These are the low-level functions that actually read and write
146 * the superblock and its associated data.
147 */
148static off_t sblock_try[] = SBLOCKSEARCH;
148
149/*
150 * These are the low-level functions that actually read and write
151 * the superblock and its associated data.
152 */
153static off_t sblock_try[] = SBLOCKSEARCH;
149static int readsuper(void *, struct fs **, off_t, int,
154static int readsuper(void *, struct fs **, off_t, int, int,
150 int (*)(void *, off_t, void **, int));
151
152/*
153 * Read a superblock from the devfd device.
154 *
155 * If an alternate superblock is specified, it is read. Otherwise the
156 * set of locations given in the SBLOCKSEARCH list is searched for a
157 * superblock. Memory is allocated for the superblock by the readfunc and

--- 14 unchanged lines hidden (view full) ---

172ffs_sbget(void *devfd, struct fs **fsp, off_t altsblock,
173 struct malloc_type *filltype,
174 int (*readfunc)(void *devfd, off_t loc, void **bufp, int size))
175{
176 struct fs *fs;
177 int i, error, size, blks;
178 uint8_t *space;
179 int32_t *lp;
155 int (*)(void *, off_t, void **, int));
156
157/*
158 * Read a superblock from the devfd device.
159 *
160 * If an alternate superblock is specified, it is read. Otherwise the
161 * set of locations given in the SBLOCKSEARCH list is searched for a
162 * superblock. Memory is allocated for the superblock by the readfunc and

--- 14 unchanged lines hidden (view full) ---

177ffs_sbget(void *devfd, struct fs **fsp, off_t altsblock,
178 struct malloc_type *filltype,
179 int (*readfunc)(void *devfd, off_t loc, void **bufp, int size))
180{
181 struct fs *fs;
182 int i, error, size, blks;
183 uint8_t *space;
184 int32_t *lp;
185 int chkhash;
180 char *buf;
181
182 fs = NULL;
183 *fsp = NULL;
186 char *buf;
187
188 fs = NULL;
189 *fsp = NULL;
184 if (altsblock != -1) {
185 if ((error = readsuper(devfd, &fs, altsblock, 1,
190 chkhash = 1;
191 if (altsblock >= 0) {
192 if ((error = readsuper(devfd, &fs, altsblock, 1, chkhash,
186 readfunc)) != 0) {
187 if (fs != NULL)
188 UFS_FREE(fs, filltype);
189 return (error);
190 }
191 } else {
193 readfunc)) != 0) {
194 if (fs != NULL)
195 UFS_FREE(fs, filltype);
196 return (error);
197 }
198 } else {
199 if (altsblock == STDSB_NOHASHFAIL)
200 chkhash = 0;
192 for (i = 0; sblock_try[i] != -1; i++) {
193 if ((error = readsuper(devfd, &fs, sblock_try[i], 0,
201 for (i = 0; sblock_try[i] != -1; i++) {
202 if ((error = readsuper(devfd, &fs, sblock_try[i], 0,
194 readfunc)) == 0)
203 chkhash, readfunc)) == 0)
195 break;
196 if (fs != NULL) {
197 UFS_FREE(fs, filltype);
198 fs = NULL;
199 }
200 if (error == ENOENT)
201 continue;
202 return (error);

--- 47 unchanged lines hidden (view full) ---

250}
251
252/*
253 * Try to read a superblock from the location specified by sblockloc.
254 * Return zero on success or an errno on failure.
255 */
256static int
257readsuper(void *devfd, struct fs **fsp, off_t sblockloc, int isaltsblk,
204 break;
205 if (fs != NULL) {
206 UFS_FREE(fs, filltype);
207 fs = NULL;
208 }
209 if (error == ENOENT)
210 continue;
211 return (error);

--- 47 unchanged lines hidden (view full) ---

259}
260
261/*
262 * Try to read a superblock from the location specified by sblockloc.
263 * Return zero on success or an errno on failure.
264 */
265static int
266readsuper(void *devfd, struct fs **fsp, off_t sblockloc, int isaltsblk,
258 int (*readfunc)(void *devfd, off_t loc, void **bufp, int size))
267 int chkhash, int (*readfunc)(void *devfd, off_t loc, void **bufp, int size))
259{
260 struct fs *fs;
261 int error, res;
262 uint32_t ckhash;
263
264 error = (*readfunc)(devfd, sblockloc, (void **)fsp, SBLOCKSIZE);
265 if (error != 0)
266 return (error);

--- 13 unchanged lines hidden (view full) ---

280 * If the filesystem has been run on a kernel without
281 * metadata check hashes, disable them.
282 */
283 if ((fs->fs_flags & FS_METACKHASH) == 0)
284 fs->fs_metackhash = 0;
285 if (fs->fs_ckhash != (ckhash = ffs_calc_sbhash(fs))) {
286#ifdef _KERNEL
287 res = uprintf("Superblock check-hash failed: recorded "
268{
269 struct fs *fs;
270 int error, res;
271 uint32_t ckhash;
272
273 error = (*readfunc)(devfd, sblockloc, (void **)fsp, SBLOCKSIZE);
274 if (error != 0)
275 return (error);

--- 13 unchanged lines hidden (view full) ---

289 * If the filesystem has been run on a kernel without
290 * metadata check hashes, disable them.
291 */
292 if ((fs->fs_flags & FS_METACKHASH) == 0)
293 fs->fs_metackhash = 0;
294 if (fs->fs_ckhash != (ckhash = ffs_calc_sbhash(fs))) {
295#ifdef _KERNEL
296 res = uprintf("Superblock check-hash failed: recorded "
288 "check-hash 0x%x != computed check-hash 0x%x\n",
289 fs->fs_ckhash, ckhash);
297 "check-hash 0x%x != computed check-hash 0x%x%s\n",
298 fs->fs_ckhash, ckhash,
299 chkhash == 0 ? " (Ignored)" : "");
290#else
291 res = 0;
292#endif
293 /*
294 * Print check-hash failure if no controlling terminal
295 * in kernel or always if in user-mode (libufs).
296 */
297 if (res == 0)
298 printf("Superblock check-hash failed: recorded "
299 "check-hash 0x%x != computed check-hash "
300#else
301 res = 0;
302#endif
303 /*
304 * Print check-hash failure if no controlling terminal
305 * in kernel or always if in user-mode (libufs).
306 */
307 if (res == 0)
308 printf("Superblock check-hash failed: recorded "
309 "check-hash 0x%x != computed check-hash "
300 "0x%x\n", fs->fs_ckhash, ckhash);
310 "0x%x%s\n", fs->fs_ckhash, ckhash,
311 chkhash == 0 ? " (Ignored)" : "");
312 if (chkhash == 0) {
313 fs->fs_flags |= FS_NEEDSFSCK;
314 fs->fs_fmod = 1;
315 return (0);
316 }
317 fs->fs_fmod = 0;
301 return (EINVAL);
302 }
303 /* Have to set for old filesystems that predate this field */
304 fs->fs_sblockactualloc = sblockloc;
305 /* Not yet any summary information */
306 fs->fs_csp = NULL;
307 return (0);
308 }

--- 313 unchanged lines hidden ---
318 return (EINVAL);
319 }
320 /* Have to set for old filesystems that predate this field */
321 fs->fs_sblockactualloc = sblockloc;
322 /* Not yet any summary information */
323 fs->fs_csp = NULL;
324 return (0);
325 }

--- 313 unchanged lines hidden ---