3

我在 OSX 中创建了一个不区分大小写的文件系统(使用 OSXFuse)。但是,当我尝试使用 来检查卷的不区分大小写时NSURLVolumeSupportsCaseSensitiveNamesKey,它报告为区分大小写。我的问题是,我需要在 OSX 上做什么,以便当我使用 检查区分大小写时NSURLVolumeSupportsCaseSensitiveNamesKey,它会正确地将我的文件系统报告为不区分大小写?

贝娄是我所做的更多细节:

这就是我用来NSURLVolumeSupportsCaseSensitiveNamesKey检查不区分大小写的方式:

NSString *path = @"/Volumes/MyVolume";
NSURL *file_system = [NSURL fileURLWithPath:path isDirectory:YES];
NSNumber *case_sensitive_fs;
BOOL has_case_sensitive_resource = [file_system getResourceValue:&case_sensitive_fs
                                                          forKey:NSURLVolumeSupportsCaseSensitiveNamesKey
                                                           error:NULL];
if (!has_case_sensitive_resource) {
  LOG("Has no case sensitive resource");
} else {
  if ([case_sensitive_fs intValue] ==1) {
    LOG("This is case sensitive file system");
  } else {
    LOG("This is case insensitive file system");
  }
}

请注意,当我使用 时getattrlist,它正确报告我的文件系统不区分大小写:

    typedef struct volume_capabilities_result {
      u_int32_t length;
      vol_capabilities_attr_t volume_capability;
    } VolumeCapabilitiesResult;
//...
    struct attrlist list = { 0 };
    list.bitmapcount = ATTR_BIT_MAP_COUNT;
    list.reserved = 0;
    list.volattr = ATTR_VOL_INFO | ATTR_VOL_CAPABILITIES;

    VolumeCapabilitiesResult volumeCapResult;
    int result = getattrlist("/Volumes/MyVolume", &list, &volumeCapResult, sizeof(volumeCapResult), 0);
    if (result != -1 &&
        (volumeCapResult.volume_capability.valid[VOL_CAPABILITIES_FORMAT] & VOL_CAP_FMT_CASE_SENSITIVE) != 0) {
      bool case_senstive = (volumeCapResult.volume_capability.capabilities[VOL_CAPABILITIES_FORMAT] &
                                    VOL_CAP_FMT_CASE_SENSITIVE) != 0;
      if (case_senstive) {
        LOG("getattrlist said we are case sensitive");
      } else {
        LOG("getattrlist said we are case insensitive");
      }
    }

我相信getattrlist报告正确,因为我使用 osxfuse 来实现 fuse_operations.init 如下:

void fuse_init(void* user_data, struct fuse_conn_info* conn) {
  conn->want |= FUSE_CAP_CASE_INSENSITIVE;
}
4

1 回答 1

0

您确定您的路径在第一个代码片段中是正确的,即开头缺少的斜杠吗?

NSString *path = @"Volumes/MyVolume";

除此之外,这段代码似乎对我有用。

于 2017-11-28T00:14:07.537 回答