hello_proc.c:
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
static int procfs_dotest(PFS_FILL_ARGS)
{
int error=0;
const char *pp;
if (uio == NULL)
{
printf("NULL Pointer\n");
return (EOPNOTSUPP);
}
printf("Check Operation\n");
if (uio->uio_rw == UIO_READ)
{
printf("read\n");
sbuf_printf(sb, "cur pid: %ld\n", (long)td->td_proc->p_pid);
}
else
{
printf("write\n");
sbuf_trim(sb);
sbuf_finish(sb);
pp = sbuf_data(sb);
printf("In: %s\n",pp);
}
return (error);
}
static int procfstest_attr(PFS_ATTR_ARGS)
{
/* XXX inefficient, split into separate functions */
vap->va_mode = 0666;
return 0;
}
static int procfstest_init(PFS_INIT_ARGS)
{
struct pfs_node *root;
root = pi->pi_root;
pfs_create_file(root, "dotest", &procfs_dotest,
procfstest_attr, NULL, NULL, PFS_RDWR|PFS_RAWWR);
return 0;
}
static int
procfstest_uninit(PFS_INIT_ARGS)
{
/* nothing to do, pseudofs will GC */
return (0);
}
PSEUDOFS(procfstest, 1);
MODULE_DEPEND(procfstest, procfs, 1, 1, 1);
Makefile:
##################################################
# Note: It is important to make sure you include
# the makefile after declaring the KMOD and SRCS variables.
# Declare Name of kernel module
KMOD = hello_proc
# Enumerate Source files for kernel module
SRCS = hello_proc.c vnode_if.h
# Include kernel module makefile
.include
##################################################
P.S.:
BSD的PROC接口不要用echo xxx>proc的方式访问,会告诉你
Operation not supported
/* we don't support locking */
if ((mode & O_SHLOCK) || (mode & O_EXLOCK))
PFS_RETURN (EOPNOTSUPP);
阅读(993) | 评论(0) | 转发(0) |