From: David van Moolenbroek Date: Sun, 14 Oct 2012 23:00:51 +0000 (+0200) Subject: part(8)/autopart(8): remove partition hack X-Git-Tag: v3.2.1~277 X-Git-Url: http://zhaoyanbai.com/repos/?a=commitdiff_plain;h=3399c2c966a57b6e50225330417f7577fd5d04ba;p=minix.git part(8)/autopart(8): remove partition hack We have actually had lseek64 for quite a while now, so it's no longer necessary to do horrible things to the partition table just to be able to access large offsets into a device. Also fix the compiler warnings in these commands. --- diff --git a/commands/autopart/autopart.c b/commands/autopart/autopart.c index 8e08fda08..e07022c51 100644 --- a/commands/autopart/autopart.c +++ b/commands/autopart/autopart.c @@ -150,9 +150,9 @@ void tty_raw(void) char t_cd[16], t_cm[32], t_so[16], t_se[16], t_md[16], t_me[16]; #define STATUSROW 10 -void putchr(int c) +int putchr(int c) { - putchar(c); + return putchar(c); } void putstr(char *s) @@ -359,7 +359,7 @@ struct part_entry table[1 + NR_PARTITIONS]; int existing[1 + NR_PARTITIONS]; unsigned long offset= 0, extbase= 0, extsize; int submerged= 0; -char sort_index[1 + NR_PARTITIONS], sort_order[1 + NR_PARTITIONS]; +int sort_index[1 + NR_PARTITIONS], sort_order[1 + NR_PARTITIONS]; unsigned cylinders= 1, heads= 1, sectors= 1, secpcyl= 1; unsigned alt_cyls= 1, alt_heads= 1, alt_secs= 1; int precise= 0; @@ -1401,44 +1401,16 @@ void installboot(unsigned char *bootblock, char *masterboot) ssize_t boot_readwrite(int rw) /* Read (0) or write (1) the boot sector. */ { - u64_t off64 = mul64u(offset, SECTOR_SIZE); int r = 0; -#if __minix_vmd - /* Minix-vmd has a 64 bit seek. */ - if (fcntl(device, F_SEEK, off64) < 0) return -1; -#else - /* Minix has to gross things with the partition base. */ - struct partition geom0, geom_seek; - - if (offset >= (LONG_MAX / SECTOR_SIZE - 1)) { - /* Move partition base. */ - if (ioctl(device, DIOCGETP, &geom0) < 0) return -1; - geom_seek.base = add64(geom0.base, off64); - geom_seek.size = cvu64(cmp64(add64u(off64, SECTOR_SIZE), - geom0.size) <= 0 ? _STATIC_BLOCK_SIZE : 0); - sync(); - if (ioctl(device, DIOCSETP, &geom_seek) < 0) return -1; - if (lseek(device, (off_t) 0, SEEK_SET) == -1) return -1; - } else { - /* Can reach this point normally. */ - if (lseek(device, (off_t) offset * SECTOR_SIZE, SEEK_SET) == -1) - return -1; - } -#endif + if (lseek64(device, (u64_t) offset * SECTOR_SIZE, SEEK_SET, NULL) < 0) + return -1; switch (rw) { case 0: r= read(device, bootblock, SECTOR_SIZE); break; case 1: r= write(device, bootblock, SECTOR_SIZE); break; } -#if !__minix_vmd - if (offset >= (LONG_MAX / SECTOR_SIZE - 1)) { - /* Restore partition base and size. */ - sync(); - if (ioctl(device, DIOCSETP, &geom0) < 0) return -1; - } -#endif return r; } diff --git a/commands/part/part.c b/commands/part/part.c index c31f3d583..18b3ee53a 100644 --- a/commands/part/part.c +++ b/commands/part/part.c @@ -121,9 +121,9 @@ void init_tty(void) tty_raw(); } -void putchr(int c) +int putchr(int c) { - putchar(c); + return putchar(c); } void putstr(char *s) @@ -852,7 +852,8 @@ void print(object_t *op) case O_LSEC: /* Partition's last sector. */ t= entry2last(pe); - sprintf(op->value, t == -1 ? "-1" : "%lu", t % sectors); + if (t == -1) strcpy(op->value, "-1"); + else sprintf(op->value, "%lu", t % sectors); if (!aligned(t + 1, sectors)) op->flags|= OF_ODD; break; case O_BASE: @@ -896,7 +897,7 @@ void print(object_t *op) } else { memset(op->value + n, ' ', op->len - n); } - op->value[op->len]= 0; + op->value[(int) op->len]= 0; if ((op->flags & (OF_ODD | OF_BAD)) == (oldflags & (OF_ODD | OF_BAD)) && strcmp(op->value, oldvalue) == 0) { @@ -1581,44 +1582,16 @@ void installboot(unsigned char *bootblock, char *masterboot) ssize_t boot_readwrite(int rw) /* Read (0) or write (1) the boot sector. */ { - u64_t off64 = mul64u(offset, SECTOR_SIZE); - int r; - -#if __minix_vmd - /* Minix-vmd has a 64 bit seek. */ - if (fcntl(device, F_SEEK, off64) < 0) return -1; -#else - /* Minix has to gross things with the partition base. */ - struct partition geom0, geom_seek; - - if (offset >= (LONG_MAX / SECTOR_SIZE - 1)) { - /* Move partition base. */ - if (ioctl(device, DIOCGETP, &geom0) < 0) return -1; - geom_seek.base = add64(geom0.base, off64); - geom_seek.size = cvu64(cmp64(add64u(off64, SECTOR_SIZE), - geom0.size) <= 0 ? _STATIC_BLOCK_SIZE : 0); - sync(); - if (ioctl(device, DIOCSETP, &geom_seek) < 0) return -1; - if (lseek(device, (off_t) 0, SEEK_SET) == -1) return -1; - } else { - /* Can reach this point normally. */ - if (lseek(device, (off_t) offset * SECTOR_SIZE, SEEK_SET) == -1) - return -1; - } -#endif + int r = 0; + + if (lseek64(device, (u64_t) offset * SECTOR_SIZE, SEEK_SET, NULL) < 0) + return -1; switch (rw) { case 0: r= read(device, bootblock, SECTOR_SIZE); break; case 1: r= write(device, bootblock, SECTOR_SIZE); break; } -#if !__minix_vmd - if (offset >= (LONG_MAX / SECTOR_SIZE - 1)) { - /* Restore partition base and size. */ - sync(); - if (ioctl(device, DIOCSETP, &geom0) < 0) return -1; - } -#endif return r; }