[英]*OSX/UNIX* Testing if a file is on a locally mounted drive vs. AFP/SMB mounted?
我正在开发一个可自动对数据集进行多机处理的应用程序。
用户从主计算机(192.168.1.2)中选择要处理的文件/文件夹。
然后,确切的文件路径将与LAN网络上的所有从属计算机共享。
只要文件在本地驱动器上,一切都很好,共享文件路径如下所示:
afp://192.168.1.2/Volumes/LOCAL_DRIVE/Projects/file.zip
但是,如果用户选择存储在AFP安装的驱动器(例如NAS)上的文件,则无法检索完整的文件路径。
因此,我能够获取已挂载的文件路径:
/Volumes/NAS/Documents/file.zip
我可以得到已安装驱动器的列表:
mbp:~ myself$ mount
/dev/disk0s2 on / (hfs, local, journaled)
devfs on /dev (devfs, local, nobrowse)
/dev/disk1s2 on /Volumes/LOCAL_DRIVE (hfs, local, journaled)
map -hosts on /net (autofs, nosuid, automounted, nobrowse)
map auto_home on /home (autofs, automounted, nobrowse)
localhost:/ndtfxrIYDV1dU5kiwHMwAy on /Volumes/MobileBackups (mtmfs, nosuid, read-only, nobrowse)
//AdminNas@NAS._afpovertcp._tcp.local/NAS on /Volumes/NAS (afpfs, nodev, nosuid, mounted by myself)
//AdminUser@Remote_MacPro._afpovertcp._tcp.local/DATA on /Volumes/DATA (afpfs, nodev, nosuid, mounted by myself)
我正在寻求帮助将这些信息解析为:
有什么线索吗?
+奖励点:检索网络容量的IP地址!
基于此链接
您应该能够从以下内容中解决问题(未尝试)。
#include <sys/param.h>
#include <sys/mount.h>
#include <stdio.h>
int main(int argc, char* argv[])
{
struct statfs buf;
if (statvfs("/tmp", &buf) == 0){
printf("filesystem typeid: %d\n", buf.f_type);
printf("filesystem type: %s\n", buf.f_fstypename);
}
return 0;
}
据推测,如果它不是本地文件系统,则不会是HFS。
问题解决了 !
我设法使用df
提取了挂载点,然后针对通过mount
来源的AFP挂载卷的列表对其进行了测试。 使用grep
和awk
清理和管理整个事情。
是一个很好的学习练习。
因此,这允许:
-测试文件是本地文件还是AFP挂载(远程)
-相应地传递文件路径
#!bin/bash
## Input as arguments, only one file or folder, with absolute filepath including "/Volumes/..."
## Get a nice $AFP_list of AFP-mounted volumes
AFP_list=$(mount |grep "afpfs" |awk {'print $1'})
## Get $base_volume of our input file
base_volume=$(df -PH "$1" |grep "%" |awk {'print $1'})
## Check if $base_volume is part of $AFP_list
if grep -q "$base_volume" <(echo "$AFP_list"); then
## If TRUE, deliver the network volume filepath
echo "afp:$base_volume"
## If FALSE, deliver the original filepath
else
echo "$1"
fi
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.