Lines 309-314
readsuper(void *devfd, struct fs **fsp, off_t sblockloc, int isaltsblk,
Link Here
|
309 |
* Verify the filesystem values. |
309 |
* Verify the filesystem values. |
310 |
*/ |
310 |
*/ |
311 |
#define ILOG2(num) (fls(num) - 1) |
311 |
#define ILOG2(num) (fls(num) - 1) |
|
|
312 |
#define FAIL(code) { printf("Failed code %d\n", code); return (ENOENT); } |
312 |
|
313 |
|
313 |
static int |
314 |
static int |
314 |
validate_sblock(struct fs *fs, int isaltsblk) |
315 |
validate_sblock(struct fs *fs, int isaltsblk) |
Lines 325-331
validate_sblock(struct fs *fs, int isaltsblk)
Link Here
|
325 |
sizeof(ufs2_daddr_t)) || |
326 |
sizeof(ufs2_daddr_t)) || |
326 |
fs->fs_nindir != fs->fs_bsize / sizeof(ufs2_daddr_t) || |
327 |
fs->fs_nindir != fs->fs_bsize / sizeof(ufs2_daddr_t) || |
327 |
fs->fs_inopb != fs->fs_bsize / sizeof(struct ufs2_dinode)) |
328 |
fs->fs_inopb != fs->fs_bsize / sizeof(struct ufs2_dinode)) |
328 |
return (ENOENT); |
329 |
FAIL(1); |
329 |
} else if (fs->fs_magic == FS_UFS1_MAGIC) { |
330 |
} else if (fs->fs_magic == FS_UFS1_MAGIC) { |
330 |
if ((!isaltsblk && (fs->fs_sblockloc > SBLOCK_UFS1 || |
331 |
if ((!isaltsblk && (fs->fs_sblockloc > SBLOCK_UFS1 || |
331 |
!(fs->fs_sblockactualloc == SBLOCK_UFS1 || |
332 |
!(fs->fs_sblockactualloc == SBLOCK_UFS1 || |
Lines 337-343
validate_sblock(struct fs *fs, int isaltsblk)
Link Here
|
337 |
fs->fs_old_inodefmt != FS_44INODEFMT || |
338 |
fs->fs_old_inodefmt != FS_44INODEFMT || |
338 |
fs->fs_old_cgoffset != 0 || |
339 |
fs->fs_old_cgoffset != 0 || |
339 |
fs->fs_old_cgmask != 0xffffffff || |
340 |
fs->fs_old_cgmask != 0xffffffff || |
340 |
fs->fs_old_size != fs->fs_size || |
|
|
341 |
fs->fs_old_rotdelay != 0 || |
341 |
fs->fs_old_rotdelay != 0 || |
342 |
fs->fs_old_rps != 60 || |
342 |
fs->fs_old_rps != 60 || |
343 |
fs->fs_old_nspf != fs->fs_fsize / sectorsize || |
343 |
fs->fs_old_nspf != fs->fs_fsize / sectorsize || |
Lines 350-372
validate_sblock(struct fs *fs, int isaltsblk)
Link Here
|
350 |
fs->fs_old_spc != fs->fs_fpg * fs->fs_old_nspf || |
350 |
fs->fs_old_spc != fs->fs_fpg * fs->fs_old_nspf || |
351 |
fs->fs_old_nsect != fs->fs_old_spc || |
351 |
fs->fs_old_nsect != fs->fs_old_spc || |
352 |
fs->fs_old_npsect != fs->fs_old_spc || |
352 |
fs->fs_old_npsect != fs->fs_old_spc || |
353 |
fs->fs_old_dsize != fs->fs_dsize || |
|
|
354 |
fs->fs_old_ncyl != fs->fs_ncg) |
353 |
fs->fs_old_ncyl != fs->fs_ncg) |
355 |
return (ENOENT); |
354 |
FAIL(2); |
356 |
} else { |
355 |
} else { |
357 |
return (ENOENT); |
356 |
FAIL(3); |
358 |
} |
357 |
} |
359 |
if (fs->fs_bsize < MINBSIZE || fs->fs_bsize > MAXBSIZE || |
358 |
if (fs->fs_bsize < MINBSIZE || fs->fs_bsize > MAXBSIZE || |
360 |
fs->fs_bsize < roundup(sizeof(struct fs), DEV_BSIZE) || |
359 |
fs->fs_bsize < roundup(sizeof(struct fs), DEV_BSIZE) || |
361 |
fs->fs_sbsize > SBLOCKSIZE || fs->fs_sbsize < fs->fs_fsize || |
360 |
fs->fs_sbsize > SBLOCKSIZE || fs->fs_sbsize < fs->fs_fsize || |
362 |
!powerof2(fs->fs_bsize)) |
361 |
!powerof2(fs->fs_bsize)) |
363 |
return (ENOENT); |
362 |
FAIL(4); |
364 |
if (fs->fs_fsize < sectorsize || fs->fs_fsize > fs->fs_bsize || |
363 |
if (fs->fs_fsize < sectorsize || fs->fs_fsize > fs->fs_bsize || |
365 |
fs->fs_fsize * MAXFRAG < fs->fs_bsize || !powerof2(fs->fs_fsize)) |
364 |
fs->fs_fsize * MAXFRAG < fs->fs_bsize || !powerof2(fs->fs_fsize)) |
366 |
return (ENOENT); |
365 |
FAIL(5); |
367 |
if (fs->fs_maxbsize < fs->fs_bsize || !powerof2(fs->fs_maxbsize) || |
366 |
if (fs->fs_maxbsize < fs->fs_bsize || !powerof2(fs->fs_maxbsize) || |
368 |
fs->fs_maxbsize > FS_MAXCONTIG * fs->fs_bsize) |
367 |
fs->fs_maxbsize > FS_MAXCONTIG * fs->fs_bsize) |
369 |
return (ENOENT); |
368 |
FAIL(6); |
370 |
if (fs->fs_bmask != ~(fs->fs_bsize - 1) || |
369 |
if (fs->fs_bmask != ~(fs->fs_bsize - 1) || |
371 |
fs->fs_fmask != ~(fs->fs_fsize - 1) || |
370 |
fs->fs_fmask != ~(fs->fs_fsize - 1) || |
372 |
fs->fs_qbmask != ~fs->fs_bmask || |
371 |
fs->fs_qbmask != ~fs->fs_bmask || |
Lines 377-383
validate_sblock(struct fs *fs, int isaltsblk)
Link Here
|
377 |
fs->fs_fragshift != ILOG2(fs->fs_frag) || |
376 |
fs->fs_fragshift != ILOG2(fs->fs_frag) || |
378 |
fs->fs_frag > MAXFRAG || |
377 |
fs->fs_frag > MAXFRAG || |
379 |
fs->fs_fsbtodb != ILOG2(fs->fs_fsize / sectorsize)) |
378 |
fs->fs_fsbtodb != ILOG2(fs->fs_fsize / sectorsize)) |
380 |
return (ENOENT); |
379 |
FAIL(7); |
381 |
if (fs->fs_sblkno != |
380 |
if (fs->fs_sblkno != |
382 |
roundup(howmany(fs->fs_sblockloc + SBLOCKSIZE, fs->fs_fsize), |
381 |
roundup(howmany(fs->fs_sblockloc + SBLOCKSIZE, fs->fs_fsize), |
383 |
fs->fs_frag) || |
382 |
fs->fs_frag) || |
Lines 385-392
validate_sblock(struct fs *fs, int isaltsblk)
Link Here
|
385 |
roundup(howmany(SBLOCKSIZE, fs->fs_fsize), fs->fs_frag) || |
384 |
roundup(howmany(SBLOCKSIZE, fs->fs_fsize), fs->fs_frag) || |
386 |
fs->fs_iblkno != fs->fs_cblkno + fs->fs_frag || |
385 |
fs->fs_iblkno != fs->fs_cblkno + fs->fs_frag || |
387 |
fs->fs_dblkno != fs->fs_iblkno + fs->fs_ipg / INOPF(fs) || |
386 |
fs->fs_dblkno != fs->fs_iblkno + fs->fs_ipg / INOPF(fs) || |
388 |
fs->fs_cgsize != fragroundup(fs, CGSIZE(fs))) |
387 |
fs->fs_cgsize > fs->fs_bsize) |
389 |
return (ENOENT); |
388 |
FAIL(8); |
390 |
if (fs->fs_csaddr != cgdmin(fs, 0) || |
389 |
if (fs->fs_csaddr != cgdmin(fs, 0) || |
391 |
fs->fs_cssize != |
390 |
fs->fs_cssize != |
392 |
fragroundup(fs, fs->fs_ncg * sizeof(struct csum)) || |
391 |
fragroundup(fs, fs->fs_ncg * sizeof(struct csum)) || |
Lines 395-408
validate_sblock(struct fs *fs, int isaltsblk)
Link Here
|
395 |
howmany(fs->fs_cssize, fs->fs_fsize) || |
394 |
howmany(fs->fs_cssize, fs->fs_fsize) || |
396 |
fs->fs_metaspace < 0 || fs->fs_metaspace > fs->fs_fpg / 2 || |
395 |
fs->fs_metaspace < 0 || fs->fs_metaspace > fs->fs_fpg / 2 || |
397 |
fs->fs_minfree > 99) |
396 |
fs->fs_minfree > 99) |
398 |
return (ENOENT); |
397 |
FAIL(9); |
399 |
maxfilesize = fs->fs_bsize * UFS_NDADDR - 1; |
398 |
maxfilesize = fs->fs_bsize * UFS_NDADDR - 1; |
400 |
for (sizepb = fs->fs_bsize, i = 0; i < UFS_NIADDR; i++) { |
399 |
for (sizepb = fs->fs_bsize, i = 0; i < UFS_NIADDR; i++) { |
401 |
sizepb *= NINDIR(fs); |
400 |
sizepb *= NINDIR(fs); |
402 |
maxfilesize += sizepb; |
401 |
maxfilesize += sizepb; |
403 |
} |
402 |
} |
404 |
if (fs->fs_maxfilesize != maxfilesize) |
403 |
if (fs->fs_maxfilesize != maxfilesize) |
405 |
return (ENOENT); |
404 |
FAIL(10); |
406 |
/* |
405 |
/* |
407 |
* These values have a tight interaction with each other that |
406 |
* These values have a tight interaction with each other that |
408 |
* makes it hard to tightly bound them. So we can only check |
407 |
* makes it hard to tightly bound them. So we can only check |
Lines 420-429
validate_sblock(struct fs *fs, int isaltsblk)
Link Here
|
420 |
fs->fs_fpg < minfpg || fs->fs_fpg > fs->fs_size || |
419 |
fs->fs_fpg < minfpg || fs->fs_fpg > fs->fs_size || |
421 |
fs->fs_ipg * fs->fs_ncg > (((int64_t)(1)) << 32) - INOPB(fs) || |
420 |
fs->fs_ipg * fs->fs_ncg > (((int64_t)(1)) << 32) - INOPB(fs) || |
422 |
fs->fs_ipg > fs->fs_fpg || fs->fs_size < 8 * fs->fs_frag) |
421 |
fs->fs_ipg > fs->fs_fpg || fs->fs_size < 8 * fs->fs_frag) |
423 |
return (ENOENT); |
422 |
FAIL(11); |
424 |
if (fs->fs_size <= (fs->fs_ncg - 1) * fs->fs_fpg || |
423 |
if (fs->fs_size <= (fs->fs_ncg - 1) * fs->fs_fpg || |
425 |
fs->fs_size > fs->fs_ncg * fs->fs_fpg) |
424 |
fs->fs_size > fs->fs_ncg * fs->fs_fpg) |
426 |
return (ENOENT); |
425 |
FAIL(12); |
427 |
/* |
426 |
/* |
428 |
* With file system clustering it is possible to allocate |
427 |
* With file system clustering it is possible to allocate |
429 |
* many contiguous blocks. The kernel variable maxphys defines |
428 |
* many contiguous blocks. The kernel variable maxphys defines |
Lines 445-456
validate_sblock(struct fs *fs, int isaltsblk)
Link Here
|
445 |
*/ |
444 |
*/ |
446 |
if (fs->fs_maxcontig < 1 || |
445 |
if (fs->fs_maxcontig < 1 || |
447 |
fs->fs_maxcontig > MAX(256, maxphys / fs->fs_bsize)) |
446 |
fs->fs_maxcontig > MAX(256, maxphys / fs->fs_bsize)) |
448 |
return (ENOENT); |
447 |
FAIL(13); |
449 |
if (fs->fs_maxcontig < 0 || |
448 |
if (fs->fs_maxcontig < 0 || |
450 |
(fs->fs_maxcontig == 0 && fs->fs_contigsumsize != 0) || |
449 |
(fs->fs_maxcontig == 0 && fs->fs_contigsumsize != 0) || |
451 |
(fs->fs_maxcontig > 1 && |
450 |
(fs->fs_maxcontig > 1 && |
452 |
fs->fs_contigsumsize != MIN(fs->fs_maxcontig, FS_MAXCONTIG))) |
451 |
fs->fs_contigsumsize != MIN(fs->fs_maxcontig, FS_MAXCONTIG))) |
453 |
return (ENOENT); |
452 |
FAIL(14); |
454 |
return (0); |
453 |
return (0); |
455 |
} |
454 |
} |
456 |
|
455 |
|