Rev 2707 | Rev 2709 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2707 | Rev 2708 | ||
---|---|---|---|
Line 45... | Line 45... | ||
45 | #include <futex.h> |
45 | #include <futex.h> |
46 | #include <rwlock.h> |
46 | #include <rwlock.h> |
47 | #include <libadt/list.h> |
47 | #include <libadt/list.h> |
48 | #include <unistd.h> |
48 | #include <unistd.h> |
49 | #include <ctype.h> |
49 | #include <ctype.h> |
- | 50 | #include <fcntl.h> |
|
50 | #include <assert.h> |
51 | #include <assert.h> |
51 | #include <atomic.h> |
52 | #include <atomic.h> |
52 | #include "vfs.h" |
53 | #include "vfs.h" |
53 | 54 | ||
54 | /** |
55 | /** |
Line 289... | Line 290... | ||
289 | int lflag = IPC_GET_ARG1(*request); |
290 | int lflag = IPC_GET_ARG1(*request); |
290 | int oflag = IPC_GET_ARG2(*request); |
291 | int oflag = IPC_GET_ARG2(*request); |
291 | int mode = IPC_GET_ARG3(*request); |
292 | int mode = IPC_GET_ARG3(*request); |
292 | size_t len; |
293 | size_t len; |
293 | 294 | ||
- | 295 | if (oflag & O_CREAT) |
|
- | 296 | lflag |= L_CREATE; |
|
- | 297 | if (oflag & O_EXCL) |
|
- | 298 | lflag |= L_EXCLUSIVE; |
|
- | 299 | ||
294 | ipc_callid_t callid; |
300 | ipc_callid_t callid; |
295 | 301 | ||
296 | if (!ipc_data_write_receive(&callid, &len)) { |
302 | if (!ipc_data_write_receive(&callid, &len)) { |
297 | ipc_answer_0(callid, EINVAL); |
303 | ipc_answer_0(callid, EINVAL); |
298 | ipc_answer_0(rid, EINVAL); |
304 | ipc_answer_0(rid, EINVAL); |
Line 323... | Line 329... | ||
323 | /* |
329 | /* |
324 | * Avoid the race condition in which the file can be deleted before we |
330 | * Avoid the race condition in which the file can be deleted before we |
325 | * find/create-and-lock the VFS node corresponding to the looked-up |
331 | * find/create-and-lock the VFS node corresponding to the looked-up |
326 | * triplet. |
332 | * triplet. |
327 | */ |
333 | */ |
- | 334 | if (lflag & L_CREATE) |
|
- | 335 | rwlock_write_lock(&namespace_rwlock); |
|
- | 336 | else |
|
328 | rwlock_read_lock(&namespace_rwlock); |
337 | rwlock_read_lock(&namespace_rwlock); |
329 | 338 | ||
330 | /* The path is now populated and we can call vfs_lookup_internal(). */ |
339 | /* The path is now populated and we can call vfs_lookup_internal(). */ |
331 | vfs_lookup_res_t lr; |
340 | vfs_lookup_res_t lr; |
332 | rc = vfs_lookup_internal(path, len, lflag, &lr, NULL); |
341 | rc = vfs_lookup_internal(path, len, lflag, &lr, NULL); |
333 | if (rc) { |
342 | if (rc) { |
- | 343 | if (lflag & L_CREATE) |
|
- | 344 | rwlock_write_unlock(&namespace_rwlock); |
|
- | 345 | else |
|
334 | rwlock_read_unlock(&namespace_rwlock); |
346 | rwlock_read_unlock(&namespace_rwlock); |
335 | ipc_answer_0(rid, rc); |
347 | ipc_answer_0(rid, rc); |
336 | free(path); |
348 | free(path); |
337 | return; |
349 | return; |
338 | } |
350 | } |
339 | 351 | ||
340 | /** Path is no longer needed. */ |
352 | /** Path is no longer needed. */ |
341 | free(path); |
353 | free(path); |
342 | 354 | ||
343 | vfs_node_t *node = vfs_node_get(&lr); |
355 | vfs_node_t *node = vfs_node_get(&lr); |
- | 356 | if (lflag & L_CREATE) |
|
- | 357 | rwlock_write_unlock(&namespace_rwlock); |
|
- | 358 | else |
|
344 | rwlock_read_unlock(&namespace_rwlock); |
359 | rwlock_read_unlock(&namespace_rwlock); |
345 | 360 | ||
346 | /* |
361 | /* |
347 | * Get ourselves a file descriptor and the corresponding vfs_file_t |
362 | * Get ourselves a file descriptor and the corresponding vfs_file_t |
348 | * structure. |
363 | * structure. |
349 | */ |
364 | */ |