File Operations

A few of the file operations have different prototypes in 2.1 than they had in 2.0. This is mainly due to the upcoming need to handle files whose size can’t fit in 32 bits. The differences are handled by the header sysdep-2.1.h, which defines a few pseudo-types according to the kernel version being used. The only serious innovation introduced in the file operations is the poll method, which replaces select with a completely different implementation.

Prototype Differences

Four file operations feature a new prototype; they are:

long long (*llseek) (struct inode *, struct file *, long long, int);
long (*read) (struct inode *, struct file *, char *, unsigned long);
long (*write) (struct inode *, struct file *, const char *,
               unsigned long);
int (*release) (struct inode *, struct file *);

The 2.0 counterparts were:

int (*lseek) (struct inode *, struct file *, off_t, int);
int (*read) (struct inode *, struct file *, char *, int);
int (*write) (struct inode *, struct file *, const char *, int);
void (*release) (struct inode *, struct file *);

The difference, as you see, lies in their return values (which allow for a greater range), and the count and offset arguments. The header sysdep-2.1.h handles the differences by defining the following macros:

read_write_t

This macro expands to the type of the count argument and the return value of read and write.

lseek_t

This macro expands to the return value’s type in llseek. The change in the method’s name (from lseek to llseek ...

Get Linux Device Drivers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.