From 8af58876004a1ae5631e1b47a79f1076bb034174 Mon Sep 17 00:00:00 2001 From: corinna Date: Tue, 20 May 2003 12:38:03 +0000 Subject: [PATCH] * winsup/cygwin/include/cygwin/version.h: Bump API minor version. * winsup/cygwin/include/cygwin/types.h: Define key_t as long long. * winsup/cygwin/cygwin.din: Add ftok, _ftok. * winsup/cygwin/ipc.cc (ftok): Rework implementation. --- winsup/cygwin/ChangeLog | 9 +++- winsup/cygwin/cygwin.din | 2 + winsup/cygwin/include/cygwin/types.h | 2 +- winsup/cygwin/include/cygwin/version.h | 3 +- winsup/cygwin/ipc.cc | 77 ++++++++++++++++++++++++++++------ 5 files changed, 78 insertions(+), 15 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index d8c7042ad6..98a2652aa9 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,6 +1,13 @@ +2003-05-20 Charles Wilson + + * winsup/cygwin/include/cygwin/version.h: Bump API minor version. + * winsup/cygwin/include/cygwin/types.h: Define key_t as long long. + * winsup/cygwin/cygwin.din: Add ftok, _ftok. + * winsup/cygwin/ipc.cc (ftok): Rework implementation. + 2003-05-18 Joe Buehler - * spawn.cc (spawn_guts): Show more of command line in strace output. + * spawn.cc (spawn_guts): Show more of command line in strace output. 2003-05-15 Thomas Pfaff diff --git a/winsup/cygwin/cygwin.din b/winsup/cygwin/cygwin.din index 2b534987ed..7cfe275a2f 100644 --- a/winsup/cygwin/cygwin.din +++ b/winsup/cygwin/cygwin.din @@ -508,6 +508,8 @@ _ftello = ftello _ftello64 = ftello64 ftime _ftime = ftime +ftok +_ftok = ftok ftruncate _ftruncate = ftruncate _ftruncate64 = ftruncate64 diff --git a/winsup/cygwin/include/cygwin/types.h b/winsup/cygwin/include/cygwin/types.h index 0afa28509f..9d810f5f47 100644 --- a/winsup/cygwin/include/cygwin/types.h +++ b/winsup/cygwin/include/cygwin/types.h @@ -101,7 +101,7 @@ typedef __ino32_t ino_t; #ifndef __key_t_defined #define __key_t_defined -typedef long key_t; +typedef long long key_t; #endif /* __key_t_defined */ #ifndef __BIT_TYPES_DEFINED diff --git a/winsup/cygwin/include/cygwin/version.h b/winsup/cygwin/include/cygwin/version.h index cd49fa5895..50646dc5a2 100644 --- a/winsup/cygwin/include/cygwin/version.h +++ b/winsup/cygwin/include/cygwin/version.h @@ -205,12 +205,13 @@ details. */ underscore. No problems with backward compatibility since no official release has been made so far. This change removes exported symbols like fopen64, which might confuse configure. + 86: Export ftok */ /* Note that we forgot to bump the api for ualarm, strtoll, strtoull */ #define CYGWIN_VERSION_API_MAJOR 0 -#define CYGWIN_VERSION_API_MINOR 85 +#define CYGWIN_VERSION_API_MINOR 86 /* There is also a compatibity version number associated with the shared memory regions. It is incremented when incompatible diff --git a/winsup/cygwin/ipc.cc b/winsup/cygwin/ipc.cc index e4a36cb7fb..d37f45947e 100644 --- a/winsup/cygwin/ipc.cc +++ b/winsup/cygwin/ipc.cc @@ -1,8 +1,9 @@ /* ipc.cc: Single unix specification IPC interface for Cygwin - Copyright 2001, 2002 Red Hat, Inc. + Copyright 2001, 2002, 2003 Red Hat, Inc. Originally written by Robert Collins + Updated to 64 bit key_t by Charles Wilson This file is part of Cygwin. @@ -14,26 +15,78 @@ #include #include -extern "C" -{ - /* Notes: we return a valid key even if id's low order 8 bits are 0. */ -key_t +extern "C" key_t ftok (const char *path, int id) { struct __stat64 statbuf; + key_t tmp; if (stat64 (path, &statbuf)) { /* stat set the appropriate errno for us */ return (key_t) -1; } - /* dev_t is short for cygwin - * ino_t is long for cygwin - * and we need 8 bits for the id. - * thus key_t is long long. - */ - return ((long long) statbuf.st_dev << (5*8)) | (statbuf.st_ino << (8) ) | (id & 0x00ff); -} + /* Since __CYGWIN_USE_BIG_TYPES__, + dev_t is 32bits for cygwin + ino_t is 64bits for cygwin + and we need 8 bits for the id. + thus key_t needs 104 bits total -- but we only have 64 (long long) + We will have to alias; leaving open the possibility that the same + key will be returned for multiple files. This possibility exists + also on Linux; the question is, how to minimize this possibility. + + How to solve? Well, based on C. Vinschen's research, the nFileIndex* + words vary as follows, on a partition with > 110,000 files + nFileIndexHigh: 564 values between 0x00010000 -- 0xffff0000 + nFileIndexLow : 103812 values between 0x00000000 -- 0x0003ffff + R. Collins suggests that these may represent a tree path, + and that it would require ~2.9M files to force the tree depth + to increase and reveal more bit usage. + + Implementation details: dev_t is 32bits, but is formed by + device(32bits) << 16 | unit(32bits) + But device is ACTUALLY == status & FH_DEVMASK, where FH_DEVMASK + is 0x00000fff --> 12 bits + + As it happens, the maximum number of devices is actually + FH_NDEV, not FH_DEVMASK, where FH_NDEV is currently 0x0000001d. + However, FH_NDEV grows as new device types are added. So + currently the device number needs 5 bits, but later? Let's + take a cue from Linux, and use the lower 8 bits (instead of the + lower 12 or 16) for the device (major?) number. + + Similarly, while 'units' is an int (32bits), it is unclear + how many of these are significant. For most devices, it seems that + 'units' is equivalent to 'minor'. For FH_TAPE, it's obvious that + only 8 bits are important. However, for FH_SOCKET...it might be + as high as 16 significant bits. + + Let's assume that we only need 8 bits from device (major) and + only 8 bits from unit (minor). (On linux, only 8 bits of minor + are used, and none from major). + ---> so, we only need 0x00ff00ff (16 bits) of dev_t + + ---> we MUST have all 8 bits of id. + + ---> So, we only have 64 - 8 - 16 = 40 bits for ino_t. But, we + need 0xffff0000 for nFileIndexHigh and 0x0003ffff for nFileIndexLow + minimum, or 16 + 18 = 34 bits. Lucky us - we have 6 more bits + to distribute. + + For lack of a better idea, we'll allocate 2 of the extra bits to + nFileIndexHigh and 4 to nFileIndexLow. */ + /* get 8 bits from dev_t (major), put into 0xff00000000000000L */ + tmp = (((key_t) statbuf.st_dev) & 0x0000000000ff0000LL) << 40; + /* get 8 bits from dev_t (minor), put into 0x00ff000000000000L */ + tmp |= (((key_t) statbuf.st_dev) & 0x00000000000000ffLL) << 48; + /* get upper 16+2 bits from nFileInfoHigh, put into 0x0000ffffc0000000L + shift down first, then mask, to avoid sign extension on rightshift */ + tmp |= (((key_t) statbuf.st_ino) & 0xffffc00000000000LL) >> 16; + /* get lower 18+4 bits from nFileInfoLow, put into 0x000000003fffff00L */ + tmp |= (((key_t) statbuf.st_ino) & 0x00000000003fffffLL) << 8; + /* use all 8 bits of id, and put into 0x00000000000000ffL */ + tmp |= (id & 0x00ff); + return tmp; } -- 2.11.0