Changeset View
Changeset View
Standalone View
Standalone View
head/sys/geom/label/g_label_ufs.c
Show All 39 Lines | |||||
#include <geom/label/g_label.h> | #include <geom/label/g_label.h> | ||||
#define G_LABEL_UFS_VOLUME_DIR "ufs" | #define G_LABEL_UFS_VOLUME_DIR "ufs" | ||||
#define G_LABEL_UFS_ID_DIR "ufsid" | #define G_LABEL_UFS_ID_DIR "ufsid" | ||||
#define G_LABEL_UFS_VOLUME 0 | #define G_LABEL_UFS_VOLUME 0 | ||||
#define G_LABEL_UFS_ID 1 | #define G_LABEL_UFS_ID 1 | ||||
/* | |||||
* G_LABEL_UFS_CMP returns true if difference between provider mediasize | |||||
* and filesystem size is less than G_LABEL_UFS_MAXDIFF sectors | |||||
*/ | |||||
#define G_LABEL_UFS_CMP(prov, fsys, size) \ | |||||
( abs( ((fsys)->size) - ( (prov)->mediasize / (fsys)->fs_fsize )) \ | |||||
< G_LABEL_UFS_MAXDIFF ) | |||||
#define G_LABEL_UFS_MAXDIFF 0x100 | |||||
static const int superblocks[] = SBLOCKSEARCH; | static const int superblocks[] = SBLOCKSEARCH; | ||||
static void | static void | ||||
g_label_ufs_taste_common(struct g_consumer *cp, char *label, size_t size, int what) | g_label_ufs_taste_common(struct g_consumer *cp, char *label, size_t size, int what) | ||||
{ | { | ||||
struct g_provider *pp; | struct g_provider *pp; | ||||
int sb, superblock; | int sb, superblock; | ||||
struct fs *fs; | struct fs *fs; | ||||
Show All 21 Lines | for (sb = 0; (superblock = superblocks[sb]) != -1; sb++) { | ||||
*/ | */ | ||||
if (superblock % cp->provider->sectorsize != 0) | if (superblock % cp->provider->sectorsize != 0) | ||||
continue; | continue; | ||||
fs = (struct fs *)g_read_data(cp, superblock, SBLOCKSIZE, NULL); | fs = (struct fs *)g_read_data(cp, superblock, SBLOCKSIZE, NULL); | ||||
if (fs == NULL) | if (fs == NULL) | ||||
continue; | continue; | ||||
/* | /* | ||||
* Check for magic. We also need to check if file system size is equal | * Check for magic. We also need to check if file system size | ||||
* to providers size, because sysinstall(8) used to bogusly put first | * is almost equal to providers size, because sysinstall(8) | ||||
* partition at offset 0 instead of 16, and glabel/ufs would find file | * used to bogusly put first partition at offset 0 | ||||
* system on slice instead of partition. | * instead of 16, and glabel/ufs would find file system on slice | ||||
* instead of partition. | |||||
* | |||||
* In addition, media size can be a bit bigger than file system | |||||
* size. For instance, mkuzip can append bytes to align data | |||||
* to large sector size (it improves compression rates). | |||||
*/ | */ | ||||
switch (fs->fs_magic){ | |||||
case FS_UFS1_MAGIC: | |||||
case FS_UFS2_MAGIC: | |||||
G_LABEL_DEBUG(1, "%s %s params: %jd, %d, %d, %jd\n", | |||||
fs->fs_magic == FS_UFS1_MAGIC ? "UFS1" : "UFS2", | |||||
pp->name, pp->mediasize, fs->fs_fsize, | |||||
fs->fs_old_size, fs->fs_providersize); | |||||
break; | |||||
default: | |||||
break; | |||||
} | |||||
if (fs->fs_magic == FS_UFS1_MAGIC && fs->fs_fsize > 0 && | if (fs->fs_magic == FS_UFS1_MAGIC && fs->fs_fsize > 0 && | ||||
((pp->mediasize / fs->fs_fsize == fs->fs_old_size) || | ( G_LABEL_UFS_CMP(pp, fs, fs_old_size) | ||||
(pp->mediasize / fs->fs_fsize == fs->fs_providersize))) { | || G_LABEL_UFS_CMP(pp, fs, fs_providersize))) { | ||||
/* Valid UFS1. */ | /* Valid UFS1. */ | ||||
} else if (fs->fs_magic == FS_UFS2_MAGIC && fs->fs_fsize > 0 && | } else if (fs->fs_magic == FS_UFS2_MAGIC && fs->fs_fsize > 0 && | ||||
((pp->mediasize / fs->fs_fsize == fs->fs_size) || | ( G_LABEL_UFS_CMP(pp, fs, fs_size) | ||||
(pp->mediasize / fs->fs_fsize == fs->fs_providersize))) { | || G_LABEL_UFS_CMP(pp, fs, fs_providersize))) { | ||||
/* Valid UFS2. */ | /* Valid UFS2. */ | ||||
} else { | } else { | ||||
g_free(fs); | g_free(fs); | ||||
continue; | continue; | ||||
} | } | ||||
if (fs->fs_sblockloc != superblock || fs->fs_ncg < 1 || | if (fs->fs_sblockloc != superblock || fs->fs_ncg < 1 || | ||||
fs->fs_bsize < MINBSIZE || | fs->fs_bsize < MINBSIZE || | ||||
fs->fs_bsize < sizeof(struct fs)) { | fs->fs_bsize < sizeof(struct fs)) { | ||||
▲ Show 20 Lines • Show All 56 Lines • Show Last 20 Lines |