Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

USB memory stick - How the get flash block size ?

3,131 views
Skip to first unread message

R.Wieser

unread,
Feb 1, 2017, 10:49:34 AM2/1/17
to
Hello All,

I've got an USB stick here that I opened in raw mode, and started to write
sectors to it. It turns out gerts up to the "really great speed" of ...
128 KiloBytes a second.

Yes, thats righ, *kilo* bytes :-(

I take it that has something to do with writing only 512 bytes each time (a
sectors worth), which, most likely, does not quite match the USB sticks
flash-blocks size.

I can ofcourse just, for testing, double the "sector" size until I find the
fastest transfer speed, but I rather be able to just ask the stick for it.
Does anyone know if this is possible ?

TL;DR: How do I get an USB memory sticks flash-block size ?

Regards,
Rudy Wieser



JJ

unread,
Feb 2, 2017, 6:54:27 AM2/2/17
to
The flash chip size is not made exposable by the SCSI specifications. If the
information is actually exposed, it would use vendor-specific SCSI
mode-sense page that returns vendor-specific data format, which only the
flash disk's manufacturer know. e.g. there are several undocumented
vendor-specific SCSI commands for DVD burner drives which are useful (check
ImgBurn software). There's also vendor-specific SCSI commands for hard
drives (e.g. reset master lock).

You can only retrieve the total number of disk blocks (sectors), and the
disk block size.

You can do a brute-force disk read test to find the block size (like
SpinRite does to find the optimal hard disk interleave), but it'd depend
whether the flash disk is plugged to an optimal USB port. e.g. you'd get
lower optimal speed if you test a USB3 flash disk plugged on a USB2 port.

R.Wieser

unread,
Feb 3, 2017, 3:39:22 AM2/3/17
to
Hey JJ,

> You can only retrieve the total number of disk blocks (sectors),
> and the disk block size.

Maybe that "disk block size" is what I'm after ... Any info/keywords to how
to retrieve it ?

> You can do a brute-force disk read test to find the block size

In the same method as I described for writing the stick ? Didn't think of
doing it that way.

Regards,
Rudy Wieser


-- Origional message:
JJ <jj4p...@vfemail.net> schreef in berichtnieuws
16uh4gsp9rz9v.5...@40tude.net...

JJ

unread,
Feb 3, 2017, 6:48:41 AM2/3/17
to
On Fri, 3 Feb 2017 09:44:31 +0100, R.Wieser wrote:
>
> Maybe that "disk block size" is what I'm after ... Any info/keywords to how
> to retrieve it ?

SCSI storage's block size is not like what you think. In SCSI storage device
specifications, "block size" refers to the storage media sector size. i.e.
LBA sector. For older and current hard disk (platter, SSD/flash), the block
size is 512 bytes. Newer ones have be 4096 bytes block size. FYI,
CD/DVD/Bluray/HD-DVD ranges from 2048 (standard) to 2352 (raw/audio; CD
only) bytes.

Send the SCSI packet using IOCTL_SCSI_PASS_THROUGH /
IOCTL_SCSI_PASS_THROUGH_DIRECT via DeviceIoControl. In Windows NT SDK's
term, it's called SPT. The other method is to use ASPI (Adaptec's SCSI API).
ASPI is simpler and easier than SPT, but it's less flexible. ASPI was
initially designed for DOS, BTW.

For crash course on accessing SCSI devices, I'd recommend ASPI's
documentation. It's brief but it'll make you grasp SCSI API model pretty
quickly.

Or you can just get right into the SCSI specifications at:

<http://www.t10.org/>

The documentations you should get are:

1. SPC. Generic commands for all SCSI devices. The SCSI command you want is
in here (Mode Sense). See SBC for the returned data format if you're
retrieving block-specific device information.

2. SBC. Commands for block devices. i.e. disks, not opticals/discs.

3. RBC (optional). Reduced command set of SBC. Only some devices support it.

Note that these documentations mostly are references, just like any other
specifications of things. There's no tutorial or how-to.

> In the same method as I described for writing the stick ? Didn't think of
> doing it that way.

Yes. By reading the disk sectors with both hardware & software cache
disabled. Writing onto a flash-based storage decreases its lifetime, as you
probably already know. IIRC, accessing a disk from a disk handle (not volume
handle) by defaults disables the disk level software cache. So, you only
need to disable the hardware cache via SCSI command.

R.Wieser

unread,
Feb 3, 2017, 7:23:57 AM2/3/17
to
JJ,

