Anyone know how FreeBSD would handle this:-
Code:if [ -e /sys/class/block/${DISK#/dev/}/start ]; then
/sys is a pseudo filesystem presented by the Linux kernel. Natively FreeBSD doesn't have a /sys pseudo filesystem because, architecturally, it's not needed.Anyone know how FreeBSD would handle this:-
Code:if [ -e /sys/class/block/${DISK#/dev/}/start ]; then
I like the idea of presenting all hardware resources & features in a properly secured filesystem namespace but not the way Linux has done it -- for example on a pi4 "find /sys | wc" reveals almost 44K entries! FreeBSD does a little of this with disk & audio devices but not in any systematic manner. The benefits are you can do a lot of system stuff in any language without needing brittle C/C++ APIs. But I don't see FreeBSD going this way.
I'm not in the least comfortable with Linux, I'm just trying to find out what this does so that I find a FreeBSD equivalent.FreeBSD doesn't have /sys. In linux emulation there is /compat/linux/sys but it is quite limited. For one thing we don't have block devices any more.
Explain what you want to do and may be we can suggest something. On the other hand, why even bother with FreeBSD if you are comfortable with Linux?
cd /sys/class/block/
ls
dm-0@ loop10@ loop14@ loop18@ loop21@ loop25@ loop29@ loop6@ sda@ sr0@
dm-1@ loop11@ loop15@ loop19@ loop22@ loop26@ loop3@ loop7@ sda1@
loop0@ loop12@ loop16@ loop2@ loop23@ loop27@ loop4@ loop8@ sda2@
loop1@ loop13@ loop17@ loop20@ loop24@ loop28@ loop5@ loop9@ sda5@
cd sda
ls
alignment_offset discard_alignment hidden power/ sda1/ stat
bdi@ events holders/ queue/ sda2/ subsystem@
capability events_async inflight range sda5/ trace/
dev events_poll_msecs integrity/ removable size uevent
device@ ext_range mq/ ro slaves/
cd sda1
ls
alignment_offset discard_alignment inflight power/ size stat trace/
dev holders/ partition ro start subsystem@ uevent
cat sda1/start
2048
cat sda2/start
1001470
[…] checking if a disk is mounted
Code:grep "$DISK" /proc/mounts
^
and
) when using grep(1)grep "^${DISK} " /proc/mounts # or pipe the output of mount(8)
findmnt(8)
Linux utilityfindmnt --source "${DISK}" # returns 1 if no match
That doesn't even exist on my Linux machine.Anyone know how FreeBSD would handle this:-Code:if [ -e /sys/class/block/${DISK#/dev/}/start ]; then
$DISK
when it’s meant to read $PARTITION
. start contains, as mer just described, the number of the partition’s first block. The info can be obtained using gpart(8).I like the idea of presenting all hardware resources & features in a properly secured filesystem namespace but not the way Linux has done it […]
sysfs
is utterly unstable. By that I mean the file system contents (can and do) change (between kernel releases). This makes it unsuitable for developing applications. A sysfs
file just provides data, but it does not explain what information these data convey (“parsing random ASCII strings from a filesystem” as cracauer@ described it). The “everything is a file” concept has its limits. (Nevertheless sysfs
still nice for solving a task now.)tcsh with ls alias to /bin/ls -hF to get the trailing "@" and "/".
/sys/class/block gives you all the block devices in the system and then some easy access to information about them.
Ubuntu system I have at hand, laptop with a single SSD in it (sda).
that specific file looks like it's the block number where the partition starts.
cd /sys/class/block/ ls dm-0@ loop10@ loop14@ loop18@ loop21@ loop25@ loop29@ loop6@ sda@ sr0@ dm-1@ loop11@ loop15@ loop19@ loop22@ loop26@ loop3@ loop7@ sda1@ loop0@ loop12@ loop16@ loop2@ loop23@ loop27@ loop4@ loop8@ sda2@ loop1@ loop13@ loop17@ loop20@ loop24@ loop28@ loop5@ loop9@ sda5@ cd sda ls alignment_offset discard_alignment hidden power/ sda1/ stat bdi@ events holders/ queue/ sda2/ subsystem@ capability events_async inflight range sda5/ trace/ dev events_poll_msecs integrity/ removable size uevent device@ ext_range mq/ ro slaves/ cd sda1 ls alignment_offset discard_alignment inflight power/ size stat trace/ dev holders/ partition ro start subsystem@ uevent cat sda1/start 2048 cat sda2/start 1001470
gpart list
should give you similar information on FreeBSD for this example.tcsh with ls alias to /bin/ls -hF to get the trailing "@" and "/".
/sys/class/block gives you all the block devices in the system and then some easy access to information about them.
Ubuntu system I have at hand, laptop with a single SSD in it (sda).
that specific file looks like it's the block number where the partition starts.
cd /sys/class/block/ ls dm-0@ loop10@ loop14@ loop18@ loop21@ loop25@ loop29@ loop6@ sda@ sr0@ dm-1@ loop11@ loop15@ loop19@ loop22@ loop26@ loop3@ loop7@ sda1@ loop0@ loop12@ loop16@ loop2@ loop23@ loop27@ loop4@ loop8@ sda2@ loop1@ loop13@ loop17@ loop20@ loop24@ loop28@ loop5@ loop9@ sda5@ cd sda ls alignment_offset discard_alignment hidden power/ sda1/ stat bdi@ events holders/ queue/ sda2/ subsystem@ capability events_async inflight range sda5/ trace/ dev events_poll_msecs integrity/ removable size uevent device@ ext_range mq/ ro slaves/ cd sda1 ls alignment_offset discard_alignment inflight power/ size stat trace/ dev holders/ partition ro start subsystem@ uevent cat sda1/start 2048 cat sda2/start 1001470
That is the problem Last I mucked with it sysfs is used mostly by device drivers to expose things. Some items are read only others are read write.OK, but where is this documented?
What does the "start" entry referenced upstairs in this thread do? All I can see is that the entry is readonly, so it obviously is not intended to be "echo"ed into.
SEE ALSO
proc(5), udev(7)
P. Mochel. (2005). The sysfs filesystem. Proceedings of the 2005 Ot‐
tawa Linux Symposium.
The kernel source file Documentation/filesystems/sysfs.txt and various
other files in Documentation/ABI and Documentation/*/sysfs.txt
Absolutely agree with sysctl description. I'd love to see default, allowed values or ranges too, but that's just me and yes, I know "patches welcome".Well, this is one reason why I like FreeBSD's sysctl: for every variable there is documentation built into the kernel and the systcl command can display it.
It would be like Linux having for every
/sys/class/foo/bar/start
a
/sys/class/foo/bar/start.doc
which you could `cat` to learn about it.