File: gtm_ftok.c

package info (click to toggle)
fis-gtm 7.0-005-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 32,264 kB
  • sloc: ansic: 336,687; asm: 5,184; csh: 4,823; sh: 1,945; awk: 291; makefile: 72; sed: 13
file content (42 lines) | stat: -rw-r--r-- 1,338 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/****************************************************************
 *                                                              *
 * Copyright (c) 2011-2020 Fidelity National Information	*
 * Services, Inc. and/or its subsidiaries. All rights reserved.	*
 *                                                              *
 *      This source code contains the intellectual property     *
 *      of its copyright holder(s), and is made available       *
 *      under a license.  If you do not know the terms of       *
 *      the license, please stop and do not read further.       *
 *                                                              *
 ****************************************************************/

#include "mdef.h"
#include "gtm_ipc.h"
#include "mmrhash.h"

#include <sys/types.h>
#include <gtm_stat.h>
#include <eintr_wrappers.h>

key_t
gtm_ftok(const char *path, int id)
{
    int rc;
    struct stat statbuf;
    uint32_t key = 0;

    STAT_FILE(path, &statbuf, rc);
    if (rc < 0)
    {
        return (key_t)-1;
    }

    MurmurHash3_x86_32(&statbuf.st_dev, sizeof statbuf.st_dev, key, &key);
    MurmurHash3_x86_32(&statbuf.st_ino, sizeof statbuf.st_ino, key, &key);

    /* substitute the id for the top 8 bits of the hash */
    key &= 0x00ffffff;
    key |= (id & 0xff) << 24;

    return (key_t)key;
}