1
1
//! A library that allows managing GUID partition tables.
2
2
//!
3
3
//! # Examples
4
+ //!
4
5
//! Reading all the partitions of a disk:
6
+ //!
5
7
//! ```
6
8
//! let mut f = std::fs::File::open("tests/fixtures/disk1.img")
7
9
//! .expect("could not open disk");
20
22
//! }
21
23
//! }
22
24
//! ```
25
+ //!
23
26
//! Creating new partitions:
27
+ //!
24
28
//! ```
25
29
//! let mut f = std::fs::File::open("tests/fixtures/disk1.img")
26
30
//! .expect("could not open disk");
44
48
//! partition_name: "A Robot Named Fight!".into(),
45
49
//! };
46
50
//! ```
51
+ //!
47
52
//! Creating a new partition table with one entry that fills the entire disk:
53
+ //!
48
54
//! ```
49
55
//! let ss = 512;
50
56
//! let data = vec![0; 100 * ss as usize];
@@ -183,7 +189,7 @@ pub struct GPTHeader {
183
189
pub disk_guid : [ u8 ; 16 ] ,
184
190
/// Location (in sectors) of the partition entries array.
185
191
///
186
- /// This is always `2` if the header is a primary header and not the backup header.
192
+ /// This is always `2` if the header is a primary header and not a backup header.
187
193
pub partition_entry_lba : u64 ,
188
194
/// Number of partition entries in the array.
189
195
pub number_of_partition_entries : u32 ,
@@ -443,6 +449,7 @@ impl Serialize for PartitionName {
443
449
/// A GPT partition's entry in the partition array.
444
450
///
445
451
/// # Examples
452
+ ///
446
453
/// Basic usage:
447
454
/// ```
448
455
/// let ss = 512;
@@ -481,6 +488,7 @@ pub struct GPTPartitionEntry {
481
488
/// The partition name.
482
489
///
483
490
/// # Examples
491
+ ///
484
492
/// Basic usage:
485
493
/// ```
486
494
/// let name: gptman::PartitionName = "A Robot Named Fight!".into();
@@ -494,6 +502,7 @@ impl GPTPartitionEntry {
494
502
/// Creates an empty partition entry
495
503
///
496
504
/// # Examples
505
+ ///
497
506
/// Basic usage:
498
507
/// ```
499
508
/// let ss = 512;
@@ -540,9 +549,11 @@ impl GPTPartitionEntry {
540
549
/// long at minimum.
541
550
///
542
551
/// # Errors
552
+ ///
543
553
/// This function will return an error if the `ending_lba` is lesser than the `starting_lba`.
544
554
///
545
- /// # Examples:
555
+ /// # Examples
556
+ ///
546
557
/// Basic usage:
547
558
/// ```
548
559
/// let ss = 512;
@@ -574,10 +585,11 @@ impl GPTPartitionEntry {
574
585
}
575
586
}
576
587
577
- /// A type representing a GUID partition table including its partition, the sector size of the disk
578
- /// and the alignment of the partitions to the sectors.
588
+ /// A type representing a GUID partition table including its partitions, the sector size of the
589
+ /// disk and the alignment of the partitions to the sectors.
590
+ ///
591
+ /// # Examples
579
592
///
580
- /// # Examples:
581
593
/// Read an existing GPT on a reader and list its partitions:
582
594
/// ```
583
595
/// let mut f = std::fs::File::open("tests/fixtures/disk1.img")
@@ -614,14 +626,16 @@ pub struct GPT {
614
626
/// so they return only values aligned to the alignment.
615
627
///
616
628
/// # Panics
629
+ ///
617
630
/// The value must be greater than 0, otherwise you will encounter divisions by zero.
618
631
pub align : u64 ,
619
632
}
620
633
621
634
impl GPT {
622
635
/// Make a new GPT based on a reader. (This operation does not write anything to disk!)
623
636
///
624
- /// # Examples:
637
+ /// # Examples
638
+ ///
625
639
/// Basic usage:
626
640
/// ```
627
641
/// let ss = 512;
@@ -715,7 +729,8 @@ impl GPT {
715
729
/// size of 512 but if it fails it will automatically try to read the GPT using a sector size
716
730
/// of 4096.
717
731
///
718
- /// # Examples:
732
+ /// # Examples
733
+ ///
719
734
/// Basic usage:
720
735
/// ```
721
736
/// let mut f_512 = std::fs::File::open("tests/fixtures/disk1.img")
@@ -881,7 +896,8 @@ impl GPT {
881
896
/// spot; and on the right: the size (in sectors) of the free spot.
882
897
/// This function will automatically align with the alignment defined in the `GPT`.
883
898
///
884
- /// # Examples:
899
+ /// # Examples
900
+ ///
885
901
/// Basic usage:
886
902
/// ```
887
903
/// let ss = 512;
@@ -933,7 +949,8 @@ impl GPT {
933
949
/// given in parameter.
934
950
/// This function will automatically align with the alignment defined in the `GPT`.
935
951
///
936
- /// # Examples:
952
+ /// # Examples
953
+ ///
937
954
/// Basic usage:
938
955
/// ```
939
956
/// let ss = 512;
@@ -968,7 +985,8 @@ impl GPT {
968
985
/// given in parameter.
969
986
/// This function will automatically align with the alignment defined in the `GPT`.
970
987
///
971
- /// # Examples:
988
+ /// # Examples
989
+ ///
972
990
/// Basic usage:
973
991
/// ```
974
992
/// let ss = 512;
@@ -1004,7 +1022,8 @@ impl GPT {
1004
1022
/// partition of the size given in parameter.
1005
1023
/// This function will automatically align with the alignment defined in the `GPT`.
1006
1024
///
1007
- /// # Examples:
1025
+ /// # Examples
1026
+ ///
1008
1027
/// Basic usage:
1009
1028
/// ```
1010
1029
/// let ss = 512;
@@ -1043,7 +1062,8 @@ impl GPT {
1043
1062
/// Get the maximum size (in sectors) of a partition you could create in the GPT.
1044
1063
/// This function will automatically align with the alignment defined in the `GPT`.
1045
1064
///
1046
- /// # Examples:
1065
+ /// # Examples
1066
+ ///
1047
1067
/// Basic usage:
1048
1068
/// ```
1049
1069
/// let ss = 512;
@@ -1086,7 +1106,8 @@ impl GPT {
1086
1106
/// `gpt[i] = gptman::GPTPartitionEntry::empty();`
1087
1107
///
1088
1108
/// # Errors
1089
- /// This function will return an error if index is lesser or equal to 0 or greater than the
1109
+ ///
1110
+ /// This function will return an error if `i` is lesser or equal to `0` or greater than the
1090
1111
/// number of partition entries (which can be obtained in the header).
1091
1112
pub fn remove ( & mut self , i : u32 ) -> Result < ( ) > {
1092
1113
if i == 0 || i > self . header . number_of_partition_entries {
@@ -1101,6 +1122,7 @@ impl GPT {
1101
1122
/// Remove a partiton entry in the array that resides at a given sector.
1102
1123
///
1103
1124
/// # Errors
1125
+ ///
1104
1126
/// It is an error to provide a sector which does not belong to a partition.
1105
1127
pub fn remove_at_sector ( & mut self , sector : u64 ) -> Result < ( ) > {
1106
1128
self . remove (
0 commit comments