gpt4 book ai didi

c - 如何使用C获取系统中连接的所有USB可移动存储的列表?

转载 作者:行者123 更新时间:2023-11-30 15:57:31 31 4
gpt4 key购买 nike

我正在编写一个程序,它将复制 USB 可移动存储中的一些文件。所以我需要所有可用可移动存储的列表。我正在使用 C。可移植性是首选。

最佳答案

Possibly libusbx

libusbx is a library that provides generic access to USB devices. As a library, it is meant to be used by developers, to facilitate the development of applications that communicate with USB hardware.

It is portable: Using a single cross-platform API, it provides access to USB devices on Linux, OS X, Windows and OpenBSD.

It is user-mode: No special privilege or elevation is required for the application to communicate with a device.

It is version-agnostic: All versions of the USB protocol, from 1.0 to 3.0 (latest), are supported.

参见libusb_get_device_list

libusb_context * usb_ctx = NULL;

int main()
{
...
libusb_init(&usb_ctx);
...
libusb_exit(usb_ctx);
...
}

some_func()
{
...
libusb_device **list;
ssize_t number_of_devices = libusb_get_device_list(usb_ctx, &list);
...
}

(警告我在网上找到了这个,我没有个人经验,代码尚未经过测试,看来使用前需要调用libusb_init/libusb_exit,请参阅

*http://libusbx.sourceforge.net/api-1.0/group__lib.html*

http://libusbx.sourceforge.net/api-1.0/contexts.html.h

关于c - 如何使用C获取系统中连接的所有USB可移动存储的列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10443969/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com