[lang]

Present Perfect

Personal
Projects
Packages
Patches
Presents
Linux

Picture Gallery
Present Perfect

modules

Filed under: Hacking — Thomas @ 17:09

2004-06-18
17:09

Linux 2.6 in Fedora Core doesn't prefer modules put in /lib/modules/`uname -r`/updates anymore. This was annoying for our server since the recent kernel updates reintroduced a pwc.ko module, but I have rpms that provide the latest version of that together with the "contains-binary-stuff" pwcx.ko module.

So, looked at a patch from someone, found some bugs, then decided to go through depmod myself. Every time I code in something on a level below GLib I am very annoyed. But there are benefits.

One is laughing out at fun code like

/* I hate strcmp. */
#define streq(a,b) (strcmp((a),(b)) == 0)

Another is getting a better understanding at how kernel modules and depmod work.

And a third is learning new tricks. Faced with this structure:

struct module
{
/* Next module in list of all modules */
struct module *next;

(... bunch of members, snipped ...)
char pathname[0];
};

and this allocator code

struct module *new;

new = NOFAIL(malloc(sizeof(*new)
+ strlen(dirname) + 1 + strlen(filename) + 1));

I tried to think why this would be done ?
Basically, a one-byte array is put at the end of the struct, and the struct is over-allocated.
Then I realized why this would be useful; this trick allows you to just free the struct and the pathname with one free, since you allocated it with one malloc. So you don't have to write code to free the members of the structure.
Of course, this only works if you have only one variable-length array in your struct and put it in at the last member.
Also, I don't know how portable this is, but I guess since even when alignment is factored in it still always allocates at least enough to hold the string.

Anyways, I made made a patch, created updated modutils packages and on Jeremy's advice sent it upstream to Rusty.

Matthias has joined in on the kernel module packaging fun and seems to be happy with the autotooling. I started on linux-wlan-ng, because someone mentioned it. It has a nice code layout, and is fun to package, so will probably be done soon as well. Now I hope the various fedora.us "players" can agree to my ideas so I can start documenting and getting packages checked and released.

No Comments

No comments yet.

RSS feed for comments on this post. TrackBack URL

Sorry, the comment form is closed at this time.

picture