linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Linus Torvalds <torvalds@linux-foundation.org>
To: Anders Larsen <al@alarsen.net>
Cc: Guenter Roeck <linux@roeck-us.net>,
	Richard Henderson <rth@twiddle.net>,
	Ivan Kokshaysky <ink@jurassic.park.msu.ru>,
	Matt Turner <mattst88@gmail.com>,
	"James E . J . Bottomley" <James.Bottomley@hansenpartnership.com>,
	Helge Deller <deller@gmx.de>,
	"David S . Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>,
	alpha <linux-alpha@vger.kernel.org>,
	Geert Uytterhoeven <geert@linux-m68k.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	linux-parisc@vger.kernel.org, Netdev <netdev@vger.kernel.org>,
	Sparse Mailing-list <linux-sparse@vger.kernel.org>
Subject: Re: [PATCH v2 0/4] Introduce and use absolute_pointer macro
Date: Thu, 16 Sep 2021 09:25:38 -0700	[thread overview]
Message-ID: <CAHk-=wh84ks6FN2fBWrGZNKNhOmTZL-r5xZG7gYZ==jESG2GgA@mail.gmail.com> (raw)
In-Reply-To: <5497691.DvuYhMxLoT@alarsen.net>

On Thu, Sep 16, 2021 at 12:02 AM Anders Larsen <al@alarsen.net> wrote:
>
> On Wednesday, 2021-09-15 23:19 Linus Torvalds wrote:
> >
> > But hey, maybe it just works so well for the very specialized user base ...
>
> it's actually the latter (although I guess the user base is shrinking)

Hey, so if it's actively used, maybe you can answer a question or two
that I have just because I looked at the code..

In particular, the inode number calculation is odd. Is there a reason
for the "-1"? Because iboth the link case and the direct inode case
have it, but t's a _different_ "-1":

For the "inode_entry", it does

                ino = blknum * QNX4_INODES_PER_BLOCK + ix - 1;

but it's worth noting that "ix" is zero-based (index within the
block), so this kind of oddly removes one from a zero-based thing, and
the 'ino' for the very first entry ends up being -1.

Of course, it's possible that the first entry is always empty, but it
does seem a bit odd.

For the "link_info" case, it does

            ino = ( le32_to_cpu(de->link.dl_inode_blk) - 1 ) *
                    QNX4_INODES_PER_BLOCK +
                    de->link.dl_inode_ndx;

so now it takes the _block_ index, and does that "-1" on it, and then
multiplies it by the "entries per block" number, and adds the index.

So now if both are zero, the inode number is -8, not -1.

But all of this matches what the *lookup* code does. It's very odd, though.

But to make it stranger, then in "qnx4_iget()", the calculations all
makes sense. There it just does "take the inode number, and look up
block and index into the block using it".

Very strange and confusing. Because it means that iget() seems to look
up a *different* inode entry than "lookup" and "readdir" actually look
at.

I must be missing something. I obviously didn't touch any of this
logic, I was just doing the "make the type system clearer for the
compiler".

Also, I have to say, since I was looking at compiler output, the
calculations in readdir() are made much worse by the fact that the
dir->pos is a "loff_t". That's signed. And then you use "%" to get the
index within a block. Using '%' instead of bitops is fairly
equivalent, but only for

 (a) unsigned types

 (b) when the divisor is a compile-time power-of-2

In the qnx4 case, (b) is true, but (a) is not.

Not a big deal. But usually, I tell people to avoid '% ENTRIES',
because it really has very different behavior from '& MASK' for signed
numbers.

                  Linus

  reply	other threads:[~2021-09-16 17:52 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-15  3:52 [PATCH v2 0/4] Introduce and use absolute_pointer macro Guenter Roeck
2021-09-15  3:52 ` [PATCH v2 1/4] compiler.h: Introduce " Guenter Roeck
2021-09-15  7:07   ` Geert Uytterhoeven
2021-09-15  7:13   ` Geert Uytterhoeven
2021-09-15 14:03     ` Guenter Roeck
2021-09-15  3:52 ` [PATCH v2 2/4] net: i825xx: Use absolute_pointer for memcpy from fixed memory location Guenter Roeck
2021-09-15  7:08   ` Geert Uytterhoeven
2021-09-15  3:52 ` [PATCH v2 3/4] alpha: Move setup.h out of uapi Guenter Roeck
2021-09-15  3:52 ` [PATCH v2 4/4] alpha: Use absolute_pointer to define COMMAND_LINE Guenter Roeck
2021-09-15 19:18 ` [PATCH v2 0/4] Introduce and use absolute_pointer macro Linus Torvalds
2021-09-15 19:35   ` Guenter Roeck
2021-09-15 19:47     ` Linus Torvalds
2021-09-15 19:50       ` Linus Torvalds
2021-09-15 21:19         ` Linus Torvalds
2021-09-16  7:02           ` Anders Larsen
2021-09-16 16:25             ` Linus Torvalds [this message]
2021-09-15 20:30       ` Helge Deller
2021-09-15 22:33       ` Guenter Roeck
2021-09-16 18:35         ` Linus Torvalds
2021-09-18  9:51           ` Michael Cree
2021-09-18 13:11             ` Ulrich Teichert
2021-09-18 17:04               ` Linus Torvalds
2021-09-18 17:17                 ` Thorsten Glaser
2021-09-18 17:21                   ` Linus Torvalds
2021-09-18 17:28                 ` Linus Torvalds
2021-09-18 20:26                 ` Ulrich Teichert
2021-09-18 20:46                   ` Linus Torvalds
2021-09-18 21:12                     ` Linus Torvalds
2021-09-18 22:09                   ` Linus Torvalds
2021-09-19 15:13                     ` Dave Taht
2021-09-20 18:25                     ` Ulrich Teichert
2021-09-20 18:46                       ` Linus Torvalds
2021-09-20 18:59                         ` Matt Turner
2021-09-20 19:45                           ` Linus Torvalds
2021-09-21 19:13                         ` Ulrich Teichert
2021-09-21 20:42                           ` Linus Torvalds
2021-09-21 21:39                           ` Linus Torvalds
2021-09-22 20:50                             ` Ulrich Teichert
2021-09-16 19:47         ` Linus Torvalds
2021-09-16  0:34   ` Michael Cree

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAHk-=wh84ks6FN2fBWrGZNKNhOmTZL-r5xZG7gYZ==jESG2GgA@mail.gmail.com' \
    --to=torvalds@linux-foundation.org \
    --cc=James.Bottomley@hansenpartnership.com \
    --cc=al@alarsen.net \
    --cc=davem@davemloft.net \
    --cc=deller@gmx.de \
    --cc=geert@linux-m68k.org \
    --cc=ink@jurassic.park.msu.ru \
    --cc=kuba@kernel.org \
    --cc=linux-alpha@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-parisc@vger.kernel.org \
    --cc=linux-sparse@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=mattst88@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=rth@twiddle.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).