return (b[510] == 0x55 && b[511] == 0xaa);
}
-unsigned long long
-get_nr_sects(struct partition *p) {
+sector_t get_nr_sects(struct partition *p) {
return read4_little_endian(p->size4);
}
unsigned int user_cylinders, user_heads, user_sectors;
unsigned int pt_heads, pt_sectors;
-unsigned long long sector_offset = 1, sectors;
+sector_t sector_offset = 1, sectors;
unsigned int heads,
cylinders,
units_per_sector = 1,
display_in_cyl_units = 0;
-unsigned long long total_number_of_sectors; /* in logical sectors */
+sector_t total_number_of_sectors; /* in logical sectors */
unsigned long grain = DEFAULT_SECTOR_SIZE,
io_size = DEFAULT_SECTOR_SIZE,
min_io_size = DEFAULT_SECTOR_SIZE,
}
static int
-lba_is_aligned(unsigned long long lba)
+lba_is_aligned(sector_t lba)
{
unsigned int granularity = max(phy_sector_size, min_io_size);
- unsigned long long offset = (lba * sector_size) & (granularity - 1);
+ sector_t offset = (lba * sector_size) & (granularity - 1);
return !((granularity + alignment_offset - offset) & (granularity - 1));
}
-unsigned long long align_lba(unsigned long long lba, int direction)
+sector_t align_lba(sector_t lba, int direction)
{
- unsigned long long res;
+ sector_t res;
if (lba_is_aligned(lba))
res = lba;
else {
- unsigned long long sects_in_phy = grain / sector_size;
+ sector_t sects_in_phy = grain / sector_size;
if (lba < sector_offset)
res = sector_offset;
"partition table format (GPT).\n\n"),
hectogiga / 10, hectogiga % 10,
bytes,
- (unsigned long long ) UINT_MAX * sector_size,
+ (sector_t ) UINT_MAX * sector_size,
sector_size);
}
}
*
* c) or for very small devices use 1 phy.sector
*/
- unsigned long long x = 0;
+ sector_t x = 0;
if (has_topology) {
if (alignment_offset)
void
get_geometry(struct fdisk_context *cxt, struct geom *g) {
- unsigned long long llcyls, nsects = 0;
+ sector_t llcyls, nsects = 0;
unsigned int kern_heads = 0, kern_sectors = 0;
get_topology(cxt);
}
static void
-check_alignment(unsigned long long lba, int partition)
+check_alignment(sector_t lba, int partition)
{
if (!lba_is_aligned(lba))
printf(_("Partition %i does not start on physical sector boundary.\n"),
}
}
-void fill_bounds(unsigned long long *first, unsigned long long *last)
+void fill_bounds(sector_t *first, sector_t *last)
{
int i;
struct pte *pe = &ptes[0];
static void
verify(void) {
int i, j;
- unsigned long long total = 1;
- unsigned long long n_sectors = total_number_of_sectors;
+ sector_t total = 1, n_sectors = total_number_of_sectors;
unsigned long long first[partitions], last[partitions];
struct partition *p;
if (extended_offset) {
struct pte *pex = &ptes[ext_index];
- unsigned long long e_last = get_start_sect(pex->part_table) +
+ sector_t e_last = get_start_sect(pex->part_table) +
get_nr_sects(pex->part_table) - 1;
for (i = 4; i < partitions; i++) {
n_sectors - total, sector_size);
}
-void print_partition_size(int num, unsigned long long start, unsigned long long stop, int sysid)
+void print_partition_size(int num, sector_t start, sector_t stop, int sysid)
{
char *str = size_to_human_string(SIZE_SUFFIX_3LETTER | SIZE_SUFFIX_SPACE,
(stop - start + 1) * sector_size);
}
}
-static unsigned long long get_dev_blocks(char *dev)
+static sector_t get_dev_blocks(char *dev)
{
int fd;
- unsigned long long size;
+ sector_t size;
if ((fd = open(dev, O_RDONLY)) < 0)
err(EXIT_FAILURE, _("unable to open %s"), dev);
unsigned int cylinders;
};
+typedef unsigned long long sector_t;
+
struct fdisk_context {
int dev_fd; /* device descriptor */
char *dev_path; /* device path */
extern unsigned int read_int(unsigned int low, unsigned int dflt,
unsigned int high, unsigned int base, char *mesg);
extern void print_menu(enum menutype);
-extern void print_partition_size(int num, unsigned long long start, unsigned long long stop, int sysid);
+extern void print_partition_size(int num, sector_t start, sector_t stop, int sysid);
extern void zeroize_mbr_buffer(void);
-extern void fill_bounds(unsigned long long *first, unsigned long long *last);
+extern void fill_bounds(sector_t *first, sector_t *last);
extern unsigned int heads, cylinders, sector_size;
-extern unsigned long long sectors;
+extern sector_t sectors;
extern char *partition_type(unsigned char type);
extern void update_units(void);
extern char read_chars(char *mesg);
extern void warn_alignment(void);
extern unsigned int read_int_with_suffix(unsigned int low, unsigned int dflt, unsigned int high,
unsigned int base, char *mesg, int *is_suffix_used);
-extern unsigned long long align_lba(unsigned long long lba, int direction);
+extern sector_t align_lba(sector_t lba, int direction);
extern int get_partition_dflt(int warn, int max, int dflt);
#define PLURAL 0
#define SINGULAR 1
extern const char * str_units(int);
-extern unsigned long long get_nr_sects(struct partition *p);
+extern sector_t get_nr_sects(struct partition *p);
enum labeltype {
DOS_LABEL = 1,
*/
extern unsigned char *MBRbuffer;
extern int MBRbuffer_changed;
-extern unsigned long long total_number_of_sectors;
+extern sector_t total_number_of_sectors;
extern unsigned long grain;
/* start_sect and nr_sects are stored little endian on all machines */
/* moreover, they are not aligned correctly */
+ ((unsigned int)(cp[3]) << 24);
}
-static inline void set_nr_sects(struct partition *p, unsigned long long nr_sects)
+static inline void set_nr_sects(struct partition *p, sector_t nr_sects)
{
store4_little_endian(p->size4, nr_sects);
}
store4_little_endian(p->start4, start_sect);
}
-static inline void seek_sector(struct fdisk_context *cxt, unsigned long long secno)
+static inline void seek_sector(struct fdisk_context *cxt, sector_t secno)
{
off_t offset = (off_t) secno * sector_size;
if (lseek(cxt->dev_fd, offset, SEEK_SET) == (off_t) -1)
fatal(cxt, unable_to_seek);
}
-static inline void read_sector(struct fdisk_context *cxt, unsigned long long secno, unsigned char *buf)
+static inline void read_sector(struct fdisk_context *cxt, sector_t secno, unsigned char *buf)
{
seek_sector(cxt, secno);
if (read(cxt->dev_fd, buf, sector_size) != sector_size)
fatal(cxt, unable_to_read);
}
-static inline void write_sector(struct fdisk_context *cxt, unsigned long long secno, unsigned char *buf)
+static inline void write_sector(struct fdisk_context *cxt, sector_t secno, unsigned char *buf)
{
seek_sector(cxt, secno);
if (write(cxt->dev_fd, buf, sector_size) != sector_size)
fatal(cxt, unable_to_write);
}
-static inline unsigned long long get_start_sect(struct partition *p)
+static inline sector_t get_start_sect(struct partition *p)
{
return read4_little_endian(p->start4);
}