osx - Why is the physical size of a .dylib file smaller than it's logical size?

08
2013-08
  • Tonin

    There is a behavior I cannot explain in OSX Lion (might be on other versions too).

    When I copy or duplicate some applications, for example iTunes, that contain some dynamic libraries, the physical size of those libraries changes (the size grows). This can be because of disk fragmentation. But it is not only that, because what is surprising is that the original physical size is smaller than the logical size (where usually the physical size is always bigger than the logical one, except when there is compression involved).

    To illustrate my case:

    antoine@amarante:/Applications$ ls -ls iTunes.app/Contents/MacOS/libgnsdk_submit.1.8.2.dylib 
    384 -rwxrwxr-x+ 1 root  admin  558704  8 jul  2011 iTunes.app/Contents/MacOS/libgnsdk_submit.1.8.2.dylib
    

    ls considers a block size of 512 bytes, 384 blocks make 196608 bytes compared to the 558704 bytes reported logical size. Or, as shown in a get info window from the Finder:

    558.704 octets (197 Ko sur disque)
    

    This is also shown after some copy operations where I copied over the whole iTunes application. The first iTunes copie is a duplicate done through the Finder and iTunes-cp is a copy done with the CLI cp -a command.

    antoine@amarante:/Applications$ ls -ls iTunes*.app/Contents/MacOS/libgnsdk_dsp.1.8.2.dylib 
    11632 -rwxr-xr-x+ 1 antoine  admin  5955104  8 jul  2011 iTunes copie.app/Contents/MacOS/libgnsdk_dsp.1.8.2.dylib
    11632 -rwxrwxr-x+ 1 antoine  admin  5955104  8 jul  2011 iTunes-cp.app/Contents/MacOS/libgnsdk_dsp.1.8.2.dylib
     3944 -rwxrwxr-x+ 2 root     admin  5955104  8 jul  2011 iTunes.app/Contents/MacOS/libgnsdk_dsp.1.8.2.dylib
    

    We see that the copied files have a physical size larger (11632*512 = 5955584 bytes) than the logical size (5955104), except for the original file which is a lot smaller. When I copy the single .dylib file on its own, the behavior is the same. This happens for a few dynamic library files, not for all.

    How can the original library file be smaller than the copies? Is there some compression involved? Or are my original files corrupted in some way? How can I check that?

  • Answers
  • Dan Pritts

    There is in fact compression in HFS+ on the mac on 10.6 and later. It's transparent, and can be difficult to even detect with standard OS tools.

    And, it isn't always done. For backward compatibility the default is not to compress, but they do compress the OS when it's installed.

    http://hints.macworld.com/article.php?story=20090902223042255 has many gory details.

    http://reviews.cnet.com/8301-13727_7-20015100-263.html lists how various command line tools view the sizes of compressed files.


  • Related Question

    osx - Why does Mac OS X sometimes complain that a copy failed because a file is in use?
  • orj

    Recently I've been copying files from DVDs to network storage on my Mac running Leopard 10.5.7.

    I'm just dragging and dropping in Finder to perform the copy.

    Occasionally the copy will fail with a dialog complaining that a file is in use. If I repeat the copy generally it completes successfully.

    I could understand this being a problem if one was trying to move a file and it was open by another app. But none of these files are open in other apps. I just pop the DVD in, drag and drop the files to my NAS's network share and sometimes it fails with the "file in use" error.

    This is very annoying. Anyone have any ideas?


  • Related Answers
  • Chris W. Rea

    The utility What's Keeping Me? for OSX may help you find out what's keeping it from working. Basically, it lets you find out what process has a file open.

    "[...] Have you ever have the problem where you can’t empty the Trash or eject a disk because something is preventing you? Usually the reason is because some application has a file open, and thus you can’t get rid of the disk or trash the file. That’s why we made What’s Keeping Me! What’s Keeping Me will identify the application that is holding the item open. You can then use What's Keeping Me to quit the problem application (or kill it if needed) so you can perform your task. What’s Keeping Me includes an Automator workflow so you can perform searches directly from the Finder too! [...]"

  • Tommy

    Show icon preview is the problem! Put it on list view and there are no problems. It's a bug!

  • slhck

    The problem is Quick Look. As soon as you open a folder in the Finder it tries to create previews.

    I'm running 10.5.7 and still get this problem all the time transferring video files from external drives. Only solution seems to be to open the folder, wait for the preview icons to appear and then try to copy the files.

    A possible solution is to disable "Show icon preview" in the Finder view options. That only occurred to me, so I haven't tested it though.

    Note that you have to manually kill the quicklookd process.

  • bjtitus

    My first thought would be that Spotlight might be trying to index the drive and is accessing the file when you are trying to copy it. This may be wrong and I'll look into the issue more but my first thought is Spotlight.

  • Chealion

    I've had QuickLook cause an error similar to this when it was rendering previews - as far as I could tell it was just bad timing but have not seen this "bug" since 10.5.3. Is QuickLook creating previews when you are copying the files?

  • Zac Thompson

    One possibility is an antivirus program, if you have one (yes, I know you're on a mac). It might be checking the file while you are in the middle of copying it. I use Symantec, and because I never put anything other than my own stuff in the drive, I have disabled scanning on that device.