summaryrefslogtreecommitdiffstats
path: root/perl-install/partition_table_raw.pm
blob: 7eee56f5abc93d215156ef53fa2ba2d8733ff628 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package partition_table_raw;

use diagnostics;
use strict;

use common qw(:common :system :file);
use devices;
use c;

my @MBR_signatures = (
    [ 'empty', 0, "\0\0\0\0" ],
    [ 'grub', 0, "\xEBG", 0x17d, "stage1 \0" ],
    [ 'grub', 0, "\xEBH", 0x18a, "stage1 \0" ],
    [ 'lilo', 0x2,  "LILO" ],
    [ 'lilo', 0x6,  "LILO" ],
    [ 'osbs', 0x2,  "OSBS" ], #- http://www.prz.tu-berlin.de/~wolf/os-bs.html
    [ 'pqmagic', 0xef, "PQV" ],
    [ 'BootStar', 0x130, "BootStar:" ],
    [ 'DocsBoot', 0x148, 'DocsBoot' ],
    [ 'system_commander', 0x1ad, "SYSCMNDRSYS" ],
    [ 'Be Os', 0x24, 'Boot Manager' ],
    [ 'TimO', 0, 'IBM Thinkpad hibernation partition' ],
    [ 'dos', 0xa0, "\x25\x03\x4E\x02\xCD\x13" ],
    [ 'dos', 0xa0, "\x00\xB4\x08\xCD\x13\x72" ], #- nt2k's
    [ 'dos', 0x60, "\xBB\x00\x7C\xB8\x01\x02\x57\xCD\x13\x5F\x73\x0C\x33\xC0\xCD\x13" ], #- nt's
    [ 'dos', 0x70, "\x0C\x33\xC0\xCD\x13\x4F\x75\xED\xBE\xA3" ],
    [ 'freebsd', 0xC0, "\x00\x30\xE4\xCD\x16\xCD\x19\xBB\x07\x00\xB4" ],
    [ 'freebsd', 0x160, "\x6A\x10\x89\xE6\x48\x80\xCC\x40\xCD\x13" ],
    [ 'dummy', 0xAC, "\x0E\xB3\x07\x56\xCD\x10\x5E\xEB" ], #- caldera?
    [ 'ranish', 0x100, "\x6A\x10\xB4\x42\x8B\xF4\xCD\x13\x8B\xE5\x73" ],
    [ 'os2', 0x1c2, "\xA" ],
);

sub typeOfMBR($) { typeFromMagic(devices::make($_[0]), @MBR_signatures) }
sub typeOfMBR_($) { typeFromMagic($_[0], @MBR_signatures) }

sub hasExtended { 0 }

sub cylinder_size($) {
    my ($hd) = @_;
    $hd->{geom}{sectors} * $hd->{geom}{heads};
}

#- default method for starting a partition, only head size or twice
#- is allowed for starting a partition after a cylinder boundarie.
sub adjustStart($$) {
    my ($hd, $part) = @_;
    my $end = $part->{start} + $part->{size};

    $part->{start} = round_up($part->{start},
			      $part->{start} % cylinder_size($hd) < 2 * $hd->{geom}{sectors} ?
   			      $hd->{geom}{sectors} : cylinder_size($hd));
    $part->{size} = $end - $part->{start};
    $part->{size} > 0 or die "adjustStart get a too small partition to handle correctly";
}
#- adjusting end to match a cylinder boundary, two methods are used and must
#- match at the end, else something is wrong and nothing will be done on
#- partition table.
#- $end2 is computed by removing 2 (or only 1 if only 2 heads on drive) groups
#- of sectors, this is necessary to handle extended partition where logical
#- partition start after 1 (or 2 accepted) groups of sectors (typically 63).
#- $end is floating (is not on cylinder boudary) so we have to choice a good
#- candidate, $end1 or $end2 should always be good except $end1 for small
#- partition size.
sub adjustEnd($$) {
    my ($hd, $part) = @_;
    my $end = $part->{start} + $part->{size};
    my $end1 = round_down($end, cylinder_size($hd));
    my $end2 = round_up($end - ($hd->{geom}{heads} > 2 ? 2 : 1) * $hd->{geom}{sectors}, cylinder_size($hd));
    $end2 <= $hd->{geom}{cylinders} * cylinder_size($hd) or die "adjustEnd go beyond end of device geometry ($end2 > $hd->{totalsectors})";
    $part->{size} = ($end1 - $part->{start} > cylinder_size($hd) ? $end1 : $end2) - $part->{start};
    $part->{size} > 0 or die "adjustEnd get a too small partition to handle correctly";
}

sub get_geometry($) {
    my ($dev) = @_;
    my $g = "";

    local *F; sysopen F, $dev, 0 or return;
    ioctl(F, c::HDIO_GETGEO(), $g) or return;
    my %geom; @geom{qw(heads sectors cylinders start)} = unpack "CCSL", $g;
    $geom{totalcylinders} = $geom{cylinders};

    #- $geom{cylinders} is no good (only a ushort, that means less than 2^16 => at best 512MB)
    if (my $total = c::total_sectors(fileno F)) {
	$geom{cylinders} = int $total / $geom{heads} / $geom{sectors};
    }

    { geom => \%geom, totalsectors => $geom{heads} * $geom{sectors} * $geom{cylinders} };
}

#- works for both hard drives and partitions ;p
sub description {
    my ($hd) = @_;
    my $win = $hd->{device_windobe};

    sprintf "%s%s (%d%s%s)", 
      $hd->{device}, 
      $win && " [$win:]", 
      ($hd->{totalsectors} || $hd->{size}) >> 11, _("MB"), 
      $hd->{info} && ", $hd->{info}";
}

sub openit($$;$) { sysopen $_[1], $_[0]{file}, $_[2] || 0; }

# cause kernel to re-read partition table
sub kernel_read($) {
    my ($hd) = @_;
    sync();
    local *F; openit($hd, *F) or return 0;
    sync(); sleep(1);
    $hd->{rebootNeeded} = !ioctl(F, c::BLKRRPART(), 0);
    sync();
    close F;
    sync(); sleep(1);
}

sub zero_MBR {
    my ($hd) = @_;
    #- force the standard partition type for the architecture
    my $type = arch() eq "alpha" ? "bsd" : arch() =~ /^sparc/ ? "sun" : arch() eq "ppc" ? "mac" : "dos";
    bless $hd, "partition_table_$type";
    $hd->{primary} = $hd->clear_raw();
    delete $hd->{extended};
}

sub zero_MBR_and_dirty {
    my ($hd) = @_;
    zero_MBR($hd);
    $hd->{isDirty} = $hd->{needKernelReread} = 1;

}

