summaryrefslogtreecommitdiffstats
path: root/sbin/fdisk
diff options
context:
space:
mode:
authorphk <phk@FreeBSD.org>2002-12-29 15:17:11 +0000
committerphk <phk@FreeBSD.org>2002-12-29 15:17:11 +0000
commitf387a3fcba910b45d8dc3c0443d8351eedc0bf6e (patch)
treed013112f95414287c692b475e25b7d7b4b0fb826 /sbin/fdisk
parent2c4226a029e9c920744effd5f4499dcef6a64bc7 (diff)
downloadFreeBSD-src-f387a3fcba910b45d8dc3c0443d8351eedc0bf6e.zip
FreeBSD-src-f387a3fcba910b45d8dc3c0443d8351eedc0bf6e.tar.gz
Make fdisk work on active GEOM devices.
Diffstat (limited to 'sbin/fdisk')
-rw-r--r--sbin/fdisk/fdisk.c41
1 files changed, 33 insertions, 8 deletions
diff --git a/sbin/fdisk/fdisk.c b/sbin/fdisk/fdisk.c
index e10929a..22ebd74 100644
--- a/sbin/fdisk/fdisk.c
+++ b/sbin/fdisk/fdisk.c
@@ -83,7 +83,8 @@ struct mboot {
};
static struct mboot mboot;
-static int fd;
+static int fd, fdw;
+
#define ACTIVE 0x80
#define BOOT_MAGIC 0xAA55
@@ -694,7 +695,10 @@ static int
open_disk(int flag)
{
struct stat st;
+ int rwmode, p;
+ char *s;
+ fdw = -1;
if (stat(disk, &st) == -1) {
if (errno == ENOENT)
return -2;
@@ -703,10 +707,26 @@ open_disk(int flag)
}
if ( !(st.st_mode & S_IFCHR) )
warnx("device %s is not character special", disk);
- if ((fd = open(disk,
- a_flag || I_flag || B_flag || flag ? O_RDWR : O_RDONLY)) == -1) {
- if(errno == ENXIO)
- return -2;
+ rwmode = a_flag || I_flag || B_flag || flag ? O_RDWR : O_RDONLY;
+ fd = open(disk, rwmode);
+ if (fd == -1 && errno == ENXIO)
+ return -2;
+ if (fd == -1 && errno == EPERM && rwmode == O_RDWR) {
+ fd = open(disk, O_RDONLY);
+ if (fd == -1)
+ return -3;
+ for (p = 1; p < 5; p++) {
+ asprintf(&s, "%ss%d", disk, p);
+ fdw = open(s, O_RDONLY);
+ free(s);
+ if (fdw == -1)
+ continue;
+ break;
+ }
+ if (fdw == -1)
+ return -4;
+ }
+ if (fd == -1) {
warnx("can't open device %s", disk);
return -1;
}
@@ -740,9 +760,14 @@ read_disk(off_t sector, void *buf)
static ssize_t
write_disk(off_t sector, void *buf)
{
- lseek(fd,(sector * 512), 0);
- /* write out in the size that the read_disk found worked */
- return write(fd, buf, secsize);
+
+ if (fdw != -1) {
+ return ioctl(fdw, DIOCSMBR, buf);
+ } else {
+ lseek(fd,(sector * 512), 0);
+ /* write out in the size that the read_disk found worked */
+ return write(fd, buf, secsize);
+ }
}
static int
OpenPOWER on IntegriCloud