Thanks for the explanation. I have to ponder about it.

Strange though, something (the flash block size) thats so important for both
the performance as well as the life of an USB memory stick is so hard hard
to retrive ...

Regards,
Rudy Wieser


-- Origional message:
JJ <jj4p...@vfemail.net> schreef in berichtnieuws
1de9uwxu0q2bs.1...@40tude.net...

Bonita Montero

unread,
Feb 3, 2017, 8:13:32 AM2/3/17
to
Am 01.02.2017 um 16:53 schrieb R.Wieser:

> I can ofcourse just, for testing, double the "sector" size until I find the
> fastest transfer speed, but I rather be able to just ask the stick for it.
> Does anyone know if this is possible ?

Try GetDiskFreeSpace (http://bit.ly/2kp5Ieu).

--
http://facebook.com/bonita.montero/

R.Wieser

unread,
Feb 3, 2017, 2:21:40 PM2/3/17
to
Bonita,

> Try GetDiskFreeSpace

That call returns info about a/the logical filesystem, not about the storage
medium itself.

Thanks anyway.

Regards,
Rudy Wieser


-- Origional message:
Bonita Montero <Bonita....@gmail.com> schreef in berichtnieuws
o71vlq$6j0$1...@news.albasani.net...

JJ

unread,
Feb 4, 2017, 9:04:45 AM2/4/17
to
On Fri, 3 Feb 2017 13:29:07 +0100, R.Wieser wrote:
> JJ,
>
> Thanks for the explanation. I have to ponder about it.
>
> Strange though, something (the flash block size) thats so important for both
> the performance as well as the life of an USB memory stick is so hard hard
> to retrive ...

You'll need an EEPROM programming unit or Arduino in order to find out a
flash chip capacity. i.e. chip specific analysis

R.Wieser

unread,
Feb 4, 2017, 11:04:16 AM2/4/17
to
JJ,

> You'll need an EEPROM programming unit or Arduino in order to
> find out a flash chip capacity. i.e.

I'm not looking for the *capacity*, but about the *flash block* size: The
minimum ammount of bytes that will be accessed by a write action, even
though you may only actually alter a single one. A whole different beast.

> chip specific analysis

Not possible anyway: the (one-or-more physical) flash chips are directly
connected to the controller thats also on the stick. Unless you ofcourse
think of removing them from that stick (and directly connect them to a
controller you program yourself).

As for that arduino ? How so ? Would it be able to send USB commands
which a computer cannot ?

My apologies if, in the above, I'm preaching to the choir or appear to be
rude. But somehow I get the feeling we are not talking about the same thing.
Or we are using different names/descriptions for it, which confuses me. :-\

Regards,
Rudy Wieser


-- Origional message:
JJ <jj4p...@vfemail.net> schreef in berichtnieuws
1fc7j50wvmoae.y...@40tude.net...

Bonita Montero

unread,
Feb 5, 2017, 5:18:35 AM2/5/17
to
Am 03.02.2017 um 17:14 schrieb R.Wieser:

>> Try GetDiskFreeSpace

> That call returns info about a/the logical filesystem,
> not about the storage medium itself.

No, it tells you also the physical sector-size.

If you have opened a non-formatted disk, you can use
IOCTL_DISK_GET_DRIVE_GEOMETRY(_EX).


--
http://facebook.com/bonita.montero/

R.Wieser

unread,
Feb 5, 2017, 6:16:34 AM2/5/17
to
Bonita,

> No, it tells you also the physical sector-size.

There is no such thing as a *physical* sector-size (at least not after the
era where hardware sector-sync was abolished). That size is whatever you
want to set it to on formatting (though lately everything seems to converge
to 512 bytes per logical sector).

But all of that does not even matter, as that sector size has got zero
bearing on the FLASH-BLOCK size (which seems to vary from 4KByte upto a few
hundereds of KB (and over ? Not sure) depending on the USB sticks
capacity).

> If you have opened a non-formatted disk, you can use
> IOCTL_DISK_GET_DRIVE_GEOMETRY(_EX).

Numbers which, for an USB memory stick, are fully bogus. It does not have
any concept of cylinders, tracks and even sectors. If at all used they
are (still) there to enable OSes which only can handle spinning platter
storage devices to access them, nothing more.


Now thats out of the way, do you have any info about retrieving the
FLASH-BLOCK size of an USB memory stick ?


Regards,
Rudy Wieser


-- Origional message:
Bonita Montero <Bonita....@gmail.com> schreef in berichtnieuws
o76u5p$1hk$1...@news.albasani.net...

JJ

unread,
Feb 5, 2017, 7:17:50 AM2/5/17
to
On Sat, 4 Feb 2017 17:08:55 +0100, R.Wieser wrote:
>
> My apologies if, in the above, I'm preaching to the choir or appear to be
> rude. But somehow I get the feeling we are not talking about the same thing.
> Or we are using different names/descriptions for it, which confuses me. :-\

My understanding of the "block size" you're referring to, is same as the
maximum number of bytes a memory data can be read in one step from a memory
module (can be a chip or subcircuit).

It depends heavily on the memory controller of the storage device. Most are
either the memory chip capacity on a memory array board (i.e. a storage
device with multiple memory chips), or the memory module capacity in a
single memory chip (i.e. a storage device with a single memory chip; here,
"module" refers to a subcircuit in the memory chip).

Either way, the information is not exposed by the memory chip or the
flash/hard disk's firmware. At least, officially and in standard way.

R.Wieser

unread,
Feb 5, 2017, 7:52:16 AM2/5/17
to
JJ,

> My understanding of the "block size" you're referring to, is same
> as the maximum number of bytes a memory data can be read in
> one step from a memory module (can be a chip or subcircuit).

That sounds logically enough (although ... writes need to be buffered, reads
do not).
> It depends heavily on the memory controller of the storage device.

Agreed.

> Either way, the information is not exposed by the memory chip or the
> flash/hard disk's firmware.

Ok, that was what I thought I understood from what you said. But its good
to see it confirmed.

> At least, officially and in standard way.

Ok. thanks. I don't think I'm going to bother with the un-official ways.
Those will often fail when you can least use it. :-\ :-)


