Ńņ ŗµiVc @sQdZddkZddkZddkZddkZddkZddkZddkZddkl Z l Z l Z ddk l Z lZlZlZlZlZlZlZlZlZlZdZdZdad„Zd„Zd „Zd „Zdd „Z d „Z!d „Z"d„Z#de$fd„ƒYZ%e%ƒd„Z&d„Z'dS(s/ Various support code for the bootmgmt package i’’’’N(tBootmgmtNotSupportedErrortBootmgmtArgumentErrort BootmgmtError( t is_gpt_disktfind_gpt_partitiontlibfdisk_find_part_by_idt zpool_opent zpool_closetzpool_get_proptZPOOL_PROP_BOOTFStzfs_opent zfs_closetzfs_get_prop_stringtZFS_PROP_ENCRYPTIONiļs$C12A7328-F81F-11D2-BA4B-00A0C93EC93BcCsOtptiƒantdjodStdjodStdtƒ‚dS(s'Returns the current architecture stringti386tx86tsparcsUnsupported platform: N(t __curarchtplatformt processorR(((s!../../common/bootmgmt/bootutil.pytget_current_arch_string0s  cCs\|iddƒ}t|ƒdjp|ddjotd|ƒ‚n|d|dfS(s=Splits the bootfs passed in into rpool and bootfs values t/iiitROOTsInvalid bootfs: %si(tsplittlenR(tbootfst bootfs_spec((s!../../common/bootmgmt/bootutil.pyt bootfs_split<s$cCsd||fS(s;Construct a bootfs string from a root pool and BE name s %s/ROOT/%s((trpooltbename((s!../../common/bootmgmt/bootutil.pyt bootfs_buildEscCs"t|ƒiƒdjotStS(s<Returns True if the string is a representation of True. ttruetyest1(RR R!(tstrtlowertTruetFalse(t bool_string((s!../../common/bootmgmt/bootutil.pyt parse_boolJsc CsĪd}|idƒ}|djotd|ƒ‚n||d }|iddƒ}||d}|idƒ}|djo||| }n9|idƒ}|djo||| }n ||}|iddƒ} |d } |djoEyt| ƒ}Wq8tj o"} td | | ifƒ‚q8Xn|o]t| tƒ} | d jo=| d jotd || dfƒ‚n| d| }qŹn/t | t ƒ} | djo| d| }n|S(s›Given a path to a wholedisk node /dev/[r]dsk/cXtYdZ, find the path to the EFI system partition and return it. This only works on x86 systems. Ri’’’’sInvalid device path: %sis/dsk/s/rdsk/tstptp0sError while accessing "%s": %siis«The EFI System Partition (ESP) for device %s is not accessible in Solaris because it is located in partition number %d (Solaris can only access the first 9 GPT partitions)ss%dsp%dN( tNonetrfindRtreplaceRtOSErrortstrerrorRt EFISYS_GUIDRt EFISYS_PARTID(tdevnametis_gpttesp_devt lastslasht firstparttlastparttlast_esst base_devnametlast_peetbase_devname_blockt wholedisktoserrt esp_indextpart_no((s!../../common/bootmgmt/bootutil.pytfind_efi_system_partitionQsB         cCsjd}y/t||ƒ}t||tƒ}t|ƒWn.tj o"|ot|ƒnd}nX|S(s?Returns the default bootfs property for the specified pool N(R+RRR RtIOError(tlzfshRtzphtpool_default_bootfs((s!../../common/bootmgmt/bootutil.pytget_zpool_default_bootfs‹s cCs|d}yGt||ƒ}t||tƒ}t|ƒ|iƒdjotSWn(tj o|ot|ƒqxnXtS(sBReturns True if the specified dataset has encryption enabled. tonN( R+R R R R R#R$RAR%(RBt dataset_nametzfshtonoff((s!../../common/bootmgmt/bootutil.pytis_zfs_encrypted_datasetšs  cCsatiƒ\}}|djogSg}x0|D](}d|jo|i|dƒq1q1W|S(sJReturns a list of bootfs strings that identify the BEs on the system. itroot_ds(tlibbe_pytbeListtappend(trettbe_listtbootfsestbootenv((s!../../common/bootmgmt/bootutil.pytget_bootfs_list_from_libbe¬s  t LoggerMixincBsĒeZdZeidƒZeiiddƒdj Z e omeidZ ei i e ƒo6ei deidei ie deiƒƒƒqŖei deiƒneƒZeed„ƒZRS(sLogging helper functions tbootmgmttBOOTMGMT_DEBUGtleveltfilenamesbootmgmt.%d.logc CsŻ|ipdSy&titidƒddƒd}Wn6tj o*}tii|i d|ƒd}nX||i j o2y||}Wq¶t j o|d}q¶Xn|}tii|i d |d |ƒdS( s%Main debugging helper method Nitcontextiis: PROBLEM INSPECTING STACK: %st?s! [[Couldn't unpack format tuple]]t.s: ( t debug_enabledtinspectt getframeinfotsyst _getframet ExceptionRTtloggertdebugt__name__t SPECIAL_OBJt ValueError(tclstlog_msgt format_tupletfunctexctlog_str((s!../../common/bootmgmt/bootutil.pyt_debugÉs &  N(Rdt __module__t__doc__tloggingt getLoggerRbtostenvirontgetR+R\tpathtisdirt basicConfigtDEBUGtjointgetpidtobjectRet classmethodRm(((s!../../common/bootmgmt/bootutil.pyRT¹s  cCsb|iddƒ}|iddƒ}|iddƒ}|iddƒ}|id||fƒ|S(sEScrubs the $ZFS-BOOTFS kernel argument, while preserving others. s ,$ZFS-BOOTFS,t,s ,$ZFS-BOOTFSts $ZFS-BOOTFS,s-B $ZFS-BOOTFSsScrubbed kargs "%s" => "%s"(R-Rm(tkargstdbobjt new_kargs((s!../../common/bootmgmt/bootutil.pyt scrub_kargsßs cCs¦d}y4tidtƒ}|i|ƒ|iƒ|iSWnetiƒd}t i d|ƒyt i |iƒWq¢tiƒd}t i d|ƒq¢XnXdS(s$Write data to a temporary file. tdeleteiswrite_temp_file failed: %sN( R+ttempfiletNamedTemporaryFileR%twritetclosetnameR_texc_infoRTRmRrtunlink(tdatattempfte((s!../../common/bootmgmt/bootutil.pytwrite_temp_fileõs   ((RoR]RLRpRrR_RR„RURRRtbootmgmt.pysolRRRRRRR R R R R R1R0R+RRRRR'R@RERJRSR{RTR‚RŽ(((s!../../common/bootmgmt/bootutil.pyts.       L   :   &