Linux 块设备接口
原片 01:14:31—01:15:30
直接操作数据结构,能避免这类读写放大,感兴趣可以课后了解。操作系统中,存储设备也有驱动。按读 block、写 block 的模型,实现 struct block_device_operations 即可。它类似 file_operations,但 file_operations 的 read、write 可以从任意 offset 读写。

文件游标能移到任意位置,block device 则按块读取、连续读取多块或写入多块。只要实现设备上的块读写,剩下的 read、write、mmap 等系统调用,就由操作系统提供。