This is a follow-up issue for #267883: parse_size() and format_size() do not use same kilo standard. Since we now have the DRUPAL_KILOBYTE, we should remove hard-coded file sizes.

CommentFileSizeAuthor
#1 335425-DRUPAL-KILOBYTE-D7.patch13.81 KBdave reid

Comments

dave reid’s picture

Status: Active » Needs review
StatusFileSize
new13.81 KB

Here's a starter patch. I hope it will pass testing. I am a little unsure of the changes made in drupalGetTestFiles().

mrharolda’s picture

Nice one!

I'm wandering if the 1024 byte fread()'s are sane candidates for the DRUPAL_KILOBYTE, though...

-H-

dave reid’s picture

Well I went for a replace-everything-I-could-find approach and figured we could narrow it down instead of trying to find more.

alexanderpas’s picture

Status: Needs review » Needs work

we also need to test with DRUPAL_KILOBYTE set to 1000, to see if there are any possible problems in the future...

quick context review

common.inc - file.inc - locale.inc
fread() and fgets() almost certainly should be working with 1024 (DRUPAL_KIBIBYTE anyone?)

blogapi.module
$usersize and $uploadsize are probaly proper changes.

filter.module
also, almost certainly should be working with DRUPAL_KIBIBYTE

simpletest.install
Certainly should be DRUPAL_KIBIBYTE, as it is clearly using powers of 2

file.test - upload.admin.inc - upload.module - upload.test - user.module - user.test
almost certainly proper changes!

also... there are some unrelated changes in your file.

mrharolda’s picture

Defining a DRUPAL_KIBIBYTE seems like a good idea. At first both the Kilobyte and the Kibibyte will be 1024 bytes...

Later (php 6?) Drupal can change the Kilobyte to 1000...

mrharolda’s picture

Late August, even Apple decided to change Mac OS X v10.6 to use 1000 bytes per kilobyte.

Isn't it time to fix Drupal's "wrong" kilobyte define yet?

define('DRUPAL_KILOBYTE', 1000);

alexanderpas’s picture

I wonder when PHP itself will be making the switch? http://bugs.php.net/bug.php?id=46534

mrharolda’s picture

Version: 7.x-dev » 8.x-dev

3 years later and Drupal 8.x is in -dev... What about correcting the kilobyte to what it should be in D8? ;)

1000!

pingers’s picture

Uh, yeah, because Drupal is hosted on Mac OSX. No.

Still agree Dave Reid's patch should go in :)
Although, probably needs a re-roll.

mrharolda’s picture

@pingers: what do you mean by "Uh, yeah, because Drupal is hosted on Mac OSX. No."?

For the record: 1 kilobyte equals 1000 bytes, just like 1 kilometer equals 1000 meters. The question is if Drupal should follow conventions and use the correct definition (1000) or make the same misstake as a lot of other implementations and lie about the value of a kilo (1024, which is a 'kibi').

jbrown’s picture

alexanderpas’s picture

It is my opinion, Drupal should always be using the correct SI and IEC units, except when handling a interface that does not handle those units correctly

pingers’s picture

@MrHaroldA What I mean is the most sensible option is to use the unit used by the most commonly used hosting OS. I.e. Linux and 1024 bytes in a kilobyte. Also this is the value used by the IEC standard noted in #12 (IEC = 2^10, SI = 10^3). Also, it has nothing to do with this issue. Please open a new issue to debate this. Feel free to link to it from this issue.

mrharolda’s picture

@pingers: IIRC, Linux uses the correct standard: 1000 bytes in a kB.

And no need for a new issue: #1114538: Use SI and/or IEC units for byte counts? covers it all...

pingers’s picture

$ dd if=/dev/zero of=testfile.txt bs=1K count=1
1+0 records in
1+0 records out
1024 bytes (1.0 kB) copied, 8.552e-05 s, 12.0 MB/s

Sorry, you're wrong.

mrharolda’s picture

@pingers: I notices that you use 'K' instead of 'k', which is also wrong in a SI approach. It's also silly to refer to an invalid application for the "truth" as dd should read "kiB" or "KB" for 1024 bytes as 1kB equals 1000 bytes.

The hosting OS has nothing to do with a website: the visiting OS is much more leading. I don't know what Windows is using these days, but OSX and a lot of Linux file managers already show correct SI sizes, with more to follow suit.

There are 2 options: use SI or IEC. PHP itself aready has plans to ditch IEC support and switch over to SI, why should our favorite CMS stay behind?

pingers’s picture

Got a link? If and when they do, I'd consider it a possibility.

mrharolda’s picture

Some nice reads:
http://drupal.org/node/267883#comment-1100817

drupal should follow standards closely, and change when standards are updated, as the drop is always moving, AND SHOUD NOT LAG BEHIND!

also, this has a usability impact, since using the same wording with two different meanings is JUST PLAIN WRONG, and should end RIGHT NOW, Regular users don't know that the units have dual meanings, and we shouldn't continue confusing them in this way.

also "man 7 units" on your linux-box ;)

https://bugs.php.net/bug.php?id=46534

Note that even Mac OS X v10.6 is using 1000 bytes per kilobyte. (http://support.apple.com/kb/TS2419)

Linux is using it for years already (units(8) manual page)

The only operating system still using 1024 for kilo is Microsoft Windows

I suggest we use the proper and full kilobyte and kibibyte definitions as soon as possible!

And even Dries agrees we should use SI instead of IEC: http://drupal.org/node/151902#comment-858570

Posted by Dries on May 27, 2008 at 9:30am
I'm OK with the patch in #5 but it could use a SimpleTest ...

alexanderpas’s picture

There are three different filesizes we need to account for.

Memory sizes expressed in base-2 (IEC) units. (1kiB = 1024 bytes)
Disk sizes expressed in base-10 (SI) units. (1kB = 1000 bytes)
Shorthand sizes returned from PHP that use the wrong type (1k for 1024) such as the memory_limit setting.

jbrown’s picture

@alexanderpas #1114538: Use SI and/or IEC units for byte counts? handles all of those combinations.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev
quietone’s picture

Assigned: dave reid » Unassigned
Issue summary: View changes
Status: Needs work » Closed (outdated)
Issue tags: +Bug Smash Initiative

I think this work has been completed in other issues, such as #3001398: format_size() fixes. I searched Drupal 10.0.x found 31 instances of 1024 (excluding files in a 'fixtures' directory) but I did not spot any one that needed to be changed. If I am wrong about that it would be better to open a new issue anyway because of the many code changes that have happened in the intervening 10 years.

I came here while triaging a related issue for bugsmash, adding tag.

Closing as outdated.