Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

USB MSC: Fix SCIS mode sense write protection bit #9572

Merged

Conversation

mluessi
Copy link
Contributor

@mluessi mluessi commented Dec 15, 2023

The USB MSC / SCSI layer currently doesn't set the write protect bit in the SCSI ModeSense response. Due to this, the Emulated FAT file system used for the internal flash doesn't get mounted read-only. When mounting the drive on Linux, the host attempts to write to the drive (I assume for the access time) , which fails and then the mounting doesn't succeed.

This fix sets the relevant bit in the SCSI ModeSense responses. The host doesn't attempt to write to the drive and the mounting works as expected.

This is only for H7 targets. The fix also should be added to F7 etc.

Fixes #9160

Before:
[1191094.145018] scsi 3:0:0:0: Direct-Access INAV FC Onboard Flash PQ: 0 ANSI: 2
[1191094.145670] sd 3:0:0:0: [sdc] 527470 512-byte logical blocks: (270 MB/258 MiB)
[1191094.145815] sd 3:0:0:0: [sdc] Write Protect is off
[1191094.145817] sd 3:0:0:0: [sdc] Mode Sense: 00 00 00 00

With this fix:
[19418.047443] scsi 4:0:0:0: Direct-Access INAV FC Onboard Flash PQ: 0 ANSI: 2
[19418.048021] sd 4:0:0:0: [sdd] 527470 512-byte logical blocks: (270 MB/258 MiB)
[19418.048224] sd 4:0:0:0: [sdd] Write Protect is on
[19418.048229] sd 4:0:0:0: [sdd] Mode Sense: 00 00 80 00

@stronnag
Copy link
Collaborator

Is this only applied to Flash or generically to MSC?
If it's generic, it's not the correct solution as MSC for SD Card should allow delete (i.e. the device is not write protected).

btw. regardless, on F4, MSC flash devices are mounted (write protected, after write sense fails) without this PR.

@mluessi
Copy link
Contributor Author

mluessi commented Dec 15, 2023

@stronnag it only sets the write protect flag if the IsWriteProtected function indicates it, so it works for both the internal flash (write protected) and SD Card (not write protected).

@stronnag
Copy link
Collaborator

Thanks for the clarification. This also needs to be applied to F4 / F7 in that case.

@stronnag stronnag changed the base branch from master to release_7.1.0 December 16, 2023 10:28
@mmosca mmosca changed the base branch from release_7.1.0 to master December 16, 2023 11:49
@stronnag
Copy link
Collaborator

@mluessi , can you please rebase this to release_7.1.0 as it's a useful bug fix. You might also make the same fix against F4 and F7. I tested F4 locally and it works perfectly.

@mluessi
Copy link
Contributor Author

mluessi commented Dec 16, 2023

@stronnag sounds good, I will add F4 and F7 and change the target branch

@mluessi mluessi changed the base branch from master to release_7.1.0 December 16, 2023 15:21
@mluessi mluessi changed the title USB MSC H7: Fix SCIS mode sense write protection bit USB MSC: Fix SCIS mode sense write protection bit Dec 16, 2023
@mluessi
Copy link
Contributor Author

mluessi commented Dec 16, 2023

@stronnag done :)

@stronnag
Copy link
Collaborator

tested by the author on H7 and by me on F4.

@stronnag stronnag added this to the 7.1 milestone Dec 16, 2023
@stronnag stronnag merged commit 0535617 into iNavFlight:release_7.1.0 Dec 16, 2023
15 checks passed
JulianTiller pushed a commit to JulianTiller/inav that referenced this pull request Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

msc mode does not work again
2 participants