mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-23 02:05:57 +01:00
Anonymous inode!
This commit is contained in:
40
kernel_module/user/anonymous_inode.c
Normal file
40
kernel_module/user/anonymous_inode.c
Normal file
@@ -0,0 +1,40 @@
|
||||
#define _GNU_SOURCE
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h> /* sleep */
|
||||
|
||||
#include "../anonymous_inode.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
char buf[1024];
|
||||
int fd_ioctl, fd_ioctl_anon, ret;
|
||||
|
||||
if (argc < 2) {
|
||||
puts("Usage: ./prog <ioctl-file>");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
fd_ioctl = open(argv[1], O_RDONLY);
|
||||
if (fd_ioctl == -1) {
|
||||
perror("open");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
ret = ioctl(fd_ioctl, LKMC_ANONYMOUS_INODE_GET_FD, &fd_ioctl_anon);
|
||||
if (ret == -1) {
|
||||
perror("ioctl");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
ret = read(fd_ioctl_anon, buf, sizeof(buf));
|
||||
printf("%.*s\n", ret, buf);
|
||||
sleep(1);
|
||||
ret = read(fd_ioctl_anon, buf, sizeof(buf));
|
||||
printf("%.*s\n", ret, buf);
|
||||
close(fd_ioctl_anon);
|
||||
close(fd_ioctl);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -15,8 +15,8 @@ int main(int argc, char **argv)
|
||||
int fd, arg_int, ret;
|
||||
lkmc_ioctl_struct arg_struct;
|
||||
|
||||
if (argc < 4) {
|
||||
puts("Usage: ./prog <ioctl-file> <cmd> <arg>");
|
||||
if (argc < 2) {
|
||||
puts("Usage: ./prog <ioctl-file>");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
fd = open(argv[1], O_RDONLY);
|
||||
|
||||
Reference in New Issue
Block a user