Productivity Sync Just another WordPress weblog

May 5, 2013

Random things this weekend…

Filed under: Uncategorized — admin @ 3:18 pm

Find tricks:

find /sys/devices/ -name driver -exec file “{}” \; | sed “s|^.*\.\.||” | sort -u | wc


Building mobi’s from XML files:

I was trying to convert a docbook based document from xml to mobi.  to mobi.

The steps are:run dbtoepub after getting the xml / docbook stuff, and any dtd files (say the safary_future.dtd files needed) Then run the kindlegen program on the ebub file.

FWIW I ended up getting the dtd file by cloning a repo on git hub git:// and copying its dblite directory to my /opt/tools/docbook/ directory.

Then I still had problems with a few missing xml files so I deleted their reference (metadata.xml, cyprt.xml)  from the book.xml The resulting mobi file looks to work fine on my tablet running the kindle reader apk.


Linux kernel spelunking of the /sys directory

The sysf directory has a lot of interesting data in it.  I’m looking to identify all the drivers and modules and devices my system thinks it has in it.  To this end I’ve been using grep and find and now setting up to implement a python program to extract the “drivers” the running kernel thinks it has access too as well as the “device”s  it knows about, and the set of “modules” it has (even if they are not loaded).  I should be able to map the drivers in use to devices and kernel config settings.  I should also be able to identify devices that are missing drivers.  I should be able to identify drivers that really are unneeded.

At least thats what I “feel” I should be able to do.  The reality is there are things happening to complicate my simple assumptions.  As I get into this exploration I’ll fill in the details.  But, by running a few find commands I can identify all the drivers the system thinks it has access too at runtime (by searching for bind in the /sysfs tree using find).  I can also know all the modules the system knows about by listing the /sys/module/ directory.  I can identify all the drivers associated with devices by searching for “driver” using find.  I can find all the devices and drivers that have issues a udev envent by finding all instances of  “modalias” using find.

The problems I have is that the numbers don’t add up yet:

Linux mgross-MOBL 3.9.0 #8 SMP Sun May 5 12:30:05 PDT 2013 x86_64 x86_64 x86_64 GNU/Linux
mgross@mgross-MOBL:~$ find /sys/ -name device -exec file "{}" \; | sed "s|^.*\.\.||" | sort -u | wc
 124 172 2795
mgross@mgross-MOBL:~$ find /sys/ -name driver -exec file "{}" \; | sed "s|^.*\.\.||" | sort -u | wc
 42 44 1121
mgross@mgross-MOBL:~$ find /sys/ -name unbind | wc
 60 63 2226
mgross@mgross-MOBL:~$ find /sys/ -name bind | wc
 62 65 2192

mgross@mgross-MOBL:~$ find /sys/ -name refcnt -exec cat "{}" \; | wc

 101 101 225
mgross@mgross-MOBL:~$ find /sys/ -name refcnt -exec cat "{}" \; | grep -v 0 | wc
 67 67 138
mgross@mgross-MOBL:~$ lsmod | wc
 102 361 4543
mgross@mgross-MOBL:~$ find /sys/ -name modalias | wc
 135 135 8093
mgross@mgross-MOBL:~$ find /sys/ -name module | wc
 33 33 1198
mgross@mgross-MOBL:~$ ls /sys/module/ | wc
 144 144 1332

So I have 101 modules loaded and 43 drivers (modules tend to be drivers and I feel the 43 “drivers” should include drivers that are loaded a modules. Yet I can bind/unbind only 62(or 60) drivers from devices and the system thinks there are 144 modules going on.

Something isn’t adding up for me just yet.  Clearly my definition of device, driver, and module I am assuming does not match up with reality here.


Powered by WordPress