@@ -130,26 +130,17 @@ where
130
130
Ok ( ( ) )
131
131
}
132
132
133
- /// Updates kernel partition representations to match the GPT table
133
+ /// Removes all kernel partitions for the specified block device
134
134
///
135
135
/// # Arguments
136
136
/// * `path` - Path to the block device
137
137
///
138
138
/// # Returns
139
139
/// `Result<(), Error>` indicating success or partition operation failure
140
- pub fn sync_gpt_partitions < P : AsRef < Path > > ( path : P ) -> Result < ( ) , Error > {
141
- info ! ( "Initiating GPT partition synchronization for {:?}" , path. as_ref( ) ) ;
140
+ pub fn remove_kernel_partitions < P : AsRef < Path > > ( path : P ) -> Result < ( ) , Error > {
141
+ debug ! ( "Beginning partition cleanup process for {:?}" , path. as_ref( ) ) ;
142
142
let file = File :: open ( & path) ?;
143
143
144
- // Read GPT table
145
- debug ! ( "Reading GPT partition table" ) ;
146
- let gpt = gpt:: GptConfig :: new ( ) . writable ( false ) . open ( & path) ?;
147
- let partitions = gpt. partitions ( ) ;
148
- let block_size = 512 ;
149
- info ! ( "Located {} partitions (block size: {})" , partitions. len( ) , block_size) ;
150
-
151
- debug ! ( "Beginning partition cleanup process" ) ;
152
-
153
144
// Find the disk for enumeration purposes
154
145
let base_name = path
155
146
. as_ref ( )
@@ -164,6 +155,28 @@ pub fn sync_gpt_partitions<P: AsRef<Path>>(path: P) -> Result<(), Error> {
164
155
let _ = delete_partition ( file. as_raw_fd ( ) , partition. number as i32 ) ;
165
156
}
166
157
158
+ info ! ( "Successfully removed all kernel partitions" ) ;
159
+ Ok ( ( ) )
160
+ }
161
+
162
+ /// Creates kernel partitions based on the current GPT table
163
+ ///
164
+ /// # Arguments
165
+ /// * `path` - Path to the block device
166
+ ///
167
+ /// # Returns
168
+ /// `Result<(), Error>` indicating success or partition operation failure
169
+ pub fn create_kernel_partitions < P : AsRef < Path > > ( path : P ) -> Result < ( ) , Error > {
170
+ info ! ( "Creating kernel partitions from GPT for {:?}" , path. as_ref( ) ) ;
171
+ let file = File :: open ( & path) ?;
172
+
173
+ // Read GPT table
174
+ debug ! ( "Reading GPT partition table" ) ;
175
+ let gpt = gpt:: GptConfig :: new ( ) . writable ( false ) . open ( & path) ?;
176
+ let partitions = gpt. partitions ( ) ;
177
+ let block_size = 512 ;
178
+ info ! ( "Located {} partitions (block size: {})" , partitions. len( ) , block_size) ;
179
+
167
180
// Add partitions from GPT
168
181
debug ! ( "Beginning partition creation from GPT table" ) ;
169
182
for ( i, partition) in partitions. iter ( ) {
@@ -175,6 +188,23 @@ pub fn sync_gpt_partitions<P: AsRef<Path>>(path: P) -> Result<(), Error> {
175
188
) ?;
176
189
}
177
190
191
+ info ! ( "GPT partition creation completed successfully" ) ;
192
+ Ok ( ( ) )
193
+ }
194
+
195
+ /// Updates kernel partition representations to match the GPT table
196
+ ///
197
+ /// # Arguments
198
+ /// * `path` - Path to the block device
199
+ ///
200
+ /// # Returns
201
+ /// `Result<(), Error>` indicating success or partition operation failure
202
+ pub fn sync_gpt_partitions < P : AsRef < Path > > ( path : P ) -> Result < ( ) , Error > {
203
+ info ! ( "Initiating GPT partition synchronization for {:?}" , path. as_ref( ) ) ;
204
+
205
+ remove_kernel_partitions ( & path) ?;
206
+ create_kernel_partitions ( & path) ?;
207
+
178
208
info ! ( "GPT partition synchronization completed successfully" ) ;
179
209
Ok ( ( ) )
180
210
}
0 commit comments