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.
This commit is contained in:
		
							parent
							
								
									ab12636b79
								
							
						
					
					
						commit
						3399c2c966
					
				@ -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];
 | 
					char t_cd[16], t_cm[32], t_so[16], t_se[16], t_md[16], t_me[16];
 | 
				
			||||||
#define STATUSROW	10
 | 
					#define STATUSROW	10
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void putchr(int c)
 | 
					int putchr(int c)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	putchar(c);
 | 
						return putchar(c);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void putstr(char *s)
 | 
					void putstr(char *s)
 | 
				
			||||||
@ -359,7 +359,7 @@ struct part_entry table[1 + NR_PARTITIONS];
 | 
				
			|||||||
int existing[1 + NR_PARTITIONS];
 | 
					int existing[1 + NR_PARTITIONS];
 | 
				
			||||||
unsigned long offset= 0, extbase= 0, extsize;
 | 
					unsigned long offset= 0, extbase= 0, extsize;
 | 
				
			||||||
int submerged= 0;
 | 
					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 cylinders= 1, heads= 1, sectors= 1, secpcyl= 1;
 | 
				
			||||||
unsigned alt_cyls= 1, alt_heads= 1, alt_secs= 1;
 | 
					unsigned alt_cyls= 1, alt_heads= 1, alt_secs= 1;
 | 
				
			||||||
int precise= 0;
 | 
					int precise= 0;
 | 
				
			||||||
@ -1401,44 +1401,16 @@ void installboot(unsigned char *bootblock, char *masterboot)
 | 
				
			|||||||
ssize_t boot_readwrite(int rw)
 | 
					ssize_t boot_readwrite(int rw)
 | 
				
			||||||
/* Read (0) or write (1) the boot sector. */
 | 
					/* Read (0) or write (1) the boot sector. */
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	u64_t off64 = mul64u(offset, SECTOR_SIZE);
 | 
					 | 
				
			||||||
	int r = 0;
 | 
						int r = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if __minix_vmd
 | 
						if (lseek64(device, (u64_t) offset * SECTOR_SIZE, SEEK_SET, NULL) < 0)
 | 
				
			||||||
	/* Minix-vmd has a 64 bit seek. */
 | 
							return -1;
 | 
				
			||||||
	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
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	switch (rw) {
 | 
						switch (rw) {
 | 
				
			||||||
	case 0:	r= read(device, bootblock, SECTOR_SIZE);	break;
 | 
						case 0:	r= read(device, bootblock, SECTOR_SIZE);	break;
 | 
				
			||||||
	case 1:	r= write(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;
 | 
						return r;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -121,9 +121,9 @@ void init_tty(void)
 | 
				
			|||||||
	tty_raw();
 | 
						tty_raw();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void putchr(int c)
 | 
					int putchr(int c)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	putchar(c);
 | 
						return putchar(c);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void putstr(char *s)
 | 
					void putstr(char *s)
 | 
				
			||||||
@ -852,7 +852,8 @@ void print(object_t *op)
 | 
				
			|||||||
	case O_LSEC:
 | 
						case O_LSEC:
 | 
				
			||||||
				/* Partition's last sector. */
 | 
									/* Partition's last sector. */
 | 
				
			||||||
		t= entry2last(pe);
 | 
							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;
 | 
							if (!aligned(t + 1, sectors)) op->flags|= OF_ODD;
 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
	case O_BASE:
 | 
						case O_BASE:
 | 
				
			||||||
@ -896,7 +897,7 @@ void print(object_t *op)
 | 
				
			|||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		memset(op->value + n, ' ', op->len - n);
 | 
							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))
 | 
						if ((op->flags & (OF_ODD | OF_BAD)) == (oldflags & (OF_ODD | OF_BAD))
 | 
				
			||||||
				&& strcmp(op->value, oldvalue) == 0) {
 | 
									&& strcmp(op->value, oldvalue) == 0) {
 | 
				
			||||||
@ -1581,44 +1582,16 @@ void installboot(unsigned char *bootblock, char *masterboot)
 | 
				
			|||||||
ssize_t boot_readwrite(int rw)
 | 
					ssize_t boot_readwrite(int rw)
 | 
				
			||||||
/* Read (0) or write (1) the boot sector. */
 | 
					/* Read (0) or write (1) the boot sector. */
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	u64_t off64 = mul64u(offset, SECTOR_SIZE);
 | 
						int r = 0;
 | 
				
			||||||
	int r;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if __minix_vmd
 | 
						if (lseek64(device, (u64_t) offset * SECTOR_SIZE, SEEK_SET, NULL) < 0)
 | 
				
			||||||
	/* Minix-vmd has a 64 bit seek. */
 | 
							return -1;
 | 
				
			||||||
	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
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	switch (rw) {
 | 
						switch (rw) {
 | 
				
			||||||
	case 0:	r= read(device, bootblock, SECTOR_SIZE);	break;
 | 
						case 0:	r= read(device, bootblock, SECTOR_SIZE);	break;
 | 
				
			||||||
	case 1:	r= write(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;
 | 
						return r;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user