[maemo-developers] Obtaining flash memory serial numbers on Nokia N800

From: Tony Maro tonymaro at gmail.com
Date: Sun Aug 12 22:01:06 EEST 2007
On 8/12/07, David Hazel <david.hazel at enchaine.com> wrote:
>  OK, so far I haven't had a reply that really answers my original
> questions, so let me rephrase them:

I'd tend to disagree, but let's go on ;-)

1. Given a full directory path, how can I determine FROM WITHIN AN
> APPLICATION which storage device (memory card) this corresponds with? In
> other words, starting with something of the form "/dir1/dir2/dir3/file", how
> can I identify the storage device that this resides on?

Well, that one would best be determined by reading the output of df or mount
I would think.  Because the Linux file system is so flexible, there may not
be an actual "device" associated with a given path.  Some of the paths in
the file system are actually output from running applications.  Others might
be mounted across the network using any number of network file systems.  For
instance, the /proc directory doesn't really exist on a Linux hard drive so
much as is output by a program running on the machine.  So when you say you
want to "find which storage device a path corresponds with" there may not be
an answer because the question is wrong.  Read on for more info...

2. Having found the above, how can I then find that storage device's serial

Um, actually that was the answer everyone provided.  No need to yell -
that's generally what gets most Linux advocates bristling and starts flame

Just read the text file at the specified location.  Where we said "cat
XXXXXX", cat was just meaning dump the contents of that file to the console,
so you could just open that file like any text file and read the serial
number out of it.  That's Linux 101, but certainly is alien to anyone who
has done Palm, PocketPC or Windows development.

So in Python for instance, you might do:

mypath = '/sys/devices/platform/mmci-omap.1/mmc1*/cid'
srcfile = open(mypath,'r')
myserial = srcfile.readline()
# tada! no need for any include's either.  Nice and simple.

You can use the same method to find the type of processor in the device, how
much memory card space is in use, and untold many other tidbits of cool
information.  Keep in mind, Linux aka Unix was originally designed around
everything communicating to each other through what is basically console
I/O.  It's a really neat system when you think about it.  This means there's
no special API that needs written or header files that must be available for
each language in order to access this information.  Other aspects of the
Linux OS are actually changed just simply by writing to these fake "text
files" in your directory structure.  These fake "text files" are just the
communications medium between applications.  And that's a Fact. ;-)

Fact: I can programmatically determine an SD card's serial number on a
> Windows Mobile device. Therefore I expect this to be possible on the Nokia
> 800 as well.

Sure, just read it from the file system as described above.  Linux provides
the /sys/devices (or on a desktop normally /proc/whatever) "file system" to
make it easier to do this, so there's not even an API you need.  Just read
the settings you're looking for from the OS supplied text file.

Fact: I can programmatically map a directory path onto its corresponding
> device under Mac OS X (which is BSD Unix with go-faster stripes). Therefore
> I expect to be able to do something similar on an N800 running a variant of
> Linux (which is Unix-like, right?).
If you're talking about "mounting" sure, but you'll need to do it as root
for security reasons.  If that's not what you mean, you'll need to clarify.

Someone who's a C programmer might be able to expound on my comments and
give other options as well.

Also, on a side note, you sent your response directly to me and not the
list, so I'm submitting it back to the list as well assuming it was an
oversight on your part.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.maemo.org/pipermail/maemo-developers/attachments/20070812/7f24eba9/attachment.htm 
More information about the maemo-developers mailing list