@@ -25,6 +25,7 @@ pub fn parse(ctx: dim.Context) !dim.Content {
25
25
};
26
26
27
27
var next_part_id : usize = 0 ;
28
+ var last_part_id : ? usize = null ;
28
29
while (next_part_id < pf .partitions .len ) {
29
30
const kw = try ctx .parse_enum (enum {
30
31
bootloader ,
@@ -45,11 +46,20 @@ pub fn parse(ctx: dim.Context) !dim.Content {
45
46
},
46
47
.part = > {
47
48
pf .partitions [next_part_id ] = try parse_partition (ctx );
49
+ last_part_id = next_part_id ;
48
50
next_part_id += 1 ;
49
51
},
50
52
}
51
53
}
52
54
55
+ if (last_part_id ) | part_id | {
56
+ for (0.. part_id - | 1 ) | prev | {
57
+ if (pf .partitions [prev ].? .size == null ) {
58
+ try ctx .report_nonfatal_error ("MBR partition {} does not have a size, but is not last." , .{prev });
59
+ }
60
+ }
61
+ }
62
+
53
63
return .create_handle (pf , .create (PartTable , .{
54
64
.guess_size_fn = guess_size ,
55
65
.render_fn = render ,
@@ -62,7 +72,7 @@ fn parse_partition(ctx: dim.Context) !Partition {
62
72
.size = null ,
63
73
.bootable = false ,
64
74
.type = .empty ,
65
- .data = .empty ,
75
+ .contains = .empty ,
66
76
};
67
77
68
78
var updater : dim .FieldUpdater (Partition , &.{
@@ -77,15 +87,15 @@ fn parse_partition(ctx: dim.Context) !Partition {
77
87
bootable ,
78
88
size ,
79
89
offset ,
80
- contents ,
90
+ contains ,
81
91
endpart ,
82
92
});
83
93
try switch (kw ) {
84
94
.type = > updater .set (.type , try ctx .parse_enum (PartitionType )),
85
95
.bootable = > updater .set (.bootable , true ),
86
96
.size = > updater .set (.size , try ctx .parse_mem_size ()),
87
97
.offset = > updater .set (.offset , try ctx .parse_mem_size ()),
88
- .contents = > updater .set (.data , try ctx .parse_content ()),
98
+ .contains = > updater .set (.contains , try ctx .parse_content ()),
89
99
.endpart = > break :parse_loop ,
90
100
};
91
101
}
@@ -96,7 +106,31 @@ fn parse_partition(ctx: dim.Context) !Partition {
96
106
}
97
107
98
108
fn guess_size (self : * PartTable ) dim.Content.GuessError ! dim.SizeGuess {
99
- _ = self ;
109
+ var upper_bound : u64 = 512 ;
110
+ var all_parts_bounded = true ;
111
+
112
+ for (self .partitions ) | mpart | {
113
+ const part = mpart orelse continue ;
114
+
115
+ if (part .offset != null and part .size != null ) {
116
+ upper_bound = @max (upper_bound , part .offset .? + part .size .? );
117
+ } else {
118
+ all_parts_bounded = false ;
119
+ }
120
+ }
121
+ if (all_parts_bounded )
122
+ return .{ .exact = upper_bound };
123
+
124
+ for (self .partitions ) | mpart | {
125
+ const part = mpart orelse continue ;
126
+
127
+ if (part .offset != null and part .size != null ) {
128
+ upper_bound = @max (upper_bound , part .offset .? + part .size .? );
129
+ } else {
130
+ all_parts_bounded = false ;
131
+ }
132
+ }
133
+
100
134
@panic ("not implemented yet!" );
101
135
}
102
136
@@ -211,7 +245,7 @@ pub const Partition = struct {
211
245
.size = 0 ,
212
246
.bootable = false ,
213
247
.type = .empty ,
214
- .data = undefined ,
248
+ .contains = .empty ,
215
249
};
216
250
217
251
offset : ? u64 = null ,
@@ -220,7 +254,7 @@ pub const Partition = struct {
220
254
bootable : bool ,
221
255
type : PartitionType ,
222
256
223
- data : dim.Content ,
257
+ contains : dim.Content ,
224
258
};
225
259
226
260
/// https://en.wikipedia.org/wiki/Partition_type
0 commit comments