I've got one old brandless giveaway USB flash pendrive, but two disks show up on the running systems instead. One of them is writable but the other is readonly even if there isn't physical write-protect switch visible outside.
On Windows:
WIN-R: diskpart
DISKPART> list disk
...
disk 1 online ...
disk 2 online ...
DISKPART> list volume
...
volume 2 normal ...
volume 3 normal ...
DISKPART> select disk 1
DISKPART> attributes disk
readonly status: no
readonly: no
DISKPART> select disk 2
DISKPART> list partition
partition 1 ...
DISKPART> attributes disk
readonly status: yes
readonly: yes
DISKPART> attributes disk clear readonly
DISKPART> attributes disk
readonly status: yes
readonly: no
DISKPART> select partition 1
DISKPART> format
error: write protection
On Linux:
$ sudo parted -l
...
Model: Generic Flash Disk
Disk /dev/sdb ...
Warning: Unable to open /dev/sdc read-write (Read-only file system). /dev/sdc has been opened read-only.
Model: Generic Flash Disk
Disk /dev/sdc ...
$ sudo parted /dev/sdc
Warning: Unable to open /dev/sdc read-write (Read-only file system). /dev/sdc has been opened read-only.
(parted) print
number 1 ...
(parted) rm 1
error: not permitted to write
I've googled around and found this article on internal hardware/firmware based USB write-protect. How to verify if it is the case as mentioned by the article? Otherwise, how to remove this sort of USB write-protect?
I've also tried to zero sector 0 with diskpart on Windows as commented @JoepvanSteen, but the readonly status remains.
DISKPART> clean
DISKPART> attributes disk
readyonly status: yes
readonly: no
DISKPART> clean
error: device i/o
Additionally, using Disk Management tool on Windows shows that the volume for disk 2 has functional FAT filesystem, but all the writable options in the sub-menu popup from this volume become grayed out.
As a side note, I firstly posted this problem on stackoverflow and was hoping some firmware devs to give diagnosis hints, but the mod considered it off-topic. It's worthless in terms of economic value to solve this problem but valuable to learn and sort out the underlying during the course of investigation.