From: Jeff Mahoney <jeffm@suse.com>
To: jenn sirp <sirpj@ecs.csus.edu>
Cc: reiserfs-list@namesys.com
Subject: Re: calling ioctl from user space
Date: Sun, 11 Apr 2004 14:39:29 -0400 [thread overview]
Message-ID: <407990E1.7060908@suse.com> (raw)
In-Reply-To: <000f01c41fe5$4f9a4a60$0533a5d1@energy>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
jenn sirp wrote:
| Hello,
|
| I am messing with ioctl() in Reiser3. I am trying to write a simple C
| program that calls the functions with the various cmd options. At the
| moment, I just want to test that I am getting into the reiser ioctl
| routines, but I am not sure I am going about this correctly.
|
| I have a Resier partition on /dev/hda6 and mounted on /mnt
| I am calling ioctl with something like ...
|
| main()
| {
| int fd;
| void * argp;
|
| fd = open("/mnt/test.txt", "w");
| ioctl(fd, REISERFS_IOC_UNPACK, argp)
| }
|
| I get various errors and have been checking errno. I get EBDAF (bad file
| descriptor) when I pass a valid 'file' file descriptor but not if I
pass '1'
| for stdout. Maybe I am going about this the wrong way...Also... if anyone
| can point me to which header files I need to include to access the right
| flags etc.. -- that would be helpful too. For some reason, no matter
what I
| #include, I am getting compiler complaints and I can't call with
| REISERFS_IOC_....etc.
|
| Sorry if this is too much of an introduction to fs programming e-mail.
Jenn -
sys_ioctl (fs/ioctl.c) handles the resolution of a file descriptor into
an internal structure that the rest of the kernel knows about. When the
file descriptor passed doesn't match anything in the file table for that
process, you get an -EBADF. This is done before the reiserfs code is
even in play. When you pass stdout, you'll make it past the file
descriptor check, but unless you're redirecting your output to a file on
a reiserfs filesystem, you're not going to run reiserfs_ioctl
eventually. Assuming you're ssh'd in or using some sort of windowing
system, your stdout will be a pseudoterminal, and you'll get the set of
ioctls associated with that driver.
The behavior you should be seeing while passing stdout to ioctl and
calling with REISERFS_IOC_UNPACK is -EINVAL.
For some reason or another, you're passing an invalid file descriptor to
ioctl when you're using a "real" file. I'm not sure if the code you've
included is pseudocode or not, but open(2) takes a different set of
arguments than fopen(3). "w" isn't a valid flag for open().
Try re-running your test with stdout and redirecting stdout to a file on
a reiserfs filesystem.
As far as including the ioctls, I'm sorry to say that there's no better
method at the moment than including <sys/ioctl.h>, followed by pasting
the ioctl #defines from include/linux/reiserfs_fs.h
There's too many kernel data structures and static inline references in
reiserfs_fs.h to be included from user space.
- -Jeff
- --
Jeff Mahoney
SuSE Labs
jeffm@suse.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iD8DBQFAeZDgLPWxlyuTD7IRAu66AJ9x5S9wVirAzSHSudFgEIzvHZAacQCfcVDa
jlm0s77TqqKn+b6M+ay0ni8=
=EhGC
-----END PGP SIGNATURE-----
prev parent reply other threads:[~2004-04-11 18:39 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-04-11 16:52 calling ioctl from user space jenn sirp
2004-04-11 18:39 ` Jeff Mahoney [this message]
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=407990E1.7060908@suse.com \
--to=jeffm@suse.com \
--cc=reiserfs-list@namesys.com \
--cc=sirpj@ecs.csus.edu \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.