@@ -318,6 +318,11 @@ def parse_genimage_config(config_path):
318318 if piname == simg .get ("image" ):
319319 partitions [pname ]["simage" ] = sname
320320
321+ # Remove filesystem attributes from all partitions
322+ for part in partitions .values ():
323+ fs_key = str (part .get ("type" , "" )).lower ()
324+ part .pop (fs_key , None )
325+
321326 # Read the partition table from the image
322327 img_path = get_artefact_path (img_name , "IGconf_image_outputdir" )
323328 try :
@@ -330,10 +335,7 @@ def parse_genimage_config(config_path):
330335 except Exception as e :
331336 raise RuntimeError (f"{ e } Failed to read partition table from { img_path } " )
332337
333- # Nodes are don't care
334338 ptable = json .loads (res .stdout )
335- for p in ptable ["partitiontable" ]["partitions" ]:
336- p .pop ("node" , None )
337339
338340 # Populate genimage partition entries with GPT attributes
339341 def insert_gptattr (genimage_partitions , table_json ):
@@ -365,89 +367,16 @@ def parse_genimage_config(config_path):
365367
366368 return genimage_partitions
367369
370+ # Assign GPT attributes from the partition table probe to each genimage partition
368371 partitions = insert_gptattr (partitions , ptable )
369372
370- return (disk_attr , partitions , ptable )
371-
372-
373- # Read all fstabs and store in a dict using UUID or label if we can,
374- # or a unique key if we can't.
375- def parse_fstab (fstab_paths ):
376- fstab_data = {}
377- fcount = 1
378- for fstab_path in fstab_paths :
379- try :
380- with open (fstab_path , "r" ) as f :
381- lcount = 1
382- for line in f :
383- line = line .strip ()
384- if line .startswith ("#" ) or line == "" :
385- continue # skip comments or empty
386-
387- parts = line .split ()
388- if len (parts ) == 4 :
389- device , mountpoint , fstype , options = parts [:4 ]
390- freq = "0"
391- passn = "0"
392- elif len (parts ) == 5 :
393- device , mountpoint , fstype , options , freq = parts [:5 ]
394- passn = "0"
395- elif len (parts ) == 6 :
396- device , mountpoint , fstype , options , freq , passn = parts [:6 ]
397- else :
398- continue # skip unusable
399-
400- mount_options = options .split ("," )
401-
402- # Supported fs_spec:
403- if device .startswith (("UUID=" , "LABEL=" , "PARTUUID=" , "PARTLABEL=" )):
404- deviceid = device .split ("=" , 1 )[1 ]
405- elif device .startswith (("/dev/disk/by-label/" , "/dev/disk/by-uuid/" )):
406- deviceid = device .rsplit ("/" , 1 )[- 1 ]
407- else :
408- deviceid = f"fstab{ fcount } _{ lcount } "
409-
410- # This will overwrite previous settings if the device exists in multiple fstabs
411- # under the same uuid/label.
412- fstab_data [deviceid ] = {"fs_spec" : device ,
413- "fs_file" : mountpoint ,
414- "fs_vfstype" : fstype ,
415- "fs_mntops" : mount_options ,
416- "fs_freq" : freq ,
417- "fs_passno" : passn }
418- lcount += 1
419-
420- except FileNotFoundError :
421- sys .exit ('invalid fstab: %s' % fstab_path )
422-
423- fcount += 1
424-
425- return fstab_data
426-
427-
428- # Try to match a genimage partition with an fstab device entry to establish mount options.
429- # Try static uuid and label first, falling back to genimage mountpoint.
430- # This lookup can only give guaranteed matching results if there is no duplication of
431- # uuid, label or mountpoint in each fstab file provided.
432- # If a match is found, the fstab section of the partition is populated.
433- def merge_configs (genimage_partitions , fstab_data ):
434- for pname , pdata in genimage_partitions .items ():
435- label = pdata .get ("fs_label" )
436- uuid = pdata .get ("fs_uuid" )
437-
438- if uuid and uuid in fstab_data :
439- pdata ["fstab" ] = fstab_data [uuid ]
440- elif label and label in fstab_data :
441- pdata ["fstab" ] = fstab_data [label ]
442- else :
443- pmnt = pdata .get ("mountpoint" )
444- if pmnt :
445- for name , contents in fstab_data .items ():
446- if pmnt == contents .get ("fs_file" ):
447- pdata ["fstab" ] = fstab_data [name ]
448-
449- return genimage_partitions
373+ # Prune non-essential partition table info
374+ pt = ptable .get ("partitiontable" )
375+ if isinstance (pt , dict ):
376+ for key in ("partitions" , "device" , "unit" , "firstlba" , "lastlba" , "sectorsize" ):
377+ pt .pop (key , None )
450378
379+ return (disk_attr , partitions , ptable )
451380
452381
453382def get_env_vars (prefix = None ):
@@ -480,11 +409,6 @@ if __name__ == '__main__':
480409 help = "Path to genimage config file" ,
481410 required = True )
482411
483- parser .add_argument ("-f" , "--fstab" ,
484- help = "Paths to one or more fstab files" ,
485- nargs = "*" ,
486- required = False )
487-
488412 parser .add_argument ("-m" , "--provisionmap" ,
489413 help = "Path to the JSON provisioning map" ,
490414 type = argparse .FileType ('r' ),
@@ -495,14 +419,7 @@ if __name__ == '__main__':
495419
496420 # Base info
497421 attributes , genimage_partitions , ptable = parse_genimage_config (genimage_file )
498-
499- # fstab is optional
500- if args .fstab :
501- fstab_files = args .fstab
502- fstab_data = parse_fstab (fstab_files )
503- partition_json = merge_configs (genimage_partitions , fstab_data )
504- else :
505- partition_json = genimage_partitions
422+ partition_json = genimage_partitions
506423
507424 top_template ["IGmeta" ] = get_image_meta ()
508425 top_template ["attributes" ]["image-name" ] = os .path .basename (attributes .get ("image-name" ))
0 commit comments