@@ -255,6 +255,7 @@ void generate_ext4_image(struct image_data *image)
255
255
#else
256
256
fd = fileno (tmpfile ());
257
257
#endif
258
+ /* reset ext4fs info so we can be called multiple times */
258
259
reset_ext4fs_info ();
259
260
info .len = image -> partition_size ;
260
261
make_ext4fs_internal (fd , NULL , NULL , NULL , 0 , 1 , 0 , 0 , 0 , NULL );
@@ -266,7 +267,7 @@ void generate_ext4_image(struct image_data *image)
266
267
close (fd );
267
268
}
268
269
269
- int fb_format (Action * a , usb_handle * usb )
270
+ int fb_format (Action * a , usb_handle * usb , int skip_if_not_supported )
270
271
{
271
272
const char * partition = a -> cmd ;
272
273
char response [FB_RESPONSE_SZ + 1 ];
@@ -281,6 +282,13 @@ int fb_format(Action *a, usb_handle *usb)
281
282
snprintf (cmd , sizeof (cmd ), "getvar:partition-type:%s" , partition );
282
283
status = fb_command_response (usb , cmd , response );
283
284
if (status ) {
285
+ if (skip_if_not_supported ) {
286
+ fprintf (stderr ,
287
+ "Erase successful, but not automatically formatting.\n" );
288
+ fprintf (stderr ,
289
+ "Can't determine partition type.\n" );
290
+ return 0 ;
291
+ }
284
292
fprintf (stderr ,"FAILED (%s)\n" , fb_get_error ());
285
293
return status ;
286
294
}
@@ -292,6 +300,13 @@ int fb_format(Action *a, usb_handle *usb)
292
300
}
293
301
}
294
302
if (!generator ) {
303
+ if (skip_if_not_supported ) {
304
+ fprintf (stderr ,
305
+ "Erase successful, but not automatically formatting.\n" );
306
+ fprintf (stderr ,
307
+ "File system type %s not supported.\n" , response );
308
+ return 0 ;
309
+ }
295
310
fprintf (stderr ,"Formatting is not supported for filesystem with type '%s'.\n" ,
296
311
response );
297
312
return -1 ;
@@ -301,6 +316,12 @@ int fb_format(Action *a, usb_handle *usb)
301
316
snprintf (cmd , sizeof (cmd ), "getvar:partition-size:%s" , partition );
302
317
status = fb_command_response (usb , cmd , response );
303
318
if (status ) {
319
+ if (skip_if_not_supported ) {
320
+ fprintf (stderr ,
321
+ "Erase successful, but not automatically formatting.\n" );
322
+ fprintf (stderr , "Unable to get partition size\n." );
323
+ return 0 ;
324
+ }
304
325
fprintf (stderr ,"FAILED (%s)\n" , fb_get_error ());
305
326
return status ;
306
327
}
@@ -329,11 +350,12 @@ int fb_format(Action *a, usb_handle *usb)
329
350
return status ;
330
351
}
331
352
332
- void fb_queue_format (const char * partition )
353
+ void fb_queue_format (const char * partition , int skip_if_not_supported )
333
354
{
334
355
Action * a ;
335
356
336
357
a = queue_action (OP_FORMAT , partition );
358
+ a -> data = (void * )skip_if_not_supported ;
337
359
a -> msg = mkmsg ("formatting '%s' partition" , partition );
338
360
}
339
361
@@ -545,7 +567,7 @@ int fb_execute_queue(usb_handle *usb)
545
567
} else if (a -> op == OP_NOTICE ) {
546
568
fprintf (stderr ,"%s\n" ,(char * )a -> data );
547
569
} else if (a -> op == OP_FORMAT ) {
548
- status = fb_format (a , usb );
570
+ status = fb_format (a , usb , ( int ) a -> data );
549
571
status = a -> func (a , status , status ? fb_get_error () : "" );
550
572
if (status ) break ;
551
573
} else {
0 commit comments