~e`|ddlZddlZddlZddlmZegdZejdZefdZ dZ dZ dZ y) N)_PY3)extext2ext3ext4reiserfsntfsmsdosdosvfatxfshpfsjfsufshfshfsplussimfsdrvfslxfszfsbtrfsz([a-z]+)[0-9]*c#Kt|D]} |jdd\}}}trtj|d}ntj|d}|||vrUd} ||}|j} |j| z|z} |j| z|z} |||| | dy#t $rYwxYw#t $rYwxYww)aZ This is a generator that yields information about mounted filesystems. @param mounts_file: A file with information about mounted filesystems, such as C{/proc/mounts}. @param statvfs_: A function to get file status information. @param filesystems_whitelist: Optionally, a list of which filesystems to stat. @return: A C{dict} with C{device}, C{mount-point}, C{filesystem}, C{total-space} and C{free-space} keys. If the filesystem information is not available, C{None} is returned. Both C{total-space} and C{free-space} are in megabytes. Nunicode_escape string_escapei)device mount-point filesystemz total-spacez free-space) opensplitrcodecsdecode ValueErrorOSErrorf_bsizef_blocksf_bfree) mounts_filestatvfs_filesystems_whitelistliner mount_pointr megabytesstats block_size total_space free_spaces 4/usr/lib/python3/dist-packages/landscape/lib/disk.pyget_mount_infor3&s$[!  .2jjl2A.> +FK$mmK9IJ $mmKI  " -"77   [)E]] ~~ 2y@ mmj0Y> &$&$   -       sMC A B+ C &B:.=C + B74C 6B77C : CC CC c d}tjj|}|jd}t ||D]A}|djd}|j |ds,|r|dt ||k(s@|}C|S)a Tries to determine to which of the mounted filesystem C{path} belongs to, and then returns information about that filesystem or C{None} if it couldn't be determined. @param path: The path we want filesystem information about. @param mounts_file: A file with information about mounted filesystems, such as C{/proc/mounts}. @param statvfs_: A function to get file status information. @return: A C{dict} with C{device}, C{mount-point}, C{filesystem}, C{total-space} and C{free-space} keys. If the filesystem information is not available, C{None} is returned. Both C{total-space} and C{free-space} are in megabytes. N/r)ospathrealpathr r3 startswithlen)r7r(r) candidate path_segmentsinfomount_segmentss r2get_filesystem_for_pathr?WsI 77  D !DJJsOM{H5!m,2237 ??4 . /-%#n%## ! ! c,tjj|jdryt |}|syd} t |d5}|j }ddd|jdk(ryy#1swYxYw#t$rYywxYw)z This function returns whether a given device is removable or not by looking at the corresponding /sys/block//removable file @param device: The filesystem path to the device, e.g. /dev/sda1 mmcblkTFNr1) r6r7basenamer9_get_device_removable_file_pathrreadliner$strip)rr7contentsfs r2is_device_removablerKss ww**84 *6 2D H $_ $zz|H $ ~~3  $ $ s* B A;B;BB BBc2tjj|rtj|}|j ddd\}t j |}|sy|jd}tjjd|d}|S)a5 Get a device's "removable" file path. This function figures out the C{/sys/block//removable} path associated with the given device. The file at that path contains either a "0" if the device is not removable, or a "1" if it is. @param device: File system path of the device. r5Nrz /sys/block/ removable) r6r7islinkreadlinkr EXTRACT_DEVICEmatchgroupsjoin)r device_namematchedremovable_files r2rFrFs~ ww~~fV$LL%bc*M["";/G .."1%KWW\\-kJN r@) r!r6relandscape.lib.compatr frozensetSTABLE_FILESYSTEMScompilerQr3r?rKrFr@r2r^sP %4,- -. b8:r@