以编程方式检测与已安装体积的连接类型 [英] Programmatically detect type of connection to mounted volume

查看:73
本文介绍了以编程方式检测与已安装体积的连接类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在本地文件系统和已安装文件系统之间复制文件,其中已安装系统可以是USB,FireWire,AFP或远程服务器.我需要确定已安装的卷正在使用哪种与计算机的连接.我可以使用 statfs 系统调用以识别要安装的文件系统类型,但是我无法弄清楚如何识别连接类型(FireWire,Wifi,eth,USB ...).我用来识别文件系统的代码是:

I am copying files between local and mounted filesystems where the mounted systems can be USB, FireWire, AFP, or remote servers. I need to identify what sort of connection to the computer the mounted volume is using. I can use the statfs system call to identify what sort of filesystem that is mounted, but I am unable to figure out how to identify the type of connection (FireWire, Wifi, eth, USB...). My code to identify the filesystem is:

-(void) getVolumeInfo:(NSURL *) myurl
{
    struct statfs buf;
    statfs([myurl.path UTF8String], &buf);
    NSLog(@"Filesystem type: %s mounted filesystem: %s mounted as:  %s",buf.f_fstypename,buf.f_mntfromname,buf.f_mntonname);
}

这将为我的笔记本电脑硬盘驱动器和NAS服务器提供以下输出.

Which gives the following output for my laptop harddrive and my NAS server.

Filesystem type: hfs mounted filesystem: /dev/disk0s2 mounted as: /
Filesystem type: afpfs mounted filesystem: //Trond%20Kristiansen@HerlighetNASserver._afpovertcp._tcp.local/home mounted as: /Volumes/home

我的问题是:1)有人知道我如何通过代码识别例如NAS服务器如何连接(wifi或网络电缆)2)反正我还能检测到连接速度吗?

My questions are: 1) Does anyone know how I can identify through code how for example the NAS server is connected (wifi or network cable) 2) Is there anyway I can detect the connection speed?

谢谢!

推荐答案

要确定连接的类型(当前处于活动状态的接口),您可以使用 SCNetworkConfiguration 中的某些功能可能提供有关当前活动界面的信息...似乎在

To determine the type of connection (currently active interface), you may be able to use the System Configuration Framework. Some of the functions in SCNetworkConfiguration may provide information on the currently active interface...It appears that there are some throughput/statistics functions defined in the SCNetworkConnection, but they appear to apply to PPP connection types.

您还可以在

You may also find some helpful methods in NSWorkspace, but it seems like you may have the filesystem information covered.

#import <Foundation/Foundation.h>
#import <AppKit/NSWorkspace.h>

int main(int argc, const char * argv[])
{

    @autoreleasepool {
    BOOL isRemovable, isWritable, isUnmountable;
    NSString *description, *type;

    [[NSWorkspace sharedWorkspace] getFileSystemInfoForPath:@"/Volumes/Users"
                                                        isRemovable:&isRemovable
                                                         isWritable:&isWritable
                                                      isUnmountable:&isUnmountable
                                                        description:&description
                                                               type:&type];

    NSLog(@"Filesystem description:%@ type:%@ removable:%d writable:%d unmountable:%d", description, type, isRemovable, isWritable, isUnmountable);

    }
    return 0;
}

这篇关于以编程方式检测与已安装体积的连接类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