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

From: David Hazel david.hazel at enchaine.com
Date: Sun Aug 12 23:59:19 EEST 2007

Thanks for the reply and for re-posting my question to the list. I'm
replying to "all" so that this goes to the list, too.

Regarding the "cat XXXXX" info that a couple of people have mentioned, the
problem I was having here is that it seemed to presume that I know a-priori
which device I need to incorporate into the path to get what I want. I won't
know this without first being able to determine which device a particular
(persistent) file is sitting on. Hence the first part of my question. I
think your suggestion about df may give me what I want. I suppose I was
expecting there to be something analogous to Mac OS's IOKit (which has
functions that do exactly the filename-to-containing-device translation that
I've described).

Sorry about the capitals. I'm aware of the connotations with shouting, but I
couldn't think of any other way of emphasising how I need to be able to get
the information I'm after (and I only capitalised the relevant words). Some
of the earlier replies read as if people thought I wanted to see the serial
number from a command line, rather than programmatically.

> That's Linux 101, but certainly is alien to anyone who has done Palm,
PocketPC or Windows development.

And to ex-VMS programmers ;-)

Actually, what's most alien is the amount of hunting around that seems to be
needed to find out how everything needs to be done on the N800 specifically
(as opposed to Linux in general). The real "how to do it" developer
information seems almost nonexistent when it comes to the specifics of
Maemo/Nokia N800. No other platform that I've ever programmed for (and there
are many, going back over 24 years) has been so couched in mystery. (Where,
for example, is the documentation - as opposed to just header comments - for
the Hildon APIs? I haven't found any yet. Even the GTK+ and GLib stuff is
little more than header comments with a few extra bits of description tacked
on. There's very little proper top-down documentation that I've been able to

Thanks for the info you've given me so far, anyway.

David Hazel

  -----Original Message-----
  From: Tony Maro [mailto:tonymaro at gmail.com]
  Sent: 12 August 2007 20:01
  To: David Hazel; maemo-developers at maemo.org
  Subject: Re: Obtaining flash memory serial numbers on Nokia N800

  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

    2. Having found the above, how can I then find that storage device's
serial number? (Again, FROM WITHIN AN APPLICATION)

  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/87128387/attachment.htm 
More information about the maemo-developers mailing list