1;
pe: Single-bit ECC System Type: Unified Associativity: 8-way Set-associative Handle 0x0007 DMI type 5, 24 bytes. Memory Controller Information Error Detecting Method: 64-bit ECC Error Correcting Capabilities: None Supported Interleave: One-way Interleave Current Interleave: One-way Interleave Maximum Memory Module Size: 1024 MB Maximum Total Memory Size: 4096 MB Supported Speeds: 70 ns 60 ns Supported Memory Types: Other Unknown Standard FPM EDO Parity ECC SIMM DIMM Burst EDO SDRAM Memory Module Voltage: 3.3 V Associated Memory Slots: 4 0x0008 0x0009 0x000A 0x000B Enabled Error Correcting Capabilities: None Handle 0x0008 DMI type 6, 12 bytes. Memory Module Information Socket Designation: DIMM1 Bank Connections: 11 12 Current Speed: 2 ns Type: DIMM Installed Size: Not Installed (Single-bank Connection) Enabled Size: Not Installed (Single-bank Connection) Error Status: OK Handle 0x0009 DMI type 6, 12 bytes. Memory Module Information Socket Designation: DIMM2 Bank Connections: 11 12 Current Speed: 2 ns Type: DIMM Installed Size: Not Installed (Single-bank Connection) Enabled Size: Not Installed (Single-bank Connection) Error Status: OK Handle 0x000A DMI type 6, 12 bytes. Memory Module Information Socket Designation: DIMM3 Bank Connections: 11 12 Current Speed: 2 ns Type: DIMM Installed Size: 512 MB (Double-bank Connection) Enabled Size: 512 MB (Double-bank Connection) Error Status: OK Handle 0x000B DMI type 6, 12 bytes. Memory Module Information Socket Designation: DIMM4 Bank Connections: 11 12 Current Speed: 2 ns Type: DIMM Installed Size: 512 MB (Double-bank Connection) Enabled Size: 512 MB (Double-bank Connection) Error Status: OK Handle 0x000C DMI type 8, 9 bytes. Port Connector Information Internal Reference Designator: J1A1 Internal Connector Type: None External Reference Designator: PS2Mouse External Connector Type: PS/2 Port Type: Mouse Port Handle 0x000D DMI type 8, 9 bytes. Port Connector Information Internal Reference Designator: J1A1 Internal Connector Type: None External Reference Designator: Keyboard External Connector Type: PS/2 Port Type: Keyboard Port Handle 0x000E DMI type 8, 9 bytes. Port Connector Information Internal Reference Designator: J2A1 Internal Connector Type: None External Reference Designator: COM 1 External Connector Type: DB-9 female Port Type: Serial Port 16550A Compatible Handle 0x000F DMI type 8, 9 bytes. Port Connector Information Internal Reference Designator: J4A2 Internal Connector Type: None External Reference Designator: LPT1 External Connector Type: DB-25 male Port Type: Parallel Port ECP/EPP Handle 0x0010 DMI type 8, 9 bytes. Port Connector Information Internal Reference Designator: JA5A1 Internal Connector Type: None External Reference Designator: USB External Connector Type: Access Bus (USB) Port Type: USB Handle 0x0011 DMI type 8, 9 bytes. Port Connector Information Internal Reference Designator: JA5A1 Internal Connector Type: None External Reference Designator: USB External Connector Type: Access Bus (USB) Port Type: USB Handle 0x0012 DMI type 8, 9 bytes. Port Connector Information Internal Reference Designator: J4A1 Internal Connector Type: None External Reference Designator: VIDEO External Connector Type: DB-15 male Port Type: Video Port Handle 0x0013 DMI type 8, 9 bytes. Port Connector Information Internal Reference Designator: J2A2 Internal Connector Type: None External Reference Designator: USB External Connector Type: Access Bus (USB) Port Type: USB Handle 0x0014 DMI type 8, 9 bytes. Port Connector Information Internal Reference Designator: J2A2 Internal Connector Type: None External Reference Designator: USB External Connector Type: Access Bus (USB) Port Type: USB Handle 0x0015 DMI type 8, 9 bytes. Port Connector Information Internal Reference Designator: JA5A1 Internal Connector Type: None External Reference Designator: RJ-45 Type External Connector Type: RJ-45 Port Type: Network Port Handle 0x0016 DMI type 8, 9 bytes. Port Connector Information Internal Reference Designator: J6A1 Internal Connector Type: None External Reference Designator: Audio Mic In External Connector Type: Mini Jack (headphones) Port Type: Audio Port Handle 0x0017 DMI type 8, 9 bytes. Port Connector Information Internal Reference Designator: J6A1 Internal Connector Type: None External Reference Designator: Audio Line In External Connector Type: Mini Jack (headphones) Port Type: Audio Port Handle 0x0018 DMI type 8, 9 bytes. Port Connector Information Internal Reference Designator: J6A1 Internal Connector Type: None External Reference Designator: Audio Line Out External Connector Type: Mini Jack (headphones) Port Type: Audio Port Handle 0x0019 DMI type 8, 9 bytes. Port Connector Information Internal Reference Designator: J5C1 - +12V Internal Connector Type: Other External Reference Designator: Not Specified External Connector Type: None Port Type: Other Handle 0x001A DMI type 8, 9 bytes. Port Connector Information Internal Reference Designator: J4H1 - FDD Internal Connector Type: On Board Floppy External Reference Designator: Not Specified External Connector Type: None Port Type: Other Handle 0x001B DMI type 8, 9 bytes. Port Connector Information Internal Reference Designator: J6H2 - PRI IDE Internal Connector Type: On Board IDE External Reference Designator: Not Specified External Connector Type: None Port Type: Other Handle 0x001C DMI type 8, 9 bytes. Port Connector Information Internal Reference Designator: J6H1 - SEC IDE Internal Connector Type: On Board IDE External Reference Designator: Not Specified External Connector Type: None Port Type: Other Handle 0x001D DMI type 8, 9 bytes. Port Connector Information Internal Reference Designator: J8B1 - CDIN Internal Connector Type: On Board Sound Input From CD-ROM External Reference Designator: Not Specified External Connector Type: None Port Type: Audio Port Handle 0x001E DMI type 8, 9 bytes. Port Connector Information Internal Reference Designator: J6B1 - AUX IN Internal Connector Type: Other External Reference Designator: Not Specified External Connector Type: None Port Type: Audio Port Handle 0x001F DMI type 8, 9 bytes. Port Connector Information Internal Reference Designator: J9G1 - FRONT PANEL HDR Internal Connector Type: Other External Reference Designator: Not Specified External Connector Type: None Port Type: Other Handle 0x0020 DMI type 8, 9 bytes. Port Connector Information Internal Reference Designator: J2F1 - CPU FAN Internal Connector Type: Other External Reference Designator: Not Specified External Connector Type: None Port Type: Other Handle 0x0021 DMI type 8, 9 bytes. Port Connector Information Internal Reference Designator: J9H3 - FNT PNL Internal Connector Type: Other External Reference Designator: Not Specified External Connector Type: None Port Type: Other Handle 0x0022 DMI type 8, 9 bytes. Port Connector Information Internal Reference Designator: J9H3 - FRONT CHASSIS FAN Internal Connector Type: Other External Reference Designator: Not Specified External Connector Type: None Port Type: Other Handle 0x0023 DMI type 8, 9 bytes. Port Connector Information Internal Reference Designator: J1B1 - REAR CHASSIS FAN Internal Connector Type: Other External Reference Designator: Not Specified External Connector Type: None Port Type: Other Handle 0x0024 DMI type 8, 9 bytes. Port Connector Information Internal Reference Designator: J9H2 - BIOS CONFIG Internal Connector Type: Other External Reference Designator: Not Specified External Connector Type: None Port Type: Other Handle 0x0025 DMI type 8, 9 bytes. Port Connector Information Internal Reference Designator: J8A1 - FP AUDIO Internal Connector Type: Proprietary External Reference Designator: Not Specified External Connector Type: None Port Type: Other Handle 0x0026 DMI type 8, 9 bytes. Port Connector Information Internal Reference Designator: J9F1 - FRONT PANEL USB Internal Connector Type: Other External Reference Designator: Not Specified External Connector Type: None Port Type: Other Handle 0x0027 DMI type 8, 9 bytes. Port Connector Information Internal Reference Designator: J2H1 - PS Internal Connector Type: Other External Reference Designator: Not Specified External Connector Type: None Port Type: Other Handle 0x0028 DMI type 8, 9 bytes. Port Connector Information Internal Reference Designator: J8H3 - CH INTR Internal Connector Type: Other External Reference Designator: Not Specified External Connector Type: None Port Type: Other Handle 0x0029 DMI type 8, 9 bytes. Port Connector Information Internal Reference Designator: J8H2 - SCSI Internal Connector Type: Other External Reference Designator: Not Specified External Connector Type: None Port Type: Other Handle 0x002A DMI type 9, 13 bytes. System Slot Information Designation: J6C1 Type: 32-bit AGP 4x Current Usage: Available Length: Long ID: 1 Characteristics: 3.3 V is provided Handle 0x002B DMI type 9, 13 bytes. System Slot Information Designation: J7B1 Type: 32-bit PCI Current Usage: Available Length: Long ID: 2 Characteristics: 3.3 V is provided PME signal is supported SMBus signal is supported Handle 0x002C DMI type 9, 13 bytes. System Slot Information Designation: J8B2 Type: 32-bit PCI Current Usage: Available Length: Long ID: 3 Characteristics: 3.3 V is provided PME signal is supported SMBus signal is supported Handle 0x002D DMI type 9, 13 bytes. System Slot Information Designation: J9B1 Type: 32-bit PCI Current Usage: Available Length: Long ID: 4 Characteristics: 3.3 V is provided PME signal is supported SMBus signal is supported Handle 0x002E DMI type 9, 13 bytes. System Slot Information Designation: J10B1 Type: 32-bit PCI Current Usage: Available Length: Long ID: 5 Characteristics: 3.3 V is provided PME signal is supported SMBus signal is supported Handle 0x002F DMI type 9, 13 bytes. System Slot Information Designation: J10B2 Type: 32-bit PCI Current Usage: Available Length: Long ID: 6 Characteristics: 3.3 V is provided PME signal is supported SMBus signal is supported Handle 0x0030 DMI type 9, 13 bytes. System Slot Information Designation: J11B1 Type: 32-bit PCI Current Usage: Available Length: Long ID: 7 Characteristics: 3.3 V is provided PME signal is supported SMBus signal is supported Handle 0x0031 DMI type 10, 6 bytes. On Board Device Information Type: Video Status: Enabled Description: Intel GMCH AGP Graphics Controller Handle 0x0032 DMI type 10, 6 bytes. On Board Device Information Type: Ethernet Status: Enabled Description: Intel 82562 Ethernet Device Handle 0x0033 DMI type 10, 6 bytes. On Board Device Information Type: Sound Status: Enabled Description: Intel ICH4 Audio Device Handle 0x0034 DMI type 12, 5 bytes. System Configuration Options Option 1: To Be Filled By O.E.M. Option 2: To Be Filled By O.E.M. Option 3: To Be Filled By O.E.M. Handle 0x0035 DMI type 13, 22 bytes. BIOS Language Information Installable Languages: 1 enUS Currently Installed Language: enUS Handle 0x0036 DMI type 15, 35 bytes. System Event Log Area Length: 2048 bytes Header Start Offset: 0x0000 Header Length: 16 bytes Data Start Offset: 0x0010 Access Method: Memory-mapped physical 32-bit address Access Address: 0xFFFEF7F0 Status: Valid, Not Full Change Token: 0x00000000 Header Format: Type 1 Supported Log Type Descriptors: 6 Descriptor 1: POST error Data Format 1: POST results bitmap Descriptor 2: Parity memory error Data Format 2: Multiple-event Descriptor 3: I/O channel block Data Format 3: Multiple-event Descriptor 4: Single-bit ECC memory error Data Format 4: Multiple-event Descriptor 5: Multi-bit ECC memory error Data Format 5: Multiple-event Descriptor 6: System limit exceeded Data Format 6: System management Handle 0x0037 DMI type 18, 23 bytes. 32-bit Memory Error Information Type: Unknown Granularity: Unknown Operation: Unknown Vendor Syndrome: Unknown Memory Array Address: Unknown Device Address: Unknown Resolution: Unknown Handle 0x0038 DMI type 16, 15 bytes. Physical Memory Array Location: System Board Or Motherboard Use: System Memory Error Correction Type: None Maximum Capacity: 4 GB Error Information Handle: 0x0037 Number Of Devices: 4 Handle 0x0039 DMI type 19, 15 bytes. Memory Array Mapped Address Starting Address: 0x00000000000 Ending Address: 0x0003EFFFFFF Range Size: 1008 MB Physical Array Handle: 0x0038 Partition Width: 0 Handle 0x003A DMI type 17, 27 bytes. Memory Device Array Handle: 0x0038 Error Information Handle: 0x0037 Total Width: 64 bits Data Width: 64 bits Size: No Module Installed Form Factor: DIMM Set: None Locator: J6G1 Bank Locator: CHANNEL A DIMM0 Type: DDR Type Detail: Synchronous Speed: 400 MHz (2.5 ns) Manufacturer: Manufacturer1 Serial Number: SerNum1 Asset Tag: AssetTagNum1 Part Number: PartNum1 Handle 0x003B DMI type 126, 19 bytes. Inactive Handle 0x003C DMI type 17, 27 bytes. Memory Device Array Handle: 0x0038 Error Information Handle: 0x0037 Total Width: 64 bits Data Width: 64 bits Size: No Module Installed Form Factor: DIMM Set: None Locator: J6G2 Bank Locator: CHANNEL A DIMM1 Type: DDR Type Detail: Synchronous Speed: 400 MHz (2.5 ns) Manufacturer: Manufacturer2 Serial Number: SerNum2 Asset Tag: AssetTagNum2 Part Number: PartNum2 Handle 0x003D DMI type 126, 19 bytes. Inactive Handle 0x003E DMI type 17, 27 bytes. Memory Device Array Handle: 0x0038 Error Information Handle: 0x0037 Total Width: 64 bits Data Width: 64 bits Size: 512 MB Form Factor: DIMM Set: None Locator: J6H1 Bank Locator: CHANNEL B DIMM0 Type: DDR Type Detail: Synchronous Speed: 400 MHz (2.5 ns) Manufacturer: Manufacturer3 Serial Number: SerNum3 Asset Tag: AssetTagNum3 Part Number: PartNum3 Handle 0x003F DMI type 20, 19 bytes. Memory Device Mapped Address Starting Address: 0x00000000000 Ending Address: 0x0001FFFFFFF Range Size: 512 MB Physical Device Handle: 0x003E Memory Array Mapped Address Handle: 0x0039 Partition Row Position: 1 Handle 0x0040 DMI type 17, 27 bytes. Memory Device Array Handle: 0x0038 Error Information Handle: 0x0037 Total Width: 64 bits Data Width: 64 bits Size: 512 MB Form Factor: DIMM Set: None Locator: J6H2 Bank Locator: CHANNEL B DIMM1 Type: DDR Type Detail: Synchronous Speed: 400 MHz (2.5 ns) Manufacturer: Manufacturer4 Serial Number: SerNum4 Asset Tag: AssetTagNum4 Part Number: PartNum4 Handle 0x0041 DMI type 20, 19 bytes. Memory Device Mapped Address Starting Address: 0x00020000000 Ending Address: 0x0003EFFFFFF Range Size: 496 MB Physical Device Handle: 0x0040 Memory Array Mapped Address Handle: 0x0039 Partition Row Position: 1 Handle 0x0042 DMI type 23, 13 bytes. System Reset Status: Disabled Watchdog Timer: No Boot Option: <OUT OF SPEC> Boot Option On Limit: <OUT OF SPEC> Reset Count: Unknown Reset Limit: Unknown Timer Interval: Unknown Timeout: Unknown Handle 0x0043 DMI type 126, 28 bytes. Inactive Handle 0x0044 DMI type 32, 20 bytes. System Boot Information Status: No errors detected Handle 0x0045 DMI type 126, 9 bytes. Inactive Handle 0x0046 DMI type 126, 9 bytes. Inactive Handle 0x0047 DMI type 187, 9 bytes. OEM-specific Type Header and Data: BB 09 47 00 3E 00 03 90 01 Handle 0x0048 DMI type 187, 9 bytes. OEM-specific Type Header and Data: BB 09 48 00 40 00 03 90 01 Handle 0x0049 DMI type 131, 12 bytes. OEM-specific Type Header and Data: 83 0C 49 00 01 01 02 01 09 01 40 01 Strings: Intel_ASF_001 Intel_ASF_001 Handle 0x004A DMI type 127, 4 bytes. End Of Table