Filename processing tricks
There are a number of tricks
that we can play when we manage our own pathname space.
For example, instead of having a plain filename for the web resource, we can have a built-in command in the
resource filename, like this:
/dev/webcounters/counter-00.gif/fg=#ffff00,bg=#00ffa0
(I would have really liked to put a ?
character instead of the last /
character,
but web-browsers strip off anything after (and including) the ?
character;
plus it would be cumbersome to use within the shell).
Here, we're accessing the /dev/webcounters/counter-00.gif resource, and
passing
it the arguments for the foreground and background colors.
The process manager doesn't care about the pathname after our registered mount point. In this example, our mount point is just /dev/webcounters — anything after that point is passed on to our io_open() as a text string. So in this case, our io_open() would receive the string:
counter-00.gif/fg=#ffffff0,bg=#00ffa0
How we choose to interpret that string is entirely up to us. For simplicity, we won't do any fancy processing in our resource manager, but I wanted to point out what could be done if you wanted to.
Our resource manager will accept a fixed-format string, as suggested above.
The format is the string counter-
followed by
two decimal digits, followed by the string .gif
and nothing further.
This lets our io_open() code parse the string
quite simply, and yet demonstrates what you can do.
searchfor anything, we simply convert the ASCII number to an integer and use it directly as an index.
The default number of counters is set to 100, but the command-line option -N can be used to set a different number.
We're also going to reorganize the storage file format of the persistent counter a little bit just to make things simpler. Rather than have 100 files that each contain one line with the count, instead we're going to have one file that contains 100 32-bit binary integers (i.e., a 400-byte file).
