Boot Linux faster!

Check our new training course

Boot Linux faster!

Check our new training course
and Creative Commons CC-BY-SA
lecture and lab materials

Bootlin logo

Elixir Cross Referencer

 * Wrapper functions for accessing the file_struct fd array.

#ifndef __LINUX_FILE_H
#define __LINUX_FILE_H

#include <asm/atomic.h>
#include <linux/posix_types.h>
#include <linux/compiler.h>
#include <linux/spinlock.h>

 * The default fd array needs to be at least BITS_PER_LONG,
 * as this is the granularity returned by copy_fdset().

 * Open file table structure
struct files_struct {
        atomic_t count;
        rwlock_t file_lock;     /* Protects all the below members.  Nests inside tsk->alloc_lock */
        int max_fds;
        int max_fdset;
        int next_fd;
        struct file ** fd;      /* current fd array */
        fd_set *close_on_exec;
        fd_set *open_fds;
        fd_set close_on_exec_init;
        fd_set open_fds_init;
        struct file * fd_array[NR_OPEN_DEFAULT];

extern void FASTCALL(fput(struct file *));
extern struct file * FASTCALL(fget(unsigned int fd));
extern void FASTCALL(set_close_on_exec(unsigned int fd, int flag));
extern void put_filp(struct file *);
extern int get_unused_fd(void);
extern void FASTCALL(put_unused_fd(unsigned int fd));

static inline struct file * fcheck_files(struct files_struct *files, unsigned int fd)
	struct file * file = NULL;

	if (fd < files->max_fds)
		file = files->fd[fd];
	return file;

 * Check whether the specified fd has an open file.
#define fcheck(fd)	fcheck_files(current->files, fd)

extern void FASTCALL(fd_install(unsigned int fd, struct file * file));
void FASTCALL(put_files_struct(struct files_struct *fs));

#endif /* __LINUX_FILE_H */