Created
August 27, 2018 01:05
-
-
Save amaciel81/bcb03a50f843f0163f7b9f0e088c102e to your computer and use it in GitHub Desktop.
ioctl example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import fcntl | |
import os | |
CD_DEVICE = '/dev/cdrom' | |
CD_EJECT = 0x5309 # From https://github.com/torvalds/linux/blob/master/include/uapi/linux/cdrom.h | |
# You need to open the device, not the link | |
if os.path.islink(CD_DEVICE): | |
device_path = os.readlink(CD_DEVICE) | |
if not device_path.startswith('/'): | |
device_path = os.path.dirname(CD_DEVICE) + '/' + device_path | |
else: | |
device_path = CD_DEVICE | |
device_fd = os.open(device_path, os.O_RDONLY | os.O_NONBLOCK ) | |
fcntl.ioctl(device_fd, CD_EJECT, 0) | |
os.close(device_fd) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment