ffs_subr.c (d9a8abf6c245f7f3f448269d58f71ef89536377b) ffs_subr.c (34816cb9aeca7b0ad3289c2de04cad0cd1b111ed)
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

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

153 * The administrator must complete newfs before using this volume.
154 */
155int
156ffs_sbget(void *devfd, struct fs **fsp, off_t altsblock,
157 struct malloc_type *filltype,
158 int (*readfunc)(void *devfd, off_t loc, void **bufp, int size))
159{
160 struct fs *fs;
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

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

153 * The administrator must complete newfs before using this volume.
154 */
155int
156ffs_sbget(void *devfd, struct fs **fsp, off_t altsblock,
157 struct malloc_type *filltype,
158 int (*readfunc)(void *devfd, off_t loc, void **bufp, int size))
159{
160 struct fs *fs;
161 struct fs_summary_info *fs_si;
161 int i, error, size, blks;
162 uint8_t *space;
163 int32_t *lp;
164 int chkhash;
165 char *buf;
166
167 fs = NULL;
168 *fsp = NULL;

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

196 * Read in the superblock summary information.
197 */
198 size = fs->fs_cssize;
199 blks = howmany(size, fs->fs_fsize);
200 if (fs->fs_contigsumsize > 0)
201 size += fs->fs_ncg * sizeof(int32_t);
202 size += fs->fs_ncg * sizeof(u_int8_t);
203 /* When running in libufs or libsa, UFS_MALLOC may fail */
162 int i, error, size, blks;
163 uint8_t *space;
164 int32_t *lp;
165 int chkhash;
166 char *buf;
167
168 fs = NULL;
169 *fsp = NULL;

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

197 * Read in the superblock summary information.
198 */
199 size = fs->fs_cssize;
200 blks = howmany(size, fs->fs_fsize);
201 if (fs->fs_contigsumsize > 0)
202 size += fs->fs_ncg * sizeof(int32_t);
203 size += fs->fs_ncg * sizeof(u_int8_t);
204 /* When running in libufs or libsa, UFS_MALLOC may fail */
205 if ((fs_si = UFS_MALLOC(sizeof(*fs_si), filltype, M_WAITOK)) == NULL) {
206 UFS_FREE(fs, filltype);
207 return (ENOSPC);
208 }
209 bzero(fs_si, sizeof(*fs_si));
210 fs->fs_si = fs_si;
204 if ((space = UFS_MALLOC(size, filltype, M_WAITOK)) == NULL) {
211 if ((space = UFS_MALLOC(size, filltype, M_WAITOK)) == NULL) {
212 UFS_FREE(fs->fs_si, filltype);
205 UFS_FREE(fs, filltype);
206 return (ENOSPC);
207 }
208 fs->fs_csp = (struct csum *)space;
209 for (i = 0; i < blks; i += fs->fs_frag) {
210 size = fs->fs_bsize;
211 if (i + fs->fs_frag > blks)
212 size = (blks - i) * fs->fs_fsize;
213 buf = NULL;
214 error = (*readfunc)(devfd,
215 dbtob(fsbtodb(fs, fs->fs_csaddr + i)), (void **)&buf, size);
216 if (error) {
217 if (buf != NULL)
218 UFS_FREE(buf, filltype);
219 UFS_FREE(fs->fs_csp, filltype);
213 UFS_FREE(fs, filltype);
214 return (ENOSPC);
215 }
216 fs->fs_csp = (struct csum *)space;
217 for (i = 0; i < blks; i += fs->fs_frag) {
218 size = fs->fs_bsize;
219 if (i + fs->fs_frag > blks)
220 size = (blks - i) * fs->fs_fsize;
221 buf = NULL;
222 error = (*readfunc)(devfd,
223 dbtob(fsbtodb(fs, fs->fs_csaddr + i)), (void **)&buf, size);
224 if (error) {
225 if (buf != NULL)
226 UFS_FREE(buf, filltype);
227 UFS_FREE(fs->fs_csp, filltype);
228 UFS_FREE(fs->fs_si, filltype);
220 UFS_FREE(fs, filltype);
221 return (error);
222 }
223 memcpy(space, buf, size);
224 UFS_FREE(buf, filltype);
225 space += size;
226 }
227 if (fs->fs_contigsumsize > 0) {

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

294 return (0);
295 }
296 fs->fs_fmod = 0;
297 return (EINTEGRITY);
298 }
299 /* Have to set for old filesystems that predate this field */
300 fs->fs_sblockactualloc = sblockloc;
301 /* Not yet any summary information */
229 UFS_FREE(fs, filltype);
230 return (error);
231 }
232 memcpy(space, buf, size);
233 UFS_FREE(buf, filltype);
234 space += size;
235 }
236 if (fs->fs_contigsumsize > 0) {

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

303 return (0);
304 }
305 fs->fs_fmod = 0;
306 return (EINTEGRITY);
307 }
308 /* Have to set for old filesystems that predate this field */
309 fs->fs_sblockactualloc = sblockloc;
310 /* Not yet any summary information */
302 fs->fs_csp = NULL;
311 fs->fs_si = NULL;
303 return (0);
304 }
305 return (ENOENT);
306}
307
308/*
309 * Write a superblock to the devfd device from the memory pointed to by fs.
310 * Write out the superblock summary information if it is present.

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

320{
321 int i, error, blks, size;
322 uint8_t *space;
323
324 /*
325 * If there is summary information, write it first, so if there
326 * is an error, the superblock will not be marked as clean.
327 */
312 return (0);
313 }
314 return (ENOENT);
315}
316
317/*
318 * Write a superblock to the devfd device from the memory pointed to by fs.
319 * Write out the superblock summary information if it is present.

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

329{
330 int i, error, blks, size;
331 uint8_t *space;
332
333 /*
334 * If there is summary information, write it first, so if there
335 * is an error, the superblock will not be marked as clean.
336 */
328 if (fs->fs_csp != NULL) {
337 if (fs->fs_si != NULL && fs->fs_csp != NULL) {
329 blks = howmany(fs->fs_cssize, fs->fs_fsize);
330 space = (uint8_t *)fs->fs_csp;
331 for (i = 0; i < blks; i += fs->fs_frag) {
332 size = fs->fs_bsize;
333 if (i + fs->fs_frag > blks)
334 size = (blks - i) * fs->fs_fsize;
335 if ((error = (*writefunc)(devfd,
336 dbtob(fsbtodb(fs, fs->fs_csaddr + i)),

--- 281 unchanged lines hidden ---
338 blks = howmany(fs->fs_cssize, fs->fs_fsize);
339 space = (uint8_t *)fs->fs_csp;
340 for (i = 0; i < blks; i += fs->fs_frag) {
341 size = fs->fs_bsize;
342 if (i + fs->fs_frag > blks)
343 size = (blks - i) * fs->fs_fsize;
344 if ((error = (*writefunc)(devfd,
345 dbtob(fsbtodb(fs, fs->fs_csaddr + i)),

--- 281 unchanged lines hidden ---