Operating System - HP-UX
1832443 Members
3176 Online
110042 Solutions
New Discussion

Re: question on program use of "mount(*filesystem, *dir) always busy

 
Stephen Joyce_1
Occasional Contributor

question on program use of "mount(*filesystem, *dir) always busy

In HP-UX 9.03, I can mount through Unix
a CD device:
"mount /dev/dsk/c201d4s0 /cdrom"

however, in a C program,
"mount("/dev/dsk/c201d4s0", "/cdrom", M_RDONLY);

always returns ERRNO for busy?
6 REPLIES 6
Mark Grant
Honored Contributor

Re: question on program use of "mount(*filesystem, *dir) always busy

Your 'C' program doesn't happen to change directory to /cdrom before you try and mount it does it?
Never preceed any demonstration with anything more predictive than "watch this"
John Carr_2
Honored Contributor

Re: question on program use of "mount(*filesystem, *dir) always busy

i take it you have checked the device is not mounted before executing the c program !

also you could do a umount on the device prior to the mount or maybe test to see if the device is mounted.

John.
Stephen Joyce_1
Occasional Contributor

Re: question on program use of "mount(*filesystem, *dir) always busy

Interestingly, I can run a "system" command from the 'C' program to mount the /cdrom device under HP-UX 9.03 that does work.

However, if the device is already mounted it prints a message to the console indicating this, although it can still be accessed.

What is the best way to check to see if the device is already mounted?

If a 'umount' is done on the device and it is already unmounted, a message to the console displays an error condition too.

thank you for the replies.
A. Clay Stephenson
Acclaimed Contributor

Re: question on program use of "mount(*filesystem, *dir) always busy

The "best" way to to call the getmntent() function in a loop until either no more entries are found or until a matching entry is found indicating that the filesystem is already mounted.
If it ain't broke, I can fix that.
Stephen Joyce_1
Occasional Contributor

Re: question on program use of "mount(*filesystem, *dir) always busy

thanks for the reply.

one more issue is that under HP-UX
9.03, the C compiler I'm using
(like c89) does not allow-

(struct mnent *) variable = getmntent(fp);

with warning: "integral value implicitly
converter to pointer in assignment"

and subsequently, the structure fields
such as 'char *mnt_dir' cannot be accessed.

However, 'cc' vs 'c89' works fine?
A. Clay Stephenson
Acclaimed Contributor

Re: question on program use of "mount(*filesystem, *dir) always busy

I really don't care what compiler allows what; you coding style is terrible. At best, the code works by accident and is guaranteed to be less than portable. Avoid the whole mess with header files and proper data structures. There's a word for this: discipline.

And yes, I pull out my baseball bat to adjust programmers for this kind of stuff.
If it ain't broke, I can fix that.