public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Olaf Dietsche <olaf.dietsche@t-online.de>
To: "anil  vijarnia" <linux_ker@rediffmail.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: writing from kernel
Date: Sun, 05 Jan 2003 01:26:19 +0100	[thread overview]
Message-ID: <87d6nccuhg.fsf@goat.bogus.local> (raw)
In-Reply-To: 20030104160255.6187.qmail@webmail28.rediffmail.com

"anil  vijarnia" <linux_ker@rediffmail.com> writes:

> can anyone tell me how to write into i file from kernel space.
> i tried sys_open,sys_write functions bbbbbut they don't work
>  from
> my module.

As others already pointed out, it's not always a good idea to do this
from kernel space. However, if you still want to do it, see snippet
below. If you want to write, you have to copy kernel_read() from
fs/exec.c and modify it for writing.

Regards, Olaf.

--cut here-->8--
#include <linux/fs.h>

struct file *filp;
unsigned long offset = 0;
char buf[1024];
int n;

filp = filp_open("/path/to/some/file", O_RDONLY, 0);
if (!filp || IS_ERR(filp)) {
   /* do some error handling */
}

n = kernel_read(filp, offset, buf, sizeof(buf));
if (n != sizeof(buf)) {
   /* do some checking */
}

filp_close(filp, 0);
--8<--cut here--

  parent reply	other threads:[~2003-01-05  0:18 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-01-04 16:02 writing from kernel anil  vijarnia
2003-01-04 16:27 ` Christian Vogel
2003-01-04 16:39 ` [PATCH] Root Raid Support for DAC960 Driver Richard Muratti
2003-01-04 22:24 ` writing from kernel Kasper Dupont
2003-01-05  0:26 ` Olaf Dietsche [this message]
  -- strict thread matches above, loose matches on Subject: below --
2003-01-04 16:05 anil  vijarnia
2003-01-04 16:11 anil  vijarnia

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=87d6nccuhg.fsf@goat.bogus.local \
    --to=olaf.dietsche@t-online.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux_ker@rediffmail.com \
    /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