Open In App

Python | os.makedev() method

Last Updated : 25 Jun, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

OS module in Python provides functions for interacting with the operating system. OS comes under Python’s standard utility modules. This module provides a portable way of using operating system dependent functionality.

os.makedev() method in Python is used to compose a raw device number from the given >major and minor device numbers.

In Unix, everything is file, some are ordinary files while some are special files. Special files can be found under /dev directory. These special files are called device files. Character and block devices are the most common type of device files. These device files are represented as a pair of numbers ( major device number and minor device number) by kernel.
Major device number indicates that which driver is used to access the hardware. Each driver in the system has a unique major number and all the device files whose major device number is same is controlled by the same driver.
While minor device number is used by the driver to distinguish between the various hardware it controls. Minor device number tells the kernel special characteristics of the device to be accessed.
A raw device is a special kind of logical device which is associated with a character device file. It allows a storage device to be accessed directly.

Note: This method is available only on UNIX platforms.

Syntax: os.makedev(major, minor)

Parameters:
major: An integer value representing the device major number
minor: An integer value representing the device minor number

Return Type: This method returns an integer value which represents a raw device number.

Code: Use of os.makedev() method to create a raw device number using major and minor device numbers




# Python program to explain os.makedev() method  
  
# importing os module 
import os
  
# Device major number
major = 8
  
# Device minor
minor = 8
  
# Compose raw device number from
# the above minor and major device number
# using os.makedev() method
raw_device = os.makedev(major, minor)
  
# Print the raw device number
print("Composed raw device number(major = % d, minor = % d):"\
%(major, minor), raw_device)
  
  
# Device major number
major = 103
  
# Device minor
minor = 0
  
# Compose raw device number from
# the above minor and major device number
# using os.makedev() method
raw_device = os.makedev(major, minor)
  
# Print the raw device number
print("Composed raw device number(major = % d, minor = % d):"\
%(major, minor), raw_device)


Output:

Composed raw device number(major = 8, minor = 8): 2056
Composed raw device number(major = 103, minor = 0): 26368

Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads