#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
#include
SYSCTL_DECL(_myctl);
SYSCTL_NODE(, OID_AUTO, myctl, CTLFLAG_RW, 0, "A new tree entry");
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);
}
static int
sysctl_int_sample(SYSCTL_HANDLER_ARGS)
{
static int sysctl_args = 0;
int error;
error = sysctl_handle_int(oidp, &sysctl_args, 0, req);
if (error != 0 || req->newptr == NULL) {
return sysctl_args;
}
printf("sysctlarg= %d\n",sysctl_args);
return 0;
}
static int
myctl_modevent(module_t mod, int type, void *unused)
{
switch (type) {
case MOD_LOAD:
printf("Load\n");
sysctl_register_oid(&sysctl___myctl);
break;
case MOD_UNLOAD:
printf("Unload\n");
sysctl_unregister_oid(&sysctl___myctl);
break;
default:
return EINVAL;
}
return 0;
}
static moduledata_t myctl_mod = {
"mysys",
myctl_modevent,
0
};
SYSCTL_PROC(_myctl, OID_AUTO, test_my_sysctl, CTLTYPE_INT|CTLFLAG_RW,
0, 0,
sysctl_int_sample, "I", "test sysctl ");
DECLARE_MODULE(myctlmod, myctl_mod, SI_SUB_PSEUDO, SI_ORDER_ANY);
MODULE_VERSION(myctlmod, 1);
PSEUDOFS(procfstest, 1);
MODULE_DEPEND(procfstest, procfs, 1, 1, 1);
///////////////////////////////////
////////Test Code
///////////////////////////////////
#include
#include
#include
#include
#include
int main(int argc,char* argv[] )
{
int data=0,newdata=8;;
size_t i=sizeof(data);
sysctlbyname("myctl.test_my_sysctl",&data,&i,&newdata,sizeof(newdata));
return 0;
}
阅读(1282) | 评论(0) | 转发(0) |