... But I still think its absense is odd, as knowing it is rather important
when (re)formatting or partitioning such flash-based storage, so its
performance can be kept up.

Oh well ...

Regards,
Rudy Wieser


-- Origional message:
JJ <jj4p...@vfemail.net> schreef in berichtnieuws
x8vcvcmh6skk$.5t35siounjks.dlg@40tude.net...

Christian Astor

unread,
Feb 5, 2017, 8:03:44 AM2/5/17
to
R.Wieser a écrit :

> I can ofcourse just, for testing, double the "sector" size until I find the
> fastest transfer speed, but I rather be able to just ask the stick for it.
> Does anyone know if this is possible ?

USBView
(https://github.com/Microsoft/Windows-driver-samples/tree/master/usb/usbview)
gives wMaxPacketSize
(https://msdn.microsoft.com/en-us/library/ee437177.aspx?f=255&MSPPError=-2147217396),

but I don't know if it is useful...

R.Wieser

unread,
Feb 5, 2017, 8:19:58 AM2/5/17
to
Christian,

> USBView
...
> but I don't know if it is useful...

I get the strong feeling that the transport-mechanisms (USB) maximum
blocksize and the flash-memories write-block size are rather different
beasts, with no direct correlation to each other ...

Nonetheless, thanks for your suggestion.

Regards,
Rudy Wieser


-- Origional message:
Christian Astor <cast...@club-internet.fr> schreef in berichtnieuws
o777rd$1par$1...@gioia.aioe.org...

Bonita Montero

unread,
Feb 5, 2017, 9:18:19 AM2/5/17
to
> Numbers which, for an USB memory stick, are fully bogus.
> It does not have any concept of cylinders, tracks and even sectors.

You get the correct raw block size (which I named the "physical
sector size") through this IOCTL when you open the device maintained
by disk.sys and ask for the block size with this ioctl. The other
data like sectors per track or whatever is pure virtual like it
was with IDE-adressing before LBA.

--
http://facebook.com/bonita.montero/

R.Wieser

unread,
Feb 5, 2017, 12:21:11 PM2/5/17
to
Bonita,

> You get the correct raw block size

No, you don't (the number is fixed to 512). No such thing as a "raw
blocksize" exists.

And as you do not seem to have a clue about that, do not wish to answer
simple questions (like what a cylinder count has to do with (flash-)memory),
and most important that it doesn't have got *any* relation to the "flash
block size" I'm after I'm going to end this conversation. Goodbye.

Regards,
Rudy Wieser


-- Origional message:
Bonita Montero <Bonita....@gmail.com> schreef in berichtnieuws
o77c7a$sbr$1...@news.albasani.net...
0 new messages