17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5d8ac9b2dSmarks * Common Development and Distribution License (the "License").
6d8ac9b2dSmarks * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
21*7257d1b4Sraf
227c478bd9Sstevel@tonic-gate /*
23d8ac9b2dSmarks * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
247c478bd9Sstevel@tonic-gate * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate */
267c478bd9Sstevel@tonic-gate
277c478bd9Sstevel@tonic-gate /* Copyright (c) 1988 AT&T */
287c478bd9Sstevel@tonic-gate /* All Rights Reserved */
297c478bd9Sstevel@tonic-gate
30*7257d1b4Sraf #pragma weak _ftok = ftok
31*7257d1b4Sraf
32*7257d1b4Sraf #include "lint.h"
33d8ac9b2dSmarks #include "libc.h"
347c478bd9Sstevel@tonic-gate #include <sys/types.h>
357c478bd9Sstevel@tonic-gate #include <sys/stat.h>
367c478bd9Sstevel@tonic-gate #include <sys/mkdev.h>
37d8ac9b2dSmarks #include <sys/nvpair.h>
38d8ac9b2dSmarks #include <fcntl.h>
39d8ac9b2dSmarks #include <attr.h>
407c478bd9Sstevel@tonic-gate
417c478bd9Sstevel@tonic-gate key_t
ftok(const char * path,int id)427c478bd9Sstevel@tonic-gate ftok(const char *path, int id)
437c478bd9Sstevel@tonic-gate {
447c478bd9Sstevel@tonic-gate struct stat64 st;
45d8ac9b2dSmarks nvlist_t *nvp;
46d8ac9b2dSmarks uint32_t devpiece;
47d8ac9b2dSmarks int error;
487c478bd9Sstevel@tonic-gate
49d8ac9b2dSmarks if (stat64(path, &st) < 0)
50d8ac9b2dSmarks return ((key_t)-1);
51d8ac9b2dSmarks
52d8ac9b2dSmarks /*
53d8ac9b2dSmarks * if getattrat works then extract the FSID from the nvlist
54d8ac9b2dSmarks * otherwise, just fall back and use the value from the stat data
55d8ac9b2dSmarks */
56d8ac9b2dSmarks if ((error = getattrat(AT_FDCWD, XATTR_VIEW_READONLY,
57d8ac9b2dSmarks path, &nvp)) == 0) {
58d8ac9b2dSmarks uint64_t value;
59d8ac9b2dSmarks
60d8ac9b2dSmarks if ((error = libc_nvlist_lookup_uint64(nvp,
61d8ac9b2dSmarks A_FSID, &value)) == 0)
62d8ac9b2dSmarks devpiece = value & 0xfff;
63d8ac9b2dSmarks libc_nvlist_free(nvp);
64d8ac9b2dSmarks }
65d8ac9b2dSmarks
66d8ac9b2dSmarks if (error)
67d8ac9b2dSmarks devpiece = st.st_dev & 0xfff;
68d8ac9b2dSmarks
69d8ac9b2dSmarks return ((key_t)((key_t)id << 24 | devpiece << 12 |
70d8ac9b2dSmarks ((uint32_t)st.st_ino & 0x0fff)));
717c478bd9Sstevel@tonic-gate }
72