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: //usr/lib/python3/dist-packages/landscape/lib/__pycache__/disk.cpython-38.pyc
U

�1Db��@s�ddlmZddlZddlZddlZddlmZedddddd	d
ddd
ddddddg�Ze�	d�Z
efdd�Zdd�Zdd�Z
dd�ZdS)�)�divisionN)�_PY3�extZext2Zext3Zext4ZreiserfsZntfsZmsdos�dosZvfatZxfsZhpfsZjfsZufsZhfsZhfsplusZsimfsz([a-z]+)[0-9]*c	cs�t|�D]�}z8|��dd�\}}}tr6t�|d�}nt�|d�}Wntk
r\YqYnX|dk	rp||krpqd}z||�}Wntk
r�YqYnX|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�Zunicode_escapeZ
string_escapei)�device�mount-point�
filesystemztotal-spacez
free-space)
�open�splitr�codecs�decode�
ValueError�OSError�f_bsize�f_blocks�f_bfree)�mounts_file�statvfs_Zfilesystems_whitelist�linerZmount_pointr	�	megabytes�stats�
block_sizeZtotal_spaceZ
free_space�r�4/usr/lib/python3/dist-packages/landscape/lib/disk.py�get_mount_infos2
�
�rcCsfd}tj�|�}|�d�}t||�D]<}|d�d�}|�|d�r$|r\|dt|��|kr$|}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)rrr�	candidateZ
path_segments�infoZmount_segmentsrrr�get_filesystem_for_path<s
�r$c	Csxtj�|��d�rdSt|�}|s&dSd}z"t|d��}|��}W5QRXWntk
rbYdSX|��dkrtdSdS)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
    ZmmcblkTFN�r�1)	rr�basenamer �_get_device_removable_file_pathr
�readline�IOError�strip)rr�contents�frrr�is_device_removableXs	r.cCs\tj�|�rt�|�}|�d�dd�\}t�|�}|s<dS|��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.
    r���Nrz/sys/block/Z	removable)	rr�islink�readlinkr�EXTRACT_DEVICE�match�groups�join)rZdevice_nameZmatchedZremovable_filerrrr(us

r()�
__future__rr�rerZlandscape.lib.compatr�	frozensetZSTABLE_FILESYSTEMS�compiler2rr$r.r(rrrr�<module>s*��
�
)