What's wrong with
/* This piece of code allows concurrent read access to the fd
array at all times. There are three lines of code that need
to be protected against concurrent write access. These are
protected by the "aquire/release_write lock". A mechanism
for this needs to be in place anyway: we don't want another
another thread allocating this very SAME fd concurrently.
Don't we? */
if (newfd >= files->cur_allocated) {
if (newfd > files->cur_allocated) {
/* Oops. Someone else must already be updating
this, Not now baby.... I have a headache */
return -ENOMEM;
}
newfds = kmalloc (1024 *sizeof (struct file *), GFP_KERNEL);
if (!newfds) {
return -ENOMEM;
}
aquire_write_lock (files);
memcpy (newfds, files->fd,
files->cur_allocated * sizeof (struct file *));
/* This is the wrong moment to be changing the old
structure. */
files->fd = newfds;
files->cur_allocated = 1024;
release_write_lock (files);
/* The old one could be freed, but it is connected to
the files structure. */
}
Left as an excercise for the reader: change 1024 to "cur_allocated * 4"
Regards,
Roger.
-- ** R.E.Wolff@BitWizard.nl ** +31-15-2137555 ** http://www.BitWizard.nl/ ** Florida -- A 39 year old construction worker woke up this morning when a 109-car freight train drove over him. According to the police the man was drunk. The man himself claims he slipped while walking the dog. 080897