#define PROC_PARTITIONS "/proc/partitions"
+#include <features.h>
#include <sys/types.h>
#include <sys/stat.h> /* stat */
#include <ctype.h>
#include <setjmp.h>
#include <assert.h> /* assert */
#include <getopt.h>
-
#include <endian.h>
-#define u_char unsigned char
-#include <scsi/scsi.h> /* SCSI_IOCTL_GET_IDLUN */
-#undef u_char
-
#include <sys/ioctl.h>
#include <sys/param.h>
#include <sys/sysmacros.h> /* major */
#define BLKGETSIZE _IO(0x12,96) /* return device size */
#define BLKFLSBUF _IO(0x12,97) /* flush buffer cache */
#define BLKSSZGET _IO(0x12,104) /* get block device sector size */
-#define BLKGETSIZE64 _IOR(0x12,114,8) /* 8 = sizeof(u64) */
+
+/* Avoid conflicts with the 2.6 kernel headers, which define
+ * _IOR rather differently */
+#undef _IOR
+#define _IOR(type,nr,size) _IOC(_IOC_READ,(type),(nr),sizeof(size))
+#define BLKGETSIZE64 _IOR(0x12,114,uint64_t)
/*
fdisk.h
#define cround(n) (display_in_cyl_units ? ((n)/units_per_sector)+1 : (n))
#define scround(x) (((x)+units_per_sector-1)/units_per_sector)
-
-#if defined(CONFIG_LFS) || defined(FDISK_SUPPORT_LARGE_DISKS) || defined(__alpha__) || defined(__ia64__) || defined(__s390x__)
-typedef long long fdisk_loff_t;
-#else
-typedef long fdisk_loff_t;
+#ifdef CONFIG_FEATURE_SUN_LABEL
+#define SCSI_IOCTL_GET_IDLUN 0x5382
#endif
unsigned char end_cyl; /* end cylinder */
unsigned char start4[4]; /* starting sector counting from 0 */
unsigned char size4[4]; /* nr of sectors in partition */
-};
+} __attribute__((__packed__));
enum failure {
ioctl_error, unable_to_open, unable_to_read, unable_to_seek,
}
-static unsigned int get_start_sect(const struct partition *p);
-static unsigned int get_nr_sects(const struct partition *p);
+static int32_t get_start_sect(const struct partition *p);
+static int32_t get_nr_sects(const struct partition *p);
/*
* per partition table entry data
#ifdef CONFIG_FEATURE_FDISK_WRITABLE
char changed; /* boolean */
#endif
- uint offset; /* disk sector number */
+ off_t offset; /* disk sector number */
char *sectorbuffer; /* disk sector contents */
} ptes[MAXIMUM_PARTS];
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
+ * must display the following acknowledgment:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
#define SUN_SSWAP32(x) (sun_other_endian ? __swap32(x) \
: (uint32_t)(x))
-#if defined(FDISK_SUPPORT_LARGE_DISKS)
-/*
- * llseek.c -- stub calling the llseek system call
- *
- * Copyright (C) 1994 Remy Card. This file may be redistributed
- * under the terms of the GNU Public License.
- */
-
-
-#include <syscall.h>
-
-
-#if defined(__alpha__) || defined(__ia64__) || defined(__s390x__)
-
-#define my_llseek lseek
-
-#else
-
-static int _llseek (unsigned int, unsigned long,
- unsigned long, fdisk_loff_t *, unsigned int);
-
-static _syscall5(int,_llseek,unsigned int,f_d,unsigned long,offset_high,
- unsigned long, offset_low,fdisk_loff_t *,result,
- unsigned int, origin)
-
-static fdisk_loff_t my_llseek (unsigned int f_d, fdisk_loff_t offset,
- unsigned int origin)
-{
- fdisk_loff_t result;
- int retval;
-
- retval = _llseek (f_d, ((unsigned long long) offset) >> 32,
- ((unsigned long long) offset) & 0xffffffff,
- &result, origin);
- return (retval == -1 ? (fdisk_loff_t) retval : result);
-}
-
-#endif /* __alpha__ */
-
-
-static fdisk_loff_t fdisk_llseek (unsigned int f_d, fdisk_loff_t offset,
- unsigned int origin)
-{
- fdisk_loff_t result;
- static int do_compat = 0;
-
- if (!do_compat) {
- result = my_llseek (f_d, offset, origin);
- if (!(result == -1 && errno == ENOSYS))
- return result;
-
- /*
- * Just in case this code runs on top of an old kernel
- * which does not support the llseek system call
- */
- do_compat = 1;
- /*
- * Now try ordinary lseek.
- */
- }
-
- if ((sizeof(off_t) >= sizeof(fdisk_loff_t)) ||
- (offset < ((fdisk_loff_t) 1 << ((sizeof(off_t)*8) -1))))
- return lseek(f_d, (off_t) offset, origin);
-
- errno = EINVAL;
- return -1;
-}
-#else
-# define fdisk_llseek lseek
-#endif /* FDISK_SUPPORT_LARGE_DISKS */
-
-
#ifdef CONFIG_FEATURE_OSF_LABEL
/*
#endif
#if defined (__alpha__)
-/* We access this through a u_int64_t * when checksumming */
+/* We access this through a uint64_t * when checksumming */
static char disklabelbuffer[BSD_BBSIZE] __attribute__((aligned(8)));
#else
static char disklabelbuffer[BSD_BBSIZE];
static void
xbsd_new_part (void)
{
- uint begin, end;
+ off_t begin, end;
char mesg[256];
int i;
sector = get_start_sect(xbsd_part);
#endif
- if (fdisk_llseek (fd, (fdisk_loff_t) sector * SECTOR_SIZE, SEEK_SET) == -1)
+ if (lseek (fd, sector * SECTOR_SIZE, SEEK_SET) == -1)
fdisk_fatal (unable_to_seek);
if (BSD_BBSIZE != write (fd, disklabelbuffer, BSD_BBSIZE))
fdisk_fatal (unable_to_write);
sector = 0;
#endif
- if (fdisk_llseek (fd, (fdisk_loff_t) sector * SECTOR_SIZE, SEEK_SET) == -1)
+ if (lseek (fd, sector * SECTOR_SIZE, SEEK_SET) == -1)
fdisk_fatal (unable_to_seek);
if (BSD_BBSIZE != read (fd, disklabelbuffer, BSD_BBSIZE))
fdisk_fatal (unable_to_read);
#if defined (__alpha__) && BSD_LABELSECTOR == 0
alpha_bootblock_checksum (disklabelbuffer);
- if (fdisk_llseek (fd, (fdisk_loff_t) 0, SEEK_SET) == -1)
+ if (lseek (fd, 0, SEEK_SET) == -1)
fdisk_fatal (unable_to_seek);
if (BSD_BBSIZE != write (fd, disklabelbuffer, BSD_BBSIZE))
fdisk_fatal (unable_to_write);
#else
- if (fdisk_llseek (fd, (fdisk_loff_t) sector * SECTOR_SIZE + BSD_LABELOFFSET,
+ if (lseek (fd, sector * SECTOR_SIZE + BSD_LABELOFFSET,
SEEK_SET) == -1)
fdisk_fatal (unable_to_seek);
if (sizeof (struct xbsd_disklabel) != write (fd, d, sizeof (struct xbsd_disklabel)))
#if defined (__alpha__)
#if !defined(__GLIBC__)
-typedef unsigned long long u_int64_t;
+typedef unsigned long long uint64_t;
#endif
static void
alpha_bootblock_checksum (char *boot)
{
- u_int64_t *dp, sum;
+ uint64_t *dp, sum;
int i;
- dp = (u_int64_t *)boot;
+ dp = (uint64_t *)boot;
sum = 0;
for (i = 0; i < 63; i++)
sum += dp[i];
*/
sgiinfo *info = fill_sgiinfo();
int infostartblock = SGI_SSWAP32(sgilabel->directory[0].vol_file_start);
- if (fdisk_llseek(fd, (long long)infostartblock*
- SECTOR_SIZE, SEEK_SET) < 0)
+ if (lseek(fd, infostartblock*SECTOR_SIZE, SEEK_SET) < 0)
fdisk_fatal(unable_to_seek);
if (write(fd, info, SECTOR_SIZE) != SECTOR_SIZE)
fdisk_fatal(unable_to_write);
}
#endif
-static unsigned int
+static int32_t
get_start_sect(const struct partition *p) {
return read4_little_endian(p->start4);
}
#ifdef CONFIG_FEATURE_FDISK_WRITABLE
static void
-set_nr_sects(struct partition *p, unsigned int nr_sects) {
+set_nr_sects(struct partition *p, int32_t nr_sects) {
store4_little_endian(p->size4, nr_sects);
}
#endif
-static unsigned int
+static int32_t
get_nr_sects(const struct partition *p) {
return read4_little_endian(p->size4);
}
static uint pt_heads, pt_sectors;
static uint kern_heads, kern_sectors;
-static uint extended_offset; /* offset of link pointers */
+static off_t extended_offset; /* offset of link pointers */
static unsigned long long total_number_of_sectors;
}
static void
-seek_sector(uint secno) {
- fdisk_loff_t offset = (fdisk_loff_t) secno * sector_size;
- if (fdisk_llseek(fd, offset, SEEK_SET) == (fdisk_loff_t) -1)
+seek_sector(off_t secno) {
+ off_t offset = secno * sector_size;
+ if (lseek(fd, offset, SEEK_SET) == (off_t) -1)
fdisk_fatal(unable_to_seek);
}
#ifdef CONFIG_FEATURE_FDISK_WRITABLE
static void
-write_sector(uint secno, char *buf) {
+write_sector(off_t secno, char *buf) {
seek_sector(secno);
if (write(fd, buf, sector_size) != sector_size)
fdisk_fatal(unable_to_write);
/* Allocate a buffer and read a partition table sector */
static void
-read_pte(struct pte *pe, uint offset) {
+read_pte(struct pte *pe, off_t offset) {
pe->offset = offset;
pe->sectorbuffer = (char *) xmalloc(sector_size);
#ifdef CONFIG_FEATURE_FDISK_WRITABLE
static void
-set_partition(int i, int doext, uint start, uint stop, int sysid) {
+set_partition(int i, int doext, off_t start, off_t stop, int sysid) {
struct partition *p;
- uint offset;
+ off_t offset;
if (doext) {
p = ptes[i].ext_pointer;
&& *line_ptr != '-' && *line_ptr != '+')
continue;
- if (*line_ptr == '+' || *line_ptr == '-') {
+ if (*line_ptr == '+' || *line_ptr == '-') {
int minus = (*line_ptr == '-');
int absolute = 0;
while (isdigit(*++line_ptr))
use_default = 0;
-
+
switch (*line_ptr) {
case 'c':
case 'C':
bytes = (unsigned long long) i * absolute;
unit = sector_size * units_per_sector;
- bytes += unit/2; /* round */
+ bytes += unit/2; /* round */
bytes /= unit;
i = bytes;
}
if (minus)
i = -i;
i += base;
- } else {
+ } else {
i = atoi(line_ptr);
while (isdigit(*line_ptr)) {
line_ptr++;
/* Ending on cylinder boundary? */
if (peh != (heads - 1) || pes != sectors) {
- printf(_("Partition %i does not end on cylinder boundary.\n"),
+ printf(_("Partition %i does not end on cylinder boundary.\n"),
partition + 1);
#if 0
printf(_(" phys=(%d, %d, %d) "), pec, peh, pes);
wrong_p_order(int *prev) {
const struct pte *pe;
const struct partition *p;
- uint last_p_start_pos = 0, p_start_pos;
+ off_t last_p_start_pos = 0, p_start_pos;
int i, last_i = 0;
for (i = 0 ; i < partitions; i++) {
p = pe->part_table;
if (p && !is_cleared_partition(p)) {
- unsigned int psects = get_nr_sects(p);
- unsigned int pblocks = psects;
+ off_t psects = get_nr_sects(p);
+ off_t pblocks = psects;
unsigned int podd = 0;
if (sector_size < 1024) {
if (sector_size > 1024)
pblocks *= (sector_size / 1024);
printf(
- "%s %c %11lu %11lu %11lu%c %2x %s\n",
+ "%s %c %11llu %11llu %11llu%c %2x %s\n",
partname(disk_device, i+1, w+2),
/* boot flag */ !p->boot_ind ? ' ' : p->boot_ind == ACTIVE_FLAG
? '*' : '?',
-/* start */ (unsigned long) cround(get_partition_start(pe)),
-/* end */ (unsigned long) cround(get_partition_start(pe) + psects
+/* start */ (unsigned long long) cround(get_partition_start(pe)),
+/* end */ (unsigned long long) cround(get_partition_start(pe) + psects
- (psects ? 1 : 0)),
-/* odd flag on end */ (unsigned long) pblocks, podd ? '+' : ' ',
+/* odd flag on end */ (unsigned long long) pblocks, podd ? '+' : ' ',
/* type id */ p->sys_ind,
/* type name */ partition_type(p->sys_ind));
check_consistency(p, i);
#ifdef CONFIG_FEATURE_FDISK_WRITABLE
static void
-fill_bounds(uint *first, uint *last) {
+fill_bounds(off_t *first, off_t *last) {
int i;
const struct pte *pe = &ptes[0];
const struct partition *p;
}
static void
-check(int n, uint h, uint s, uint c, uint start) {
- uint total, real_s, real_c;
+check(int n, uint h, uint s, uint c, off_t start) {
+ off_t total, real_s, real_c;
real_s = sector(s) - 1;
real_c = cylinder(s, c);
fprintf(stderr, _("Partition %d: sector %d greater than "
"maximum %d\n"), n, s, sectors);
if (real_c >= cylinders)
- fprintf(stderr, _("Partitions %d: cylinder %d greater than "
- "maximum %d\n"), n, real_c + 1, cylinders);
+ fprintf(stderr, _("Partitions %d: cylinder %llu greater than "
+ "maximum %d\n"), n, (unsigned long long)real_c + 1, cylinders);
if (cylinders <= 1024 && start != total)
fprintf(stderr,
- _("Partition %d: previous sectors %d disagrees with "
- "total %d\n"), n, start, total);
+ _("Partition %d: previous sectors %llu disagrees with "
+ "total %llu\n"), n, (unsigned long long)start, (unsigned long long)total);
}
static void
verify(void) {
int i, j;
uint total = 1;
- uint first[partitions], last[partitions];
+ off_t first[partitions], last[partitions];
struct partition *p;
if (warn_geometry())
if (extended_offset) {
struct pte *pex = &ptes[ext_index];
- uint e_last = get_start_sect(pex->part_table) +
+ off_t e_last = get_start_sect(pex->part_table) +
get_nr_sects(pex->part_table) - 1;
for (i = 4; i < partitions; i++) {
struct partition *p = ptes[n].part_table;
struct partition *q = ptes[ext_index].part_table;
long long llimit;
- uint start, stop = 0, limit, temp,
+ off_t start, stop = 0, limit, temp,
first[partitions], last[partitions];
if (p && p->sys_ind) {
if (start > limit)
break;
if (start >= temp+units_per_sector && readed) {
- printf(_("Sector %d is already allocated\n"), temp);
+ printf(_("Sector %llu is already allocated\n"), (unsigned long long)temp);
temp = start;
readed = 0;
}
if (!readed && start == temp) {
- uint saved_start;
+ off_t saved_start;
saved_start = start;
start = read_int(cround(saved_start), cround(saved_start), cround(limit),
free_primary += !ptes[i].part_table->sys_ind;
if (!free_primary && partitions >= MAXIMUM_PARTS) {
- printf(_("The maximum number of partitions has been created\n"));
- return;
+ printf(_("The maximum number of partitions has been created\n"));
+ return;
}
if (!free_primary) {
move_begin(int i) {
struct pte *pe = &ptes[i];
struct partition *p = pe->part_table;
- uint new, first;
+ off_t new, first;
if (warn_geometry())
return;