2

On a linux system many device names can be seen under /dev. This must be defined somewhere in the linux kernel source code, the udev code, device trees or driver code.

For example, where is the source code located that determines a floppy drive should start with fd or that a hard disk starts with sd ?

2

There's the LXR (Linux cross reference) project where you can select your kernel version and search the code.

(Note: The old http://lxr.linux.no doesn't work properly anymore, at least for me; search is broken for newer kernel versions.)

Searching for "floppy" (without quotes) and a couple of attempts peeking into the results grepping for "fd" (with quotes) led me to the implementation of the floppy block device (here in kernel 4.9):

http://lxr.free-electrons.com/source/drivers/block/floppy.c#L4219

Now being a crossreference you can follow register_blkdev to its other places of use.

2

An easier one to find might be something like /dev/null or /dev/zero. For those, take a look at ${kernel_root}/drivers/char/mem.c. For 4.9.6 (and it's probably been this way for a while now), there's an array of struct memdev named devlist, where each entry in the array corresponds to a memory device:

...
[3] = { "null", 0666, &null_fops, 0 },
...
[5] = { "zero", 0666, &zero_fops, 0 },
...

The null_fops and zero_fops contain the file operation structures for the corresponding devices.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.