Files
Sam Demeulemeester 33a5eeeffa Add support for USB Mass Storage Devices (#607)
* Initial commit for USB Mass Storage Support

* Add support for SCSI_16 and various fixes by debrouxl

* Fix USB HCD registration to skip failed probes (when a mass storage device was already found)

* Fix xHCI bulk transfer completion matching & accept short packets for IN transfers

* Add USB BOT error recovery and match xHCI control events by slot/EP

* Add EHCI bulk timeout/size guard, fix per-controller MSD port handling, and make xHCI keyboard re-arm precise

* Harden FAT/GPT parsing (cluster validation & block-size check) and fix RTC read issue due to R/W race

* Fix report varargs on x86_64, truncate F6 drive label, and clean up failed FAT file writes

* Fix stale hub VID/PID read, refactor USB MSD detection to helper & tidy usbhcd/display/config layout

* Scan for USB drives on demand when saving a report
Keep EHCI/xHCI controllers registered when empty and rescan free root ports on F6.
Also fix xHCI keyboard re-arm losing a key release, dropping the next same-key press.
2026-07-11 11:49:41 +02:00

53 lines
1.5 KiB
C

// SPDX-License-Identifier: GPL-2.0
#ifndef USBMSD_H
#define USBMSD_H
/**
* \file
*
* Provides USB Mass Storage (Bulk-Only Transport) support for reading and
* writing sectors on a USB drive.
*
*//*
* Copyright (C) 2026 Sam Demeulemeester.
*/
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "usbhcd.h"
/**
* Initialises the mass storage device by issuing TEST UNIT READY and
* READ CAPACITY commands. Populates msd->block_count and msd->block_size.
*
* \returns true if the device is ready and capacity was read successfully.
*/
bool msd_init(usb_msd_t *msd);
/**
* Reads one or more sectors from the mass storage device.
*
* \param msd - the mass storage device context.
* \param lba - the starting logical block address.
* \param count - the number of sectors to read.
* \param buffer - the destination buffer (must be at least count * block_size).
*
* \returns true if all sectors were read successfully.
*/
bool msd_read_sectors(usb_msd_t *msd, uint64_t lba, uint32_t count, void *buffer);
/**
* Writes one or more sectors to the mass storage device.
*
* \param msd - the mass storage device context.
* \param lba - the starting logical block address.
* \param count - the number of sectors to write.
* \param buffer - the source buffer (must be at least count * block_size).
*
* \returns true if all sectors were written successfully.
*/
bool msd_write_sectors(usb_msd_t *msd, uint64_t lba, uint32_t count, const void *buffer);
#endif // USBMSD_H