Sync with news68k:
- use MAKEDISKDEV() macro - make readdisklabel(9) return more usable default label - some cosmetics
This commit is contained in:
parent
a69fbd6a18
commit
f8402eeaeb
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: disksubr.c,v 1.17 2005/02/06 02:18:02 tsutsui Exp $ */
|
||||
/* $NetBSD: disksubr.c,v 1.18 2005/05/25 12:47:24 tsutsui Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1982, 1986, 1988 Regents of the University of California.
|
||||
@ -32,7 +32,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: disksubr.c,v 1.17 2005/02/06 02:18:02 tsutsui Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: disksubr.c,v 1.18 2005/05/25 12:47:24 tsutsui Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
@ -50,19 +50,30 @@ __KERNEL_RCSID(0, "$NetBSD: disksubr.c,v 1.17 2005/02/06 02:18:02 tsutsui Exp $"
|
||||
* Returns null on success and an error string on failure.
|
||||
*/
|
||||
const char *
|
||||
readdisklabel(dev_t dev, void (*strat)(struct buf *bp), struct disklabel *lp,
|
||||
readdisklabel(dev_t dev, void (*strat)(struct buf *), struct disklabel *lp,
|
||||
struct cpu_disklabel *osdep)
|
||||
{
|
||||
struct buf *bp;
|
||||
struct disklabel *dlp;
|
||||
char *msg = NULL;
|
||||
int i;
|
||||
|
||||
if (lp->d_secsize == 0)
|
||||
lp->d_secsize = DEV_BSIZE;
|
||||
if (lp->d_secperunit == 0)
|
||||
lp->d_secperunit = 0x1fffffff;
|
||||
lp->d_npartitions = 1;
|
||||
if (lp->d_partitions[0].p_size == 0)
|
||||
lp->d_partitions[0].p_size = 0x1fffffff;
|
||||
lp->d_partitions[0].p_offset = 0;
|
||||
if (lp->d_npartitions < RAW_PART + 1)
|
||||
lp->d_npartitions = RAW_PART + 1;
|
||||
for (i = 0; i < RAW_PART; i++) {
|
||||
lp->d_partitions[i].p_size = 0;
|
||||
lp->d_partitions[i].p_offset = 0;
|
||||
}
|
||||
if (lp->d_partitions[RAW_PART].p_size == 0)
|
||||
lp->d_partitions[RAW_PART].p_size = lp->d_secperunit;
|
||||
lp->d_partitions[RAW_PART].p_offset = 0;
|
||||
|
||||
lp->d_partitions[0].p_size = lp->d_partitions[RAW_PART].p_size;
|
||||
lp->d_partitions[0].p_fstype = FS_BSDFFS;
|
||||
|
||||
bp = geteblk((int)lp->d_secsize);
|
||||
bp->b_dev = dev;
|
||||
@ -71,10 +82,10 @@ readdisklabel(dev_t dev, void (*strat)(struct buf *bp), struct disklabel *lp,
|
||||
bp->b_flags |= B_READ;
|
||||
bp->b_cylinder = LABELSECTOR / lp->d_secpercyl;
|
||||
(*strat)(bp);
|
||||
if (biowait(bp)) {
|
||||
if (biowait(bp))
|
||||
msg = "I/O error";
|
||||
} else for (dlp = (struct disklabel *)bp->b_data;
|
||||
dlp <= (struct disklabel *)(bp->b_data+DEV_BSIZE-sizeof(*dlp));
|
||||
else for (dlp = (struct disklabel *)bp->b_data;
|
||||
dlp <= (struct disklabel *)(bp->b_data + DEV_BSIZE - sizeof(*dlp));
|
||||
dlp = (struct disklabel *)((char *)dlp + sizeof(long))) {
|
||||
if (dlp->d_magic != DISKMAGIC || dlp->d_magic2 != DISKMAGIC) {
|
||||
if (msg == NULL)
|
||||
@ -93,8 +104,7 @@ readdisklabel(dev_t dev, void (*strat)(struct buf *bp), struct disklabel *lp,
|
||||
}
|
||||
|
||||
/*
|
||||
* Check new disk label for sensibility
|
||||
* before setting it.
|
||||
* Check new disk label for sensibility before setting it.
|
||||
*/
|
||||
int
|
||||
setdisklabel(struct disklabel *olp, struct disklabel *nlp, u_long openmask,
|
||||
@ -126,8 +136,8 @@ setdisklabel(struct disklabel *olp, struct disklabel *nlp, u_long openmask,
|
||||
npp->p_cpg = opp->p_cpg;
|
||||
}
|
||||
}
|
||||
nlp->d_checksum = 0;
|
||||
nlp->d_checksum = dkcksum(nlp);
|
||||
nlp->d_checksum = 0;
|
||||
nlp->d_checksum = dkcksum(nlp);
|
||||
*olp = *nlp;
|
||||
return 0;
|
||||
}
|
||||
@ -136,7 +146,7 @@ setdisklabel(struct disklabel *olp, struct disklabel *nlp, u_long openmask,
|
||||
* Write disk label back to device after modification.
|
||||
*/
|
||||
int
|
||||
writedisklabel(dev_t dev, void (*strat)(struct buf *bp), struct disklabel *lp,
|
||||
writedisklabel(dev_t dev, void (*strat)(struct buf *), struct disklabel *lp,
|
||||
struct cpu_disklabel *osdep)
|
||||
{
|
||||
struct buf *bp;
|
||||
@ -151,7 +161,7 @@ writedisklabel(dev_t dev, void (*strat)(struct buf *bp), struct disklabel *lp,
|
||||
labelpart = 0;
|
||||
}
|
||||
bp = geteblk((int)lp->d_secsize);
|
||||
bp->b_dev = makedev(major(dev), DISKMINOR(DISKUNIT(dev), labelpart));
|
||||
bp->b_dev = MAKEDISKDEV(major(dev), DISKUNIT(dev), labelpart);
|
||||
bp->b_blkno = LABELSECTOR;
|
||||
bp->b_bcount = lp->d_secsize;
|
||||
bp->b_flags |= B_READ;
|
||||
@ -173,14 +183,12 @@ writedisklabel(dev_t dev, void (*strat)(struct buf *bp), struct disklabel *lp,
|
||||
}
|
||||
}
|
||||
error = ESRCH;
|
||||
done:
|
||||
done:
|
||||
brelse(bp);
|
||||
return error;
|
||||
}
|
||||
|
||||
/*
|
||||
* UNTESTED !!
|
||||
*
|
||||
* Determine the size of the transfer, and make sure it is
|
||||
* within the boundaries of the partition. Adjust transfer
|
||||
* if needed, and signal errors or early completion.
|
||||
@ -222,7 +230,7 @@ bounds_check_with_label(struct disk *dk, struct buf *bp, int wlabel)
|
||||
/* calculate cylinder for disksort to order transfers with */
|
||||
bp->b_resid = (bp->b_blkno + p->p_offset) / lp->d_secpercyl;
|
||||
return 1;
|
||||
bad:
|
||||
bad:
|
||||
bp->b_flags |= B_ERROR;
|
||||
return -1;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user