Why does my .sparseimage file size not reflect the amount of data insde of it?

SUMMARY

I have an uncompressed sparese image file that has over 35GB of data inside of it, yet the image file always claims to be taking up 4.29GB of space on the drive on which it resides.



DETAILS

The image file was created with Disk Utility useing the following settings:


User uploaded file


When I mount the image and Show Inspector for the contents, I see this:


User uploaded file



However, when I Get Info on the image file itself, mounted or not, I get this:


User uploaded file


I was expecting that the size of the file would be reported as roughly the same as the size of it's contents.



What gives?


-t

MacBook Air, Mac OS X (10.7.3)

Posted on Mar 2, 2012 9:24 PM

Reply
7 replies

Mar 6, 2012 5:53 AM in response to Doc.Caliban

Are the files inside the .sparseimage, also sparse?


Using Applications -> Utilities -> Terminal you should be able to see the file allocations


/bin/ls -sl /path/to/your/bin.sparseimage. The value in column 1 is the allocated storage in kilobytes. The file system allocates storage in increments of 4096 bytes (4K).


Then mounting the bin.sparseimage, look at


/bin/ls -slR /Volumes/whatever.name.it.is.mounted.under/


This should list all the files inside your bin.sparseimage, and again the numbers in column 1 are the allocated storage for each file in kilobytes.

Mar 6, 2012 7:30 PM in response to BobHarris

Hi Bob,


Thank you for ther reply ... very informative.


ls -sl reports:


8386880 -rwxrwxrwx 1 <username> staff 4294061568 Mar 6 21:17 bin.sparseimage


Does this indicates the file is using 8,386,880KB (7.9GB) of space on the hard drive? Finder indicates that it is only using 4.29GB of space on the drive.


The thing that really loses me is that mounting the image reveals 60GB of contents ... I use the image file as a backup / archive of files from my camera, be it RAW files, JPG's, or MOV files, and the current contents of the mounted image file use up 60GB.


So I'm still very confused ... I thought an image file is effectively an archive like .zip/.rar etc, and that a sparseimage file grew in size as needed, like a .zip file, but with a maximum capacity that is set when it is created.


So how do I have 60GB of media inside of an 8GB file, and why does Finder say that it's only a 4.29GB file?

I am expecting to see a much, much larger .sparseimage file, and I'm also expecting Terminal and Finder to agree on the file size.


I think I need some schooling!


-t

Mar 6, 2012 8:07 PM in response to Doc.Caliban

I was wrong about the column 1 units. They are a sector count with each sector being 512 bytes. So 8386880 * 512 = 4,294,082,560 (approx 4GB). So that is the actual amount of space being used by the bin.sparseimage.


You would also suppose to look at the column 1 values inside the sparseimage so make sure those files were using what you think they were (I've added an @ to the options so we can also see if any of the files inside the bin.sparseimage have extend attributes attached to them - it may or may not be useful, but better to get it now, then ask later):


/bin/ls -slR@ /Volumes/whatever.name.it.is.mounted.under/


And yes a sparseimage (and all the other Mac OS X image files) are containerized file systems, like an archive.


Without the above /bin/ls -slR@ output, it is difficult to guess what is inside the bin.sparseimage.


I'm also expecting Terminal and Finder to agree on the file size

Well from what I'm seeing the Terminal output does agree with the Finder. What we don't know is what is inside the sparseimage

Mar 8, 2012 7:53 PM in response to BobHarris

Hello, and thank you for the new reply.


I'm sorry to be slow with my responses, but I am wrapped up in the task of sorting out what has turned out to be over 100GB of photos and videos that I shot over the last ten years and have backed up all over the place ... I'm sorting through all of it and getting it all organized for the first time.


OK, here are the results of ls -lR@ /Volumes/Bin/


$ ls -lR@ /Volumes/Bin/

total 8382080

-rwxrwxrwx@ 1 <username> staff 4291448832 Nov 12 09:04 00000.MTS

com.apple.ResourceFork 286

drwxrwxrwx 32 <username> staff 1088 Jan 30 15:38 Misc

drwxr-xr-x 1638 <username> staff 55692 Mar 3 00:02 Images

drwxr-xr-x 922 <username> staff 31348 Mar 3 00:02 Videos


That'st the first bit, and there there are a zillion pages listing the contents of the top level directories. (Over 17k files)


Again, when I mount the sparseimage file, I see everything that I expect to see inside of it ... my backups of thousands of photos and hundreds of video files. I can view all of them, so the data is definitely there. This is why I am confused as to why the sparseimage file itself is being reported as so small!


I just noticed this ... there is a large video file in the root of the mounted image; 00000.MTS which happens to be 4.29GB in size ... everything else is located in one of the three directories that are listed. Now, the sparseimage happens to be reported as 4.29GB in size. That can't be a coincidence. Is the OS reporting the size of the sparseimage file based on the total reported contents of only the root directory? If so, that would explain why it shows as being 4.29GB. That would, however, be kind of a bug, no? Should it not report the size of the sparseimage as being the total size of all of the contents of the image?


As a test, I just moved that file into the Videos directory and then unmounted the image. bin.sparseimage is still reported as being 4.29GB.


Thanks,


-t

Mar 8, 2012 9:56 PM in response to Doc.Caliban

Here are the info windows for, left to right, the sparseimage file and the mounted image:


User uploaded file


So, again, how is it that the image contains 66GB of media files, yet the container, the sparseimage file itself, only takes up 4.3GB of space?


Am I to understand that the image file incorporates some kind of crazy-effective and wicked-fast compression that can reduce compressed images and videos to a small fraction of their original size?


-t

Mar 9, 2012 7:35 AM in response to Doc.Caliban

First you were suppose to use


/bin/ls -slR@ /Volumes/Bin/


Notice the 's', which would give the actual allocation for each file inside the .sparseimage


Second, you have only showed 3 directories, which is not going to tell us anything about how much space each file inside the .sparseimage thinks it is taking up.


A .sparseimage on the outside is "Just a Regular File". From the outside, there is nothing special about it. The "Sparse" part of its name means it can take advantage of the host's file system's ability to create what are called sparse files. That to say, if nothing is written to a range of the file, than the host file system does not need to allocate storage for that range, but later if something is written to that range, the host file system will allocate storage. This behavior is idea for .sparseimage files, as the inside is yet another file system, and it can be configured so its maximum potential size is much bigger than the amount of storage needed to initially create the .sparseimage file, and as the inner file system grows, the .sparseimage container file can have more stroage allocated to it by the host file system. That means you do not need to preallocate the maximum amount of storage for the maximum potential size. Much more strorage efficient.


However, that being said, the bin.sparseimage file using /bin/ls -sl@ will tell you exactly how much physical storage was allocated to the .sparseimage file.


I trust this value, so I unsure of what is inside the .sparseimage container file. Which is why I wanted to see /bin/ls -slR@ /Volumes/Bin so we could see if ...


a) the physical allocation for each individual file (not directories) matched the byte size of the file (I guess a moderate sample of real files would be good enough, but make that a hundred or so, and not just the few directories).


b) I would like to confirm that the /bin/ls command thinks they are real files, and not Mac OS X aliases, or Unix symlinks. Aliases and symlinks would just poing back to the originals on the boot disk, and take up very little space in the .sparseimage


c) other.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Why does my .sparseimage file size not reflect the amount of data insde of it?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.