首页 文章

* OSX / UNIX *测试文件是否安装在本地安装的驱动器上,而安装了AFP / SMB?

提问于
浏览
0

我正在开发一个自动化数据集多机处理的应用程序 .

在主计算机(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)

我正在寻求帮助来解析这些信息:

  • 测试文件是否安装在AFP上

  • 如果为true,则提取URL(afp://NAS._afpovertcp._tcp.local/NAS/Documents/file.zip)

有线索吗?

加分点:检索网络卷的IP地址!

2 回答

  • 1

    基于此link

    您应该可以从以下(未经测试)中解决问题 .

    #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 .

  • 0

    问题解决了 !

    我设法使用 df 提取挂载点,然后针对源自 mount 的AFP挂载卷列表进行测试 . 整个事情正在使用 grepawk 进行清理和管理 .
    是一次很好的学习练习 .

    所以这允许:

    • 测试文件是本地文件还是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
    

相关问题