IOKit和DiskArbitration框架可以告诉我很多关于mac上挂载卷的事情,但它们似乎无法区分HFS +和HFS标准卷.
由于IOKit/DA键Content,DAVolumeKind并且DAMediaContent总是Apple_HFS和两个HFS标准和HFS +卷HFS.
diskutil和DiskUtility.app 可以区分,但我似乎没有Apple开源.
ps statfs(2)没有区分
我使用函数“IOPMSchedulePowerEvent”来安排睡眠或唤醒事件,并使用“IORegisterForSystemPower”注册我的守护进程以接收电源状态变化。一切正常!
当系统进入睡眠状态然后在预定时间醒来时,我的守护进程会做一些工作,然后系统应该再次进入睡眠状态。
现在我的问题:
我如何检测系统是被用户唤醒还是按预定时间唤醒?
我如何检测用户当前是否在使用系统,因此守护程序不必将其置于睡眠模式???
谢谢诺比克
matchingDict = IOServiceMatching(kIOUSBDeviceClassName);
numberRef = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &vendorId);
CFDictionarySetValue(matchingDict, CFSTR(kUSBVendorID), numberRef);
CFRelease(numberRef);
numberRef = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &deviceProductId);
CFDictionarySetValue(matchingDict, CFSTR(kUSBProductID), numberRef);
CFRelease(numberRef);
numberRef = NULL;
kr = IOServiceAddMatchingNotification(gNotifyPort,
kIOFirstMatchNotification,
matchingDict,
DeviceAdded,
NULL,
&gAddedIter);
Run Code Online (Sandbox Code Playgroud)
为了在将USB设备添加到Mac PC时处理通知是可以的,但是当用户按下USB设备上的按钮时,我能获得信号吗?
谢谢大家!
我正在尝试在 MAC OSX 下发现 USB 大容量存储设备。我希望获得设备类别,并在此基础上决定该设备是否是大容量存储。但是,对于我拥有的所有 USB 闪存驱动器,我得到的设备类 == 0,这似乎是一个复合设备。请帮助我弄清楚我做错了什么,或者,也许还有什么其他可靠的方法来发现 USB 大容量存储设备(我需要获取 PID、VID 和安装点)。这是我的代码:
#import <iostream>
#import <IOKit/IOkitLib.h>
#import <IOKit/usb/IOUSBLib.h>
#import <IOKit/IOCFPlugIn.h>
#import <IOKit/usb/USBSpec.h>
#import <CoreFoundation/CoreFoundation.h>
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
CFMutableDictionaryRef matchingDictionary = NULL;
io_iterator_t foundIterator = 0;
io_service_t usbDevice;
matchingDictionary = IOServiceMatching(kIOUSBDeviceClassName);
IOServiceGetMatchingServices(kIOMasterPortDefault, matchingDictionary, &foundIterator);
for(usbDevice = IOIteratorNext(foundIterator); usbDevice; usbDevice = IOIteratorNext(foundIterator))
{
IOCFPlugInInterface** plugin = NULL;
SInt32 theScore=0;
IOReturn err;
err = IOCreatePlugInInterfaceForService(usbDevice, kIOUSBDeviceUserClientTypeID, kIOCFPlugInInterfaceID, &plugin, &theScore);
if (err!= 0){
std::cout<<"error, error …Run Code Online (Sandbox Code Playgroud) 我通过以下方式在I/O Kit驱动程序模板中编写代码:
#include <IOKit/IOService.h>
class com_osxkernel_driver_IOKitTest : public IOService
{
OSDeclareDefaultStructors(com_osxkernel_driver_IOKitTest)
public:
virtual bool init (OSDictionary* dictionary = NULL);
virtual void free (void);
virtual IOService* probe (IOService* provider, SInt32* score);
virtual bool start (IOService* provider);
virtual void stop (IOService* provider);
};
#include "IOKitTest.h"
#include <IOKit/IOLib.h>
#define super IOService
OSDefineMetaClassAndStructors(com_osxkernel_driver_IOKitTest, IOService)
bool com_osxkernel_driver_IOKitTest::init (OSDictionary* dict)
{
bool res = super::init(dict);
IOLog("IOKitTest::init\n");
return res;
}
void com_osxkernel_driver_IOKitTest::free(void)
?{
IOLog("IOKitTest::free\n");
super::free();
}
IOService* com_osxkernel_driver_IOKitTest::probe (IOService* provider, SInt32* score)
{
IOService *res = super::probe(provider, …Run Code Online (Sandbox Code Playgroud)