macOS Finder still can't work out the size of files

https://eclecticlight.co/2024/05/03/finder-still-cant-work-out-the-size-of-files/

For the last six years I have been concerned that file sizes shown by the Finder aren’t accurate. Go back to the last century, and that was something that Classic Mac OS got right. To get the definitive answer, all you had to do was use ResEdit’s Get Info command.

filesize04

In those days, files came with two forks, regular data and the Resource Fork. This dialog gives the size in bytes for each, in this case 117,836 in the Resource fork, and 144,788 bytes data.

In January 2018, High Sierra couldn’t match that.

filesize02

The size of this text file is given as 391 bytes in the Finder’s Get Info, but as you’ll see below it contains over 90,000 bytes of extended attributes that figure simply ignores.

filesize01

Since then, macOS has tried harder, but still isn’t up to the job, as shown in Sonoma 14.4.1.

resfinder1

Here Get Info claims this crafted example file is 263,195 bytes in size.

resfinder2

My free utility Precize begs to differ: according to figures obtained from the file system, there are 183,136 bytes of data and 161,326 bytes of extended attributes, coming to a total of 344,462 bytes.

resfinder3

That’s not surprising, as xattred reveals that it has two extended attributes each of 80,059 bytes accounting for much of their size.

The clue as to what the Finder is getting wrong comes in the URL Keys line from Precize, where the total size matches that given by the Finder, 263,195 bytes. So how come information taken from the URL of a file can get its size so wrong?

As Precize shows, those figures are derived from two different sources. The correct numbers come from the size key in its file attribute dictionary “whose value indicates the file’s size in bytes.” To that, Apple adds a highlighted box marked Important, and explains that “if the file has a resource fork, the returned value does not include the size of the resource fork.” Interpreting that for modern macOS, that’s the size of the data, excluding extended attributes. So Precize then adds the total size of all the file’s extended attributes to give the final total from the file system.

The figures given for URL Keys are taken from URL resourceValues for fileSize and totalFileSize. Apple defines those as:

  • fileSize is “the total file size, in bytes”
  • totalFileSize is “the total displayable size of the file, in bytes. The allocated size in bytes may include space used by metadata.”

and that’s as close to a total file size including extended attributes that macOS seems able to give. In this case, totalFileSize includes around half the extended attributes, but not all of them, making it incorrect for just the data size, and incorrect for the total of data and extended attributes. Apple doesn’t explain how it chooses which to include, but it renders the figure of little or no use. Although for some reason, the Finder seems to believe it.

Over the last six years we have progressed from Get Info omitting extended attributes altogether, to including some of them apparently at random. Maybe in another six years, the Finder will prove more accurate.

