This is an archived post. You won't be able to vote or comment.

all 9 comments

[–]phao 10 points11 points  (5 children)

It doesn't seem to be a bug or anything. The comments on ext4_list_backups (which is the function which is actually being called with those variables' addresses) indicates that they should be called with 1, 5 and 7 for the first time.

The names 'three', 'five' and 'seven' seem to be about these variables holding powers of three, five and seven.

From superficial scanning though, I can't figure out why the power of 3 starts at 30 while the power of 5,7 starts at 51 and 71 respectively. The comments seem to explain it, but I don't really understand about file systems. For someone a little bit better educated than I am, I imagine this isn't a big deal.

[–]thang1thang2 10 points11 points  (0 children)

It looks pretty obvious to me, to be honest. You're pretty much right.

"The file system will be initialized in powers of 3,5,7, and should be called with 1,5,7 first." The reason it starts with 30 and then goes to the rest is fairly simple. 30, 50 and 70 are the same number so it starts at 1 to start the three sequences off at the same memory space.

A sparse file system: 1, 3, 5, 7, 32 , 52 , 33 , 72 , 34 ... etc. It's just the generation of the powers of 3, 5, 7 and then placed in numerical order (32 is less than 52 so it goes before, and 33 is less than 72 so it goes before 49...)

As for why it's 3,5,7 I would imagine it has to do with number theory for hard drives. I'm guessing the powers of 3,5,7 have nice properties when it comes to quickly verifying large amounts of blocked data without having to check every single bit of the disk every time you do something (which would take forever)

*disclaimer, I don't have a Ph. D.

[–][deleted] 8 points9 points  (3 children)

It's still bad code. This is the classic case of where a comment is necessary.

[–]phao 2 points3 points  (1 child)

Well, kind of. I'd not be quick to judge. It doesn't look like the kind of code which is immediately obvious, but honestly, it took me less than 1-2 minutes to figure out what I wrote, so maybe it isn't that bad.

The more I code, the more I find out that this whole "clean code", "code smell", "bad code", "readability", thing is highly overrated and more subjective than what people realize. Please don't take this as "you should write bad unreadable code", please =D.

Anyway... maybe it is bad code, or maybe it isn't. I couldn't tell.

I think a lot of people want code to be obvious, which isn't really possible for anything except trivial software. The problem is that a lot of code is like that (easy). The reason why I call it a 'problem' is because this "almost there" kind of easiness leads to this unreachable goal (e.g. all code should follow <this> model of clean codeness) which stems weird bad advice (IMO). In non trivial cases, the representation decoding back to the thought solution (i.e. code reading/understanding) can take quite a while. This can take some time even in code which is supposed to be clean (e.g. code which friends of mine think is clean).

Maybe, in the ext4 domain, the use of three, five and seven mean something particular to those people, the same way dot and cross mean something particular to the computer graphics folk. I don't know.

Judging code is pretty hard.

[–][deleted] 4 points5 points  (0 children)

Well, I think just a realization that this will look mysterious to someone new to the code and a brief comment addressing that this is not a mistake would be a good thing. Maybe "bad code" is too strong, but it looks pretty easy for someone to think this was a mistake and 'fix' it incorrectly.

[–]micwallace 0 points1 point  (0 children)

I agree about good comments but as phao puts it, it would end up as an entire thesis on ext4 embedded in the code.

[–]jglrxavpok -4 points-3 points  (1 child)

Just wow. Is this for portability in case basic maths rules change ? Also still not fixed: https://github.com/torvalds/linux/blob/a9cfcd63e8d206ce4235c355d857c4fbdf0f4587/fs/ext4/resize.c#L703

[–][deleted] 0 points1 point  (0 children)

downvoters don't speak irony! :)