KNF-ified by Scott Reynolds a long time ago.
This commit is contained in:
parent
c12cfe6530
commit
d03a91c75f
|
@ -1,4 +1,4 @@
|
||||||
/* $NetBSD: disksubr.c,v 1.10 1995/07/23 21:51:47 briggs Exp $ */
|
/* $NetBSD: disksubr.c,v 1.11 1996/02/11 15:23:19 briggs Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 1982, 1986, 1988 Regents of the University of California.
|
* Copyright (c) 1982, 1986, 1988 Regents of the University of California.
|
||||||
|
@ -70,26 +70,25 @@
|
||||||
|
|
||||||
/* rewritten, 2-5-93 MLF */
|
/* rewritten, 2-5-93 MLF */
|
||||||
/* its alot cleaner now, and adding support for new partition types
|
/* its alot cleaner now, and adding support for new partition types
|
||||||
isn't a bitch anymore
|
* isn't a bitch anymore
|
||||||
known bugs:
|
* known bugs:
|
||||||
1) when only an HFS_PART part exists on a drive it gets assigned to "B"
|
* 1) when only an HFS_PART part exists on a drive it gets assigned to "B"
|
||||||
this is because of line 623 of sd.c, I think this line should go.
|
* this is because of line 623 of sd.c, I think this line should go.
|
||||||
2) /sbin/disklabel expects the whole disk to be in "D", we put it in
|
* 2) /sbin/disklabel expects the whole disk to be in "D", we put it in
|
||||||
"C" (I think) and we don't set that position in the disklabel structure
|
* "C" (I think) and we don't set that position in the disklabel structure
|
||||||
as used. Again, not my fault.
|
* as used. Again, not my fault.
|
||||||
*/
|
*/
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <sys/systm.h>
|
#include <sys/systm.h>
|
||||||
#include <sys/buf.h>
|
#include <sys/buf.h>
|
||||||
#include <sys/disklabel.h>
|
#include <sys/disklabel.h>
|
||||||
#include <sys/syslog.h>
|
#include <sys/syslog.h>
|
||||||
|
|
||||||
#include "dpme.h" /* MF the structure of a mac partition entry */
|
#include "dpme.h" /* MF the structure of a mac partition entry */
|
||||||
|
|
||||||
#define b_cylin b_resid
|
#define b_cylin b_resid
|
||||||
|
|
||||||
static int print=0;
|
static int print = 0;
|
||||||
static char *mstr2upper(char *str);
|
|
||||||
|
|
||||||
#define ROOT_PART 1
|
#define ROOT_PART 1
|
||||||
#define UFS_PART 2
|
#define UFS_PART 2
|
||||||
|
@ -97,214 +96,231 @@ static char *mstr2upper(char *str);
|
||||||
#define HFS_PART 4
|
#define HFS_PART 4
|
||||||
#define SCRATCH_PART 5
|
#define SCRATCH_PART 5
|
||||||
|
|
||||||
int getFreeLabelEntry(struct disklabel *lp)
|
|
||||||
{
|
|
||||||
/*
|
/*
|
||||||
find an entry in the disk label that is unused and return it
|
* Find an entry in the disk label that is unused and return it
|
||||||
or -1 if no entry
|
* or -1 if no entry
|
||||||
*/
|
*/
|
||||||
int i=0;
|
int
|
||||||
|
getFreeLabelEntry(lp)
|
||||||
|
struct disklabel *lp;
|
||||||
|
{
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
for(i=0;i<MAXPARTITIONS;i++)
|
for (i = 0; i < MAXPARTITIONS; i++) {
|
||||||
{
|
if ((i != RAW_PART)
|
||||||
if ( (i != RAW_PART)
|
&& (lp->d_partitions[i].p_fstype == FS_UNUSED))
|
||||||
&& (lp->d_partitions[i].p_fstype==FS_UNUSED) )
|
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int whichType(struct partmapentry *part)
|
/*
|
||||||
|
* figure out what the type of the given part is and return it
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
whichType(part)
|
||||||
|
struct partmapentry *part;
|
||||||
{
|
{
|
||||||
struct blockzeroblock *bzb;
|
struct blockzeroblock *bzb;
|
||||||
|
|
||||||
/*
|
if (part->pmPartType[0] == '\0')
|
||||||
figure out what the type of the given part is and return it
|
return 0;
|
||||||
*/
|
|
||||||
if (part->pmPartType[0]=='\0') return 0;
|
|
||||||
|
|
||||||
if (strcmp(PART_DRIVER_TYPE,(char *)part->pmPartType)==0 ) return 0;
|
if (strcmp(PART_DRIVER_TYPE, (char *)part->pmPartType) == 0)
|
||||||
if (strcmp(PART_PARTMAP_TYPE,(char *)part->pmPartType)==0 ) return 0;
|
return 0;
|
||||||
|
if (strcmp(PART_PARTMAP_TYPE, (char *)part->pmPartType) == 0)
|
||||||
if (strcmp(PART_UNIX_TYPE,(char *)part->pmPartType)==0)
|
return 0;
|
||||||
{
|
if (strcmp(PART_UNIX_TYPE, (char *)part->pmPartType) == 0) {
|
||||||
/* unix part, swap, root, usr */
|
/* unix part, swap, root, usr */
|
||||||
bzb= (struct blockzeroblock *)(&part->pmBootArgs);
|
bzb = (struct blockzeroblock *)(&part->pmBootArgs);
|
||||||
if (bzb->bzbMagic!=BZB_MAGIC)
|
if (bzb->bzbMagic != BZB_MAGIC)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if(bzb->bzbFlags & BZB_ROOTFS) return ROOT_PART;
|
if (bzb->bzbFlags & BZB_ROOTFS)
|
||||||
|
return ROOT_PART;
|
||||||
|
|
||||||
if(bzb->bzbFlags & BZB_USRFS) return UFS_PART;
|
if (bzb->bzbFlags & BZB_USRFS)
|
||||||
|
return UFS_PART;
|
||||||
|
|
||||||
if(bzb->bzbType == BZB_TYPESWAP) return SWAP_PART;
|
if (bzb->bzbType == BZB_TYPESWAP)
|
||||||
|
return SWAP_PART;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (strcmp(PART_MAC_TYPE,(char *)part->pmPartType)==0 ) return HFS_PART;
|
if (strcmp(PART_MAC_TYPE, (char *)part->pmPartType) == 0)
|
||||||
|
return HFS_PART;
|
||||||
/*
|
/*
|
||||||
if (strcmp(PART_SCRATCH,(char *)part->pmPartType)==0 ) return SCRATCH_PART;
|
if (strcmp(PART_SCRATCH, (char *)part->pmPartType) == 0)
|
||||||
|
return SCRATCH_PART;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
return SCRATCH_PART; /* no known type, but label it, anyway */
|
return SCRATCH_PART; /* no known type, but label it, anyway */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int fixPartTable(struct partmapentry *partTable,long size,char *base)
|
|
||||||
{
|
|
||||||
int i=0;
|
|
||||||
struct partmapentry *pmap;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
take part table in crappy form, place it in a structure we can depend
|
* Take part table in crappy form, place it in a structure we can depend
|
||||||
upon. make sure names are null terminated. Capitalize the names
|
* upon. Make sure names are NUL terminated. Capitalize the names
|
||||||
of part types.
|
* of part types.
|
||||||
*/
|
*/
|
||||||
|
static void
|
||||||
|
fixPartTable(partTable, size, base)
|
||||||
|
struct partmapentry *partTable;
|
||||||
|
long size;
|
||||||
|
char *base;
|
||||||
|
{
|
||||||
|
int i = 0;
|
||||||
|
struct partmapentry *pmap;
|
||||||
|
char *s;
|
||||||
|
|
||||||
for(i=0;i<MAXPARTITIONS;i++)
|
for (i = 0; i < MAXPARTITIONS; i++) {
|
||||||
{
|
pmap = (struct partmapentry *)((i * size) + base);
|
||||||
pmap=(struct partmapentry *)((i*size)+base);
|
pmap->pmPartName[31] = '\0';
|
||||||
pmap->pmPartName[31]='\0';
|
pmap->pmPartType[31] = '\0';
|
||||||
pmap->pmPartType[31]='\0';
|
|
||||||
|
|
||||||
mstr2upper((char *)pmap->pmPartType);
|
for (s = pmap->pmPartType; *s; s++)
|
||||||
|
if ((*s >= 'a') && (*s <= 'z'))
|
||||||
|
*s = (*s - 'a' + 'A');
|
||||||
|
|
||||||
if (pmap->pmSig!=DPME_MAGIC) /* this is not valid */
|
if (pmap->pmSig != DPME_MAGIC) /* this is not valid */
|
||||||
pmap->pmPartType[0]='\0';
|
pmap->pmPartType[0] = '\0';
|
||||||
|
|
||||||
partTable[i]=*pmap;
|
|
||||||
|
|
||||||
|
partTable[i] = *pmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
int setRoot(struct partmapentry *part,struct disklabel *lp,int slot)
|
setRoot(part, lp, slot)
|
||||||
|
struct partmapentry *part;
|
||||||
|
struct disklabel *lp;
|
||||||
|
int slot;
|
||||||
{
|
{
|
||||||
lp->d_partitions[slot].p_size =part->pmPartBlkCnt;
|
lp->d_partitions[slot].p_size = part->pmPartBlkCnt;
|
||||||
lp->d_partitions[slot].p_offset=part->pmPyPartStart;
|
lp->d_partitions[slot].p_offset = part->pmPyPartStart;
|
||||||
lp->d_partitions[slot].p_fstype=FS_BSDFFS;
|
lp->d_partitions[slot].p_fstype = FS_BSDFFS;
|
||||||
|
|
||||||
#if PRINT_DISKLABELS
|
#if PRINT_DISKLABELS
|
||||||
printf("%c: Root '%s' at %d size %d\n",slot+'a',
|
printf("%c: Root '%s' at %d size %d\n", slot + 'a',
|
||||||
part->pmPartName,
|
part->pmPartName,
|
||||||
part->pmPyPartStart,
|
part->pmPyPartStart,
|
||||||
part->pmPartBlkCnt);
|
part->pmPartBlkCnt);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
part->pmPartType[0]='\0';
|
part->pmPartType[0] = '\0';
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int setSwap(struct partmapentry *part,struct disklabel *lp,int slot)
|
static void
|
||||||
|
setSwap(part, lp, slot)
|
||||||
|
struct partmapentry *part;
|
||||||
|
struct disklabel *lp;
|
||||||
|
int slot;
|
||||||
{
|
{
|
||||||
lp->d_partitions[slot].p_size =part->pmPartBlkCnt;
|
lp->d_partitions[slot].p_size = part->pmPartBlkCnt;
|
||||||
lp->d_partitions[slot].p_offset=part->pmPyPartStart;
|
lp->d_partitions[slot].p_offset = part->pmPyPartStart;
|
||||||
lp->d_partitions[slot].p_fstype=FS_SWAP;
|
lp->d_partitions[slot].p_fstype = FS_SWAP;
|
||||||
|
|
||||||
#if PRINT_DISKLABELS
|
#if PRINT_DISKLABELS
|
||||||
printf("%c: Swap '%s' at %d size %d\n",slot+'a',
|
printf("%c: Swap '%s' at %d size %d\n", slot + 'a',
|
||||||
part->pmPartName,
|
part->pmPartName,
|
||||||
part->pmPyPartStart,
|
part->pmPyPartStart,
|
||||||
part->pmPartBlkCnt);
|
part->pmPartBlkCnt);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
part->pmPartType[0]='\0';
|
part->pmPartType[0] = '\0';
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int setUfs(struct partmapentry *part,struct disklabel *lp,int slot)
|
static void
|
||||||
|
setUfs(part, lp, slot)
|
||||||
|
struct partmapentry *part;
|
||||||
|
struct disklabel *lp;
|
||||||
|
int slot;
|
||||||
{
|
{
|
||||||
lp->d_partitions[slot].p_size =part->pmPartBlkCnt;
|
lp->d_partitions[slot].p_size = part->pmPartBlkCnt;
|
||||||
lp->d_partitions[slot].p_offset=part->pmPyPartStart;
|
lp->d_partitions[slot].p_offset = part->pmPyPartStart;
|
||||||
lp->d_partitions[slot].p_fstype=FS_BSDFFS;
|
lp->d_partitions[slot].p_fstype = FS_BSDFFS;
|
||||||
|
|
||||||
#if PRINT_DISKLABELS
|
#if PRINT_DISKLABELS
|
||||||
printf("%c: Usr '%s' at %d size %d\n",slot+'a',
|
printf("%c: Usr '%s' at %d size %d\n", slot + 'a',
|
||||||
part->pmPartName,
|
part->pmPartName,
|
||||||
part->pmPyPartStart,
|
part->pmPyPartStart,
|
||||||
part->pmPartBlkCnt);
|
part->pmPartBlkCnt);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
part->pmPartType[0]='\0';
|
part->pmPartType[0] = '\0';
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int setHfs(struct partmapentry *part,struct disklabel *lp,int slot)
|
static void
|
||||||
|
setHfs(part, lp, slot)
|
||||||
|
struct partmapentry *part;
|
||||||
|
struct disklabel *lp;
|
||||||
|
int slot;
|
||||||
{
|
{
|
||||||
lp->d_partitions[slot].p_size =part->pmPartBlkCnt;
|
lp->d_partitions[slot].p_size = part->pmPartBlkCnt;
|
||||||
lp->d_partitions[slot].p_offset=part->pmPyPartStart;
|
lp->d_partitions[slot].p_offset = part->pmPyPartStart;
|
||||||
lp->d_partitions[slot].p_fstype=FS_HFS;
|
lp->d_partitions[slot].p_fstype = FS_HFS;
|
||||||
|
|
||||||
#if PRINT_DISKLABELS
|
#if PRINT_DISKLABELS
|
||||||
printf("%c: HFS_PART '%s' at %d size %d\n",slot+'a',
|
printf("%c: HFS_PART '%s' at %d size %d\n", slot + 'a',
|
||||||
part->pmPartName,
|
part->pmPartName,
|
||||||
part->pmPyPartStart,
|
part->pmPyPartStart,
|
||||||
part->pmPartBlkCnt);
|
part->pmPartBlkCnt);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
part->pmPartType[0]='\0';
|
part->pmPartType[0] = '\0';
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int setScratch(struct partmapentry *part,struct disklabel *lp,int slot)
|
static void
|
||||||
|
setScratch(part, lp, slot)
|
||||||
|
struct partmapentry *part;
|
||||||
|
struct disklabel *lp;
|
||||||
|
int slot;
|
||||||
{
|
{
|
||||||
lp->d_partitions[slot].p_size =part->pmPartBlkCnt;
|
lp->d_partitions[slot].p_size = part->pmPartBlkCnt;
|
||||||
lp->d_partitions[slot].p_offset=part->pmPyPartStart;
|
lp->d_partitions[slot].p_offset = part->pmPyPartStart;
|
||||||
lp->d_partitions[slot].p_fstype=FS_OTHER;
|
lp->d_partitions[slot].p_fstype = FS_OTHER;
|
||||||
|
|
||||||
#if PRINT_DISKLABELS
|
#if PRINT_DISKLABELS
|
||||||
printf("%c: Other (%s) '%s' at %d size %d\n",slot+'a',
|
printf("%c: Other (%s) '%s' at %d size %d\n", slot + 'a',
|
||||||
part->pmPartType,
|
part->pmPartType,
|
||||||
part->pmPartName,
|
part->pmPartName,
|
||||||
part->pmPyPartStart,
|
part->pmPyPartStart,
|
||||||
part->pmPartBlkCnt);
|
part->pmPartBlkCnt);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
part->pmPartType[0]='\0';
|
part->pmPartType[0] = '\0';
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int getNamedType(struct partmapentry *part,struct disklabel *lp,int type, int alt)
|
int
|
||||||
|
getNamedType(part, lp, type, alt)
|
||||||
|
struct partmapentry *part;
|
||||||
|
struct disklabel *lp;
|
||||||
|
int type, alt;
|
||||||
{
|
{
|
||||||
struct blockzeroblock *bzb;
|
struct blockzeroblock *bzb;
|
||||||
int i=0;
|
int i = 0;
|
||||||
|
|
||||||
for(i=0;i<MAXPARTITIONS;i++)
|
for (i = 0; i < MAXPARTITIONS; i++) {
|
||||||
{
|
if (whichType(&(part[i])) == type) {
|
||||||
if (whichType(&(part[i]))==type)
|
switch (type) {
|
||||||
{
|
case ROOT_PART:
|
||||||
switch(type)
|
bzb = (struct blockzeroblock *)
|
||||||
{
|
(&part[i].pmBootArgs);
|
||||||
case ROOT_PART:
|
if (alt >= 0 && alt != bzb->bzbCluster)
|
||||||
bzb = (struct blockzeroblock *)
|
goto skip;
|
||||||
(&part[i].pmBootArgs);
|
setRoot(&(part[i]), lp, 0);
|
||||||
if (alt >= 0 && alt != bzb->bzbCluster)
|
break;
|
||||||
goto skip;
|
case UFS_PART:
|
||||||
setRoot(&(part[i]),lp,0);
|
bzb = (struct blockzeroblock *)
|
||||||
break;
|
(&part[i].pmBootArgs);
|
||||||
case UFS_PART:
|
if (alt >= 0 && alt != bzb->bzbCluster)
|
||||||
bzb = (struct blockzeroblock *)
|
goto skip;
|
||||||
(&part[i].pmBootArgs);
|
setUfs(&(part[i]), lp, 6);
|
||||||
if (alt >= 0 && alt != bzb->bzbCluster)
|
break;
|
||||||
goto skip;
|
case SWAP_PART:
|
||||||
setUfs(&(part[i]),lp,6);
|
setSwap(&(part[i]), lp, 1);
|
||||||
break;
|
break;
|
||||||
case SWAP_PART:
|
default:
|
||||||
setSwap(&(part[i]),lp,1);
|
printf("disksubr.c: can't do type \n", type);
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
printf("disksubr.c: can't do type \n",type);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -316,12 +332,11 @@ skip:
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Attempt to read a disk label from a device
|
* Attempt to read a disk label from a device using the indicated stategy
|
||||||
* using the indicated stategy routine.
|
* routine. The label must be partly set up before this: secpercyl and
|
||||||
* The label must be partly set up before this:
|
* anything required in the strategy routine (e.g., sector size) must be
|
||||||
* secpercyl and anything required in the strategy routine
|
* filled in before calling us. Returns null on success and an error
|
||||||
* (e.g., sector size) must be filled in before calling us.
|
* string on failure.
|
||||||
* Returns null on success and an error string on failure.
|
|
||||||
*/
|
*/
|
||||||
char *
|
char *
|
||||||
readdisklabel(dev, strat, lp, osdep)
|
readdisklabel(dev, strat, lp, osdep)
|
||||||
|
@ -335,28 +350,28 @@ readdisklabel(dev, strat, lp, osdep)
|
||||||
struct blockzeroblock *bzb;
|
struct blockzeroblock *bzb;
|
||||||
|
|
||||||
/* MF
|
/* MF
|
||||||
here's what i'm gonna do:
|
* here's what i'm gonna do:
|
||||||
read in the entire diskpartition table, it may be bigger or smaller
|
* read in the entire diskpartition table, it may be bigger or smaller
|
||||||
than MAXPARTITIONS but read that many entries. Each entry has a magic
|
* than MAXPARTITIONS but read that many entries. Each entry has a magic
|
||||||
number so we'll know if an entry is crap.
|
* number so we'll know if an entry is crap.
|
||||||
next fill in the disklabel with info like this
|
* next fill in the disklabel with info like this
|
||||||
next fill in the root, usr, and swap parts.
|
* next fill in the root, usr, and swap parts.
|
||||||
Then look for anything else and fit it in
|
* then look for anything else and fit it in.
|
||||||
A: root
|
* A: root
|
||||||
B: Swap
|
* B: Swap
|
||||||
C: Whole disk
|
* C: Whole disk
|
||||||
G: Usr
|
* G: Usr
|
||||||
|
*
|
||||||
|
*
|
||||||
I'm not entirely sure what netbsd386 wants in c &d
|
* I'm not entirely sure what netbsd386 wants in c & d
|
||||||
386bsd wants other stuff, so i'll leave them alone
|
* 386bsd wants other stuff, so i'll leave them alone
|
||||||
|
*
|
||||||
AKB -- I added to Mike's original algorithm by searching for a bzbCluster
|
* AKB -- I added to Mike's original algorithm by searching for a bzbCluster
|
||||||
of zero for root, first. This allows A/UX to live on cluster 1 and
|
* of zero for root, first. This allows A/UX to live on cluster 1 and
|
||||||
NetBSD to live on cluster 0--regardless of the actual order on the
|
* NetBSD to live on cluster 0--regardless of the actual order on the
|
||||||
disk. This whole algorithm should probably be changed in the future.
|
* disk. This whole algorithm should probably be changed in the future.
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
if (lp->d_secperunit == 0)
|
if (lp->d_secperunit == 0)
|
||||||
lp->d_secperunit = 0x1fffffff;
|
lp->d_secperunit = 0x1fffffff;
|
||||||
|
|
||||||
|
@ -366,64 +381,60 @@ AKB -- I added to Mike's original algorithm by searching for a bzbCluster
|
||||||
bp = geteblk((int)lp->d_secsize * MAXPARTITIONS);
|
bp = geteblk((int)lp->d_secsize * MAXPARTITIONS);
|
||||||
|
|
||||||
bp->b_dev = dev;
|
bp->b_dev = dev;
|
||||||
bp->b_blkno = 1; /* pmap starts at block 1 */
|
bp->b_blkno = 1; /* pmap starts at block 1 */
|
||||||
bp->b_bcount = lp->d_secsize * MAXPARTITIONS;
|
bp->b_bcount = lp->d_secsize * MAXPARTITIONS;
|
||||||
bp->b_flags = B_BUSY | B_READ;
|
bp->b_flags = B_BUSY | B_READ;
|
||||||
bp->b_cylin = 1 / lp->d_secpercyl;
|
bp->b_cylin = 1 / lp->d_secpercyl;
|
||||||
(*strat)(bp);
|
(*strat)(bp);
|
||||||
if (biowait(bp)) {
|
if (biowait(bp)) {
|
||||||
msg = "I/O error";
|
msg = "I/O error";
|
||||||
}
|
} else {
|
||||||
else {
|
int i = 0;
|
||||||
int i=0;
|
|
||||||
struct partmapentry pmap[MAXPARTITIONS];
|
struct partmapentry pmap[MAXPARTITIONS];
|
||||||
|
|
||||||
fixPartTable(pmap,lp->d_secsize,bp->b_un.b_addr);
|
fixPartTable(pmap, lp->d_secsize, bp->b_un.b_addr);
|
||||||
if (getNamedType(pmap,lp,ROOT_PART, 0))
|
if (getNamedType(pmap, lp, ROOT_PART, 0))
|
||||||
getNamedType(pmap,lp,ROOT_PART, -1);
|
getNamedType(pmap, lp, ROOT_PART, -1);
|
||||||
if (getNamedType(pmap,lp,UFS_PART, 0))
|
if (getNamedType(pmap, lp, UFS_PART, 0))
|
||||||
getNamedType(pmap,lp,UFS_PART, -1);
|
getNamedType(pmap, lp, UFS_PART, -1);
|
||||||
getNamedType(pmap,lp,SWAP_PART, -1);
|
getNamedType(pmap, lp, SWAP_PART, -1);
|
||||||
for(i=0;i<MAXPARTITIONS;i++)
|
for (i = 0; i < MAXPARTITIONS; i++) {
|
||||||
{
|
|
||||||
int partType;
|
int partType;
|
||||||
int slot;
|
int slot;
|
||||||
|
|
||||||
slot=getFreeLabelEntry(lp);
|
slot = getFreeLabelEntry(lp);
|
||||||
if (slot < 0)
|
if (slot < 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
partType=whichType(&(pmap[i]));
|
partType = whichType(&(pmap[i]));
|
||||||
|
|
||||||
switch (partType)
|
switch (partType) {
|
||||||
{
|
|
||||||
|
|
||||||
case ROOT_PART:
|
case ROOT_PART:
|
||||||
/*
|
/*
|
||||||
another root part will turn into a plain old UFS_PART partition,
|
* another root part will turn into a plain old
|
||||||
live with it.
|
* UFS_PART partition, live with it.
|
||||||
*/
|
*/
|
||||||
case UFS_PART:
|
case UFS_PART:
|
||||||
setUfs(&(pmap[i]),lp,slot);
|
setUfs(&(pmap[i]), lp, slot);
|
||||||
break;
|
break;
|
||||||
case SWAP_PART:
|
case SWAP_PART:
|
||||||
setSwap(&(pmap[i]),lp,slot);
|
setSwap(&(pmap[i]), lp, slot);
|
||||||
break;
|
break;
|
||||||
case HFS_PART:
|
case HFS_PART:
|
||||||
setHfs(&(pmap[i]),lp,slot);
|
setHfs(&(pmap[i]), lp, slot);
|
||||||
break;
|
break;
|
||||||
case SCRATCH_PART:
|
case SCRATCH_PART:
|
||||||
setScratch(&(pmap[i]),lp,slot);
|
setScratch(&(pmap[i]), lp, slot);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lp->d_npartitions = MAXPARTITIONS;
|
||||||
lp->d_npartitions=MAXPARTITIONS;
|
|
||||||
|
|
||||||
bp->b_flags = B_INVAL | B_AGE;
|
bp->b_flags = B_INVAL | B_AGE;
|
||||||
brelse(bp);
|
brelse(bp);
|
||||||
|
@ -431,9 +442,9 @@ live with it.
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check new disk label for sensibility
|
* Check new disk label for sensibility before setting it.
|
||||||
* before setting it.
|
|
||||||
*/
|
*/
|
||||||
|
int
|
||||||
setdisklabel(olp, nlp, openmask, osdep)
|
setdisklabel(olp, nlp, openmask, osdep)
|
||||||
register struct disklabel *olp, *nlp;
|
register struct disklabel *olp, *nlp;
|
||||||
u_long openmask;
|
u_long openmask;
|
||||||
|
@ -466,18 +477,13 @@ setdisklabel(olp, nlp, openmask, osdep)
|
||||||
npp->p_cpg = opp->p_cpg;
|
npp->p_cpg = opp->p_cpg;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
nlp->d_checksum = 0;
|
nlp->d_checksum = 0;
|
||||||
nlp->d_checksum = dkcksum(nlp);
|
nlp->d_checksum = dkcksum(nlp);
|
||||||
*olp = *nlp;
|
*olp = *nlp;
|
||||||
#endif
|
#endif
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* encoding of disk minor numbers, should be elsewhere... */
|
|
||||||
#define dkunit(dev) (minor(dev) >> 3)
|
|
||||||
#define dkpart(dev) (minor(dev) & 07)
|
|
||||||
#define dkminor(unit, part) (((unit) << 3) | (part))
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Write disk label back to device after modification.
|
* Write disk label back to device after modification.
|
||||||
*
|
*
|
||||||
|
@ -496,14 +502,14 @@ writedisklabel(dev, strat, lp, osdep)
|
||||||
int labelpart;
|
int labelpart;
|
||||||
int error = 0;
|
int error = 0;
|
||||||
|
|
||||||
labelpart = dkpart(dev);
|
labelpart = DISKPART(dev);
|
||||||
if (lp->d_partitions[labelpart].p_offset != 0) {
|
if (lp->d_partitions[labelpart].p_offset != 0) {
|
||||||
if (lp->d_partitions[0].p_offset != 0)
|
if (lp->d_partitions[0].p_offset != 0)
|
||||||
return (EXDEV); /* not quite right */
|
return (EXDEV); /* not quite right */
|
||||||
labelpart = 0;
|
labelpart = 0;
|
||||||
}
|
}
|
||||||
bp = geteblk((int)lp->d_secsize);
|
bp = geteblk((int)lp->d_secsize);
|
||||||
bp->b_dev = makedev(major(dev), dkminor(dkunit(dev), labelpart));
|
bp->b_dev = MAKEDISKDEV(major(dev), DISKUNIT(dev), labelpart);
|
||||||
bp->b_blkno = LABELSECTOR;
|
bp->b_blkno = LABELSECTOR;
|
||||||
bp->b_bcount = lp->d_secsize;
|
bp->b_bcount = lp->d_secsize;
|
||||||
bp->b_flags = B_READ;
|
bp->b_flags = B_READ;
|
||||||
|
@ -512,7 +518,7 @@ writedisklabel(dev, strat, lp, osdep)
|
||||||
goto done;
|
goto done;
|
||||||
for (dlp = (struct disklabel *)bp->b_un.b_addr;
|
for (dlp = (struct disklabel *)bp->b_un.b_addr;
|
||||||
dlp <= (struct disklabel *)
|
dlp <= (struct disklabel *)
|
||||||
(bp->b_un.b_addr + lp->d_secsize - sizeof(*dlp));
|
(bp->b_un.b_addr + lp->d_secsize - sizeof(*dlp));
|
||||||
dlp = (struct disklabel *)((char *)dlp + sizeof(long))) {
|
dlp = (struct disklabel *)((char *)dlp + sizeof(long))) {
|
||||||
if (dlp->d_magic == DISKMAGIC && dlp->d_magic2 == DISKMAGIC &&
|
if (dlp->d_magic == DISKMAGIC && dlp->d_magic2 == DISKMAGIC &&
|
||||||
dkcksum(dlp) == 0) {
|
dkcksum(dlp) == 0) {
|
||||||
|
@ -538,84 +544,66 @@ done:
|
||||||
* if needed, and signal errors or early completion.
|
* if needed, and signal errors or early completion.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
bounds_check_with_label(struct buf *bp, struct disklabel *lp, int wlabel)
|
bounds_check_with_label(bp, lp, wlabel)
|
||||||
|
struct buf *bp;
|
||||||
|
struct disklabel *lp;
|
||||||
|
int wlabel;
|
||||||
{
|
{
|
||||||
struct partition *p = lp->d_partitions + dkpart(bp->b_dev);
|
struct partition *p = lp->d_partitions + DISKPART(bp->b_dev);
|
||||||
int labelsect = lp->d_partitions[0].p_offset;
|
int labelsect = lp->d_partitions[0].p_offset;
|
||||||
int maxsz = p->p_size,
|
int maxsz = p->p_size;
|
||||||
sz = (bp->b_bcount + DEV_BSIZE - 1) >> DEV_BSHIFT;
|
int sz = (bp->b_bcount + DEV_BSIZE - 1) >> DEV_BSHIFT;
|
||||||
|
|
||||||
/* overwriting disk label ? */
|
/* overwriting disk label ? */
|
||||||
/* XXX should also protect bootstrap in first 8K */
|
/* XXX should also protect bootstrap in first 8K */
|
||||||
#if 0 /* MF this is crap, especially on swap !! */
|
#if 0 /* MF this is crap, especially on swap !! */
|
||||||
if (bp->b_blkno + p->p_offset <= LABELSECTOR + labelsect &&
|
if (bp->b_blkno + p->p_offset <= LABELSECTOR + labelsect &&
|
||||||
#if LABELSECTOR != 0
|
#if LABELSECTOR != 0
|
||||||
bp->b_blkno + p->p_offset + sz > LABELSECTOR + labelsect &&
|
bp->b_blkno + p->p_offset + sz > LABELSECTOR + labelsect &&
|
||||||
#endif
|
#endif
|
||||||
(bp->b_flags & B_READ) == 0 && wlabel == 0) {
|
(bp->b_flags & B_READ) == 0 && wlabel == 0) {
|
||||||
bp->b_error = EROFS;
|
bp->b_error = EROFS;
|
||||||
goto bad;
|
goto bad;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(DOSBBSECTOR) && defined(notyet)
|
#if defined(DOSBBSECTOR) && defined(notyet)
|
||||||
/* overwriting master boot record? */
|
/* overwriting master boot record? */
|
||||||
if (bp->b_blkno + p->p_offset <= DOSBBSECTOR &&
|
if (bp->b_blkno + p->p_offset <= DOSBBSECTOR &&
|
||||||
(bp->b_flags & B_READ) == 0 && wlabel == 0) {
|
(bp->b_flags & B_READ) == 0 && wlabel == 0) {
|
||||||
bp->b_error = EROFS;
|
bp->b_error = EROFS;
|
||||||
goto bad;
|
goto bad;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* beyond partition? */
|
/* beyond partition? */
|
||||||
if (bp->b_blkno < 0 || bp->b_blkno + sz > maxsz) {
|
if (bp->b_blkno < 0 || bp->b_blkno + sz > maxsz) {
|
||||||
/* if exactly at end of disk, return an EOF */
|
/* if exactly at end of disk, return an EOF */
|
||||||
if (bp->b_blkno == maxsz) {
|
if (bp->b_blkno == maxsz) {
|
||||||
bp->b_resid = bp->b_bcount;
|
bp->b_resid = bp->b_bcount;
|
||||||
return(0);
|
return (0);
|
||||||
}
|
|
||||||
/* or truncate if part of it fits */
|
|
||||||
sz = maxsz - bp->b_blkno;
|
|
||||||
if (sz <= 0) {
|
|
||||||
bp->b_error = EINVAL;
|
|
||||||
goto bad;
|
|
||||||
}
|
}
|
||||||
bp->b_bcount = sz << DEV_BSHIFT;
|
/* or truncate if part of it fits */
|
||||||
}
|
sz = maxsz - bp->b_blkno;
|
||||||
|
if (sz <= 0) {
|
||||||
|
bp->b_error = EINVAL;
|
||||||
|
goto bad;
|
||||||
|
}
|
||||||
|
bp->b_bcount = sz << DEV_BSHIFT;
|
||||||
|
}
|
||||||
/* calculate cylinder for disksort to order transfers with */
|
/* calculate cylinder for disksort to order transfers with */
|
||||||
bp->b_cylin = (bp->b_blkno + p->p_offset) / lp->d_secpercyl;
|
bp->b_cylin = (bp->b_blkno + p->p_offset) / lp->d_secpercyl;
|
||||||
return(1);
|
return (1);
|
||||||
|
|
||||||
bad:
|
bad:
|
||||||
bp->b_flags |= B_ERROR;
|
bp->b_flags |= B_ERROR;
|
||||||
return(-1);
|
return (-1);
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
mtoupper(int c)
|
|
||||||
{
|
|
||||||
if (( c>='a' ) && ( c<='z') )
|
|
||||||
return ( c-'a' + 'A' );
|
|
||||||
else
|
|
||||||
return c;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
static char *
|
|
||||||
mstr2upper(char *str)
|
|
||||||
{
|
|
||||||
char *p;
|
|
||||||
|
|
||||||
for(p=str;*p;p++)
|
|
||||||
*p=mtoupper(*p);
|
|
||||||
return str;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
dk_establish(dk, dev)
|
dk_establish(dk, dev)
|
||||||
struct dkdevice *dk;
|
struct dkdevice *dk;
|
||||||
struct device *dev;
|
struct device *dev;
|
||||||
{
|
{
|
||||||
/* Empty for now. -- XXX */
|
/* Empty for now. -- XXX */
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue