diff options
author | Joel Sing <jsing@cvs.openbsd.org> | 2010-06-27 00:14:07 +0000 |
---|---|---|
committer | Joel Sing <jsing@cvs.openbsd.org> | 2010-06-27 00:14:07 +0000 |
commit | fa5bd8327c7cdb17542e820cdd0162eb31df213a (patch) | |
tree | 00e77afbcc819e7fc9df87dd47d4a7126e7d74b8 /sys | |
parent | 64aa8c59b267dc3fe0526d53b6ebe28b91de7358 (diff) |
Factor out code used to read a disklabel. We'll be making use of this soon.
ok deraadt@
Diffstat (limited to 'sys')
-rw-r--r-- | sys/kern/subr_disk.c | 84 |
1 files changed, 56 insertions, 28 deletions
diff --git a/sys/kern/subr_disk.c b/sys/kern/subr_disk.c index a91a5a26636..be255ccede3 100644 --- a/sys/kern/subr_disk.c +++ b/sys/kern/subr_disk.c @@ -1,4 +1,4 @@ -/* $OpenBSD: subr_disk.c,v 1.103 2010/05/03 15:27:28 jsing Exp $ */ +/* $OpenBSD: subr_disk.c,v 1.104 2010/06/27 00:14:06 jsing Exp $ */ /* $NetBSD: subr_disk.c,v 1.17 1996/03/16 23:17:08 christos Exp $ */ /* @@ -81,6 +81,8 @@ int disk_change; /* set if a disk has been attached/detached /* softraid callback, do not use! */ void (*softraid_disk_attach)(struct disk *, int); +char *disk_readlabel(struct disklabel *, dev_t); + /* * Seek sort for disks. We depend on the driver which calls us using b_resid * as the current cylinder number. @@ -917,38 +919,14 @@ disk_unlock(struct disk *dk) int dk_mountroot(void) { - dev_t rawdev, rrootdev; int part = DISKPART(rootdev); int (*mountrootfn)(void); struct disklabel dl; - struct vnode *vn; - int error; - - rrootdev = blktochr(rootdev); - rawdev = MAKEDISKDEV(major(rrootdev), DISKUNIT(rootdev), RAW_PART); -#ifdef DEBUG - printf("rootdev=0x%x rrootdev=0x%x rawdev=0x%x\n", rootdev, - rrootdev, rawdev); -#endif + char *error; - /* - * open device, ioctl for the disklabel, and close it. - */ - if (cdevvp(rawdev, &vn)) - panic("cannot obtain vnode for 0x%x/0x%x", rootdev, rrootdev); - error = VOP_OPEN(vn, FREAD, NOCRED, curproc); - if (error) - panic("cannot open disk, 0x%x/0x%x, error %d", - rootdev, rrootdev, error); - error = VOP_IOCTL(vn, DIOCGDINFO, (caddr_t)&dl, FREAD, NOCRED, 0); + error = disk_readlabel(&dl, rootdev); if (error) - panic("cannot read disk label, 0x%x/0x%x, error %d", - rootdev, rrootdev, error); - error = VOP_CLOSE(vn, FREAD, NOCRED, 0); - if (error) - panic("cannot close disk , 0x%x/0x%x, error %d", - rootdev, rrootdev, error); - vput(vn); + panic(error); if (DL_GETPSIZE(&dl.d_partitions[part]) == 0) panic("root filesystem has size 0"); @@ -1283,6 +1261,56 @@ findblkname(int maj) return (NULL); } +char * +disk_readlabel(struct disklabel *dl, dev_t dev) +{ + static char errbuf[100]; + struct vnode *vn; + dev_t chrdev, rawdev; + int error; + + chrdev = blktochr(dev); + rawdev = MAKEDISKDEV(major(chrdev), DISKUNIT(chrdev), RAW_PART); + +#ifdef DEBUG + printf("dev=0x%x chrdev=0x%x rawdev=0x%x\n", dev, chrdev, rawdev); +#endif + + if (cdevvp(rawdev, &vn)) { + snprintf(errbuf, sizeof(errbuf), + "cannot obtain vnode for 0x%x/0x%x", dev, rawdev); + return (errbuf); + } + + error = VOP_OPEN(vn, FREAD, NOCRED, curproc); + if (error) { + snprintf(errbuf, sizeof(errbuf), + "cannot open disk, 0x%x/0x%x, error %d", + dev, rawdev, error); + return (errbuf); + } + + error = VOP_IOCTL(vn, DIOCGDINFO, (caddr_t)dl, FREAD, NOCRED, 0); + if (error) { + snprintf(errbuf, sizeof(errbuf), + "cannot read disk label, 0x%x/0x%x, error %d", + dev, rawdev, error); + return (errbuf); + } + + error = VOP_CLOSE(vn, FREAD, NOCRED, 0); + if (error) { + snprintf(errbuf, sizeof(errbuf), + "cannot close disk, 0x%x/0x%x, error %d", + dev, rawdev, error); + return (errbuf); + } + + vput(vn); + + return (NULL); +} + int disk_map(char *path, char *mappath, int size, int flags) { |