Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion ftok() on Linux generated different keys for the same inode and the same file name
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
André Gillibert  
View profile  
 More options Dec 17 2011, 5:57 am
Newsgroups: comp.unix.programmer, comp.os.linux.development.system
From: André Gillibert <MetaEntropy.removeT...@gmail.com>
Date: Sat, 17 Dec 2011 11:57:33 +0100
Local: Sat, Dec 17 2011 5:57 am
Subject: Re: ftok() on Linux generated different keys for the same inode and the same file name

Alex Vinokur <alex.vino...@gmail.com> wrote:
> On Dec 15, 8:16 pm, Huibert Bol <huibert....@quicknet.nl> wrote:
> > Alex Vinokur wrote:
> > > It seems that ftok() on Linux generated different keys for the same
> > > inode and the same file name.

> > > Linux 2.6.18-238.12.1.el5 #1 SMP Sat May 7 20:18:50 EDT 2011 x86_64
> > > x86_64 x86_64 GNU/Linux

> > > AccessTime = 20111020-153001   Inode = 6914144   ShmKeyDec =
> > > 1091272800   ShmKeyHex = 0x410b8060
> > > AccessTime = 20111020-155359   Inode = 6914144   ShmKeyDec =
> > > 1091338336   ShmKeyHex = 0x410c8060

> > After a reboot, right?  From the source:

> >   key = ((st.st_ino & 0xffff) | ((st.st_dev & 0xff) << 16)
> >          | ((proj_id & 0xff) << 24));

> > The parts that differ are set to the device number, perhaps your disks
> > were detected in a different order.

> > --
> > Huibert
> > "Okay... really not something I needed to see."  --Raven

> I am not sure that it was after reboot: difference between asscess
> times is about 4 min.
> I don't know.

> AccessTime = 20111020-153001   Inode = 6914144   ShmKeyDec =
> 1091272800   ShmKeyHex = 0x410b8060
> AccessTime = 20111020-155359   Inode = 6914144   ShmKeyDec =
> 1091338336   ShmKeyHex = 0x410c8060

> Where can I see ftok()-source for Linux?

Download GLIBC source code at
<ftp://ftp.gnu.org/gnu/glibc/>.

Or, assuming you are using RHEL, CentOS or Scientific Linux 5, you can
get the source code, with additionnal patches at:
<http://vault.centos.org/5.7/os/SRPMS/glibc-2.5-65.src.rpm>

CentOS glibc-2.5-65.src.rpm source code:
/* sysvipc/ftok.c */
key_t
ftok (pathname, proj_id)
     const char *pathname;
     int proj_id;
{
  struct stat64 st;
  key_t key;

  if (__xstat64 (_STAT_VER, pathname, &st) < 0)
    return (key_t) -1;

  key = ((st.st_ino & 0xffff) | ((st.st_dev & 0xff) << 16)
         | ((proj_id & 0xff) << 24));

  return key;

}

inode is unreliable on some file systems that have not been designed
for UNIX systems (e.g. remote FAT file system shared through SMB), but
that's not your problem, as the inode is kept consistent and
inode&0xFFFF = 0x8060 is unchanged. Your proj_id is unchanged too
(0x41), but the device node is changed. 0x0B -> 0x0C.

If the device is physically, or logically, unplugged and replugged, the
device identifier may be changed (or, the test has been done on
different machines, with NFS shares, but you didn't gave us enough
info to know).
Look at the kernel messages with dmesg, to see if the device
connection gets lost at some point, and revived later.

This may happen with some unreliable USB mass storage device, or
theoritically, this may happen with some SATA drive, although, in my
experience I've only seen SATA drives loose connexion, not regain it.

Warning: 16 bits is not enough to store the inode on any file system
having more than 65536 files & directories. This function may return
the same value for two different files.

--
André Gillibert


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.