首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用挂载(2)通过afp挂载目录?

如何使用挂载(2)通过afp挂载目录?
EN

Stack Overflow用户
提问于 2017-05-26 19:50:41
回答 1查看 328关注 0票数 0

我想挂载一个驻留在我网络上另一个主机上的目录。到目前为止,我已经通过afp成功地实现了这一点,通过系统调用使用了山(8),如下所示:

代码语言:javascript
复制
std::string syscmd = "mount -v -t afp -r \"afp://user:password@host/dir\" \"/tmp/foo/bar\"";
FILE *fd;
if(!(fd = popen(syscmd.c_str(), "r"))) {
    std::cout << "oops. popen() failed." << std::endl;
    exit(1);
}    

但是,我希望使用函数调用直接挂载,而不需要使用popen()调用shell的额外开销。我不知道如何使用具有以下签名的山(2)进行此操作:

代码语言:javascript
复制
 int mount(const char *type, const char *dir, int flags, void *data);

data应该是什么?手册页面并没有详细解释这一点。例如,它说:

Data是指向包含要挂载的类型特定参数的结构的指针。这些参数结构的格式在每个文件系统的手册页中描述。

它所指的手册页在哪里?还有其他我遗漏的文件吗?有人能给我举一个简单的例子来说明如何在afp上安装(2)吗?有更好的方法吗?

EN

回答 1

Stack Overflow用户

发布于 2017-05-26 23:40:22

你有理由要求通过mount(2)来完成吗?

苹果从NetFSMountURLSync()框架中提供了NetFS函数来挂载网络文件系统。遗憾的是,唯一的文档是头文件,所以我无法链接到它,但是下面是相关的声明:

代码语言:javascript
复制
/*
 * Given a URL that refers to a file server, connect to that server
 * and mount stuff.
 *
 * If the URL just specifies a server and you can't just mount the
 * "root directory" of the server, the user will be prompted with
 * a window to let them select one or more items to mount from that
 * server, otherwise whatever item the URL specifies to mount will
 * be mounted.
 *
 * If the mountpath is provided it will be used as the mount point.
 * If the mountpath is set to NULL, a default mount point will be used.
 *
 * If the user and passwd are set, they will override any user name
 * or password that may be set in the URL. These calls go through the NetAuth agent.
 * If the URL doesn't specify a password, and one is needed, the
 * user will be prompted with a window requesting password.
 *
 * Options can be provided for the session open and the mount itself.
 * If the mount is successful, the POSIX path to each mountpoint is
 * returned as a CFStringRef in mountpoints.
 *
 * If the return value is zero the mount has succeeded.
 *
 * A positive non-zero return value represents an errno value
 * (see /usr/include/sys/errno.h).  For instance, a missing mountpoint
 * error will be returned as ENOENT (2).
 *
 * A negative non-zero return value represents an OSStatus error.
 * For instance, error -128 is userCanceledErr, returned when a mount
 * operation is canceled by the user. These OSStatus errors are
 * extended to include:
 *
 *  from this header:
 *  ENETFSPWDNEEDSCHANGE        -5045
 *  ENETFSPWDPOLICY         -5046
 *  ENETFSACCOUNTRESTRICTED     -5999
 *  ENETFSNOSHARESAVAIL     -5998
 *  ENETFSNOAUTHMECHSUPP        -5997
 *  ENETFSNOPROTOVERSSUPP       -5996
 *
 *  from <NetAuth/NetAuthErrors.h>
 *  kNetAuthErrorInternal       -6600
 *  kNetAuthErrorMountFailed    -6602
 *  kNetAuthErrorNoSharesAvailable  -6003
 *  kNetAuthErrorGuestNotSupported  -6004
 *  kNetAuthErrorAlreadyClosed  -6005
 *
 */
int
NetFSMountURLSync(
    CFURLRef url,               // URL to mount, e.g. nfs://server/path
    CFURLRef mountpath,         // Path for the mountpoint
    CFStringRef user,           // Auth user name (overrides URL)
    CFStringRef passwd,             // Auth password (overrides URL)
    CFMutableDictionaryRef open_options,    // Options for session open (see below)
    CFMutableDictionaryRef mount_options,   // Options for mounting (see below)
    CFArrayRef *mountpoints)        // Array of mountpoints
    __OSX_AVAILABLE_STARTING(__MAC_10_8, __IPHONE_NA);

如果异步版本对您的用例有用,也有异步版本。

这个答案所示,如果要指定挂载点,则需要使用kNetFSMountAtMountDirKey选项。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44209200

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档