usr/src/lib/libc/port/gen/ftok.c
author Jon Tibble <meths@btinternet.com>
Thu, 09 Dec 2010 22:32:39 +0100
changeset 13255 4afa820d78b9
parent 6812 febeba71273d
permissions -rw-r--r--
298 SPARC build fails in smt_pause.o 478 Build needs fixing for pkgdepend flag day Reviewed by: [email protected] Reviewed by: [email protected] Reviewed by: [email protected] Approved by: [email protected]
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
     1
/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
     2
 * CDDL HEADER START
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
     3
 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
     4
 * The contents of this file are subject to the terms of the
6082
30337f24796b 6472375 zpool export/import causes ftok() to generate a new key and semget() to create a new semaphore
marks
parents: 0
diff changeset
     5
 * Common Development and Distribution License (the "License").
30337f24796b 6472375 zpool export/import causes ftok() to generate a new key and semget() to create a new semaphore
marks
parents: 0
diff changeset
     6
 * You may not use this file except in compliance with the License.
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
     7
 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
     8
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
     9
 * or http://www.opensolaris.org/os/licensing.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    10
 * See the License for the specific language governing permissions
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    11
 * and limitations under the License.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    12
 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    13
 * When distributing Covered Code, include this CDDL HEADER in each
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    14
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    15
 * If applicable, add the following below this CDDL HEADER, with the
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    16
 * fields enclosed by brackets "[]" replaced with your own identifying
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    17
 * information: Portions Copyright [yyyy] [name of copyright owner]
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    18
 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    19
 * CDDL HEADER END
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    20
 */
6812
febeba71273d PSARC 2008/309 expunge synonyms.h
raf
parents: 6082
diff changeset
    21
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    22
/*
6082
30337f24796b 6472375 zpool export/import causes ftok() to generate a new key and semget() to create a new semaphore
marks
parents: 0
diff changeset
    23
 * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    24
 * Use is subject to license terms.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    25
 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    26
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    27
/*	Copyright (c) 1988 AT&T	*/
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    28
/*	  All Rights Reserved  	*/
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    29
6812
febeba71273d PSARC 2008/309 expunge synonyms.h
raf
parents: 6082
diff changeset
    30
#pragma ident	"%Z%%M%	%I%	%E% SMI"
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    31
6812
febeba71273d PSARC 2008/309 expunge synonyms.h
raf
parents: 6082
diff changeset
    32
#pragma weak _ftok = ftok
febeba71273d PSARC 2008/309 expunge synonyms.h
raf
parents: 6082
diff changeset
    33
febeba71273d PSARC 2008/309 expunge synonyms.h
raf
parents: 6082
diff changeset
    34
#include "lint.h"
6082
30337f24796b 6472375 zpool export/import causes ftok() to generate a new key and semget() to create a new semaphore
marks
parents: 0
diff changeset
    35
#include "libc.h"
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    36
#include <sys/types.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    37
#include <sys/stat.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    38
#include <sys/mkdev.h>
6082
30337f24796b 6472375 zpool export/import causes ftok() to generate a new key and semget() to create a new semaphore
marks
parents: 0
diff changeset
    39
#include <sys/nvpair.h>
30337f24796b 6472375 zpool export/import causes ftok() to generate a new key and semget() to create a new semaphore
marks
parents: 0
diff changeset
    40
#include <fcntl.h>
30337f24796b 6472375 zpool export/import causes ftok() to generate a new key and semget() to create a new semaphore
marks
parents: 0
diff changeset
    41
