Python Glossary Русский

all Python 3Linux · macOSosfunction

os.major

os — device numbers

Extract the major device number from a raw device id.

Syntax

os.major(...)

A device number from st_dev or st_rdev has two parts: the major number identifies the driver, the minor a specific device of that driver. On Linux, for instance, major 8 is SCSI and SATA disks. The bit layout is system-specific, so never decode the number by hand — only with this function.

Examples

import os
st = os.stat('/dev/null')
print(os.major(st.st_rdev))  # → ? только Unix: старший номер устройства /dev/null, в Linux 1
print(f'{os.major(st.st_rdev)}:{os.minor(st.st_rdev)}')  # → ? только Unix: пара номеров, как в колонке ls -l /dev/null, в Linux 1:3
print(os.major(os.makedev(8, 1)))  # → 8 — major достаёт обратно то, что упаковала makedev
print(os.major(os.stat('/tmp').st_rdev))  # → 0 — у обычного файла или каталога st_rdev нулевой: это не устройство

See also

Open in the full glossarydocs.python.orgReport an inaccuracy