@@ -712,210 +712,6 @@ pub const Content = union(enum) {
712
712
}
713
713
};
714
714
715
- pub const mbr = struct {
716
- pub const Table = struct {
717
- bootloader : [440 ]u8 = .{0 } ** 440 ,
718
- disk_id : ? u32 = null ,
719
- partitions : [4 ]? * const Partition ,
720
- };
721
-
722
- pub const Partition = struct {
723
- offset : ? u64 = null ,
724
- size : u64 ,
725
-
726
- bootable : bool ,
727
- type : PartitionType ,
728
-
729
- data : Content ,
730
- };
731
-
732
- /// https://en.wikipedia.org/wiki/Partition_type
733
- pub const PartitionType = enum (u8 ) {
734
- empty = 0x00 ,
735
-
736
- fat12 = 0x01 ,
737
- ntfs = 0x07 ,
738
-
739
- fat32_chs = 0x0B ,
740
- fat32_lba = 0x0C ,
741
-
742
- fat16_lba = 0x0E ,
743
-
744
- linux_swap = 0x82 ,
745
- linux_fs = 0x83 ,
746
- linux_lvm = 0x8E ,
747
-
748
- // Output from fdisk (util-linux 2.38.1)
749
- // 00 Leer 27 Verst. NTFS Win 82 Linux Swap / So c1 DRDOS/sec (FAT-
750
- // 01 FAT12 39 Plan 9 83 Linux c4 DRDOS/sec (FAT-
751
- // 02 XENIX root 3c PartitionMagic 84 versteckte OS/2 c6 DRDOS/sec (FAT-
752
- // 03 XENIX usr 40 Venix 80286 85 Linux erweitert c7 Syrinx
753
- // 04 FAT16 <32M 41 PPC PReP Boot 86 NTFS Datenträge da Keine Dateisyst
754
- // 05 Erweiterte 42 SFS 87 NTFS Datenträge db CP/M / CTOS / .
755
- // 06 FAT16 4d QNX4.x 88 Linux Klartext de Dell Dienstprog
756
- // 07 HPFS/NTFS/exFAT 4e QNX4.x 2. Teil 8e Linux LVM df BootIt
757
- // 08 AIX 4f QNX4.x 3. Teil 93 Amoeba e1 DOS-Zugriff
758
- // 09 AIX bootfähig 50 OnTrack DM 94 Amoeba BBT e3 DOS R/O
759
- // 0a OS/2-Bootmanage 51 OnTrack DM6 Aux 9f BSD/OS e4 SpeedStor
760
- // 0b W95 FAT32 52 CP/M a0 IBM Thinkpad Ru ea Linux erweitert
761
- // 0c W95 FAT32 (LBA) 53 OnTrack DM6 Aux a5 FreeBSD eb BeOS Dateisyste
762
- // 0e W95 FAT16 (LBA) 54 OnTrackDM6 a6 OpenBSD ee GPT
763
- // 0f W95 Erw. (LBA) 55 EZ-Drive a7 NeXTSTEP ef EFI (FAT-12/16/
764
- // 10 OPUS 56 Golden Bow a8 Darwin UFS f0 Linux/PA-RISC B
765
- // 11 Verst. FAT12 5c Priam Edisk a9 NetBSD f1 SpeedStor
766
- // 12 Compaq Diagnost 61 SpeedStor ab Darwin Boot f4 SpeedStor
767
- // 14 Verst. FAT16 <3 63 GNU HURD oder S af HFS / HFS+ f2 DOS sekundär
768
- // 16 Verst. FAT16 64 Novell Netware b7 BSDi Dateisyste f8 EBBR geschützt
769
- // 17 Verst. HPFS/NTF 65 Novell Netware b8 BSDI Swap fb VMware VMFS
770
- // 18 AST SmartSleep 70 DiskSecure Mult bb Boot-Assistent fc VMware VMKCORE
771
- // 1b Verst. W95 FAT3 75 PC/IX bc Acronis FAT32 L fd Linux RAID-Auto
772
- // 1c Verst. W95 FAT3 80 Altes Minix be Solaris Boot fe LANstep
773
- // 1e Verst. W95 FAT1 81 Minix / altes L bf Solaris ff BBT
774
- // 24 NEC DOS
775
-
776
- _ ,
777
- };
778
-
779
- pub fn encodeMbrChsEntry (lba : u32 ) [3 ]u8 {
780
- var chs = lbaToChs (lba );
781
-
782
- if (chs .cylinder >= 1024 ) {
783
- chs = .{
784
- .cylinder = 1023 ,
785
- .head = 255 ,
786
- .sector = 63 ,
787
- };
788
- }
789
-
790
- const cyl : u10 = @intCast (chs .cylinder );
791
- const head : u8 = @intCast (chs .head );
792
- const sect : u6 = @intCast (chs .sector );
793
-
794
- const sect_cyl : u8 = @as (u8 , 0xC0 ) & @as (u8 , @truncate (cyl >> 2 )) + sect ;
795
- const sect_8 : u8 = @truncate (cyl );
796
-
797
- return .{ head , sect_cyl , sect_8 };
798
- }
799
-
800
- const CHS = struct {
801
- cylinder : u32 ,
802
- head : u8 , // limit: 256
803
- sector : u6 , // limit: 64
804
-
805
- pub fn init (c : u32 , h : u8 , s : u6 ) CHS {
806
- return .{ .cylinder = c , .head = h , .sector = s };
807
- }
808
- };
809
-
810
- pub fn lbaToChs (lba : u32 ) CHS {
811
- const hpc = 255 ;
812
- const spt = 63 ;
813
-
814
- // C, H and S are the cylinder number, the head number, and the sector number
815
- // LBA is the logical block address
816
- // HPC is the maximum number of heads per cylinder (reported by disk drive, typically 16 for 28-bit LBA)
817
- // SPT is the maximum number of sectors per track (reported by disk drive, typically 63 for 28-bit LBA)
818
- // LBA = (C * HPC + H) * SPT + (S - 1)
819
-
820
- const sector = (lba % spt );
821
- const cyl_head = (lba / spt );
822
-
823
- const head = (cyl_head % hpc );
824
- const cyl = (cyl_head / hpc );
825
-
826
- return CHS {
827
- .sector = @intCast (sector + 1 ),
828
- .head = @intCast (head ),
829
- .cylinder = cyl ,
830
- };
831
- }
832
- };
833
-
834
- // test "lba to chs" {
835
- // // table from https://en.wikipedia.org/wiki/Logical_block_addressing#CHS_conversion
836
- // try std.testing.expectEqual(mbr.CHS.init(0, 0, 1), mbr.lbaToChs(0));
837
- // try std.testing.expectEqual(mbr.CHS.init(0, 0, 2), mbr.lbaToChs(1));
838
- // try std.testing.expectEqual(mbr.CHS.init(0, 0, 3), mbr.lbaToChs(2));
839
- // try std.testing.expectEqual(mbr.CHS.init(0, 0, 63), mbr.lbaToChs(62));
840
- // try std.testing.expectEqual(mbr.CHS.init(0, 1, 1), mbr.lbaToChs(63));
841
- // try std.testing.expectEqual(mbr.CHS.init(0, 15, 1), mbr.lbaToChs(945));
842
- // try std.testing.expectEqual(mbr.CHS.init(0, 15, 63), mbr.lbaToChs(1007));
843
- // try std.testing.expectEqual(mbr.CHS.init(1, 0, 1), mbr.lbaToChs(1008));
844
- // try std.testing.expectEqual(mbr.CHS.init(1, 0, 63), mbr.lbaToChs(1070));
845
- // try std.testing.expectEqual(mbr.CHS.init(1, 1, 1), mbr.lbaToChs(1071));
846
- // try std.testing.expectEqual(mbr.CHS.init(1, 1, 63), mbr.lbaToChs(1133));
847
- // try std.testing.expectEqual(mbr.CHS.init(1, 2, 1), mbr.lbaToChs(1134));
848
- // try std.testing.expectEqual(mbr.CHS.init(1, 15, 63), mbr.lbaToChs(2015));
849
- // try std.testing.expectEqual(mbr.CHS.init(2, 0, 1), mbr.lbaToChs(2016));
850
- // try std.testing.expectEqual(mbr.CHS.init(15, 15, 63), mbr.lbaToChs(16127));
851
- // try std.testing.expectEqual(mbr.CHS.init(16, 0, 1), mbr.lbaToChs(16128));
852
- // try std.testing.expectEqual(mbr.CHS.init(31, 15, 63), mbr.lbaToChs(32255));
853
- // try std.testing.expectEqual(mbr.CHS.init(32, 0, 1), mbr.lbaToChs(32256));
854
- // try std.testing.expectEqual(mbr.CHS.init(16319, 15, 63), mbr.lbaToChs(16450559));
855
- // try std.testing.expectEqual(mbr.CHS.init(16382, 15, 63), mbr.lbaToChs(16514063));
856
- // }
857
-
858
- pub const gpt = struct {
859
- pub const Guid = [16 ]u8 ;
860
-
861
- pub const Table = struct {
862
- disk_id : Guid ,
863
-
864
- partitions : []const Partition ,
865
- };
866
-
867
- pub const Partition = struct {
868
- type : Guid ,
869
- part_id : Guid ,
870
-
871
- offset : ? u64 = null ,
872
- size : u64 ,
873
-
874
- name : [36 ]u16 ,
875
-
876
- attributes : Attributes ,
877
-
878
- data : Content ,
879
-
880
- pub const Attributes = packed struct (u32 ) {
881
- system : bool ,
882
- efi_hidden : bool ,
883
- legacy : bool ,
884
- read_only : bool ,
885
- hidden : bool ,
886
- no_automount : bool ,
887
-
888
- padding : u26 = 0 ,
889
- };
890
- };
891
-
892
- /// https://en.wikipedia.org/wiki/GUID_Partition_Table#Partition_type_GUIDs
893
- pub const PartitionType = struct {
894
- pub const unused : Guid = .{};
895
-
896
- pub const microsoft_basic_data : Guid = .{};
897
- pub const microsoft_reserved : Guid = .{};
898
-
899
- pub const windows_recovery : Guid = .{};
900
-
901
- pub const plan9 : Guid = .{};
902
-
903
- pub const linux_swap : Guid = .{};
904
- pub const linux_fs : Guid = .{};
905
- pub const linux_reserved : Guid = .{};
906
- pub const linux_lvm : Guid = .{};
907
- };
908
-
909
- pub fn nameLiteral (comptime name : []const u8 ) [36 ]u16 {
910
- return comptime blk : {
911
- var buf : [36 ]u16 = undefined ;
912
- const len = std .unicode .utf8ToUtf16Le (& buf , name ) catch | err | @compileError (@tagName (err ));
913
- @memset (buf [len .. ], 0 );
914
- break :blk & buf ;
915
- };
916
- }
917
- };
918
-
919
715
pub const FileSystem = struct {
920
716
pub const Format = union (enum ) {
921
717
pub const Tag = std .meta .Tag (@This ());
0 commit comments