1

Let's say that I have three files with the following sizes:

FileA: 15468bytes

FileB: 3874235bytes

FileC: 10452326bytes

and I want to create a UDIF, GPTSPUD, HFS+ DMG with hdiutil which will exactly the size needed to hold these files. I can, of course, tell hdiutil to create a dmg of the size 14342029 bytes, but the dmg will have < 14342029 bytes in free space available due to the number of bytes needed to support the file system.

Is there a known way to calculate how large to make the DMG so it will hold the files?

p.s. In the 'real' case, there are thousands of files of various sizes.

p.s.s. I am aware of various issues that files actual use X number of blocks on a disk and that a block is a fixed size.

ericg
  • 544
  • 2
  • 6
  • 16
  • 1
    Why do you want to create a disk image with the exact size for the files? Is creating a sparse image (which will be only take up the space required for its contents, rather than its entire capacity, including free space) somehow unsuitable? – Scott Aug 29 '11 at 13:01
  • 1
    Because I am curious about how to determine the exact size (or reasonably close). It is simply a question that I am seeking the answer to. – ericg Aug 29 '11 at 13:40
  • Well this is a hard one - you need to take into account the metadata for the .dmg itself. Why not simply use hdiutil create with the -srcfolder option, which will make a formfitting DMG? – w00t Sep 02 '11 at 17:34
  • Again, there are many solutions to the general problem is creating a DMG to hold a set of files. I am simple seeking a specific answer to this one. – ericg Sep 02 '11 at 18:29

0 Answers0