Skip to content

Commit

Permalink
[core] clean up the RUFUS_DRIVE_INFO struct
Browse files Browse the repository at this point in the history
* Remove the duplication of DISK_GEOMETRY to keep only the variables we actually use
* Also set rufus-next to 2.10
  • Loading branch information
pbatard committed May 23, 2016
1 parent 258a4f7 commit 81673ad
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 71 deletions.
20 changes: 10 additions & 10 deletions configure
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! /bin/sh
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.69 for rufus 2.9.
# Generated by GNU Autoconf 2.69 for rufus 2.10.
#
# Report bugs to <https://github.com/pbatard/rufus/issues>.
#
Expand Down Expand Up @@ -580,8 +580,8 @@ MAKEFLAGS=
# Identity of this package.
PACKAGE_NAME='rufus'
PACKAGE_TARNAME='rufus'
PACKAGE_VERSION='2.9'
PACKAGE_STRING='rufus 2.9'
PACKAGE_VERSION='2.10'
PACKAGE_STRING='rufus 2.10'
PACKAGE_BUGREPORT='https://github.com/pbatard/rufus/issues'
PACKAGE_URL='http://rufus.akeo.ie'

Expand Down Expand Up @@ -1228,7 +1228,7 @@ if test "$ac_init_help" = "long"; then
# Omit some internal or obsolete options to make the list less imposing.
# This message is too long to be a string in the A/UX 3.1 sh.
cat <<_ACEOF
\`configure' configures rufus 2.9 to adapt to many kinds of systems.
\`configure' configures rufus 2.10 to adapt to many kinds of systems.
Usage: $0 [OPTION]... [VAR=VALUE]...
Expand Down Expand Up @@ -1294,7 +1294,7 @@ fi

if test -n "$ac_init_help"; then
case $ac_init_help in
short | recursive ) echo "Configuration of rufus 2.9:";;
short | recursive ) echo "Configuration of rufus 2.10:";;
esac
cat <<\_ACEOF
Expand Down Expand Up @@ -1385,7 +1385,7 @@ fi
test -n "$ac_init_help" && exit $ac_status
if $ac_init_version; then
cat <<\_ACEOF
rufus configure 2.9
rufus configure 2.10
generated by GNU Autoconf 2.69
Copyright (C) 2012 Free Software Foundation, Inc.
Expand Down Expand Up @@ -1440,7 +1440,7 @@ cat >config.log <<_ACEOF
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
It was created by rufus $as_me 2.9, which was
It was created by rufus $as_me 2.10, which was
generated by GNU Autoconf 2.69. Invocation command line was
$ $0 $@
Expand Down Expand Up @@ -2303,7 +2303,7 @@ fi
# Define the identity of the package.
PACKAGE='rufus'
VERSION='2.9'
VERSION='2.10'
cat >>confdefs.h <<_ACEOF
Expand Down Expand Up @@ -4482,7 +4482,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
# report actual input values of CONFIG_FILES etc. instead of their
# values after options handling.
ac_log="
This file was extended by rufus $as_me 2.9, which was
This file was extended by rufus $as_me 2.10, which was
generated by GNU Autoconf 2.69. Invocation command line was
CONFIG_FILES = $CONFIG_FILES
Expand Down Expand Up @@ -4536,7 +4536,7 @@ _ACEOF
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
ac_cs_version="\\
rufus config.status 2.9
rufus config.status 2.10
configured by $0, generated by GNU Autoconf 2.69,
with options \\"\$ac_cs_config\\"
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
AC_INIT([rufus], [2.9], [https://github.com/pbatard/rufus/issues], [rufus], [http://rufus.akeo.ie])
AC_INIT([rufus], [2.10], [https://github.com/pbatard/rufus/issues], [rufus], [http://rufus.akeo.ie])
AM_INIT_AUTOMAKE([-Wno-portability foreign no-dist no-dependencies])
AC_CONFIG_SRCDIR([src/rufus.c])
AC_CONFIG_MACRO_DIR([m4])
Expand Down
43 changes: 23 additions & 20 deletions src/drive.c
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ BOOL AnalyzeMBR(HANDLE hPhysicalDrive, const char* TargetName)
int i;

fake_fd._handle = (char*)hPhysicalDrive;
set_bytes_per_sector(SelectedDrive.Geometry.BytesPerSector);
set_bytes_per_sector(SelectedDrive.SectorSize);

if (!is_br(fp)) {
uprintf("%s does not have an x86 %s\n", TargetName, mbr_name);
Expand Down Expand Up @@ -628,7 +628,7 @@ BOOL AnalyzePBR(HANDLE hLogicalVolume)
int i;

fake_fd._handle = (char*)hLogicalVolume;
set_bytes_per_sector(SelectedDrive.Geometry.BytesPerSector);
set_bytes_per_sector(SelectedDrive.SectorSize);

if (!is_br(fp)) {
uprintf("Volume does not have an x86 %s\n", pbr_name);
Expand Down Expand Up @@ -690,15 +690,18 @@ BOOL GetDrivePartitionData(DWORD DriveIndex, char* FileSystemName, DWORD FileSys
safe_closehandle(hPhysical);
return 0;
}
if (DiskGeometry->Geometry.BytesPerSector < 512) {
SelectedDrive.DiskSize = DiskGeometry->DiskSize.QuadPart;
SelectedDrive.SectorSize = DiskGeometry->Geometry.BytesPerSector;
if (SelectedDrive.SectorSize < 512) {
suprintf("Warning: Drive 0x%02x reports a sector size of %d - Correcting to 512 bytes.\n",
DriveIndex, DiskGeometry->Geometry.BytesPerSector);
DiskGeometry->Geometry.BytesPerSector = 512;
DriveIndex, SelectedDrive.SectorSize);
SelectedDrive.SectorSize = 512;
}
SelectedDrive.DiskSize = DiskGeometry->DiskSize.QuadPart;
memcpy(&SelectedDrive.Geometry, &DiskGeometry->Geometry, sizeof(DISK_GEOMETRY));
suprintf("Disk type: %s, Sector Size: %d bytes\n", (DiskGeometry->Geometry.MediaType == FixedMedia)?"Fixed":"Removable",
DiskGeometry->Geometry.BytesPerSector);
SelectedDrive.SectorsPerTrack = DiskGeometry->Geometry.SectorsPerTrack;
SelectedDrive.MediaType = DiskGeometry->Geometry.MediaType;

suprintf("Disk type: %s, Sector Size: %d bytes\n", (SelectedDrive.MediaType == FixedMedia)?"Fixed":"Removable",
SelectedDrive.SectorSize);
suprintf("Cylinders: %" PRIi64 ", TracksPerCylinder: %d, SectorsPerTrack: %d\n",
DiskGeometry->Geometry.Cylinders, DiskGeometry->Geometry.TracksPerCylinder, DiskGeometry->Geometry.SectorsPerTrack);

Expand Down Expand Up @@ -1031,7 +1034,7 @@ BOOL CreatePartition(HANDLE hDrive, int partition_style, int file_system, BOOL m
BOOL r;
DWORD i, size, bufsize, pn = 0;
LONGLONG main_part_size_in_sectors, extra_part_size_in_tracks = 0, ms_efi_size;
const LONGLONG bytes_per_track = ((LONGLONG)SelectedDrive.Geometry.SectorsPerTrack) * SelectedDrive.Geometry.BytesPerSector;
const LONGLONG bytes_per_track = ((LONGLONG)SelectedDrive.SectorsPerTrack) * SelectedDrive.SectorSize;

PrintInfoDebug(0, MSG_238, PartitionTypeName[partition_style]);

Expand Down Expand Up @@ -1078,7 +1081,7 @@ BOOL CreatePartition(HANDLE hDrive, int partition_style, int file_system, BOOL m
// Set our main data partition
main_part_size_in_sectors = (SelectedDrive.DiskSize - DriveLayoutEx.PartitionEntry[pn].StartingOffset.QuadPart) /
// Need 33 sectors at the end for secondary GPT
SelectedDrive.Geometry.BytesPerSector - ((partition_style == PARTITION_STYLE_GPT)?33:0);
SelectedDrive.SectorSize - ((partition_style == PARTITION_STYLE_GPT)?33:0);
if (main_part_size_in_sectors <= 0)
return FALSE;

Expand All @@ -1088,9 +1091,9 @@ BOOL CreatePartition(HANDLE hDrive, int partition_style, int file_system, BOOL m
if (extra_partitions & XP_EFI) {
// The size of the EFI partition depends on the minimum size we're able to format in FAT32,
// which in turn depends on the cluster size used, which in turn depends on the disk sector size.
if (SelectedDrive.Geometry.BytesPerSector <= 1024)
if (SelectedDrive.SectorSize <= 1024)
ms_efi_size = 100*MB;
else if (SelectedDrive.Geometry.BytesPerSector <= 4096)
else if (SelectedDrive.SectorSize <= 4096)
ms_efi_size = 300*MB;
else
ms_efi_size = 1200*MB; // That'll teach you to have a nonstandard disk!
Expand All @@ -1101,12 +1104,12 @@ BOOL CreatePartition(HANDLE hDrive, int partition_style, int file_system, BOOL m
extra_part_size_in_tracks = 1; // One track for the extra partition
uprintf("Reserved %" PRIi64" tracks (%s) for extra partition", extra_part_size_in_tracks,
SizeToHumanReadable(extra_part_size_in_tracks * bytes_per_track, TRUE, FALSE));
main_part_size_in_sectors = ((main_part_size_in_sectors / SelectedDrive.Geometry.SectorsPerTrack) -
extra_part_size_in_tracks) * SelectedDrive.Geometry.SectorsPerTrack;
main_part_size_in_sectors = ((main_part_size_in_sectors / SelectedDrive.SectorsPerTrack) -
extra_part_size_in_tracks) * SelectedDrive.SectorsPerTrack;
if (main_part_size_in_sectors <= 0)
return FALSE;
}
DriveLayoutEx.PartitionEntry[pn].PartitionLength.QuadPart = main_part_size_in_sectors * SelectedDrive.Geometry.BytesPerSector;
DriveLayoutEx.PartitionEntry[pn].PartitionLength.QuadPart = main_part_size_in_sectors * SelectedDrive.SectorSize;
if (partition_style == PARTITION_STYLE_MBR) {
DriveLayoutEx.PartitionEntry[pn].Mbr.BootIndicator = IsChecked(IDC_BOOT);
switch (file_system) {
Expand Down Expand Up @@ -1139,7 +1142,7 @@ BOOL CreatePartition(HANDLE hDrive, int partition_style, int file_system, BOOL m
DriveLayoutEx.PartitionEntry[pn].StartingOffset.QuadPart = DriveLayoutEx.PartitionEntry[pn-1].StartingOffset.QuadPart +
DriveLayoutEx.PartitionEntry[pn-1].PartitionLength.QuadPart;
DriveLayoutEx.PartitionEntry[pn].PartitionLength.QuadPart = (extra_partitions & XP_UEFI_NTFS)?uefi_ntfs_size:
extra_part_size_in_tracks * SelectedDrive.Geometry.SectorsPerTrack * SelectedDrive.Geometry.BytesPerSector;
extra_part_size_in_tracks * SelectedDrive.SectorsPerTrack * SelectedDrive.SectorSize;
if (partition_style == PARTITION_STYLE_GPT) {
DriveLayoutEx.PartitionEntry[pn].Gpt.PartitionType = (extra_partitions & XP_UEFI_NTFS)?
PARTITION_BASIC_DATA_GUID:PARTITION_SYSTEM_GUID;
Expand All @@ -1149,7 +1152,7 @@ BOOL CreatePartition(HANDLE hDrive, int partition_style, int file_system, BOOL m
DriveLayoutEx.PartitionEntry[pn].Mbr.PartitionType = (extra_partitions & XP_UEFI_NTFS)?0xef:RUFUS_EXTRA_PARTITION_TYPE;
if (extra_partitions & XP_COMPAT)
// Set the one track compatibility partition to be all hidden sectors
DriveLayoutEx.PartitionEntry[pn].Mbr.HiddenSectors = SelectedDrive.Geometry.SectorsPerTrack;
DriveLayoutEx.PartitionEntry[pn].Mbr.HiddenSectors = SelectedDrive.SectorsPerTrack;
}

// We need to write the UEFI:NTFS partition before we refresh the disk
Expand Down Expand Up @@ -1207,8 +1210,8 @@ BOOL CreatePartition(HANDLE hDrive, int partition_style, int file_system, BOOL m
DriveLayoutEx.PartitionStyle = PARTITION_STYLE_GPT;
DriveLayoutEx.PartitionCount = pn;
// At the very least, a GPT disk has 34 reserved sectors at the beginning and 33 at the end.
DriveLayoutEx.Type.Gpt.StartingUsableOffset.QuadPart = 34 * SelectedDrive.Geometry.BytesPerSector;
DriveLayoutEx.Type.Gpt.UsableLength.QuadPart = SelectedDrive.DiskSize - (34+33) * SelectedDrive.Geometry.BytesPerSector;
DriveLayoutEx.Type.Gpt.StartingUsableOffset.QuadPart = 34 * SelectedDrive.SectorSize;
DriveLayoutEx.Type.Gpt.UsableLength.QuadPart = SelectedDrive.DiskSize - (34+33) * SelectedDrive.SectorSize;
DriveLayoutEx.Type.Gpt.MaxPartitionCount = MAX_GPT_PARTITIONS;
DriveLayoutEx.Type.Gpt.DiskId = CreateDisk.Gpt.DiskId;
break;
Expand Down
8 changes: 5 additions & 3 deletions src/drive.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,16 @@ static __inline BOOL UnlockDrive(HANDLE hDrive) {

/* Current drive info */
typedef struct {
DWORD DeviceNumber;
LONGLONG DiskSize;
DISK_GEOMETRY Geometry;
DWORD DeviceNumber;
DWORD SectorsPerTrack;
DWORD SectorSize;
DWORD FirstSector;
char proposed_label[16];
MEDIA_TYPE MediaType;
int PartitionType;
int nPartitions; // number of partitions we actually care about
int FSType;
char proposed_label[16];
BOOL has_protective_mbr;
BOOL has_mbr_uefi_marker;
struct {
Expand Down
Loading

0 comments on commit 81673ad

Please sign in to comment.