HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //lib/python3/dist-packages/landscape/lib/__pycache__/disk.cpython-310.pyc
o

�1Db��@snddlmZddlZddlZddlZddlmZegd��Ze�	d�Z
efdd�Zdd	�Zd
d�Z
dd
�ZdS)�)�divisionN)�_PY3)�ext�ext2�ext3�ext4�reiserfs�ntfs�msdos�dos�vfat�xfs�hpfs�jfs�ufs�hfs�hfsplus�simfsz([a-z]+)[0-9]*c	cs��t|�D]]}z|��dd�\}}}trt�|d�}nt�|d�}Wn	ty,Yqw|dur6||vr6qd}z||�}Wn	tyGYqw|j}	|j|	|}
|j	|	|}||||
|d�VqdS)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.
    N��unicode_escape�
string_escapei)�device�mount-point�
filesystemztotal-spacez
free-space)
�open�splitr�codecs�decode�
ValueError�OSError�f_bsize�f_blocks�f_bfree)�mounts_file�statvfs_�filesystems_whitelist�liner�mount_pointr�	megabytes�stats�
block_size�total_space�
free_space�r-�4/usr/lib/python3/dist-packages/landscape/lib/disk.py�get_mount_infos8����
��r/cCsfd}tj�|�}|�d�}t||�D]}|d�d�}|�|d�r0|r.|dt|��|kr0|}q|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)�os�path�realpathrr/�
startswith�len)r2r#r$�	candidate�
path_segments�info�mount_segmentsr-r-r.�get_filesystem_for_path<s
�r:cCs�tj�|��d�rdSt|�}|sdSd}zt|d��}|��}Wd�n1s*wYWn
ty:YdSw|��dkrCdSdS)z�
    This function returns whether a given device is removable or not by looking
    at the corresponding /sys/block/<device>/removable file

    @param device: The filesystem path to the device, e.g. /dev/sda1
    �mmcblkTFN�r�1)	r1r2�basenamer4�_get_device_removable_file_pathr�readline�IOError�strip)rr2�contents�fr-r-r.�is_device_removableXs"	
���rEcCs\tj�|�rt�|�}|�d�dd�\}t�|�}|sdS|��d}tj�d|d�}|S)a5
    Get a device's "removable" file path.

    This function figures out the C{/sys/block/<device>/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.
    r0���Nrz/sys/block/�	removable)	r1r2�islink�readlinkr�EXTRACT_DEVICE�match�groups�join)r�device_name�matched�removable_filer-r-r.r?us

r?)�
__future__rr1�rer�landscape.lib.compatr�	frozenset�STABLE_FILESYSTEMS�compilerJr/r:rEr?r-r-r-r.�<module>s�

�)