324 |
char *name, struct node **np) |
char *name, struct node **np) |
325 |
{ |
{ |
326 |
error_t err; |
error_t err; |
327 |
int flags = O_RDWR|O_EXEC; |
int flags; |
328 |
file_t file = file_name_lookup_under (dir->nn->file, name, |
const file_t dirfile = dir->nn->file; |
329 |
flags | O_NOLINK, 0); |
file_t file; |
330 |
|
|
331 |
|
/* We must unlock the directory before making RPCs to the underlying |
332 |
|
filesystem in case they somehow wind up trying to refer back to one of |
333 |
|
our nodes. The DIRFILE port will not change or die as long as DIR |
334 |
|
lives, and our caller holds a reference keeping it alive. */ |
335 |
|
mutex_unlock (&dir->lock); |
336 |
|
|
337 |
|
flags = O_RDWR|O_EXEC; |
338 |
|
file = file_name_lookup_under (dirfile, name, flags | O_NOLINK, 0); |
339 |
if (file == MACH_PORT_NULL && errno == EACCES) |
if (file == MACH_PORT_NULL && errno == EACCES) |
340 |
{ |
{ |
341 |
flags = O_RDWR; |
flags = O_RDWR; |
342 |
file = file_name_lookup_under (dir->nn->file, name, flags | O_NOLINK, 0); |
file = file_name_lookup_under (dirfile, name, flags | O_NOLINK, 0); |
343 |
} |
} |
344 |
if (file == MACH_PORT_NULL && errno == EACCES) |
if (file == MACH_PORT_NULL && errno == EACCES) |
345 |
{ |
{ |
346 |
flags = O_READ|O_EXEC; |
flags = O_READ|O_EXEC; |
347 |
file = file_name_lookup_under (dir->nn->file, name, flags | O_NOLINK, 0); |
file = file_name_lookup_under (dirfile, name, flags | O_NOLINK, 0); |
348 |
} |
} |
349 |
if (file == MACH_PORT_NULL && errno == EACCES) |
if (file == MACH_PORT_NULL && errno == EACCES) |
350 |
{ |
{ |
351 |
flags = O_READ; |
flags = O_READ; |
352 |
file = file_name_lookup_under (dir->nn->file, name, flags | O_NOLINK, 0); |
file = file_name_lookup_under (dirfile, name, flags | O_NOLINK, 0); |
353 |
} |
} |
354 |
*np = 0; |
*np = 0; |
355 |
if (file == MACH_PORT_NULL) |
if (file == MACH_PORT_NULL) |
381 |
} |
} |
382 |
} |
} |
383 |
} |
} |
384 |
mutex_unlock (&dir->lock); |
|
385 |
if (*np) |
if (*np) |
386 |
mutex_lock (&(*np)->lock); |
mutex_lock (&(*np)->lock); |
387 |
return err; |
return err; |