From: "immortal1015" <immortal1015@hotpop.com>
To: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: question about ioctl and kiobuf interface
Date: Mon, 14 Oct 2002 19:29:50 +0800 [thread overview]
Message-ID: <20021014112303.65D7C2F8104@smtp-1.hotpop.com> (raw)
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
reply other threads:[~2002-10-14 11:17 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20021014112303.65D7C2F8104@smtp-1.hotpop.com \
--to=immortal1015@hotpop.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®