General TC > Programming & Scripting - Unofficial
Tinkering with rebuildfstab
Rich:
Hi curaga
--- Quote from: curaga on February 25, 2023, 11:09:43 AM --- ... Everyone is welcome to go over the TC scripts. rebuildfstab's speed is fast enough for me personally, but if you find it too slow, please do look into it. ...
--- End quote ---
I think I may have an approach that doesn't need the find command.
The /dev/block/* directory seems to contain the information being searched for.
I used a cut down version of rebuildfstab containing the find loop that isolates
the value of DEVNAME and DEVMAJOR as a baseline. I included an echo
statement to list the found devices.
Here are the timing results:
--- Code: ---tc@E310:~/rebuildfstab$ time ./findblockdevs > /dev/null
real 0m 0.71s
user 0m 0.22s
sys 0m 0.53s
tc@E310:~/rebuildfstab$ time ./newfindblockdevs > /dev/null
real 0m 0.09s
user 0m 0.04s
sys 0m 0.05s
tc@E310:~/rebuildfstab$
--- End code ---
It finds the same devices (order does not matter):
--- Code: ---tc@E310:~/rebuildfstab$ time ./findblockdevs
DEVNAME=sda4 DEVMAJOR=8
DEVNAME=sda2 DEVMAJOR=8
DEVNAME=sda DEVMAJOR=8
DEVNAME=sda7 DEVMAJOR=8
DEVNAME=sda5 DEVMAJOR=8
DEVNAME=sda3 DEVMAJOR=8
DEVNAME=sda1 DEVMAJOR=8
DEVNAME=sda6 DEVMAJOR=8
DEVNAME=sdb DEVMAJOR=8
DEVNAME=sdb1 DEVMAJOR=8
DEVNAME=sdc DEVMAJOR=8
DEVNAME=sdd DEVMAJOR=8
DEVNAME=sde DEVMAJOR=8
DEVNAME=sdf DEVMAJOR=8
DEVNAME=sr0 DEVMAJOR=11
DEVNAME=sr1 DEVMAJOR=11
real 0m 0.70s
user 0m 0.22s
sys 0m 0.52s
tc@E310:~/rebuildfstab$ time ./newfindblockdevs
DEVNAME=sr0 DEVMAJOR=11
DEVNAME=sr1 DEVMAJOR=11
DEVNAME=sda DEVMAJOR=8
DEVNAME=sda1 DEVMAJOR=8
DEVNAME=sdb DEVMAJOR=8
DEVNAME=sdb1 DEVMAJOR=8
DEVNAME=sda2 DEVMAJOR=8
DEVNAME=sda3 DEVMAJOR=8
DEVNAME=sdc DEVMAJOR=8
DEVNAME=sda4 DEVMAJOR=8
DEVNAME=sdd DEVMAJOR=8
DEVNAME=sda5 DEVMAJOR=8
DEVNAME=sda6 DEVMAJOR=8
DEVNAME=sde DEVMAJOR=8
DEVNAME=sda7 DEVMAJOR=8
DEVNAME=sdf DEVMAJOR=8
real 0m 0.09s
user 0m 0.03s
sys 0m 0.06s
tc@E310:~/rebuildfstab$
--- End code ---
I've attached the baseline file (findblockdevs) and the version with my changes (newfindblockdevs).
Lines beginning with ### were commented out by me.
curaga:
I worry about a potential race there - is it certain those devices (/the newest of them) exist when rebuildfstab is called. /sys gets populated early, but I don't remember when exactly udev creates devices wrt the called scripts.
No interest in the C approach :P
Rich:
Hi curaga
How do you feel about using /proc/partitions? I can cut the time
by another factor of 2 parsing that source.
hiro:
7x faster, nice :D
maybe we should also replace blkid with a shellscript, then? /s
curaga:
/proc should be fine.
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version