您尚未登录。

楼主 #1 2019-07-08 16:52:53

tom
会员
注册时间: 2018-03-14
已发帖子: 128
积分: 127.5

g_file_storage的同步问题

在n32926上面用g_file_storage.ko可以实现虚拟U盘功能。

基本操作没有问题,但是存在一个同步问题,比如,在pc端对某文件进行了删除操作,此时如果不重新插拔,在arm端仍然会认为该文件存在。

是不是g_file_storage设计上就是这样的?还是有什么办法设置下,让文件删除、修改等操作能立即同步到arm端?

离线

#2 2019-07-08 16:56:16

晕哥
管理员
所在地: 微信 whycan_cn
注册时间: 2017-09-06
已发帖子: 9,234
积分: 9197

Re: g_file_storage的同步问题

http://chinaunix.net/uid-29305275-id-5569813.html

注意:如果此时在PC端再次修改了文件。这设备端不能立即看到PC修改的结果。即PC和设备端不能同步。

此时可以在设备进行umount /media,然后重新mount一次就可以看到PC更改的结果。同样在设备端修改的文件,PC端也不能立即看到修改结果,需重新插拔USB线才能看到更新。至于原因,暂时不知道。


以前就看到过这种讨论, 一搜, 果然是有。





离线

楼主 #3 2019-07-08 16:58:14

tom
会员
注册时间: 2018-03-14
已发帖子: 128
积分: 127.5

Re: g_file_storage的同步问题

我看nuvoton sdk里面的方法首先是unmount掉SD卡,然后再执行insmod /usr/g_file_storage.ko file=/dev/mmcblk0p1 removable=1,相当于是直接禁止arm端访问了。     

如果要同时访问,该怎么操作?

离线

#4 2019-07-08 17:03:54

cityf
会员
注册时间: 2017-11-03
已发帖子: 195
积分: 195

Re: g_file_storage的同步问题

我觉得应该做不到同时访问,因为他们分别属于两个系统。

离线

楼主 #5 2019-07-08 17:04:49

tom
会员
注册时间: 2018-03-14
已发帖子: 128
积分: 127.5

Re: g_file_storage的同步问题

这篇文章也这是提到了这个问题,并没有很好解决。arm端并不知道pc端什么时候会修改卡里面的内容

离线

#6 2019-07-08 17:05:57

smartcar
会员
注册时间: 2018-02-19
已发帖子: 735
积分: 735

Re: g_file_storage的同步问题

早期的安卓机也是这么干的吧,插入电脑当U盘的时候,安卓机不能再访问了。

而且很容易把整个文件系统弄挂掉,所以后来的安卓已经换成其他协议了。

离线

楼主 #7 2019-07-08 17:07:31

tom
会员
注册时间: 2018-03-14
已发帖子: 128
积分: 127.5

Re: g_file_storage的同步问题

早期的Android确实是这么干,pc连上手机后,直接就禁止访问外置卡了

离线

#8 2019-07-08 21:30:40

ippen
会员
注册时间: 2018-07-22
已发帖子: 345
积分: 339.5

Re: g_file_storage的同步问题

不应该让两个系统同时访问存储,会导致存储上的数据结构被破坏的

离线

楼主 #9 2019-07-09 11:51:53

tom
会员
注册时间: 2018-03-14
已发帖子: 128
积分: 127.5

Re: g_file_storage的同步问题

看来这个方式只能尽量避免了。
昨天查了下hotplug相关资料,发现基本上针对usb host挂载wifi、u盘之类的应用。不知道针对usb slave是怎么实现hotplug的?

我尝试使用网上提到的NETlink方式截获内核消息,在虚拟机上试验,能截获到U盘插拔动作。在arm linux端试验,无法截获usb slave的插拔。不知道是不是内核配置问题?

int main(void)
{
    struct sockaddr_nl clt;
    struct timeval t1;
    fd_set fd;
    int buf_size = 2048, len, ret, usb_test;
    //创建套接字
    usb_test = socket(AF_NETLINK, SOCK_RAW, NETLINK_KOBJECT_UEVENT);
    memset(&clt, 0, sizeof(clt));
    clt.nl_pid = getpid();
    clt.nl_family = AF_NETLINK;
    clt.nl_groups = 1;
    setsockopt(usb_test, SOL_SOCKET, SO_RCVBUF, &buf_size, sizeof(buf_size));
    //绑定套接字
    bind(usb_test, (struct sockaddr*)&clt, sizeof(clt));
    while (1)
    {
        char buf[2048];
        memset(&buf,0,sizeof(buf));
        FD_ZERO(&fd);
        FD_SET(usb_test, &fd);
        //监测频率周期
        t1.tv_sec = 0;
        t1.tv_usec = 50 * 1000;
        //监测
        ret = select(usb_test + 1, &fd, NULL, NULL, &t1);
        if(ret < 0)
            continue;
        if(!(ret > 0 && FD_ISSET(usb_test, &fd)))
            continue;
        
        len = recv(usb_test, &buf, sizeof(buf), 0);
        if (len > 0)
        {
            printf("%s\n", buf);//打印收到的数据
        }
    }
    close(usb_test);
    return 0;
}

离线

#10 2019-07-09 14:56:54

晕哥
管理员
所在地: 微信 whycan_cn
注册时间: 2017-09-06
已发帖子: 9,234
积分: 9197

Re: g_file_storage的同步问题

# ./test
remove@/devices/platform/soc/1c1a400.usb/usb2/2-1/2-1:1.0/host0/target0:0:0/0:0:0:0/bsg/0:0:0:0
remove@/devices/platform/soc/1c1a400.usb/usb2/2-1/2-1:1.0/host0/target0:0:0/0:0:0:0/scsi_device/0:0:0:0
remove@/devices/platform/soc/1c1a400.usb/usb2/2-1/2-1:1.0/host0/target0:0:0/0:0:0:0/scsi_disk/0:0:0:0
remove@/devices/platform/soc/1c1a400.usb/usb2/2-1/2-1:1.0/host0/target0:0:0/0:0:0:0/block/sda/sda1
remove@/devices/virtual/bdi/8:0
remove@/devices/platform/soc/1c1a400.usb/usb2/2-1/2-1:1.0/host0/target0:0:0/0:0:0:0/block/sda
remove@/devices/platform/soc/1c1a400.usb/usb2/2-1/2-1:1.0/host0/target0:0:0/0:0:0:0
remove@/devices/platform/soc/1c1a400.usb/usb2/2-1/2-1:1.0/host0/target0:0:0
remove@/devices/platform/soc/1c1a400.usb/usb2/2-1/2-1:1.0/host0/scsi_host/host0
remove@/devices/platform/soc/1c1a400.usb/usb2/2-1/2-1:1.0/host0
remove@/devices/platform/soc/1c1a400.usb/usb2/2-1/2-1:1.0
remove@/devices/platform/soc/1c1a400.usb/usb2/2-1
add@/devices/platform/soc/1c1a000.usb/usb1/1-1
add@/devices/platform/soc/1c1a000.usb/usb1/1-1/1-1:1.0
add@/devices/platform/soc/1c1a000.usb/usb1/1-1/1-1:1.0/host0
add@/devices/platform/soc/1c1a000.usb/usb1/1-1/1-1:1.0/host0/scsi_host/host0
remove@/devices/platform/soc/1c1a000.usb/usb1/1-1/1-1:1.0/host0/scsi_host/host0
remove@/devices/platform/soc/1c1a000.usb/usb1/1-1/1-1:1.0/host0
remove@/devices/platform/soc/1c1a000.usb/usb1/1-1/1-1:1.0
remove@/devices/platform/soc/1c1a000.usb/usb1/1-1
add@/devices/platform/soc/1c1a000.usb/usb1/1-1
add@/devices/platform/soc/1c1a000.usb/usb1/1-1/1-1:1.0
add@/devices/platform/soc/1c1a000.usb/usb1/1-1/1-1:1.0/host0
add@/devices/platform/soc/1c1a000.usb/usb1/1-1/1-1:1.0/host0/scsi_host/host0
remove@/devices/platform/soc/1c1a000.usb/usb1/1-1/1-1:1.0/host0/scsi_host/host0
remove@/devices/platform/soc/1c1a000.usb/usb1/1-1/1-1:1.0/host0
remove@/devices/platform/soc/1c1a000.usb/usb1/1-1/1-1:1.0
remove@/devices/platform/soc/1c1a000.usb/usb1/1-1
add@/devices/platform/soc/1c1a000.usb/usb1/1-1
add@/devices/platform/soc/1c1a000.usb/usb1/1-1/1-1:1.0
add@/devices/platform/soc/1c1a000.usb/usb1/1-1/1-1:1.0/host0
add@/devices/platform/soc/1c1a000.usb/usb1/1-1/1-1:1.0/host0/scsi_host/host0
remove@/devices/platform/soc/1c1a000.usb/usb1/1-1/1-1:1.0/host0/scsi_host/host0
remove@/devices/platform/soc/1c1a000.usb/usb1/1-1/1-1:1.0/host0
remove@/devices/platform/soc/1c1a000.usb/usb1/1-1/1-1:1.0
remove@/devices/platform/soc/1c1a000.usb/usb1/1-1
add@/devices/platform/soc/1c1a000.usb/usb1/1-1
add@/devices/platform/soc/1c1a000.usb/usb1/1-1/1-1:1.0
add@/devices/platform/soc/1c1a000.usb/usb1/1-1/1-1:1.0/host0
add@/devices/platform/soc/1c1a000.usb/usb1/1-1/1-1:1.0/host0/scsi_host/host0

我加了头文件

#include <asm/types.h>
#include <sys/socket.h>
#include <linux/netlink.h>
#include <stdlib.h>
#include <string.h>

在 V3s linux4.13 下测试正常。





离线

楼主 #11 2019-07-09 21:28:59

tom
会员
注册时间: 2018-03-14
已发帖子: 128
积分: 127.5

Re: g_file_storage的同步问题

这个应该也是arm usb做主机吧?  我那个是做从机

离线

#12 2019-07-09 23:01:10

晕哥
管理员
所在地: 微信 whycan_cn
注册时间: 2017-09-06
已发帖子: 9,234
积分: 9197

Re: g_file_storage的同步问题

tom 说:

这个应该也是arm usb做主机吧?  我那个是做从机

对哦, 那有空我再试一试.





离线

#13 2019-07-19 16:17:16

晕哥
管理员
所在地: 微信 whycan_cn
注册时间: 2017-09-06
已发帖子: 9,234
积分: 9197

Re: g_file_storage的同步问题

我试了, 有反应, 作为 usb device:

root@test4:~# modprobe g_mass_storage file=/dev/mmcblk0 removable=1
[   98.990609] Mass Storage Function, version: 2009/09/11
[   98.995891] LUN: removable file: (no medium)
[   99.000359] LUN: removable file: /dev/mmcblk0
[   99.004801] Number of LUNs=1
[   99.019202] g_mass_storage gadget: Mass Storage Gadget, version: 2009/09/11
[   99.026356] g_mass_storage gadget: userspace failed to provide iSerialNumber
[   99.033446] g_mass_storage gadget: g_mass_storage ready
[   99.548345] g_mass_storage gadget: high-speed config #1: Linux File-Backed Storage

add@/module/g_mass_storage
change@/devices/platform/soc/1c19000.usb/musb-hdrc.1.auto/udc/musb-hdrc.1.auto

root@test4:~#
root@test4:~# rmmod g_mass_storage

change@/devices/platform/soc/1c19000.usb/musb-hdrc.1.auto/udc/musb-hdrc.1.auto
remove@/module/g_mass_storage





离线

页脚

工信部备案:粤ICP备20025096号 Powered by FluxBB

感谢为中文互联网持续输出优质内容的各位老铁们。 QQ: 516333132, 微信(wechat): whycan_cn (哇酷网/挖坑网/填坑网) service@whycan.cn