* question about ioctl and kiobuf interface
@ 2002-10-14 11:29 immortal1015
0 siblings, 0 replies; only message in thread
From: immortal1015 @ 2002-10-14 11:29 UTC (permalink / raw)
To: linux-kernel
Hi, all. The question is somewhat out of the topics here.
I am trying to use kiobuf interface in my module.
In module, I use create_proc_entry(PROC_FILE_NAME, 0, NULL) to create an entry
named "/proc/test". In my application, first open the file "/proc/test" to get a handle,
and then use malloc to allocate some memory, then use ioctl method to pass the memory address to my module. The codes as following:
/////////////////////////////////////////////////
//application codes:
int main()
{
int file_desc, ret_val;
unsigned char *buf;
file_desc = open(DEVICE_FILE_NAME, O_RDONLY);
buf = (unsigned char *)malloc(TEST_SIZE);
printf("malloc: %d\n", buf);
ioctl(file_desc, SM_IOC_SHAREMEM, buf);
printf(buf);
printf("\r\n");
close(file_desc);
free(buf);
printf("Goodbye\n");
exit(0);
}
/////////////////////////////////////////
The ioctl interface provided by my module is as following:
int sm_ioctl(struct inode *inode, struct file *filp,
unsigned int cmd, unsigned long arg)
{
int ret;
switch(cmd)
{
case SM_IOC_SHAREMEM:
{
printk("<1>buf address is %d\n", (unsigned char *)arg);
sm_test_kiobuf(arg);
ret = SUCCESS;
}
break;
default:
ret = SUCCESS;
break;
}
return ret;
}
void sm_test_kiobuf(unsigned long userbuf)
{
//KernelBuff is a global viriable defined as
//unsigned char KernelBuff[12];
memcpy((unsigned char *)userbuf, KernelBuff, 12);
}
///////////////////////////////////////////////////////////////////////////////
The module and the application work fine. That means I can manipulate user space buffer
directory in my module's ioctl interface. And then why use KIOBUF interfaces?
What is wrong with my concepts?
Please give me advices.
Thanks
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2002-10-14 11:17 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-10-14 11:29 question about ioctl and kiobuf interface immortal1015
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®