• Peiyu Li's avatar
    usb: gadget: storage: adapt logic block size to bound block devices · 3f565a36
    Peiyu Li authored
    Now the mass storage driver has fixed logic block size of 512 bytes.
    
    The mass storage gadget read/write bound devices only through VFS, so the
    bottom level devices actually are just RAW devices to the driver and connected
    PC. As a RAW, hosts can always format, read and write it right in 512 bytes
    logic block and don't care about the actual logic block size of devices bound
    to the gadget.
    
    But if we want to share the bound block device partition between target board
    and PC, in case the logic block size of the bound block device is 4KB, we
    execute the following steps:
    
    1. connect a board with mass storage gadget to PC(the board has set one
    	partition of on-board block device as file name of the mass storage)
    2. PC format the mass storage to VFAT by default logic block size and
    	read/write it
    3. disconnect boards from PC
    4. target board mount the partition as VFAT
    
    Step 4 will fail since kernel on target thinks the logic block size of the
    bound partition as 4KB.
    A typical error is "FAT: logical sector size too small for device (logical
    sector size = 512)"
    
    If we execute opposite steps:
    1. format the partition to VFAT on target board and read/write this partition
    2. connect the board to Windows PC as usb mass storage gadget, windows will
    	think the disk is not formatted
    
    So the conclusion is that only as a gadget, the mass storage driver has no any
    problem.  But being shared VFAT or other filesystem on PC and target board, it
    will fail.
    
    This patch adapts logic block size to bound block devices and fix the issue.
    
    Cc: Michal Nazarewicz <mina86@mina86.com>
    Acked-by: default avatarAlan Stern <stern@rowland.harvard.edu>
    Signed-off-by: default avatarPeiyu Li <peiyu.li@csr.com>
    Signed-off-by: default avatarXianglong Du <xianglong.du@csr.com>
    Signed-off-by: default avatarHuayi Li <huayi.li@csr.com>
    Signed-off-by: default avatarBarry Song <Baohua.Song@csr.com>
    Signed-off-by: default avatarFelipe Balbi <balbi@ti.com>
    3f565a36
file_storage.c 103 KB