【问题标题】:How to find the format of a disk volume如何查找磁盘卷的格式
【发布时间】:2013-02-06 14:51:36
【问题描述】:

我正在更新我在 Mac App Store 上编写并拥有的备份实用程序。

在 Macintosh Cocoa 应用程序中,我如何找到磁盘卷的格式化方式?我发现的唯一正式的事情是执行 GetResourceValue: for 'NSURLVolumeLocalizedFormatDescriptionKey',但这取决于语言。

我的实用程序不支持格式化为 FAT32 的卷。我的实用程序需要对 XSan 驱动器进行特殊处理。

【问题讨论】:

    标签: macos cocoa disk


    【解决方案1】:

    statfs(2) 会给你一个非本地化的名字:

    struct statfs volinfo;
    if(statfs("/path/to/your/volume", &volinfo) != 0)
    {
      perror("statfs");
      return -1;
    }
    
    fprintf(stderr, "%s\n", volinfo.f_fstypename);
    

    有关将在f_fstypename 中返回的名称,请参阅/System/Library/Filesystems

    【讨论】:

    • 有效!我注意到“MobileBackups”iCloud 驱动器是“mtmfs”,它不是列出的文件系统之一。将 url.path 转换为 C 字符串时,我使用什么编码?我正在使用“NSASCIIStringEncoding”。
    • 使用[[url path] fileSystemRepresentation];参看。 developer.apple.com/library/mac/#documentation/Cocoa/Reference/…
    【解决方案2】:

    这个问题已经回答了,但我会把我的 2 美分投入...

    /sbin/mount | grep acfs | awk '{print $3}'
    

    这个输出

    /Volumes/XsanVolumeName1
    /Volumes/XsanVolumeName2
    

    【讨论】:

    • 我需要找出特定卷的 格式,而不是相反,我需要在 Objective C 中进行。您向我展示了使用特定的文件系统——有趣的想法,但这不是我想要的……
    猜你喜欢
    • 2015-05-26
    • 1970-01-01
    • 1970-01-01
    • 2012-03-31
    • 1970-01-01
    • 2017-09-16
    • 1970-01-01
    • 2010-09-10
    • 1970-01-01
    相关资源
    最近更新 更多