mount -t devtmpfs
นอกจากนี้ยังเป็นที่น่าสนใจที่จะเห็นว่าในระบบที่ทันสมัย/devเป็นปกติประเภทระบบไฟล์ที่สามารถติดตั้งได้ทุกที่ Ubuntu 16.04:
mkdir d
sudo mount -t devtmpfs none d
head -c 10 d/random
sudo umount d
สิ่งนี้เปิดใช้งานโดยCONFIG_DEVTMPFS=yและอนุญาตให้เคอร์เนลสร้างและทำลายไฟล์อุปกรณ์ได้ตามต้องการ
CONFIG_DEVTMPFS_MOUNT=y
ตัวเลือกนี้จะทำให้เมล็ดอัตโนมัติ-mount devtmpfs /devบน
drivers/base/Kconfig เอกสาร:
config DEVTMPFS_MOUNT
bool "Automount devtmpfs at /dev, after the kernel mounted the rootfs"
depends on DEVTMPFS
help
This will instruct the kernel to automatically mount the
devtmpfs filesystem at /dev, directly after the kernel has
mounted the root filesystem. The behavior can be overridden
with the commandline parameter: devtmpfs.mount=0|1.
This option does not affect initramfs based booting, here
the devtmpfs filesystem always needs to be mounted manually
after the rootfs is mounted.
With this option enabled, it allows to bring up a system in
rescue mode with init=/bin/sh, even when the /dev directory
on the rootfs is completely empty.
file_operations
สุดท้ายคุณควรสร้างโมดูลเคอร์เนลอุปกรณ์อักขระของคุณเองเพื่อดูว่าเกิดอะไรขึ้น
นี่คือตัวอย่างที่เรียกใช้น้อยที่สุด: การทำความเข้าใจกับไฟล์อุปกรณ์อักขระ (หรืออักขระพิเศษ)
ขั้นตอนที่สำคัญที่สุดคือการตั้งค่าโครงสร้างfile_operationsเช่น:
static const struct file_operations fops = {
.owner = THIS_MODULE,
.read = read,
.open = open,
};
static int myinit(void)
{
major = register_chrdev(0, NAME, &fops);
return 0;
}
ซึ่งมีพอยน์เตอร์ของฟังก์ชันที่เรียกใช้สำหรับการเรียกระบบที่เกี่ยวข้องกับไฟล์แต่ละครั้ง
/dev/zeroมันก็จะกลายเป็นที่ชัดเจนว่าคุณแทนที่ระบบไฟล์ที่เกี่ยวข้องกับผู้ที่เรียกร้องให้ทำสิ่งที่คุณต้องการและดังนั้นนี้เป็นวิธีที่เคอร์เนลใช้อุปกรณ์เช่น
สร้าง/devรายการโดยอัตโนมัติโดยไม่ต้องmknod
ความลึกลับสุดท้ายคือเคอร์เนลสร้าง/devรายการโดยอัตโนมัติอย่างไร
สามารถตรวจสอบกลไกได้โดยสร้างโมดูลเคอร์เนลที่ทำด้วยตัวคุณเองดังที่แสดงไว้ที่: https://stackoverflow.com/questions/5970595/how-to-create-a-device-node-from-the-init-module- https://stackoverflow.com/questions/ code-of-a-linux-kernel-module / 45531867 # 45531867และลงมาที่การdevice_createโทร