Python | os.major () method

Python Methods and Functions

os.major() in Python is used to extract the major device number from the specified raw device number (usually the value of the st_dev attribute or st_rdev of the object & # 39; os.stat_result & # 39; returned by os.stat () ). ,

In Linux everything is file-based, some are regular files and some — special files. Special files can be found in the / dev directory. These special files are called device files. Character and block devices are the most common type of device file. These device files are represented by the Linux kernel as a pair of numbers (major device number and minor device number). 
The major device number indicates which driver is used to access the hardware. Each driver on the system has a unique major number, and all device files with the same major device number are controlled by the same driver. 
Whereas the sub device number is used by the driver to distinguish between the different hardware it controls. The minor device number tells the kernel the special characteristics of the device being accessed.

Syntax: os.major (device)

Parameter:
device : An integer value representing the raw device number

Return Type: This method returns an integer value which represents the device major number.

Code: using the os method .major () to extract the major device number from the raw device number.

# Python program to explain the os.major () method

 
# import of the os module

import os

  
# Receives ь raw device number
# file

device = os.stat ( "file.txt" ) .st_dev

 
# Print raw device number

print ( "Raw device number:" , device)

 
# Retrieve main number device
# from the above raw device number

major = os.major (device)

 
# Print main device number

print ( "Device major number:" , major)

Output:

 Raw device number: 2056 Device major number: 8 

Link: https://docs.python.org/3/library/os.html#os.major





Tutorials