Re: Eject event when using USB Mass Storage Gadget

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Alan,
On Mon, Feb 11, 2019 at 5:28 PM Alan Stern <stern@xxxxxxxxxxxxxxxxxxx> wrote:
>
> On Mon, 11 Feb 2019, Martin Townsend wrote:
>
> > Hi,
> >
> > I've been trying to find a way of informing user space that the eject
> > button has been pressed on the host PC.  I put some debug in
> > do_scsi_command and I only see the TEST_UNIT_READY command with
> > nothing in it to distinguish it from other TEST_UNIT_READY commands.
> > After loading the gadget kernel module with removable=y I then see
> > commands with id 0x03 Request Sense but reading up on this I can't see
> > how this would help either.
>
> The host computer should send a START-STOP command when it wants to
> eject the media.
>
> > Is there anywhere else in the mass storage gadget code that is called
> > when the media has been ejected event occurs.
>
> fsg_lun_close().  That routine gets called from do_start_stop() when an
> eject event occurs.  (It also gets called from some other places in
> other circumstances, such as when the gadget driver is unloaded.)
>
> >  Failing that is there
> > any other way I could poll something something from userspace say is
> > sysfs that could be used to detect that the host has finished with the
> > backing file/eject media has occurred.
>
> No, that's pretty much it.
>
> Alan Stern
>
> > Many Thanks in advance,
> > Martin.
>

I can confirm that do_start_stop is called and the code where it
closes the LUN captures the EJECT (tested using Linux and Windows
host).

up_read(&common->filesem);
down_write(&common->filesem);
printk(KERN_ERR "do_start_stop -> fsg_lun_close (EJECT)\n");
fsg_lun_close(curlun);
up_write(&common->filesem);
down_read(&common->filesem);

Thank you very much for this as we were about to abandon MSG :)

I have one more problem, if I specify removable=y I can't re-insert
the device and after reading the documentation it looks like I have to
reset the backing file attribute in sysfs but I can't seem to write to
the file attribute:
root@beeker:/sys/module/g_mass_storage/parameters# ls -la
total 0
drwxr-xr-x 2 root root    0 Feb  4 19:16 .
drwxr-xr-x 6 root root    0 Feb  4 19:15 ..
-r--r--r-- 1 root root 4096 Feb  4 19:16 bcdDevice
-r--r--r-- 1 root root 4096 Feb  4 19:16 cdrom
-r--r--r-- 1 root root 4096 Feb  4 19:16 file
-r--r--r-- 1 root root 4096 Feb  4 19:16 iManufacturer
-r--r--r-- 1 root root 4096 Feb  4 19:16 iProduct
-r--r--r-- 1 root root 4096 Feb  4 19:16 iSerialNumber
-r--r--r-- 1 root root 4096 Feb  4 19:16 idProduct
-r--r--r-- 1 root root 4096 Feb  4 19:16 idVendor
-r--r--r-- 1 root root 4096 Feb  4 19:16 luns
-r--r--r-- 1 root root 4096 Feb  4 19:16 nofua
-r--r--r-- 1 root root 4096 Feb  4 19:16 removable
-r--r--r-- 1 root root 4096 Feb  4 19:16 ro
-r--r--r-- 1 root root 4096 Feb  4 19:16 stall

Even if I set the file to writable I just get an IO error.
root@beeker:/sys/module/g_mass_storage/parameters# chmod 666 file
root@beeker:/sys/module/g_mass_storage/parameters# echo
/data/mass_storage/msg.bin > file
-sh: echo: write error: Input/output error

Any ideas as to why I'm seeing this? If I remove and reinsert the
g_mass_storage gadget kernel module I can re-insert the device.  I
would like to build the gadget driver into the kernel as mass storage
is the only gadget function we have and I believe it can be built into
the kernel if this is the case.

Thanks Again, Martin.



[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux