【发布时间】:2016-02-03 15:15:38
【问题描述】:
在内核配置中包含 g_mass_storage 模块的嵌入式系统上工作,我想定义设备的名称。后者对于在插入主机时识别设备很有用。
我正在使用以下功能:
int usb_gadget(void)
{
char cmd[512];
int fd = -1;
int len = -1;
memset((void *)cmd, 0x00, sizeof(cmd));
fd = open("proc/modules", O_RDONLY);
if (fd > 0)
{
len = read(fd, cmd, sizeof(cmd));
if (len > 0)
{
if (strstr(cmd, "g_mass_storage") > 0)
{
fprintf(stderr, "Missing module \n");
}
else
{
strcpy(cmd, "modprobe ");
strcat(cmd, "g_mass_storage");
strcat(cmd, " file=");
strcat(cmd, "tmp/testfile");
strcat(cmd," idVendor=2000 ");
strcat(cmd," idProduct=2000 ");
strcat(cmd," bcdDevice=2000 ");
strcat(cmd," iManufacturer=TEST ");
strcat(cmd," iProduct=BOARD1 ");
strcat(cmd," iSerialNumber=1 ");
system(cmd);
}
close(fd);
}
}
return 0;
}
当设备连接到 Windows PC 时,设备定义为Local Disk(E:)。
如何通过特定名称交换 Local Disk,就像我的 USB Key SnPKey 完成的那样?
编辑 1:
根据上一个链接中给出的信息,我尝试通过iProduct 指定USB 产品字符串,但没有成功。
【问题讨论】:
-
经过多次研究,这个写入似乎是在分区步骤中实现的。我很快就会在平台上实现测试。
标签: linux kernel usb usb-mass-storage removable-storage