Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 7 Oct 2021 10:56:15 -0600
From:      Alan Somers <asomers@freebsd.org>
To:        Mariusz Zaborski <oshogbo@freebsd.org>
Cc:        Ian Lepore <ian@freebsd.org>, src-committers <src-committers@freebsd.org>,  "<dev-commits-src-all@freebsd.org>" <dev-commits-src-all@freebsd.org>, dev-commits-src-main@freebsd.org
Subject:   Re: git: 824bbb9a4082 - main - diff: consider two files with same inodes as identical
Message-ID:  <CAOtMX2jXaZ0MXD_=Q5hjH-B0G5XD0bwbJH8whLS_tDrT9i1ADw@mail.gmail.com>
In-Reply-To: <CAGOYWV_ud8CLX6a=2nJ9sQNuHEgdf7ik0t%2BLweAJhYkvmo2-CQ@mail.gmail.com>
References:  <202110071509.197F9kqv094488@gitrepo.freebsd.org> <CAOtMX2gfBsuXSCCfN-8EQHR%2ByCVOu8qJ7_3BxLxe=dDqY_9uEw@mail.gmail.com> <e479e95ebc85acf4eda0e729d3e6373de674fd13.camel@freebsd.org> <CAGOYWV_ud8CLX6a=2nJ9sQNuHEgdf7ik0t%2BLweAJhYkvmo2-CQ@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, Oct 7, 2021 at 9:54 AM Mariusz Zaborski <oshogbo@freebsd.org> wrote:
>
> Like Ian said from what I know this is the way of uniquely identify the file.
> We use this technique in flopen(3), pidfile_open(3) or fts(3).
>
> On Thu, 7 Oct 2021 at 17:40, Ian Lepore <ian@freebsd.org> wrote:
>>
>> On Thu, 2021-10-07 at 09:32 -0600, Alan Somers wrote:
>> > On Thu, Oct 7, 2021 at 9:09 AM Mariusz Zaborski <oshogbo@freebsd.org>
>> > wrote:
>> > >
>> > > The branch main has been updated by oshogbo:
>> > >
>> > > URL:
>> > > https://cgit.FreeBSD.org/src/commit/?id=824bbb9a40820fb62bde0a91c0f13e0b894da149
>> > >
>> > > commit 824bbb9a40820fb62bde0a91c0f13e0b894da149
>> > > Author:     Mariusz Zaborski <oshogbo@FreeBSD.org>
>> > > AuthorDate: 2021-10-07 15:07:00 +0000
>> > > Commit:     Mariusz Zaborski <oshogbo@FreeBSD.org>
>> > > CommitDate: 2021-10-07 15:07:00 +0000
>> > >
>> > >     diff: consider two files with same inodes as identical
>> > >
>> > >     Obtained from:  OpenBSD
>> > >     MFC after:      1 week
>> > > ---
>> > >  usr.bin/diff/diffreg.c | 4 ++++
>> > >  1 file changed, 4 insertions(+)
>> > >
>> > > diff --git a/usr.bin/diff/diffreg.c b/usr.bin/diff/diffreg.c
>> > > index fc3c3406a073..995843f9e539 100644
>> > > --- a/usr.bin/diff/diffreg.c
>> > > +++ b/usr.bin/diff/diffreg.c
>> > > @@ -440,6 +440,10 @@ files_differ(FILE *f1, FILE *f2, int flags)
>> > >         if ((flags & (D_EMPTY1|D_EMPTY2)) || stb1.st_size !=
>> > > stb2.st_size ||
>> > >             (stb1.st_mode & S_IFMT) != (stb2.st_mode & S_IFMT))
>> > >                 return (1);
>> > > +
>> > > +       if (stb1.st_dev == stb2.st_dev && stb1.st_ino ==
>> > > stb2.st_ino)
>> > > +               return (0);
>> > > +
>> >
>> > Checking st_dev is not correct.  It does necessarily bear any
>> > relation
>> > to the specific mounted file system.  It might, but that's up to the
>> > file system driver.  fusefs, for example, allows the server to
>> > populate that field with whatever it damn well pleases.  diff should
>> > use statfs instead, and check the f_fsid field.  That would probably
>> > work.
>> > -Alan
>>
>> That may be a fusefs bug, then.  Posix states
>>
>>    The st_ino and st_dev fields taken together uniquely identify the
>>    file within the system.
>>
>> And I've seen real-world code more than once that uses st_dev equality
>> to decide whether to rename versus copy-and-delete a file.
>>
>> -- Ian

Nevermind, I was confusing st_dev with st_rdev.  Everything's fine,
and this looks like a good optimization.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAOtMX2jXaZ0MXD_=Q5hjH-B0G5XD0bwbJH8whLS_tDrT9i1ADw>