Example 1: gjgjh
void memcpy_fromfs(void *to, const void *from, unsigned long count);
void memcpy_tofs(void *to, const void *from, unsigned long count);
Example 2: gjgjh
#ifdef LINUX_20
# ifdef MUTEX_LOCKED /* Only if semaphore.h included */
extern inline void sema_init (struct semaphore *sem, int val)
{
sem->count = val;
sem->waking = sem->lock = 0;
sem->wait = NULL;
}
# endif
#endif /* LINUX_20 */
Example 3: gjgjh
#include <devfs_fs_kernel.h>
int init_module()
{
/* request a major: does nothing if devfs is used */
result = devfs_register_chrdev(major, "name", &fops);
if (result < 0) return result;
/* register using devfs: does nothing if not in use */
devfs_register(NULL, "name", /* .... */ );
return 0;
}
Example 4: gjgjh
/*
* The following wrappers are meant to make things work with 2.0 kernels
*/
#ifdef LINUX_20
int scull_lseek_20(struct inode *ino, struct file *f,
off_t offset, int whence)
{
return (int)scull_llseek(f, offset, whence);
}
int scull_read_20(struct inode *ino, struct file *f, char *buf,
int count)
{
return (int)scull_read(f, buf, count, &f->f_pos);
}
int scull_write_20(struct inode *ino, struct file *f, const char *b,
int c)
{
return (int)scull_write(f, b, c, &f->f_pos);
}
void scull_release_20(struct inode *ino, struct file *f)
{
scull_release(ino, f);
}
/* Redefine "real" names to the 2.0 ones */
#define scull_llseek scull_lseek_20
#define scull_read scull_read_20
#define scull_write scull_write_20
#define scull_release scull_release_20
#define llseek lseek
#endif /* LINUX_20 */
Example 5: gjgjh
crw-rw-rw- 1 root root 144, 1 Jan 1 1970 0
crw-rw-rw- 1 root root 144, 2 Jan 1 1970 1
crw-rw-rw- 1 root root 144, 3 Jan 1 1970 2
crw-rw-rw- 1 root root 144, 4 Jan 1 1970 3
crw-rw-rw- 1 root root 144, 5 Jan 1 1970 pipe0
crw-rw-rw- 1 root root 144, 6 Jan 1 1970 pipe1
crw-rw-rw- 1 root root 144, 7 Jan 1 1970 pipe2
crw-rw-rw- 1 root root 144, 8 Jan 1 1970 pipe3
crw-rw-rw- 1 root root 144, 12 Jan 1 1970 priv
crw-rw-rw- 1 root root 144, 9 Jan 1 1970 single
crw-rw-rw- 1 root root 144, 10 Jan 1 1970 user
crw-rw-rw- 1 root root 144, 11 Jan 1 1970 wuser
Example 6: gjgjh
#ifdef LINUX_20
# define INODE_FROM_F(filp) ((filp)->f_inode)
#else
# define INODE_FROM_F(filp) ((filp)->f_dentry->d_inode)
#endif
Example 7: gjgjh
/*
* If private data is not valid, we are not using devfs
* so use the type (from minor nr.) to select a new f_op
*/
if (!filp->private_data && type) {
if (type > SCULL_MAX_TYPE) return -ENODEV;
filp->f_op = scull_fop_array[type];
return filp->f_op->open(inode, filp); /* dispatch to specific open */
}
/* type 0, check the device number (unless private_data valid) */
dev = (Scull_Dev *)filp->private_data;
if (!dev) {
if (num >= scull_nr_devs) return -ENODEV;
dev = &scull_devices[num];
filp->private_data = dev; /* for other methods */
}
Example 8: gjgjh
#include <linux/devfs_fs_kernel.h>
devfs_handle_t devfs_mk_dir (devfs_handle_t dir,
const char *name, void *info);
devfs_handle_t devfs_register (devfs_handle_t dir,
const char *name, unsigned int flags,
unsigned int major, unsigned int minor,
umode_t mode, void *ops, void *info);
void devfs_unregister (devfs_handle_t de);
Example 9: gjgjh
struct iovec
{
void *iov_base;
_ _kernel_size_t iov_len;
};
Example 10: gjgjh
ssize_t (*readv) (struct file *filp, const struct iovec *iov,
unsigned long count, loff_t *ppos);
ssize_t (*writev) (struct file *filp, const struct iovec *iov,
unsigned long count, loff_t *ppos);