2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Wrapper functions for accessing the file_struct fd array.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __LINUX_FILE_H
|
|
|
|
#define __LINUX_FILE_H
|
|
|
|
|
|
|
|
#include <linux/compiler.h>
|
[PATCH] Shrinks sizeof(files_struct) and better layout
1) Reduce the size of (struct fdtable) to exactly 64 bytes on 32bits
platforms, lowering kmalloc() allocated space by 50%.
2) Reduce the size of (files_struct), using a special 32 bits (or
64bits) embedded_fd_set, instead of a 1024 bits fd_set for the
close_on_exec_init and open_fds_init fields. This save some ram (248
bytes per task) as most tasks dont open more than 32 files. D-Cache
footprint for such tasks is also reduced to the minimum.
3) Reduce size of allocated fdset. Currently two full pages are
allocated, that is 32768 bits on x86 for example, and way too much. The
minimum is now L1_CACHE_BYTES.
UP and SMP should benefit from this patch, because most tasks will touch
only one cache line when open()/close() stdin/stdout/stderr (0/1/2),
(next_fd, close_on_exec_init, open_fds_init, fd_array[0 .. 2] being in the
same cache line)
Signed-off-by: Eric Dumazet <dada1@cosmosbay.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-03-23 19:00:12 +08:00
|
|
|
#include <linux/types.h>
|
2008-04-24 19:44:08 +08:00
|
|
|
#include <linux/posix_types.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-04-24 19:44:08 +08:00
|
|
|
struct file;
|
2006-12-07 12:32:52 +08:00
|
|
|
|
2008-02-14 07:03:15 +08:00
|
|
|
extern void fput(struct file *);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-10-17 14:31:13 +08:00
|
|
|
struct file_operations;
|
|
|
|
struct vfsmount;
|
|
|
|
struct dentry;
|
2009-08-09 04:52:35 +08:00
|
|
|
struct path;
|
|
|
|
extern struct file *alloc_file(struct path *, fmode_t mode,
|
|
|
|
const struct file_operations *fop);
|
2007-10-17 14:31:13 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
static inline void fput_light(struct file *file, int fput_needed)
|
|
|
|
{
|
2010-12-14 08:38:08 +08:00
|
|
|
if (fput_needed)
|
2005-04-17 06:20:36 +08:00
|
|
|
fput(file);
|
|
|
|
}
|
|
|
|
|
2008-02-14 07:03:15 +08:00
|
|
|
extern struct file *fget(unsigned int fd);
|
|
|
|
extern struct file *fget_light(unsigned int fd, int *fput_needed);
|
New kind of open files - "location only".
New flag for open(2) - O_PATH. Semantics:
* pathname is resolved, but the file itself is _NOT_ opened
as far as filesystem is concerned.
* almost all operations on the resulting descriptors shall
fail with -EBADF. Exceptions are:
1) operations on descriptors themselves (i.e.
close(), dup(), dup2(), dup3(), fcntl(fd, F_DUPFD),
fcntl(fd, F_DUPFD_CLOEXEC, ...), fcntl(fd, F_GETFD),
fcntl(fd, F_SETFD, ...))
2) fcntl(fd, F_GETFL), for a common non-destructive way to
check if descriptor is open
3) "dfd" arguments of ...at(2) syscalls, i.e. the starting
points of pathname resolution
* closing such descriptor does *NOT* affect dnotify or
posix locks.
* permissions are checked as usual along the way to file;
no permission checks are applied to the file itself. Of course,
giving such thing to syscall will result in permission checks (at
the moment it means checking that starting point of ....at() is
a directory and caller has exec permissions on it).
fget() and fget_light() return NULL on such descriptors; use of
fget_raw() and fget_raw_light() is needed to get them. That protects
existing code from dealing with those things.
There are two things still missing (they come in the next commits):
one is handling of symlinks (right now we refuse to open them that
way; see the next commit for semantics related to those) and another
is descriptor passing via SCM_RIGHTS datagrams.
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2011-03-13 15:51:11 +08:00
|
|
|
extern struct file *fget_raw(unsigned int fd);
|
|
|
|
extern struct file *fget_raw_light(unsigned int fd, int *fput_needed);
|
2008-02-14 07:03:15 +08:00
|
|
|
extern void set_close_on_exec(unsigned int fd, int flag);
|
2005-04-17 06:20:36 +08:00
|
|
|
extern void put_filp(struct file *);
|
2008-07-30 16:13:04 +08:00
|
|
|
extern int alloc_fd(unsigned start, unsigned flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
extern int get_unused_fd(void);
|
2008-07-30 16:13:04 +08:00
|
|
|
#define get_unused_fd_flags(flags) alloc_fd(0, (flags))
|
2008-02-14 07:03:15 +08:00
|
|
|
extern void put_unused_fd(unsigned int fd);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-02-14 07:03:15 +08:00
|
|
|
extern void fd_install(unsigned int fd, struct file *file);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#endif /* __LINUX_FILE_H */
|