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-312.pyc
�

�1Db����ddlmZddlZddlZddlZddlmZegd��Zejd�Z
efd�Zd�Zd�Z
d	�Zy)
�)�divisionN)�_PY3)�ext�ext2�ext3�ext4�reiserfs�ntfs�msdos�dos�vfat�xfs�hpfs�jfs�ufs�hfs�hfsplus�simfsz([a-z]+)[0-9]*c#�K�t|�D]�}	|j�dd\}}}trtj|d�}ntj|d�}|�||vr�Ud}	||�}|j}	|j|	z|z}
|j|	z|z}||||
|d�����y#t
$rY��wxYw#t$rY��wxYw�w)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_spaces            �4/usr/lib/python3/dist-packages/landscape/lib/disk.py�get_mount_infor0s������[�!��	�.2�j�j�l�2�A�.>�+�F�K���$�m�m�K�9I�J��$�m�m�K��I��
"�-��3�3���	�	��[�)�E��]�]�
��~�~�
�2�y�@���m�m�j�0�Y�>�
���'��'�)�	)�+"���	��	���	��	�sM�C	�A
B+�	C	�&B:�.=C	�+	B7�4C	�6B7�7C	�:	C�C	�C�C	c�
�d}tjj|�}|jd�}t	||�D]A}|djd�}|j|d�s�,|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)�os�path�realpathrr0�
startswith�len)r4r%r&�	candidate�
path_segments�info�mount_segmentss       r/�get_filesystem_for_pathr<<s����I�
�7�7���D�!�D��J�J�s�O�M��{�H�5���m�,�2�2�3�7���?�?�4�
�.�/���2�s�>�2�3�~�E� �	�
6���c�,�tjj|�jd�ryt	|�}|syd}	t|d�5}|j
�}ddd�|j�dk(ryy#1swY�xYw#t$rYywxYw)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)	r3r4�basenamer6�_get_device_removable_file_pathr�readline�IOError�strip)rr4�contents�fs    r/�is_device_removablerIXs���
�w�w�����*�*�8�4��*�6�2�D����H��
�$��_���z�z�|�H��
�~�~��3�����_������s*�B�
A;�B�;B�B�	B�Bc�2�tjj|�rtj|�}|j	d�dd\}t
j
|�}|sy|j�d}tjjd|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.
    r2���Nrz/sys/block/�	removable)	r3r4�islink�readlinkr�EXTRACT_DEVICE�match�groups�join)r�device_name�matched�removable_files    r/rCrCus~��
�w�w�~�~�f�����V�$���L�L��%�b�c�*�M�[��"�"�;�/�G����.�.�"�1�%�K��W�W�\�\�-��k�J�N��r=)�
__future__rr3�rer�landscape.lib.compatr�	frozenset�STABLE_FILESYSTEMS�compilerOr0r<rIrC�r=r/�<module>r]sS���	�	�
�%��=�>��
����,�-��*<�&)�R�8�:r=