Troubleshooting for USB drives
To get persistent drive letters for external drives assign one exclusive 'high' letter per drive.
My USB Drive Letter Manager solves all this.
Obviously Windows XP doesn't enable a write cache for USB drives that appear as 'Removable'. The option "Enable write caching on the disk" is grayed out for USB drive (this mean the hardware cache of the drive) and the removal policy setting ('Quick removal' or 'Optimize for performance') doesn't seem to make any difference, except that the latter enables the user to format 'Removable' USB drives with NTFS. But with NTFS Windows XP enables a write cache, writing small files becomes lightning fast.
Update Feb 2011
I was pointed to the fact that by means of the registry value WriteCacheEnableOverride a write cache can be forced for any USB drive, even FAT formatted removeable drives. And it indeed works!
I have made a litte tool: USB-WriteCache
Update Feb 2011
Since Windows 8 the USB disk device policies have the expected effect on NTFS formatted removable drives, 'Better performance' actually activates a write cache while with the default policy 'Quick removal' there is none (in contrast to XP..Win7). The policies still have no effect on FAT formatted USB removable drives. Here WriteCacheEnableOverwrite is required.
Use NTFS anyway for USB flash drives?
Advantages:
But actually NTFS isn't suitable for flash medias because as journalling file system it has some overhead that wears out flash memory. But Windows XP optimizes and bundles write accesses to pen drives only when they are NTFS formatted, so I see NTFS as the right choice.
Furthermore NTFS stores small files together with the file information so they are written into the same flash block which is the best that can happen.
A drawback with NTFS and flash medias is that NTFS saves the access time when you read a file, so a simple read access causes flash wear out. In fact it is not as dramatically because Windows writes the data not immediately onto the media. It does it when it has to update something else there, when one hour is over on when a media is unmounted. Actually I've never seen XP writing a last access time to a USB drive.
The last access time is also updated on 'directory listing' (whatever this means).
This can be disabled, unfortunately for all drives only:
Create a new DWord value under [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem] called
NtfsDisableLastAccessUpdate and set it to 1. Or download the following REG file and doubleclick it:
NtfsDisableLastAccessUpdate1.reg
Since Vista this can be configured more detailed:
NtfsDisableLastAccessUpdate at Microsoft
To format a pen drive with NTFS there is no need to switch to 'optimize for speed'. Using the commandline tool CONVERT you can convert a FAT formatted drive to NTFS. Sample:
convert u: /fs:ntfsBut XP's CONVERT creates a NTFS with a cluster size of 512 Bytes if the FAT clusters are not 4K aligned. If the drive is FAT formatted under XP, then the clusers are 4K aligned and XP's CONVERT works fine. W2K's CONVERT seems to creates 512 Bytes clusters in any case.
Of course a NTFS formatted drive doesn't work under Windows 95/98/ME. Furthermore devices with a standalone functionality as MP3 players or image tanks may not work with NTFS.
If both, format and convert fail while formatting with FAT/FAT32 works, then the drive is a fake with a fraction of real memory only. The NTFS file system is written into the middle of the drive while the FAT is written to at the begin of the drive. So, if the drive is (a simple) fake then the NTFS file system is written into non existent memory. Newer fake drives are made more clever, the first write accesses go to existing memory, so formatting with NTFS does not fail. But as soon as more data then really build in is wriiten in sum, the problems begin.
The effect of having a write cache or not depends on the USB drive: Hard drives have an 2..64 MB of cache RAM which prevents to much performance impact. Most USB flash have no such cache, so their access times are very important for their real live speed.
By means of HD Tune you can check the read access times. Here a screenshot of the bad example 'Corsair Flash Voyager' (2GB) - have a look at the yellow dots above the diagram...
It's from 2005, the current exemplars are better.
To test the file cache behaviour I've made FileCacheTest
It can read and write a test file using different flags for the API function CreateFile and using different block sizes. Remember the difference between writing a file for the first time and to an existing file: Writing the first time, the file size has to be adjusted after each block.
The most remarkable effects under XP are:
Deactivate write-cache
There is no known way to deactivate a write cache if Windows decided to activate it, e.g. on NTFS formatted drives there is always a write cache.
Update August 2021: Windows 10 1903 with disk device policy "Quick removal" even NTFS formatted drives have almost no write cache. Only small block writes are buffered (<=32KB per block).
There are some useful commandline tools for this purpose but they all have some disadvantages. So I wrote my own:
Reactivate a USB drive
When a drive has been prepared for safe removal then it can be reactivated only by replugging it.
Meanwhile I have learned that this is true only for devices which have the problem code 47 after the safe removal (which is the case after using the safe removal tray icon). Devices which have "Code 21" can be reactivated, I have made a command-line tool for this: RestartSrDev. This works when RemoveDrive was started with admin privileges. Since V2.0 RestartSrDev can restart the USB hub the device is attached to, if required.
Another option is to restart the USB port which is possible under XP, Windows 8 and 10. I have made a command-line tool for this too: RestartUsbPort.
UsbTreeView can do all this too.
If a flash drive is partitioned or formatted by the user it is essential to use the right tool. Windows Vista and Windows 7/8/10 do a good job here. They align new partitions and data clusters very well. In contrast Windows XP creates partitions in the classic way at track or cylinder borders which nearly always results in unaligned partitions.
Data clusters: The NTFS file system has its tables somewhere in the middle of the partition, so the data clusters just start at the beginning, no alignment issues here. FAT/FAT32 have their allocation tables at the beginning, the data cluster follow after some 'reserved' sectors. Modifying the reserved sector count is the key to align the data clusters and this is what Vista and Win7/8/10 do very well while XP does a 4K alignment only.
But all this is relative to the partitions!. With non aligned partitions the data clusters are created non aligned too!
I've implemented the display of partition and cluster alignment in UsbDriveInfo. As explained above it shows these information only if they are relevant. For SuperFloppy formatted drives there is no partition alignment and for NTFS drives the first cluster alignment is identical to the partition alignment.
Even with a perfectly aligned first cluster, with a cluster size smaller than the flash block size files are perfectly aligned only with a certain probility: If the cluster have half the size of the flash blocks the every second file is perfectly aligned, with a quarter every fourth and so on. Only with clusters of the size of the flash blocks and at least this alignment full write speed is guaranteed.
But larger clusters lead to more non-usable memory (slack space). And with clusters larger than 4KB there is no more NTFS compression.
By the way: TrueCrypt since V6.0 aligns the data as the container is aligned. From the history: "the start of the data area will always be aligned with the start of a host-filesystem/physical sector"
How to align a partition
Aligning a partition without data loss is reported being possible by means of GParted (based upon a bootable Linux) by moving the partition back and forth, but for a flash drive I think it is not worth the effort. Just delete and recreate it under Vista/Win7/8/10.
On "removable" drives the Windows disk management does no like to delete or create partitions. But the Vista/Win7/8/10 commandline tool DISKPART can.
Another alternative is the SD Memory Card Formatting Software which creates an partition with aligned clusters on USB "removable" drives. The partition is aligned only if the drive is 4GB or larger, so don't format smaller drives with NTFS after formatting them by means of this software!
A nice and free partition software for Windows which supports alignment is the "Active@ Partition Manager". By default it (V2) uses the classic alignment but it offers an option for the exact partition offset. Increase this number to the next value which can be evenly divided by 1024 to get a 512K alignment and decrease the size by the value you have increased the start offset with.
Then it shows a warning plus question "Partition geometry is not aligned with disk track borders. Align on track borders?", we answer "No" because we know aligning to track borders is a thing from the past.
Letting format the drive with FAT resulted here in a 1K cluster alignment. Formatting again with XP (FORMAT or dialog) resulted in the expected 4K alignment. So, better let Windows do the formatting...
What will we get? Depends on the device... With an old 128MB SD card I had no improvement of the write speed at all while a Corsair Voyager 16GB writes large files now with 15 MB/s instead of 6.5 thanks to aligned 64K clusters.
Automatic actions on arrival of a USB drive can be easily abused to copy interesting data from it in the background. So, never, never attach a USB drive with sensible data to a foreign computer even if you stand beside all the time! It's very easy to copy all DOC, XLS and PDF files in the background!
But there are more dangerous mechanisms, see here:
How to: Quick intro to hacking autorun for USB flash drives
In August 2008 Microsoft finally recognized that there is a security problem and offers updates which apply the autorun settings to the manual actions too, see here:
http://support.microsoft.com/kb/953252
BadUSB
USB flash drives today use quite flexible micro controller which can do way more than acting as a USB mass storage device. For the Phison 2251-03 all tools required to turn it into a BadUSB device have been published:
How it works:
The USB flash drive acts as a USB composite device hosting the expected USB mass storage function but also a bad USB keyboard. Windows comes with standard driver for USB keyboards, so they are installed and get ready without further user requests. Some moments later the keyboard devices "plays" a keyboard macro, ususally pressing Win+R, entering CMD and pressing Enter to open a command prompt. Then they enter a command to eithter start a bad executable from its mass storage device or download a bad executrable from the internet an start it.
Easy counter measures:
Other counter measures Windows XP:
Other counter measures Windows Vista,7,8,10:
{4D36E96B-E325-11CE-BFC1-08002BE10318} (GUID_DEVCLASS_KEYBOARD)
{4D36E972-E325-11CE-BFC1-08002BE10318} (GUID_DEVCLASS_NET)
REG file for keyboard devices
REG file for net devices
For Windows 98 you get drivers with the drive. If not you can try to use a driver of a foreign drive. Here is a german howto:
http://www.techwriter.de/beispiel/usb-mem2.htm
From COS Memory there are drivers which can be adopted in the same way:
http://www.cos-memory.de/downloads/treiberdownload.htm
Meanwhile there is an universal driver package for USB drives:
http://www.technical-assistance.co.uk/kb/usbmsd98.php
It uses Windows 2000 files, so you should have an additional valid Windows 2000 licence when you use this package...
Windows NT4 got no USB support by Microsoft - we shall buy a new system from time to time... Other vendors help:
NTFS encryption is no help too because dealing with certificates is no fun and they are not compatible between Windows 2000 and XP.
Solution: The approved open source software TrueCrypt V7.1a:
https://www.grc.com/misc/truecrypt/truecrypt.htm
or
https://truecrypt.ch
It requires admin privileges too but only once for installation.
In May 2014 the TrueCrypt developers lost interest in developing the software and declared it as potential unsafe because "it may contain unfixed security issues". An audit of the TrueCrypt source code didn't reveal any real issues, so V7.1 can be assumed as safe.
Using TrueCrypt is documented on countless pages in the internet, just enter TrueCrypt at your preferred search engine.
Meanwhile there is a new project based upon TrueCrypt: VeraCrypt
SD Memory Card Formatting Software
Fixing Windows 2000/XP Drive Letters
Letter Assigner for Windows 95/98/ME
Uwe Sieber