# define USE_FEATURE_FDISK_BLKSIZE(a)
#endif
-#define DEFAULT_SECTOR_SIZE 512
-#define MAX_SECTOR_SIZE 2048
-#define SECTOR_SIZE 512 /* still used in osf/sgi/sun code */
-#define MAXIMUM_PARTS 60
+#define DEFAULT_SECTOR_SIZE 512
+#define DEFAULT_SECTOR_SIZE_STR "512"
+#define MAX_SECTOR_SIZE 2048
+#define SECTOR_SIZE 512 /* still used in osf/sgi/sun code */
+#define MAXIMUM_PARTS 60
-#define ACTIVE_FLAG 0x80
+#define ACTIVE_FLAG 0x80
-#define EXTENDED 0x05
-#define WIN98_EXTENDED 0x0f
-#define LINUX_PARTITION 0x81
-#define LINUX_SWAP 0x82
-#define LINUX_NATIVE 0x83
-#define LINUX_EXTENDED 0x85
-#define LINUX_LVM 0x8e
-#define LINUX_RAID 0xfd
+#define EXTENDED 0x05
+#define WIN98_EXTENDED 0x0f
+#define LINUX_PARTITION 0x81
+#define LINUX_SWAP 0x82
+#define LINUX_NATIVE 0x83
+#define LINUX_EXTENDED 0x85
+#define LINUX_LVM 0x8e
+#define LINUX_RAID 0xfd
enum {
unsigned user_set_sector_size;
unsigned sector_offset; // = 1;
unsigned g_heads, g_sectors, g_cylinders;
- enum label_type current_label_type;
+ smallint /* enum label_type */ current_label_type;
smallint display_in_cyl_units; // = 1;
#if ENABLE_FEATURE_OSF_LABEL
smallint possibly_osf_label;
#endif
+ smallint listing; /* no aborts for fdisk -l */
+ smallint dos_compatible_flag; // = 1;
+#if ENABLE_FEATURE_FDISK_WRITABLE
+ //int dos_changed;
+ smallint nowarn; /* no warnings for fdisk -l/-s */
+#endif
+ int ext_index; /* the prime extended partition */
+ unsigned user_cylinders, user_heads, user_sectors;
+ unsigned pt_heads, pt_sectors;
+ unsigned kern_heads, kern_sectors;
+ ullong extended_offset; /* offset of link pointers */
+ ullong total_number_of_sectors;
+
jmp_buf listingbuf;
char line_buffer[80];
char partname_buffer[80];
#define current_label_type (G.current_label_type )
#define display_in_cyl_units (G.display_in_cyl_units)
#define possibly_osf_label (G.possibly_osf_label )
+#define listing (G.listing )
+#define dos_compatible_flag (G.dos_compatible_flag )
+#define nowarn (G.nowarn )
+#define ext_index (G.ext_index )
+#define user_cylinders (G.user_cylinders )
+#define user_heads (G.user_heads )
+#define user_sectors (G.user_sectors )
+#define pt_heads (G.pt_heads )
+#define pt_sectors (G.pt_sectors )
+#define kern_heads (G.kern_heads )
+#define kern_sectors (G.kern_sectors )
+#define extended_offset (G.extended_offset )
+#define total_number_of_sectors (G.total_number_of_sectors)
#define listingbuf (G.listingbuf)
#define line_buffer (G.line_buffer)
#define partname_buffer (G.partname_buffer)
g_partitions = 4; \
display_in_cyl_units = 1; \
units_per_sector = 1; \
+ dos_compatible_flag = 1; \
} while (0)
return read4_little_endian(p->size4);
}
-static int ext_index; /* the prime extended partition */
-static smallint listing; /* no aborts for fdisk -l */
-static smallint dos_compatible_flag = 1;
-#if ENABLE_FEATURE_FDISK_WRITABLE
-//static int dos_changed;
-static smallint nowarn; /* no warnings for fdisk -l/-s */
-#endif
-
-static unsigned user_cylinders, user_heads, user_sectors;
-static unsigned pt_heads, pt_sectors;
-static unsigned kern_heads, kern_sectors;
-
-static ullong extended_offset; /* offset of link pointers */
-static ullong total_number_of_sectors;
-
static void fdisk_fatal(const char *why)
{
if (listing) {
write_sector(ullong secno, char *buf)
{
seek_sector(secno);
- if (write(dev_fd, buf, sector_size) != sector_size)
- fdisk_fatal(unable_to_write);
+ xwrite(dev_fd, buf, sector_size);
}
#endif
read_pte(struct pte *pe, ullong offset)
{
pe->offset = offset;
- pe->sectorbuffer = xmalloc(sector_size);
+ pe->sectorbuffer = xzalloc(sector_size);
seek_sector(offset);
- if (read(dev_fd, pe->sectorbuffer, sector_size) != sector_size)
+ /* xread would make us abort - bad for fdisk -l */
+ if (full_read(dev_fd, pe->sectorbuffer, sector_size) != sector_size)
fdisk_fatal(unable_to_read);
#if ENABLE_FEATURE_FDISK_WRITABLE
pe->changed = 0;
if (ioctl(dev_fd, BLKSSZGET, &arg) == 0)
sector_size = arg;
if (sector_size != DEFAULT_SECTOR_SIZE)
- printf("Note: sector size is %d (not %d)\n",
- sector_size, DEFAULT_SECTOR_SIZE);
+ printf("Note: sector size is %d "
+ "(not " DEFAULT_SECTOR_SIZE_STR ")\n",
+ sector_size);
}
}
printf("'%s' is opened for read only\n", disk_device);
}
xmove_fd(fd, dev_fd);
- if (512 != read(dev_fd, MBRbuffer, 512)) {
+ if (512 != full_read(dev_fd, MBRbuffer, 512)) {
if (what == TRY_ONLY) {
close_dev_fd();
return 1;
fd = open(disk_device, O_RDONLY);
if (fd < 0)
return 1;
- if (512 != read(fd, MBRbuffer, 512)) {
+ if (512 != full_read(fd, MBRbuffer, 512)) {
close(fd);
return 1;
}
{
int fdb;
- fdb = open(path, O_RDONLY);
+ fdb = open_or_warn(path, O_RDONLY);
if (fdb < 0) {
- perror(path);
return 0;
}
- if (read(fdb, ptr, size) < 0) {
- perror(path);
+ if (full_read(fdb, ptr, size) < 0) {
+ bb_simple_perror_msg(path);
close(fdb);
return 0;
}
sector = get_start_sect(xbsd_part);
#endif
- if (lseek(dev_fd, sector * SECTOR_SIZE, SEEK_SET) == -1)
- fdisk_fatal(unable_to_seek);
- if (BSD_BBSIZE != write(dev_fd, disklabelbuffer, BSD_BBSIZE))
- fdisk_fatal(unable_to_write);
+ seek_sector(sector);
+ xwrite(dev_fd, disklabelbuffer, BSD_BBSIZE);
#if defined(__alpha__)
printf("Bootstrap installed on %s\n", disk_device);
sector = 0;
#endif
- if (lseek(dev_fd, sector * SECTOR_SIZE, SEEK_SET) == -1)
- fdisk_fatal(unable_to_seek);
- if (BSD_BBSIZE != read(dev_fd, disklabelbuffer, BSD_BBSIZE))
+ seek_sector(sector);
+ if (BSD_BBSIZE != full_read(dev_fd, disklabelbuffer, BSD_BBSIZE))
fdisk_fatal(unable_to_read);
memmove(d, &disklabelbuffer[BSD_LABELSECTOR * SECTOR_SIZE + BSD_LABELOFFSET],
#if defined(__alpha__) && BSD_LABELSECTOR == 0
alpha_bootblock_checksum(disklabelbuffer);
- if (lseek(dev_fd, 0, SEEK_SET) == -1)
- fdisk_fatal(unable_to_seek);
- if (BSD_BBSIZE != write(dev_fd, disklabelbuffer, BSD_BBSIZE))
- fdisk_fatal(unable_to_write);
+ seek_sector(0);
+ xwrite(dev_fd, disklabelbuffer, BSD_BBSIZE);
#else
- if (lseek(dev_fd, sector * SECTOR_SIZE + BSD_LABELOFFSET, SEEK_SET) == -1)
- fdisk_fatal(unable_to_seek);
- if (sizeof(struct xbsd_disklabel) != write(dev_fd, d, sizeof(struct xbsd_disklabel)))
- fdisk_fatal(unable_to_write);
+ seek_sector(sector);
+ lseek(dev_fd, BSD_LABELOFFSET, SEEK_CUR);
+ xwrite(dev_fd, d, sizeof(*d));
#endif
sync_disks();
return 1;