ó ºµiVc@sQdZddlZddlZddlZddlZddlZddlZddlZddlm Z m Z m Z ddl m Z mZmZmZmZmZmZmZmZmZmZdZdZdad„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-00A0C93EC93BcCsItstjƒantdkr%dStdkr5dStdtƒ‚dS(s'Returns the current architecture stringti386tx86tsparcsUnsupported platform: N(t __curarchtplatformt processorR(((s!../../common/bootmgmt/bootutil.pytget_current_arch_string0s  cCsY|jddƒ}t|ƒdks4|ddkrGtd|ƒ‚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|ƒjƒdkrtStS(s<Returns True if the string is a representation of True. ttruetyest1(RR R!(tstrtlowertTruetFalse(t bool_string((s!../../common/bootmgmt/bootutil.pyt parse_boolJscCs¼d}|jdƒ}|dkr4td|ƒ‚n||d }|jddƒ}||d}|jdƒ}|dkrŽ||| }n6|jdƒ}|dkrº||| }n ||}|jddƒ} |d } |dkr.yt| ƒ}Wq.tk r*} td | | jfƒ‚q.Xn|rŒt| tƒ} | d kr¸| d krxtd || dfƒ‚n| d| }q¸n,t | t ƒ} | dkr¸| 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         cCsfd}y/t||ƒ}t||tƒ}t|ƒWn*tk ra|rXt|ƒ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   cCsvd}yEt||ƒ}t||tƒ}t|ƒ|jƒdkrJtSWn$tk rq|rrt|ƒqrnXtS(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  cCs]tjƒ\}}|dkr"gSg}x.|D]&}d|kr/|j|dƒq/q/W|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ÃeZdZejdƒZejjddƒdk Z e r¦ejdZ ej j e ƒrej dejdej je dejƒƒƒq¦ej dejƒneƒZeed„ƒZRS(sLogging helper functions tbootmgmttBOOTMGMT_DEBUGtleveltfilenamesbootmgmt.%d.logcCsÕ|js dSy&tjtjdƒddƒd}Wn4tk ri}tjj|j d|ƒd}nX||j k r¨y||}Wq®t k r¤|d}q®Xn|}tjj|j 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|jddƒ}|jddƒ}|jddƒ}|jddƒ}|jd||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}y4tjdtƒ}|j|ƒ|jƒ|jSWnetjƒd}t j d|ƒyt j |jƒWq¢tjƒd}t j 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   :   &