简体   繁体   中英

mount() failing while mounting sysfs

This is the function I am using in one of my applications:

  #include <sys/mount.h>

   void  mount_sys() {
    if (0 != mount("none", "/sys", "sysfs", 0, "")) {
     printf("there is an error in mounting \n");   /* handle error */
    }
}

The output shows:

there is an error in mounting

How do I get more information about why exactly it is failing?

OS: RHEL 6 , 64 bit

Rather than printf , you can use:

perror ("There is an error in mounting");

after the call to get the error written out to standard error, along the lines of:

There is an error in mounting: <some reason here>

Then consult the man page for mount :

man 2 mount

and it shows you the (rather lengthy) list of possibilities, such as:


EACCES : A component of a path was not searchable. (See also path_resolution(7).) Or, mounting a read-only file system was attempted without giving the MS_RDONLY flag. Or, the block device source is located on a file system mounted with the MS_NODEV option.

EBUSY : source is already mounted. Or, it cannot be remounted read-only, because it still holds files open for writing. Or, it cannot be mounted on target because target is still busy (it is the working directory of some thread, the mount point of another device, has open files, etc.).

EFAULT : One of the pointer arguments points outside the user address space.

EINVAL : source had an invalid superblock. Or, a remount (MS_REMOUNT) was attempted, but source was not already mounted on target. Or, a move (MS_MOVE) was attempted, but source was not a mount point, or was '/'.

ELOOP : Too many links encountered during pathname resolution. Or, a move was attempted, while target is a descendant of source.

EMFILE : (In case no block device is required:) Table of dummy devices is full.

ENAMETOOLONG : A pathname was longer than MAXPATHLEN.

ENODEV : filesystemtype not configured in the kernel.

ENOENT : A pathname was empty or had a nonexistent component.

ENOMEM : The kernel could not allocate a free page to copy filenames or data into.

ENOTBLK : source is not a block device (and a device was required).

ENOTDIR : target, or a prefix of source, is not a directory.

ENXIO : The major number of the block device source is out of range.

EPERM : The caller does not have the required privileges.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM