代码之家  ›  专栏  ›  技术社区  ›  robottobor

如何判断Mac OS X中是否安装了给定路径的可移动媒体?

  •  3
  • robottobor  · 技术社区  · 16 年前

    1 回复  |  直到 16 年前
        1
  •  6
  •   nall    16 年前

    看看苹果的 VolumeToBSDNode 示例代码。我相信它应该有你需要的代码位。

    描述

    显示如何遍历所有已装入的卷,并检索每个卷的BSD节点名(/dev/disk*)。该信息用于确定卷是否位于CD、DVD或其他存储介质上。

    PBHGetVolParmsSync 本例中的调用已弃用。以下是使用较新功能的区别:

    -            HParamBlockRec pb;
    
    -            // Use the volume reference number to retrieve the volume parameters. See the documentation
    -            // on PBHGetVolParmsSync for other possible ways to specify a volume.
    -            pb.ioParam.ioNamePtr = NULL;
    -            pb.ioParam.ioVRefNum = actualVolume;
    -            pb.ioParam.ioBuffer = (Ptr) &volumeParms;
    -            pb.ioParam.ioReqCount = sizeof(volumeParms);
    -            
    -            // A version 4 GetVolParmsInfoBuffer contains the BSD node name in the vMDeviceID field.
    -            // It is actually a char * value. This is mentioned in the header CoreServices/CarbonCore/Files.h.
    -            result = PBHGetVolParmsSync(&pb);
    +            // Use FSGetVolumeParms instead of the deprecated PBHGetVolParmsSync
    +            result = FSGetVolumeParms(actualVolume, &volumeParms, sizeof(volumeParms));
    +