{
"by": "ingve",
"descendants": 0,
"id": 40245053,
"score": 4,
"time": 1714720637,
"title": "macOS Finder still can't work out the size of files",
"type": "story",
"url": "https://eclecticlight.co/2024/05/03/finder-still-cant-work-out-the-size-of-files/"
}
{
"author": "hoakley",
"date": "2024-05-03T08:50:16.000Z",
"description": "Classic Mac OS could give the size of data and resource forks. High Sierra ignored extended attributes, and Sonoma tries to add them, but only includes some.",
"image": "https://eclecticlight.co/wp-content/uploads/2024/05/resfinder2.jpg",
"logo": "https://eclecticlight.co/wp-content/uploads/2015/01/eclecticlightlogo-e1421784280911.png?w=103",
"publisher": "The Eclectic Light Company",
"title": "Finder still can’t work out the size of files",
"url": "https://eclecticlight.co/2024/05/03/finder-still-cant-work-out-the-size-of-files/"
}
{
"url": "https://eclecticlight.co/2024/05/03/finder-still-cant-work-out-the-size-of-files/",
"title": "Finder still can’t work out the size of files",
"description": "For the last six years I have been concerned that file sizes shown by the Finder aren’t accurate. Go back to the last century, and that was something that Classic Mac OS got right. To get the definitive...",
"links": [
"https://eclecticlight.co/2024/05/03/finder-still-cant-work-out-the-size-of-files/",
"https://wp.me/p5CIcf-kTm"
],
"image": "https://eclecticlight.co/wp-content/uploads/2024/05/resfinder2.jpg?w=640",
"content": "<div>\n\t\t<p>For the last six years I have been concerned that file sizes shown by the Finder aren’t accurate. Go back to the last century, and that was something that Classic Mac OS got right. To get the definitive answer, all you had to do was use ResEdit’s <strong>Get Info</strong> command.</p>\n<p><span><img src=\"https://eclecticlight.co/wp-content/uploads/2018/01/filesize04.jpg?w=940\" alt=\"filesize04\" srcset=\"https://eclecticlight.co/wp-content/uploads/2018/01/filesize04.jpg 1358w, https://eclecticlight.co/wp-content/uploads/2018/01/filesize04.jpg?w=150&amp;h=112 150w, https://eclecticlight.co/wp-content/uploads/2018/01/filesize04.jpg?w=300&amp;h=225 300w, https://eclecticlight.co/wp-content/uploads/2018/01/filesize04.jpg?w=768&amp;h=575 768w, https://eclecticlight.co/wp-content/uploads/2018/01/filesize04.jpg?w=1024&amp;h=767 1024w\" /></span></p>\n<p>In those days, files came with two forks, regular data and the Resource Fork. This dialog gives the size in bytes for each, in this case 117,836 in the Resource fork, and 144,788 bytes data.</p>\n<p>In January 2018, High Sierra couldn’t match that.</p>\n<p><span><img src=\"https://eclecticlight.co/wp-content/uploads/2018/01/filesize02.jpg?w=940\" alt=\"filesize02\" srcset=\"https://eclecticlight.co/wp-content/uploads/2018/01/filesize02.jpg 801w, https://eclecticlight.co/wp-content/uploads/2018/01/filesize02.jpg?w=150&amp;h=74 150w, https://eclecticlight.co/wp-content/uploads/2018/01/filesize02.jpg?w=300&amp;h=148 300w, https://eclecticlight.co/wp-content/uploads/2018/01/filesize02.jpg?w=768&amp;h=378 768w\" /></span></p>\n<p>The size of this text file is given as 391 bytes in the Finder’s <strong>Get Info</strong>, but as you’ll see below it contains over 90,000 bytes of extended attributes that figure simply ignores.</p>\n<p><span><img src=\"https://eclecticlight.co/wp-content/uploads/2018/01/filesize01.jpg?w=940\" alt=\"filesize01\" srcset=\"https://eclecticlight.co/wp-content/uploads/2018/01/filesize01.jpg 961w, https://eclecticlight.co/wp-content/uploads/2018/01/filesize01.jpg?w=150&amp;h=91 150w, https://eclecticlight.co/wp-content/uploads/2018/01/filesize01.jpg?w=300&amp;h=182 300w, https://eclecticlight.co/wp-content/uploads/2018/01/filesize01.jpg?w=768&amp;h=466 768w\" /></span></p>\n<p>Since then, macOS has tried harder, but still isn’t up to the job, as shown in Sonoma 14.4.1.</p>\n<p><span><img src=\"https://eclecticlight.co/wp-content/uploads/2024/05/resfinder1.jpg?w=940\" alt=\"resfinder1\" srcset=\"https://eclecticlight.co/wp-content/uploads/2024/05/resfinder1.jpg 530w, https://eclecticlight.co/wp-content/uploads/2024/05/resfinder1.jpg?w=140&amp;h=150 140w, https://eclecticlight.co/wp-content/uploads/2024/05/resfinder1.jpg?w=281&amp;h=300 281w\" /></span></p>\n<p>Here <strong>Get Info</strong> claims this crafted example file is 263,195 bytes in size.</p>\n<p><span><img src=\"https://eclecticlight.co/wp-content/uploads/2024/05/resfinder2.jpg?w=940\" alt=\"resfinder2\" srcset=\"https://eclecticlight.co/wp-content/uploads/2024/05/resfinder2.jpg 804w, https://eclecticlight.co/wp-content/uploads/2024/05/resfinder2.jpg?w=150&amp;h=68 150w, https://eclecticlight.co/wp-content/uploads/2024/05/resfinder2.jpg?w=300&amp;h=136 300w, https://eclecticlight.co/wp-content/uploads/2024/05/resfinder2.jpg?w=768&amp;h=348 768w\" /></span></p>\n<p>My free utility <a target=\"_blank\" href=\"https://eclecticlight.co/taccy-signet-precize-alifix-utiutility-alisma/\">Precize</a> begs to differ: according to figures obtained from the file system, there are 183,136 bytes of data and 161,326 bytes of extended attributes, coming to a total of 344,462 bytes.</p>\n<p><span><img src=\"https://eclecticlight.co/wp-content/uploads/2024/05/resfinder3.jpg?w=940\" alt=\"resfinder3\" srcset=\"https://eclecticlight.co/wp-content/uploads/2024/05/resfinder3.jpg 962w, https://eclecticlight.co/wp-content/uploads/2024/05/resfinder3.jpg?w=150&amp;h=143 150w, https://eclecticlight.co/wp-content/uploads/2024/05/resfinder3.jpg?w=300&amp;h=286 300w, https://eclecticlight.co/wp-content/uploads/2024/05/resfinder3.jpg?w=768&amp;h=733 768w\" /></span></p>\n<p>That’s not surprising, as <a target=\"_blank\" href=\"https://eclecticlight.co/xattred-sandstrip-xattr-tools/\">xattred</a> reveals that it has two extended attributes each of 80,059 bytes accounting for much of their size.</p>\n<p>The clue as to what the Finder is getting wrong comes in the URL Keys line from Precize, where the total size matches that given by the Finder, 263,195 bytes. So how come information taken from the URL of a file can get its size so wrong?</p>\n<p>As Precize shows, those figures are derived from two different sources. The correct numbers come from the <code>size</code> key in its file attribute dictionary “whose value indicates the file’s size in bytes.” To that, Apple adds a highlighted box marked <strong>Important</strong>, and explains that “if the file has a resource fork, the returned value does not include the size of the resource fork.” Interpreting that for modern macOS, that’s the size of the data, excluding extended attributes. So Precize then adds the total size of all the file’s extended attributes to give the final total from the file system.</p>\n<p>The figures given for URL Keys are taken from URL resourceValues for <code>fileSize</code> and <code>totalFileSize</code>. Apple defines those as:</p>\n<ul>\n<li><code>fileSize</code> is “the total file size, in bytes”</li>\n<li><code>totalFileSize</code> is “the total displayable size of the file, in bytes. The allocated size in bytes may include space used by metadata.”</li>\n</ul>\n<p>and that’s as close to a total file size including extended attributes that macOS seems able to give. In this case, <code>totalFileSize</code> includes around half the extended attributes, but not all of them, making it incorrect for just the data size, and incorrect for the total of data <em>and</em> extended attributes. Apple doesn’t explain how it chooses which to include, but it renders the figure of little or no use. Although for some reason, the Finder seems to believe it.</p>\n<p>Over the last six years we have progressed from <strong>Get Info</strong> omitting extended attributes altogether, to including some of them apparently at random. Maybe in another six years, the Finder will prove more accurate.</p>\n\t</div>",
"author": "@howardnoakley",
"favicon": "https://eclecticlight.co/wp-content/uploads/2015/01/cropped-eclecticlightlogo-e1421784280911.png?w=192",
"source": "eclecticlight.co",
"published": "2024-05-03T08:50:16+00:00",
"ttr": 105,
"type": "article"
}