# Removing sparse file attribute

The question is a bit broaded:

What's the sparse file attribute on NTFS partitions and how can I remove it?

Using Windows 7 and Windows 8.

-
Why would you want to remove it? –  MJZ Dec 14 '12 at 2:14
@MJZ: I just want to know how can I achieve this. –  m0nhawk Dec 14 '12 at 17:57

Nicole Hamilton provided the description of what sparse files are.
Let's learn it with an experiment.

## Creating a Sparse File

Start a Command Prompt (cmd.exe) as Administrator.

1. Creating large file:

fsutil file createnew test.nul 1048576

2. Check its size in Explorer:
• Size: 1.00 MB (1,048,576 bytes)
• Size on disk: 1.00 MB (1,048,576 bytes)
3. Let's mark it sparse:

fsutil sparse setflag test.nul

4. Nothing changed so far, the both sizes are still 1.00 MB.
5. Let's mark the entire byte range as sparse:

fsutil sparse setrange test.nul 0 1048576

6. Now the sizes changed dramatically:
• Size: 1.00 MB (1,048,576 bytes)
• Size on disk: 1.00 KB (1 024 bytes)
7. You can query if the file is sparse or not with fsutil:

fsutil sparse queryflag test.nul
This file is set as sparse


Or

This file is NOT set as sparse


The value of Size on disk depends on the cluster size of the file system. The default cluster size on NTFS is 4 KB. The drive I used for testing was formatted with 1 KB cluster.

## Removing Sparse Attribute

The utility I used in the example does not provide a flag to remove sparse attribute.

The simplest way to do is to copy the file. The file will lose this special attribute if the application that copies it does not specially preserve the sparse attribute and sparse range.

You can use Far Manager to clear the sparse attribute. Navigate to the file and press Ctrl + A to open Attribute dialog. Clear Sparse check box. And click Set button.

-

This sparse attrib problem happens all the time with downloaded isos for me.

Put this in a batch file and drag-and-drop the target file into it (with Windows Explorer). Et voilá

fsutil sparse queryflag %1 pause fsutil sparse setflag %1 0 fsutil sparse queryflag %1 pause

-

A sparse file is one that has holes in it. Large sections of binary zeros aren't written to disk. Here's Microsoft's explanation from Sparse Files (Windows):

When sparse file functionality is enabled, the system does not allocate hard disk drive space to a file except in regions where it contains nonzero data. When a write operation is attempted where a large amount of the data in the buffer is zeros, the zeros are not written to the file. Instead, the file system creates an internal list containing the locations of the zeros in the file, and this list is consulted during all read operations. When a read operation is performed in areas of the file where zeros were located, the file system returns the appropriate number of zeros in the buffer allocated for the read operation. In this way, maintenance of the sparse file is transparent to all processes that access it, and is more efficient than compression for this particular scenario.

-