lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date:	Fri, 12 Jan 2007 15:47:32 +0800
From:	"congwen" <congwen@...il.com>
To:	"linux-kernel" <linux-kernel@...r.kernel.org>
Subject: How can I create or read/write a file in linux device driver?

Hello everyone, I want to create and read/write a file in Linux kernel or device driver, I have write some code, the file could be created successfully, but it can not be wrote in anything, the function "write" always return a negative number, the content of the file is still empty. The following code is what I wrote in my device driver, the code reference the function sys_open() in open.c and sys_write() in read_write.c, please give me a help, thanks!

struct file *filp;
char testbuf[100] = {0};
char *ptestbuf = NULL;
ssize_t count = 0;
ssize_t ret = 0;
int ii = 0;
   
filp = filp_open("/logfile", O_CREAT | O_WRONLY | O_TRUNC, 0666);
if (IS_ERR(filp))
   printk("<0>Create record file error!\n\r");
for(ii = 0; ii < 100; ii++)
   testbuf[ii] = 1;
ptestbuf = testbuf;

if (filp->f_mode & FMODE_WRITE) 
{
   struct inode *inode = filp->f_dentry->d_inode;
   ret = locks_verify_area(FLOCK_VERIFY_WRITE, inode, filp, filp->f_pos, count);
   if (!ret) 
   {
      ssize_t (*write)(struct file *, const char *, size_t, loff_t *);
      if (filp->f_op && (filp->f_op->write) != NULL) 
      {
         write = filp->f_op->write;
         count = 99;
         ret = write(filp, (const char *)ptestbuf, count, &filp->f_pos);
         printk("<0>After write, ret = %d   \n\r");
      }
   }
}

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