Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch/hp300/hp300 - make readdisklabel(9) return more usa...
details: https://anonhg.NetBSD.org/src/rev/e64189caef51
branches: trunk
changeset: 581092:e64189caef51
user: tsutsui <tsutsui%NetBSD.org@localhost>
date: Tue May 24 10:27:24 2005 +0000
description:
- make readdisklabel(9) return more usable default label
if disk doesn't have disklabel (sync with news68k)
- most hp300 machines have a boot patition and partition a doesn't
start at 0, so RAW_PART should be used in bounds_check_with_label(9)
- remove unneeded <sys/syslog.h>
- remove b_cylinder definition, which is in <sys/buf.h>
- some other cosmetics
diffstat:
sys/arch/hp300/hp300/disksubr.c | 62 +++++++++++++++++++++++-----------------
1 files changed, 35 insertions(+), 27 deletions(-)
diffs (169 lines):
diff -r b0a031041302 -r e64189caef51 sys/arch/hp300/hp300/disksubr.c
--- a/sys/arch/hp300/hp300/disksubr.c Tue May 24 10:06:43 2005 +0000
+++ b/sys/arch/hp300/hp300/disksubr.c Tue May 24 10:27:24 2005 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: disksubr.c,v 1.20 2004/08/28 19:11:19 thorpej Exp $ */
+/* $NetBSD: disksubr.c,v 1.21 2005/05/24 10:27:24 tsutsui Exp $ */
/*
* Copyright (c) 1982, 1986, 1988, 1993
@@ -37,16 +37,13 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: disksubr.c,v 1.20 2004/08/28 19:11:19 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: disksubr.c,v 1.21 2005/05/24 10:27:24 tsutsui Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/buf.h>
+#include <sys/disk.h>
#include <sys/disklabel.h>
-#include <sys/disk.h>
-#include <sys/syslog.h>
-
-#define b_cylinder b_resid
/*
* Attempt to read a disk label from a device using the indicated strategy
@@ -62,13 +59,24 @@
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 = RAW_PART + 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;
@@ -96,7 +104,7 @@
}
}
brelse(bp);
- return (msg);
+ return msg;
}
/*
@@ -111,16 +119,16 @@
if (nlp->d_magic != DISKMAGIC || nlp->d_magic2 != DISKMAGIC ||
dkcksum(nlp) != 0)
- return (EINVAL);
+ return EINVAL;
while ((i = ffs(openmask)) != 0) {
i--;
openmask &= ~(1 << i);
if (nlp->d_npartitions <= i)
- return (EBUSY);
+ return EBUSY;
opp = &olp->d_partitions[i];
npp = &nlp->d_partitions[i];
if (npp->p_offset != opp->p_offset || npp->p_size < opp->p_size)
- return (EBUSY);
+ return EBUSY;
/*
* Copy internally-set partition information
* if new label doesn't include it. XXX
@@ -135,7 +143,7 @@
nlp->d_checksum = 0;
nlp->d_checksum = dkcksum(nlp);
*olp = *nlp;
- return (0);
+ return 0;
}
/*
@@ -153,7 +161,7 @@
labelpart = DISKPART(dev);
if (lp->d_partitions[labelpart].p_offset != 0) {
if (lp->d_partitions[0].p_offset != 0)
- return (EXDEV); /* not quite right */
+ return EXDEV; /* not quite right */
labelpart = 0;
}
bp = geteblk((int)lp->d_secsize);
@@ -162,7 +170,7 @@
bp->b_bcount = lp->d_secsize;
bp->b_flags |= B_READ;
(*strat)(bp);
- if ((error = biowait(bp)))
+ if ((error = biowait(bp)) != 0)
goto done;
for (dlp = (struct disklabel *)bp->b_data;
dlp <= (struct disklabel *)
@@ -179,9 +187,9 @@
}
}
error = ESRCH;
-done:
+ done:
brelse(bp);
- return (error);
+ return error;
}
/*
@@ -194,25 +202,25 @@
{
struct disklabel *lp = dk->dk_label;
struct partition *p = &lp->d_partitions[DISKPART(bp->b_dev)];
- int labelsect = lp->d_partitions[0].p_offset;
+ u_int labelsector = lp->d_partitions[RAW_PART].p_offset + LABELSECTOR;
int maxsz = p->p_size;
int sz = (bp->b_bcount + DEV_BSIZE - 1) >> DEV_BSHIFT;
/* Overwriting disk label? */
- if (bp->b_blkno + p->p_offset <= LABELSECTOR + labelsect &&
- (bp->b_flags & B_READ) == 0 && !wlabel) {
+ if (bp->b_blkno + p->p_offset <= labelsector &&
+ (bp->b_flags & B_READ) == 0 && wlabel == 0) {
bp->b_error = EROFS;
goto bad;
}
/* beyond partition? */
if (bp->b_blkno < 0 || bp->b_blkno + sz > maxsz) {
+ /* if exactly at end of disk, return an EOF */
if (bp->b_blkno == maxsz) {
- /* If exactly at end of disk, return EOF. */
bp->b_resid = bp->b_bcount;
- return (0);
+ return 0;
}
- /* ...or truncate if part of it fits */
+ /* or truncate if part of it fits */
sz = maxsz - bp->b_blkno;
if (sz <= 0) {
bp->b_error = EINVAL;
@@ -223,9 +231,9 @@
/* calculate cylinder for disksort to order transfers with */
bp->b_resid = (bp->b_blkno + p->p_offset) / lp->d_secpercyl;
- return (1);
+ return 1;
bad:
bp->b_flags |= B_ERROR;
- return (-1);
+ return -1;
}
Home |
Main Index |
Thread Index |
Old Index