views:

433

answers:

5

Has someone maybe a good source where all available file operations like fopen, fread, mkdir, etc are described? When I am googleing for Linux file operations most pages explain me how the filesystem hierarchy looks like.

+1  A: 

Yep -- use the man pages. man fopen, man fread, man mkdir, etc., will describe the usage of those functions. Many man pages also have a "See Also" section that will direct you to the man pages of related functions, sort of like a primitive Wikipedia. :)

mipadi
Thanks, but I would like to have an overview over all the existing linux file system functions like fopen, fread, mkdir, chown etc
+2  A: 

I 'm not sure if this helps, but this is directly out of the kernel source:

struct file_operations {
    struct module *owner;
    loff_t (*llseek) (struct file *, loff_t, int);
    ssize_t (*read) (struct file *, char *, size_t, loff_t *);
    ssize_t (*write) (struct file *, const char *, size_t, loff_t *);
    int (*readdir) (struct file *, void *, filldir_t);
    unsigned int (*poll) (struct file *, struct poll_table_struct *);
    int (*ioctl) (struct inode *, struct file *, unsigned int, unsigned long);
    int (*mmap) (struct file *, struct vm_area_struct *);
    int (*open) (struct inode *, struct file *);
    int (*flush) (struct file *);
    int (*release) (struct inode *, struct file *);
    int (*fsync) (struct file *, struct dentry *, int datasync);
    int (*fasync) (int, struct file *, int);
    int (*lock) (struct file *, int, struct file_lock *);
    ssize_t (*readv) (struct file *, const struct iovec *, unsigned long, loff_t *);
    ssize_t (*writev) (struct file *, const struct iovec *, unsigned long, loff_t *);
    ssize_t (*sendpage) (struct file *, struct page *, int, size_t, loff_t *, int);
    unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
};

Filesystems generally register all their implementations to these callbacks.

Jeremy Powell
That looks quite interesting, thanks for that!
These are lower level than you'll often want. Some of these functions don't seem to be accessible from userland, and as a userland developer, you'll often be using functions like fopen and fread that are implemented in libc rather than the kernel.
Josh Kelley
Yeah, probably got a little carried away. But at least it contributes to the answer in some small way :)
Jeremy Powell
+5  A: 

The functions you're asking about actually fall under several categories - file stream I/O (fopen, fread, etc.), lower-level file descriptor I/O (open, read, etc.), and filesystem/directory manipulation (chown, mkdir, etc.).

For an overview of file stream I/O functions, see man stdio.

For searching Google, try "posix file api" instead of "linux file operations."

You can also check the GNU C Libary Manual:

Josh Kelley
+1 for the tip about `man stdio`, which I didn't know about.
mipadi
neither did I. Great stuff
Jeremy Powell
A: 

use man 2 open and man 2 mkdir. at the bottom of this man pages are the name of related command.

Alternatively, if you search a browseable version of this man pages, you can try here

shodanex
+1  A: 

There a several file operations APIs on different levels of the stack, e.g. POSIX API, Standard C API, Linux VFS API (as Jeremy mentioned), and the FUSE API. All the APIs do more or less the same thing, but the details are very different.

These two APIs are the most important for the normal user.

A good book about the topic is "Advanced Programming in the UNIX Environment" by Stevens and Rago

dmeister