#include <attr.h>
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    42
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    43
key_t
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    44
ftok(const char *path, int id)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    45
{
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    46
	struct stat64 st;
6082
30337f24796b 6472375 zpool export/import causes ftok() to generate a new key and semget() to create a new semaphore
marks
parents: 0
diff changeset
    47
	nvlist_t *nvp;
30337f24796b 6472375 zpool export/import causes ftok() to generate a new key and semget() to create a new semaphore
marks
parents: 0
diff changeset
    48
	uint32_t devpiece;
30337f24796b 6472375 zpool export/import causes ftok() to generate a new key and semget() to create a new semaphore
marks
parents: 0
diff changeset
    49
	int error;
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    50
6082
30337f24796b 6472375 zpool export/import causes ftok() to generate a new key and semget() to create a new semaphore
marks
parents: 0
diff changeset
    51
	if (stat64(path, &st) < 0)
30337f24796b 6472375 zpool export/import causes ftok() to generate a new key and semget() to create a new semaphore
marks
parents: 0
diff changeset
    52
		return ((key_t)-1);
30337f24796b 6472375 zpool export/import causes ftok() to generate a new key and semget() to create a new semaphore
marks
parents: 0
diff changeset
    53
30337f24796b 6472375 zpool export/import causes ftok() to generate a new key and semget() to create a new semaphore
marks
parents: 0
diff changeset
    54
	/*
30337f24796b 6472375 zpool export/import causes ftok() to generate a new key and semget() to create a new semaphore
marks
parents: 0
diff changeset
    55
	 * if getattrat works then extract the FSID from the nvlist
30337f24796b 6472375 zpool export/import causes ftok() to generate a new key and semget() to create a new semaphore
marks
parents: 0
diff changeset
    56
	 * otherwise, just fall back and use the value from the stat data
30337f24796b 6472375 zpool export/import causes ftok() to generate a new key and semget() to create a new semaphore
marks
parents: 0
diff changeset
    57
	 */
30337f24796b 6472375 zpool export/import causes ftok() to generate a new key and semget() to create a new semaphore
marks
parents: 0
diff changeset
    58
	if ((error = getattrat(AT_FDCWD, XATTR_VIEW_READONLY,
30337f24796b 6472375 zpool export/import causes ftok() to generate a new key and semget() to create a new semaphore
marks
parents: 0
diff changeset
    59
	    path, &nvp)) == 0) {
30337f24796b 6472375 zpool export/import causes ftok() to generate a new key and semget() to create a new semaphore
marks
parents: 0
diff changeset
    60
		uint64_t value;
30337f24796b 6472375 zpool export/import causes ftok() to generate a new key and semget() to create a new semaphore
marks
parents: 0
diff changeset
    61
30337f24796b 6472375 zpool export/import causes ftok() to generate a new key and semget() to create a new semaphore
marks
parents: 0
diff changeset
    62
		if ((error = libc_nvlist_lookup_uint64(nvp,
30337f24796b 6472375 zpool export/import causes ftok() to generate a new key and semget() to create a new semaphore
marks
parents: 0
diff changeset
    63
		    A_FSID, &value)) == 0)
30337f24796b 6472375 zpool export/import causes ftok() to generate a new key and semget() to create a new semaphore
marks
parents: 0
diff changeset
    64
			devpiece = value & 0xfff;
30337f24796b 6472375 zpool export/import causes ftok() to generate a new key and semget() to create a new semaphore
marks
parents: 0
diff changeset
    65
		libc_nvlist_free(nvp);
30337f24796b 6472375 zpool export/import causes ftok() to generate a new key and semget() to create a new semaphore
marks
parents: 0
diff changeset
    66
	}
30337f24796b 6472375 zpool export/import causes ftok() to generate a new key and semget() to create a new semaphore
marks
parents: 0
diff changeset
    67
30337f24796b 6472375 zpool export/import causes ftok() to generate a new key and semget() to create a new semaphore
marks
parents: 0
diff changeset
    68
	if (error)
30337f24796b 6472375 zpool export/import causes ftok() to generate a new key and semget() to create a new semaphore
marks
parents: 0
diff changeset
    69
		devpiece = st.st_dev & 0xfff;
30337f24796b 6472375 zpool export/import causes ftok() to generate a new key and semget() to create a new semaphore
marks
parents: 0
diff changeset
    70
30337f24796b 6472375 zpool export/import causes ftok() to generate a new key and semget() to create a new semaphore
marks
parents: 0
diff changeset
    71
	return ((key_t)((key_t)id << 24 | devpiece << 12 |
30337f24796b 6472375 zpool export/import causes ftok() to generate a new key and semget() to create a new semaphore
marks
parents: 0
diff changeset
    72
	    ((uint32_t)st.st_ino & 0x0fff)));
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    73
}