mount函数失败!

风吹草低现羊牛 2012-08-25 12:04:26
例如在shell中: mount /dev/sdd1 /mnt/test (这样子能够成功)

如果在程序中: mount("/dev/sdd1", "/mnt/test", "ext2", 0, ""); 这样总是错误的。

不知道是什么原因!


(终于发出来了,不容易啊!)
...全文
501 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
昵称很不好取 2012-08-25
  • 打赏
  • 举报
回复
看看出了什么错误:
On success, zero is returned. On error, -1 is returned, and errno is set
appropriately.

The error values given below result from filesystem type independent
errors. Each file-system type may have its own special errors and its own
special behavior. See the kernel source code for details.

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.
昵称很不好取 2012-08-25
  • 打赏
  • 举报
回复
看看出了什么错误:
On success, zero is returned. On error, -1 is returned, and errno is set
appropriately.

The error values given below result from filesystem type independent
errors. Each file-system type may have its own special errors and its own
special behavior. See the kernel source code for details.

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.
昵称很不好取 2012-08-25
  • 打赏
  • 举报
回复
看看出了什么错误:
The error values given below result from filesystem type independent
errors. Each file-system type may have its own special errors and its own
special behavior. See the kernel source code for details.

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.
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 的回复:]

16指device or resource busy
19指no such device
[/Quote]

我知道呀,但是无论怎么搞还是不能成功,表示很纠结!
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 的回复:]

16指device or resource busy
19指no such device
[/Quote]

我知道呀,但是无论怎么搞还是不能成功,表示很纠结!
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 的回复:]

16指device or resource busy
19指no such device
[/Quote]

我知道呀,但是无论怎么搞还是不能成功,表示很纠结!
fdl19881 2012-08-25
  • 打赏
  • 举报
回复
16指device or resource busy
19指no such device
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 的回复:]

看看出了什么错误:
On success, zero is returned. On error, -1 is returned, and errno is set
appropriately.

The error values given below result from filesystem type independent
erro……
[/Quote]
[Quote=引用 6 楼 的回复:]

C/C++ code
if(mount("/dev/sdd1", "/mnt/test", "ext2", 0, "") < 0) {
perror("mount error"); //观察这句的输出,然后把错误原因帖出来。
exit(-1);
}
[/Quote]

我用了 errno 输出了。 不是 16 就是19 很是纠结的问题! 在shell里面又不会出现这种问题!
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 的回复:]

看看出了什么错误:
On success, zero is returned. On error, -1 is returned, and errno is set
appropriately.

The error values given below result from filesystem type independent
erro……
[/Quote]
[Quote=引用 6 楼 的回复:]

C/C++ code
if(mount("/dev/sdd1", "/mnt/test", "ext2", 0, "") < 0) {
perror("mount error"); //观察这句的输出,然后把错误原因帖出来。
exit(-1);
}
[/Quote]

我用了 errno 输出了。 不是 16 就是19 很是纠结的问题! 在shell里面又不会出现这种问题!
fdl19881 2012-08-25
  • 打赏
  • 举报
回复
if(mount("/dev/sdd1", "/mnt/test", "ext2", 0, "") < 0) {
perror("mount error"); //观察这句的输出,然后把错误原因帖出来。
exit(-1);
}
fdl19881 2012-08-25
  • 打赏
  • 举报
回复
if(mount("/dev/sdd1", "/mnt/test", "ext2", 0, "") < 0) {
perror("mount error"); //观察这句的输出,然后把错误原因帖出来。
exit(-1);
}
fdl19881 2012-08-25
  • 打赏
  • 举报
回复
请在mount函数调用改成:
if(mount(("/dev/sdd1", "/mnt/test", "ext2", 0, "") < 0) {
perror("mount error"); //观察这句的输出,然后把错误原因帖出来。
exit(-1);
}

23,120

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