07-28-04 11:19 PM
Hi,
I am currently writing a Unix software ( Unix means "Unix portable") and
i'm facing a problem with writing data on a floppy as a simple user.
I'v given below a working example of what my problem is.
As a user the program answers :
# ./main
mount failed : Operation not permitted.
umount failed : Invalid argument.
Though as root it succeeds and replies:
# su -c ./main
Password:
mount succeeded.
umount succeeded.
What embarasses me, is that in /etc/fstab i can add the option "user" to
the floppy entry:
/dev/fd0 /mnt/floppy auto noauto,user,kudzu 0 0
and then in a shell as a user I can succesfully do "mount /mnt/floppy".
So I was wondering how to do the same in a C program WITHOUT making a
system("mount /mnt/floppy") call as far as i wan't to check the return
value of the mounting operation to be able to detect if there is a
floppy in the drive or not, not being able to write the file if the user
retrieves the floppy too fast...
Does anyone know how to do that?
Thanks by advance.
--
Dalbosco
Jean-François
#include <stdio.h>
#include <string.h>
#include <sys/mount.h>
#include <errno.h>
static void
check_error_ret(int ret, const char* szCmd)
{
if( -1 == ret )
{
printf("%s failed : %s.\n", szCmd, strerror(errno));
}
else
{
printf("%s succeeded.\n", szCmd);
}
}
int
main(int argc, char** argv)
{
int ret = 0;
ret = mount("/dev/fd0", "/mnt/floppy", "vfat", MS_MGC_VAL, "");
check_error_ret(ret, "mount");
ret = umount("/mnt/floppy");
check_error_ret(ret, "umount");
}
[ Post a follow-up to this message ]
|