Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Writing a NetBSD Kernel Module (saurvs.github.io)
75 points by jayp1418 on April 6, 2022 | hide | past | favorite | 8 comments


This reminded me of https://mveg.es/posts/writing-a-device-driver-for-unix-v6/, which was recently discussed here under https://news.ycombinator.com/item?id=30679923

Also... have you considered contributing this content to the NetBSD Internals book? https://www.netbsd.org/docs/internals/en/netbsd-internals.ht... :)


Cool. Thanks for links


as that would end up copying the \0 along with the rest of the string into the driver

What? echo definitely doesn't append null terminators. It does append a newline, which you can omit with the -n option or ending the string with \c, depending on which standard it follows.


... as long as you don't want to do fancy IOCTL() work. basically, its the jump table model from 1980s with a few extra twists like templating.

"here, steal this mknod number" is dangerous. It pays to check nothing else is using that value. Thats what registries are for in the end.


That's why FreeBSD doesn't use mknod(8) - or device numbers - at all. You can kind of work around this obsolete idea instead - that's what Linux is doing - but it's not optimal.


Wait, how can you do it without any device numbers? Are they binding drivers directly to file names?


Precisely. That's one of the reasons devfs isn't optional in FreeBSD. (Note that FreeBSD devfs is very different from the one that's been there in Linux years ago, and doesn't have its deficiencies.)


Why would one want to write a module instead of using a library to achieve the same?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: