gpt4 book ai didi

c - 安装 sysfs 时 mount() 失败

转载 作者:行者123 更新时间:2023-11-30 15:34:05 25 4
gpt4 key购买 nike

这是我在我的一个应用程序中使用的函数:

  #include <sys/mount.h>

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

输出显示:

there is an error in mounting

如何获取有关失败原因的更多信息?

操作系统:RHEL 6,64 位

最佳答案

除了 printf,您还可以使用:

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

在调用将错误写入标准错误之后,大致如下:

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

然后查阅mount的手册页:

man 2 mount

它会向您显示(相当长的)可能性列表,例如:

<小时/>

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.

关于c - 安装 sysfs 时 mount() 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23442807/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com