Is it necessary to understand the root filesystem when writing a general application, like controlling an LED from a switch? Or is understanding the root filesystem mainly necessary when we are creating a custom Linux image?
I’m asking because I’m currently trying to understand things at a higher level, rather than going into the details of the entire filesystem.
Two paths. Depends where YOU draw YOUR line.
If you want to remain in the "Unix / POSIX" world and comply with that eco-system and standards, then you MUST use the SFS layout and use it as your interface.
"Everything is a file". That is the Unix way. That is the Unix programmer interface. You "can" sys call the kernel and ask about the CPU, but it would prefer your open a file handle on /proc/cpu hierarchy and look yourself. Thus the ACL file perms can manage it seemlessly.
cat /proc/cpuinfo
Just look at how machine and human parsable that is. Hint.
In your case, I see a /dev/my_led at least. Possibly a /dev/my_switch. Your app opens file handles to both and does what it does in user space. Your dev files are assigned to your kernel driver/drivers via "udev" or systemd.
If you do (DONT!) as root:
echo 1 > /dev/sda
It will literally.... and I mean literally, write a 1 into the first addressable byte of that Hard disk. EDIT (and a newline!)
cat /dev/sda
WILL dump it contents to standard out. Or your terminal, which will not be wise.
To set the speed of my CPU fan to 50% I can do something like:
echo 128 > /proc/sys/bus/pcie/0110/pwn_5
The other way...
Draw the line at "Thanks Linux, I'll take over now". Just do whatever you want. Run your app as root, let it peek and poke directly into /proc/sys/bus/pci or make direct syscalls into the kernel for that same access, whatever floats your boat. At the "per package" "source code" level, Linux is more like an OS building toolkit. Your way.
The cost is compatibility. If you need to move to another kernel or anoher POSIX OS, you would need to rewrite it.
EDIT: One area you can very likely ignore completely is the entire "multi-user" aspect. When setting things you avoid being dragged into multi-user requirements.
Linux broadly speaking boots to one of a few specific levels:
0 - Bare root console - physical access hack via your EUFI bootloader.
1 - "Single user" - the above but an actual shell and basic init, like auto mounts. No "login getties", no networking.
2 - "Multi-user" - often just combined with the next.
3 - "MU + Networking"
4 - never seen it used.
5 - Full GUI boot with GUI based login management.
6 - reboot
Im not even sure "init" accepts "init 0" which might be shutdown if it exists at all, but I put "0" level as a hard "init=/bin/bash" boot level.
In times gone by you used to be able to just "init 1" and get a root terminal with everything shutdown and just "init 5" it to bring it back up. These days however, multi-user linux distros block access to the init 1 terminal and as root hasno password set in /etc/shadow it fails.