Windows 2000 supports compression on individual files, folders, and entire NTFS volumes. Files compressed on an NTFS volume can be read and written by any Windows-based application without first being decompressed by another program. Decompression occurs automatically when the file is read. The file is compressed again when it is closed or saved. Compressed files and folders have an attribute of C when viewed in Windows Explorer.
Only NTFS can read the compressed form of the data. When an application such as Microsoft Word or an operating system command such as copy requests access to the file, the compression filter driver decompresses the file before making it available. For example, if you copy a compressed file from another Windows 2000based computer to a compressed folder on your hard disk, the file is decompressed when read, copied, and then recompressed when saved.
This compression algorithm is similar to that used by the Windows 98 application DriveSpace 3, with one important difference the limited functionality compresses the entire primary volume or logical volume. NTFS allows for the compression of an entire volume, of one or more folders within a volume, or even one or more files within a folder of an NTFS volume.
The compression algorithms in NTFS are designed to support cluster sizes of up to 4 KB. When the cluster size is greater than 4 KB on an NTFS volume, none of the NTFS compression functions are available.
Compressing and Decompressing Volumes, Folders, and Files
Volumes, folders and files on an NTFS volume are either compressed or decompressed. The compression state of a folder does not necessarily reflect the compression state of the files in that folder. For instance, a folder might be compressed, yet some or all the files in that folder can be decompressed if you selectively decompressed them.
You can set the compression state of folders and compress or decompress files by using Windows Explorer or the command-line program Compact.
Using Windows Explorer
With Windows Explorer, you can set the compression state of an NTFS folder without changing the compression state of existing files in that folder. If you have Read or Write permission, you can change the compression state locally or across a network. You can select individual folders or files to compress or decompress.
To set the compression state of a volume
Open Windows Explorer . In the left pane, right-click the root folder of the volume that you want to compress or decompress.
Click Properties to display the Properties dialog box.
On the General tab, select or clear the Compress drive to save disk space check box.
In the Confirm Attribute Changes dialog box, select whether to make the compression apply only to the root folder or the entire volume, and then click OK .
The change to the compression attribute is applied to the files and folders you specified. If you compress the entire volume, it might take a few minutes to complete the process, depending on the size of the volume, the number of files and folders to compress, and the speed of the computer.
To set the compression state of a folder or file
Open Windows Explorer . In the left pane, right-click the folder that you want to compress or decompress.
Click Properties to display the Properties dialog box.
On the General tab, click Advanced .
In the Advanced Attributes dialog box, select or clear the Compress contents to save disk space check box, and then click OK .
In the Properties dialog box, click OK .
If the compression state was altered for a folder, in the Confirm Attribute Changes dialog box, select whether to make the compression apply only to the selected folder or to all files and subfolders. Click OK when done.
Windows 2000 allows closed page files to be compressed. However, when you restart Windows 2000, the page files automatically revert to an uncompressed state. For information about page files, see the topics on virtual memory in Windows 2000 Professional Help.
You can set Windows Explorer to display alternate colors for compressed files and folders by using the following procedure:
To display alternate colors for compressed files and folders
In Windows Explorer , click the Tools menu.
On the Tools menu, click Folder Options .
On the View tab, select the Display compressed files and folders with alternate color check box.
Click OK to return to Windows Explorer .
Compact is the command-line version of the compression functionality in Windows Explorer. The compact command displays and alters the compression of folders and files on NTFS volumes. It also displays the compression state of folders.
There are two reasons why you might want to use Compact instead of Windows Explorer:
You can use Compact in a batch script.
If the system fails during compression or decompression, the file or folder is marked as Compressed or Uncompressed. If the operation did not complete, Compact forces the operation to complete in the background.
Unlike Windows Explorer, Compact automatically compresses or decompresses any files that are not already in the compression state that you set for the folder.
For more information about Compact, see File System Tools later in this chapter.
Effects of Compression on Moving and Copying Files
Moving and copying files and folders on disk volumes can change their compression state. The compression state of these files and folders, and the file system in which they were created, can impact the way they are affected while being moved or copied. The compression state of an NTFS file or folder is controlled by its compression attribute.
The default behavior for dragging and dropping files and folders in Windows Explorer depends on the relationship between the source and the target location. If the selected item is dragged to a folder on the same volume, the item is moved. If the selected item is dragged to a folder on a different volume, the item is copied. You can force a copy by holding down the CTRL key as you drop the item to its new location. Holding down the SHIFT key as you drop the item moves it. If you right-click and drag the selected item, a context popup menu appears that allows you to select whether to copy, move, or create a shortcut to the item, or cancel the task.
Moving Files or Folders on NTFS Volumes
When you move an uncompressed file or folder to another folder, the file remains uncompressed, regardless of the compression state of the folder to which it was moved. For example, if you move an uncompressed file to a compressed folder, the file remains uncompressed after the move, as shown in Figure 17.7.
Figure 17.7 Moving an Uncompressed File to a Compressed Folder
When you move a compressed file or folder to another folder, the file remains compressed after the move, regardless of the compression state of the folder, as shown in Figure 17.8.
Figure 17.8 Moving a Compressed File to an Uncompressed Folder
Copying Files or Folders on NTFS Volumes
When you copy a file to a folder, the file takes on the compression attribute of the target folder. For example, if you copy a compressed file to an uncompressed folder, the file is uncompressed when it is copied to the folder, as shown in Figure 17.9.
Figure 17.9 Copying a Compressed File to an Uncompressed Folder
When you copy a file to a folder that already contains a file of the same name, the copied file takes on the compression attribute of the target file, regardless of the compression state of the folder, as shown in Figure 17.10.
Figure 17.10 Copying a File to a Folder that Contains a File of the Same Name
Moving and Copying Files Between FAT16, FAT32, and NTFS Volumes
Like files copied between NTFS folders, files moved or copied from a FAT folder to an NTFS folder take on the compression attribute of the target folder. Because Windows 2000 supports compression only on NTFS volumes, compressed NTFS files moved or copied to a FAT volume are automatically decompressed. Similarly, compressed NTFS files copied or moved to a floppy disk are automatically decompressed.
Adding Files to an Almost Full NTFS Volume
Adding files to an NTFS volume that is almost full generates error messages indicating that there is not enough disk space to write the entire file if the file cannot be compressed, regardless of the compression in the file when it is opened. For this reason, it is possible to get a read error when you are trying to open a compressed file.
Because NTFS allocates space based on the uncompressed size of the files to be copied, if you copy files to a compressed NTFS folder that does not have enough room for the files in their uncompressed state, you receive a message indicating that there is not enough space on the disk. NTFS does not wait for the compression and writing of one file to complete before it works on subsequent files, and the system does not reclaim the unused space from compression until after the buffer is compressed.
When you run a program and save files to a compressed folder on a volume that is almost full, the success of the save depends on factors such as how much the file compresses and whether the beginning of the file compresses well.
If you cannot delete any files or do not have any files that you can compress, you can usually copy all of the files if you first copy the largest or those that compress best, such as BMP and document files. You can also copy them in smaller groups, rather than all at once.
NTFS Compression Algorithm
NTFS compression uses a 3-byte minimum search rather than the 2-byte minimum used by DoubleSpace. This search enables faster compressing and decompressing (roughly two times faster), while sacrificing only 2 percent compression for the average text file.
Each NTFS data stream contains information that indicates whether any part of the stream is compressed. Individual compressed buffers are identified by holes following them in the information stored for that stream. If there is a hole, NTFS automatically decompresses the preceding buffer to fill the hole.
NTFS provides real-time access to a compressed file, decompressing the file when it is opened and compressing it when it is closed. When writing a compressed file, the system reserves disk space for the uncompressed size. The system gets back unused space as each individual compression buffer is compressed.
Some programs do not allocate space before beginning a save operation and only display an error message when they run out of disk space.
NTFS compression might cause performance degradation because a compressed NTFS file is decompressed, copied, and then recompressed as a new file, even when copied on the same computer. Similarly, on network transfers, the file is decompressed, which affects bandwidth as well as speed.
The current implementation of NTFS compression runs more efficiently on Windows 2000 Professional than on Windows 2000 Server.
The two ways to measure the performance of NTFS data compression are size and speed. You can tell how well compression works by comparing the uncompressed and compressed file and folder sizes. For more information about seeing the compressed size of folders, see File System Tools later in this chapter.
Other Compression Methods
Other compression tools are available to compress files on computers running Windows 2000. These tools differ from NTFS compression in the following ways:
They usually run from either the command line or as a stand-alone application.
Files cannot be opened when they are in a compressed state the file must first be decompressed. When you close the file, it is saved in an uncompressed state, and you must use a program to compress it.
The Windows 2000 Resource Kit includes a tool called Compress, which can only be run from the command line. For more information about this and other programs, see File System Tools later in this chapter.