Home |
Function USBDiskInitDevice |
Function USBDiskInitDeviceUSBDiskInitDevice must be called from the system driver function RTUSYSNewDiskDevice to initialize a newly attached USB disk device: int USBDiskInitDevice(RTUDeviceHandle Device, RTUDiskData * Data, UINT LUNs, const RTUConfigurationDescriptor * C, const RTUInterfaceDescriptor * I); ParametersDeviceA handle to the new USB device. DataA pointer to an array of RTUDiskData structures. LUNsNumber of elements in the array pointed to by Data. CPointer to a configuration descriptor to use to configure the device. IPointer to an interface descriptor of the interface to implement. return valueRTU_SUCCESS if the device was successfully initialized and is ready for use, RTU_ACCESS_DENIED if the given *Data is already in use, or a negative error code on failure. This function must only be called from system driver function RTUSYSNewDiskDevice (see Rtusys.h for details). Parameters Device, C, and I are supplied by RTUSYSNewDiskDevice and can be passed on unmodified. LUNs can be passed on as is (in this case, Data must point to an array of that size), or it can be less, if the file system is not interested in handling additional LUNs. For example, if a file system driver does not plan to support multi LUN devices such as card readers, it can always set LUNs to 1. RTUSYSNewDiskDevice's main purpose is allocating RTUDiskData data structures to be passed to USBDiskInitDevice. The first time an RTUDiskData structure is used, it should be initialized to zero. A file system driver may never alter any fields within an RTUDiskData structure, not even after RTUSYSDiskRemoved has been called. The design of the mass storage device driver assumes that all RTUDiskData structures have been statically allocated and are zero-initialized at program startup. A file system driver does not need to keep track of which of its RTUDiskData structures is currently in use. USBDiskInitDevice will check if the supplied structure is free. If it is not, RTU_ACCESS_DENIED is returned and the driver can select another structure and call USBDiskInitDevice again until either a call succeeds or the number of available RTUDiskData structures is exhausted. The I/O functions USBDiskMountDevice, USBDiskReadSectors, USBDiskWriteSectors, USBDiskMediaChanged, USBDiskGetSize, and USBDiskSCSICommand all require a pointer to an RTUDiskData structure to identify the disk device they want to access. For the first LUN of a device, the same value as passed to USBDiskInitDevice's Data parameter should be used. To access the second LUN, Data + 1 is used, etc.
|