diff options
author | Marc Aurele La France <tsi@cvs.openbsd.org> | 2007-09-19 23:47:51 +0000 |
---|---|---|
committer | Marc Aurele La France <tsi@cvs.openbsd.org> | 2007-09-19 23:47:51 +0000 |
commit | a707b36c0d40dd8a7a80672030e1f8a5e0016778 (patch) | |
tree | 9a28f4c790692a302cd77056bdae24d10ea791bf /sys | |
parent | 9b25d264b12c1dae43c84ade0563d93fee3f2e14 (diff) |
On sparc & sparc64, change `mount -a` to recognise Linux ext2 partitions
by interpreting more fields out of a standard Sun disk label.
ok krw@
Diffstat (limited to 'sys')
-rw-r--r-- | sys/arch/sparc/sparc/disksubr.c | 59 | ||||
-rw-r--r-- | sys/arch/sparc64/sparc64/disksubr.c | 59 | ||||
-rw-r--r-- | sys/dev/sun/disklabel.h | 91 |
3 files changed, 190 insertions, 19 deletions
diff --git a/sys/arch/sparc/sparc/disksubr.c b/sys/arch/sparc/sparc/disksubr.c index 7587d46c810..995aeeadd79 100644 --- a/sys/arch/sparc/sparc/disksubr.c +++ b/sys/arch/sparc/sparc/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.70 2007/07/01 19:06:58 miod Exp $ */ +/* $OpenBSD: disksubr.c,v 1.71 2007/09/19 23:47:50 tsi Exp $ */ /* $NetBSD: disksubr.c,v 1.16 1996/04/28 20:25:59 thorpej Exp $ */ /* @@ -238,6 +238,7 @@ disklabel_sun_to_bsd(struct sun_disklabel *sl, struct disklabel *lp) { struct partition *npp; struct sun_dkpart *spp; + struct sun_partinfo *ppp; int i, secpercyl; u_short cksum = 0, *sp1, *sp2; @@ -334,13 +335,67 @@ disklabel_sun_to_bsd(struct sun_disklabel *sl, struct disklabel *lp) npp->p_cpg = 16; } } - if (sl->sl_xpmag == SL_XPMAGTYP) + if (sl->sl_xpmag == SL_XPMAGTYP) { for (i = 0; i < MAXPARTITIONS; i++) { npp = &lp->d_partitions[i]; npp->p_fstype = sl->sl_types[i]; npp->p_fragblock = sl->sl_fragblock[i]; npp->p_cpg = sl->sl_cpg[i]; } + } + } else if (sl->sl_nparts <= 8) { + /* + * A more traditional Sun label. Recognise certain filesystem + * types from it, if they are available. + */ + if ((i = sl->sl_nparts) == 0) { + for (i = 8; i-- > 0; ) { + npp = &lp->d_partitions[i]; + if (npp->p_size == 0) + continue; + + ppp = &sl->sl_ipart[i]; + if ((ppp->spi_tag == 0) && (ppp->spi_flag == 0)) + continue; + + i = 8; + break; + } + } + + while (i-- > 0) { + npp = &lp->d_partitions[i]; + if (npp->p_size == 0) + continue; + + ppp = &sl->sl_ipart[i]; + switch (ppp->spi_tag) { + case SPTAG_EMPTY: + case SPTAG_BOOT: + case SPTAG_WHOLE_DISK: + npp->p_fstype = FS_UNUSED; + break; + case SPTAG_SUNOS_SWAP: + case SPTAG_LINUX_SWAP: + npp->p_fstype = FS_UNUSED; /* FS_SWAP? */ + break; + case SPTAG_SUNOS_ROOT: + case SPTAG_SUNOS_USR: + case SPTAG_SUNOS_VAR: + case SPTAG_SUNOS_HOME: + npp->p_fstype = FS_BSDFFS; + npp->p_fragblock = + DISKLABELV1_FFS_FRAGBLOCK(2048, 8); + npp->p_cpg = 16; + break; + case SPTAG_LINUX_EXT2: + npp->p_fstype = FS_EXT2FS; + break; + default: + npp->p_fstype = FS_UNUSED; + break; + } + } } lp->d_checksum = 0; diff --git a/sys/arch/sparc64/sparc64/disksubr.c b/sys/arch/sparc64/sparc64/disksubr.c index fbae3ef8a45..7addd06835e 100644 --- a/sys/arch/sparc64/sparc64/disksubr.c +++ b/sys/arch/sparc64/sparc64/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.46 2007/06/20 18:15:46 deraadt Exp $ */ +/* $OpenBSD: disksubr.c,v 1.47 2007/09/19 23:47:50 tsi Exp $ */ /* $NetBSD: disksubr.c,v 1.13 2000/12/17 22:39:18 pk Exp $ */ /* @@ -231,6 +231,7 @@ disklabel_sun_to_bsd(struct sun_disklabel *sl, struct disklabel *lp) { struct partition *npp; struct sun_dkpart *spp; + struct sun_partinfo *ppp; int i, secpercyl; u_short cksum = 0, *sp1, *sp2; @@ -327,13 +328,67 @@ disklabel_sun_to_bsd(struct sun_disklabel *sl, struct disklabel *lp) npp->p_cpg = 16; } } - if (sl->sl_xpmag == SL_XPMAGTYP) + if (sl->sl_xpmag == SL_XPMAGTYP) { for (i = 0; i < MAXPARTITIONS; i++) { npp = &lp->d_partitions[i]; npp->p_fstype = sl->sl_types[i]; npp->p_fragblock = sl->sl_fragblock[i]; npp->p_cpg = sl->sl_cpg[i]; } + } + } else if (sl->sl_nparts <= 8) { + /* + * A more traditional Sun label. Recognise certain filesystem + * types from it, if they are available. + */ + if ((i = sl->sl_nparts) == 0) { + for (i = 8; i-- > 0; ) { + npp = &lp->d_partitions[i]; + if (npp->p_size == 0) + continue; + + ppp = &sl->sl_ipart[i]; + if ((ppp->spi_tag == 0) && (ppp->spi_flag == 0)) + continue; + + i = 8; + break; + } + } + + while (i-- > 0) { + npp = &lp->d_partitions[i]; + if (npp->p_size == 0) + continue; + + ppp = &sl->sl_ipart[i]; + switch (ppp->spi_tag) { + case SPTAG_EMPTY: + case SPTAG_BOOT: + case SPTAG_WHOLE_DISK: + npp->p_fstype = FS_UNUSED; + break; + case SPTAG_SUNOS_SWAP: + case SPTAG_LINUX_SWAP: + npp->p_fstype = FS_UNUSED; /* FS_SWAP? */ + break; + case SPTAG_SUNOS_ROOT: + case SPTAG_SUNOS_USR: + case SPTAG_SUNOS_VAR: + case SPTAG_SUNOS_HOME: + npp->p_fstype = FS_BSDFFS; + npp->p_fragblock = + DISKLABELV1_FFS_FRAGBLOCK(2048, 8); + npp->p_cpg = 16; + break; + case SPTAG_LINUX_EXT2: + npp->p_fstype = FS_EXT2FS; + break; + default: + npp->p_fstype = FS_UNUSED; + break; + } + } } lp->d_checksum = 0; diff --git a/sys/dev/sun/disklabel.h b/sys/dev/sun/disklabel.h index 79baa56a232..947719cd15a 100644 --- a/sys/dev/sun/disklabel.h +++ b/sys/dev/sun/disklabel.h @@ -1,4 +1,4 @@ -/* $OpenBSD: disklabel.h,v 1.4 2007/05/31 00:30:10 deraadt Exp $ */ +/* $OpenBSD: disklabel.h,v 1.5 2007/09/19 23:47:50 tsi Exp $ */ /* $NetBSD: disklabel.h,v 1.2 1998/08/22 14:55:28 mrg Exp $ */ /* @@ -43,36 +43,97 @@ /* * SunOS disk label layout (only relevant portions discovered here). + * This describes the format typically found on SPARC systems, but not + * that usually seen on SunOS/x86 and SunOS/amd64 systems. */ #define SUN_DKMAGIC 55998 /* partition info */ struct sun_dkpart { - int sdkp_cyloffset; /* starting cylinder */ - int sdkp_nsectors; /* number of sectors */ + u_int sdkp_cyloffset; /* starting cylinder */ + u_int sdkp_nsectors; /* number of sectors */ }; +/* partition types */ +struct sun_partinfo { + u_short spi_tag; /* filesystem type */ + u_short spi_flag; /* flags */ +}; + +/* some spi_tag values */ +#define SPTAG_EMPTY 0x00 +#define SPTAG_BOOT 0x01 +#define SPTAG_SUNOS_ROOT 0x02 +#define SPTAG_SUNOS_SWAP 0x03 +#define SPTAG_SUNOS_USR 0x04 +#define SPTAG_WHOLE_DISK 0x05 +#define SPTAG_SUNOS_STAND 0x06 +#define SPTAG_SUNOS_VAR 0x07 +#define SPTAG_SUNOS_HOME 0x08 +#define SPTAG_LINUX_SWAP 0x82 +#define SPTAG_LINUX_EXT2 0x83 + #define SUNXPART 8 #define SL_XPMAG (0x199d1fe2+SUNXPART) #define SL_XPMAGTYP (0x199d1fe2+SUNXPART+1) /* contains types */ struct sun_disklabel { /* total size = 512 bytes */ char sl_text[128]; - u_int sl_xpsum; /* additive cksum, [xl_xpmag,sl_xx1) */ - u_int sl_xpmag; /* "extended" magic number */ - struct sun_dkpart sl_xpart[SUNXPART]; /* "extended" partitions, i through p */ - u_char sl_types[MAXPARTITIONS]; - u_int8_t sl_fragblock[MAXPARTITIONS]; - u_int16_t sl_cpg[MAXPARTITIONS]; - char sl_xxx1[292 - sizeof(u_int) - sizeof(u_int) - - (sizeof(struct sun_dkpart) * SUNXPART) - - sizeof(u_char) * MAXPARTITIONS - - sizeof(u_int8_t) * MAXPARTITIONS - - sizeof(u_int16_t) * MAXPARTITIONS]; + union { + /* Sun standard fields, also used on Linux */ + struct { + /* label version */ + u_int sli_version; + /* short volume name */ + char sli_volume[8]; + /* partition count */ + u_short sli_nparts; + struct sun_partinfo sli_part[8]; + char sli_xxx1[292 - sizeof(u_int) - + (sizeof(char) * 8) - sizeof(u_short) - + (sizeof(struct sun_partinfo) * 8)]; + } i; + /* BSD-specific extensions */ + struct { + /* additive cksum, [xl_xpmag,sl_xx1) */ + u_int slx_xpsum; + /* "extended" magic number */ + u_int slx_xpmag; + /* "extended" partitions, i through p */ + struct sun_dkpart slx_xpart[SUNXPART]; + u_char slx_types[MAXPARTITIONS]; + u_int8_t slx_fragblock[MAXPARTITIONS]; + u_int16_t slx_cpg[MAXPARTITIONS]; + char slx_xxx1[292 - sizeof(u_int) - + sizeof(u_int) - + (sizeof(struct sun_dkpart) * + SUNXPART) - + (sizeof(u_char) * + MAXPARTITIONS) - + (sizeof(u_int8_t) * + MAXPARTITIONS) - + (sizeof(u_int16_t) * + MAXPARTITIONS)]; + } x; + } u; +/* Compatibility */ +#define sl_xpsum u.x.slx_xpsum +#define sl_xpmag u.x.slx_xpmag +#define sl_xpart u.x.slx_xpart +#define sl_types u.x.slx_types +#define sl_fragblock u.x.slx_fragblock +#define sl_cpg u.x.slx_cpg +#define sl_xxx1 u.x.slx_xxx1 +/* Convenience */ +#define sl_version u.i.sli_version +#define sl_volume u.i.sli_volume +#define sl_nparts u.i.sli_nparts +#define sl_ipart u.i.sli_part +#define sl_xxx1i u.i.sli_xxx1 u_short sl_rpm; /* rotational speed */ u_short sl_pcylinders; /* number of physical cyls */ -#define sl_pcyl sl_pcylinders /* XXX: old sun3 */ +#define sl_pcyl sl_pcylinders /* XXX: old sun3 */ u_short sl_sparespercyl; /* spare sectors per cylinder */ char sl_xxx3[4]; u_short sl_interleave; /* interleave factor */ |