android ums名字,android - Selective USB UMS-Mode - Stack Overflow

is there a way to regulate the UMS-mode? I would like to implement a feature, that lets the user select which files he wants to share with a pc. Say you only want the pc see the picture subfolder, but not all the other folders on your sd. I am not sure if this is possible and most likely I will require root access when possible.

I know this will bring no real security, because you can always remove the sd card and read all the files on it. I thought of this feature mainly because of my crappy car radio. It can read mp3 files from a usb stick. But the many different folders and strange files on a android sd card seems to kill it. Furthermore I think there are a lot of other situation when you would prefer only to show a smaller part of your sd memory to a pc.

Can you imagine any other way to simulate the described behaviour? Can I generate completely new usb modes and implement my own UMS?

Every idea is welcome.

Sincerely Erik

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在Linux中,可以使用udev来监听USB设备的插拔事件。udev是一个Linux内核的子系统,用于管理设备,包括设备的插拔和属性的变化等。下面是一个简单的示例代码,可供参考: ```C #include <stdio.h> #include <stdlib.h> #include <libudev.h> int main() { struct udev *udev; struct udev_monitor *mon; int fd; udev = udev_new(); if (!udev) { printf("udev_new() failed\n"); return 1; } mon = udev_monitor_new_from_netlink(udev, "udev"); if (!mon) { printf("udev_monitor_new_from_netlink() failed\n"); goto cleanup; } udev_monitor_filter_add_match_subsystem_devtype(mon, "usb", "usb_device"); udev_monitor_enable_receiving(mon); fd = udev_monitor_get_fd(mon); while (1) { fd_set fds; FD_ZERO(&fds); FD_SET(fd, &fds); if (select(fd + 1, &fds, NULL, NULL, NULL) <= 0) { continue; } if (FD_ISSET(fd, &fds)) { struct udev_device *dev = udev_monitor_receive_device(mon); if (dev) { const char *action = udev_device_get_action(dev); const char *devnode = udev_device_get_devnode(dev); if (action && devnode) { printf("USB device %s has been %s\n", devnode, action); } udev_device_unref(dev); } } } udev_monitor_unref(mon); cleanup: udev_unref(udev); return 0; } ``` 在这个示例代码中,我们创建了一个udev_monitor,然后添加了一个过滤器,以便只监听USB设备的插拔事件。然后,我们使用select()函数来等待事件的到来,一旦有事件到来,就调用udev_monitor_receive_device()函数来获取事件的信息。最后,我们打印相应的提示信息。 注意,运行此代码需要root权限。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值