I'm a few days behind on email but this came in while I was looking, so...

On 09/11/2013 05:32:22 PM, Conroy, Bradley Quentin wrote:
I have a semi-functional (getting ntfs device name eludes me) implementation of blkid that I would be willing to toybox if there is any interest (Its not on the
list AFAICT, so I will be brief)

I'm happy to look at an implementation, sure.

The implementation is as follows:
1. read 65k buffer from file (reiserfs and others have superblock starting
at 64k)

Reserving space for a bootloader. :)

2.  perform switch cases @ 0 offset to compare to many magics
(0 is a fairly common offset)
**Note: the switch case really provides no benefit over if-else in this situation since the Magic values are too far apart to be optimized into a jump table.
 I can change this for uniformity if desired.

I've noticed that if/else tends to produce smaller code, both in the binary and in the source. (It's the label/statement/break; pattern eating 3 lines. Plus the jump table is a speed optimization but not a size optimization, and given that outside of tight loops the dominant performance factor on modern architectures is cache line loading, smaller code _is_ faster code until proven otherwise...)

So I lean towards if/else unless there's a good reason not to. :)

3. Then go through the rest of the fs types and check for #defined magic @ #defined offset(s)

Woot.

At some point, I need to do file. It's a posix command, but all the brains of the thing are in a file of match heuristics, and so far toybox doesn't depend on external data files.

  http://pubs.opengroup.org/onlinepubs/9699919799/utilities/file.html

(I'll probably hardwire in the "example" magic file.)

4. If a match is found it returns the result of print_fsinfo(char *fstype, int UUID_offset, int UUID_type, int name_offset, int name_len) where the UUID_offset, UUID_type, name_offset, name_len are also #defined in the header for that fs type.

I know many people only want to get the fs type (for mount) instead of the full blkid output. Does toybox have some kind of facility for setting function pointers based on the name it is called with or a way to get the current toy-command name to use for conditional code?

There's a global array in toys.h:

  struct toy_list toy_list[];

And a global structure of command-independent context, called "this" (also in toys.h).

The current command's name is this.which->name (because this.which is a pointer to our entry in toylist[], and then name is the command name field, main is the function pointer, and so on).

The function toy_find("name") returns a pointer to the toy_list entry for that command, or NULL if it wasn't found.

Rob
_______________________________________________
Toybox mailing list
[email protected]
http://lists.landley.net/listinfo.cgi/toybox-landley.net

Reply via email to