From: Jan Hudec <bulb@ucw.cz>
To: Weber Matthias <weber@faps.uni-erlangen.de>
Cc: kernelnewbies@nl.linux.org, linux-kernel@vger.kernel.org
Subject: Re: Writing data > PAGESIZE into kernel with proc fs
Date: Wed, 9 Mar 2005 16:36:23 +0100 [thread overview]
Message-ID: <20050309153620.GA30232@vagabond> (raw)
In-Reply-To: <09766A6E64A068419B362367800D50C0B58A58@moritz.faps.uni-erlangen.de>
[-- Attachment #1: Type: text/plain, Size: 2376 bytes --]
On Wed, Mar 09, 2005 at 11:26:30 +0100, Weber Matthias wrote:
> On Tue, Mar 08, 2005 at 20:05:42 +0100, Weber Matthias wrote:
> >> is there any chance to signal an EOF when writing data to kernel via proc fs? >> Actually if the length of data is N*PAGE_SIZE it seems not to be detectable.
> >> I followed up the "struct file" but haven't found anything that helped...
>
> > End-of-file is signified by closing the file. As usual.
>
> Having only this struct describing an proc entry, i have no idea on how to detect when the file is closed. For this i expect to register a callback function but where and how?
>
> struct proc_dir_entry {
> unsigned int low_ino;
> unsigned short namelen;
> const char *name;
> mode_t mode;
> nlink_t nlink;
> uid_t uid;
> gid_t gid;
> unsigned long size;
> struct inode_operations * proc_iops;
> struct file_operations * proc_fops;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
When it comes to that, you can always prepare your won file operations
instead of the default ones (that use read_proc and write_proc) below
and turn the proc entry into whatever you want.
> get_info_t *get_info;
> struct module *owner;
> struct proc_dir_entry *next, *parent, *subdir;
> void *data;
> read_proc_t *read_proc;
> write_proc_t *write_proc;
> atomic_t count; /* use count */
> int deleted; /* delete flag */
> };
The simple way of working with proc files is to have userland just fill
in the buffer and process that buffer when you need to, not when the
userland sends the data. So you just take the "data" buffer when you
need it.
When you need something more fancy, you simply create your own
proc_fops. That has read and write functions, where you need to take
care of the offset yourself, but you can treat each open separately
(open is called when userland process opens your proc entry and IIRC
fput or release or something like that when it closes it (you do NOT
want "close" -- that might be called more than once for one open)), turn
it into character-device-alike, implement ioctl, implement select/poll
on your entry and other fancy stuff.
Of course, you can copy the default proc_fops and only implement the
ones you actualy need different.
-------------------------------------------------------------------------------
Jan 'Bulb' Hudec <bulb@ucw.cz>
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
next prev parent reply other threads:[~2005-03-09 15:40 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-03-09 10:26 Writing data > PAGESIZE into kernel with proc fs Weber Matthias
2005-03-09 15:36 ` Jan Hudec [this message]
-- strict thread matches above, loose matches on Subject: below --
2005-03-08 19:05 Weber Matthias
2005-03-08 21:18 ` Jan Hudec
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=20050309153620.GA30232@vagabond \
--to=bulb@ucw.cz \
--cc=kernelnewbies@nl.linux.org \
--cc=linux-kernel@vger.kernel.org \
--cc=weber@faps.uni-erlangen.de \
/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