diff options
author | Al Viro <viro@zeniv.linux.org.uk> | 2012-08-12 17:27:30 -0400 |
---|---|---|
committer | Al Viro <viro@zeniv.linux.org.uk> | 2012-09-26 21:08:53 -0400 |
commit | dcfadfa4ec5a12404a99ad6426871a6b03a62b37 (patch) | |
tree | a8c2898366470e795dac369040b905985c0bb9fc /fs/file.c | |
parent | f33ff9927f42045116d738ee47ff7bc59f739bd7 (diff) |
new helper: __alloc_fd()
Essentially, alloc_fd() in a files_struct we own a reference to.
Most of the time wanting to use it is a sign of lousy API
design (such as android/binder). It's *not* a general-purpose
interface; better that than open-coding its guts, but again,
playing with other process' descriptor table is a sign of bad
design.
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'fs/file.c')
-rw-r--r-- | fs/file.c | 12 |
1 files changed, 8 insertions, 4 deletions
@@ -420,11 +420,10 @@ struct files_struct init_files = { | |||
420 | /* | 420 | /* |
421 | * allocate a file descriptor, mark it busy. | 421 | * allocate a file descriptor, mark it busy. |
422 | */ | 422 | */ |
423 | int alloc_fd(unsigned start, unsigned flags) | 423 | int __alloc_fd(struct files_struct *files, |
424 | unsigned start, unsigned end, unsigned flags) | ||
424 | { | 425 | { |
425 | struct files_struct *files = current->files; | ||
426 | unsigned int fd; | 426 | unsigned int fd; |
427 | unsigned end = rlimit(RLIMIT_NOFILE); | ||
428 | int error; | 427 | int error; |
429 | struct fdtable *fdt; | 428 | struct fdtable *fdt; |
430 | 429 | ||
@@ -479,8 +478,13 @@ out: | |||
479 | return error; | 478 | return error; |
480 | } | 479 | } |
481 | 480 | ||
481 | int alloc_fd(unsigned start, unsigned flags) | ||
482 | { | ||
483 | return __alloc_fd(current->files, start, rlimit(RLIMIT_NOFILE), flags); | ||
484 | } | ||
485 | |||
482 | int get_unused_fd_flags(unsigned flags) | 486 | int get_unused_fd_flags(unsigned flags) |
483 | { | 487 | { |
484 | return alloc_fd(0, flags); | 488 | return __alloc_fd(current->files, 0, rlimit(RLIMIT_NOFILE), flags); |
485 | } | 489 | } |
486 | EXPORT_SYMBOL(get_unused_fd_flags); | 490 | EXPORT_SYMBOL(get_unused_fd_flags); |