PageRenderTime 50ms CodeModel.GetById 29ms RepoModel.GetById 1ms app.codeStats 0ms

/usr/src/lib/libc/port/gen/ftok.c

https://bitbucket.org/illumos/illumos-gate/
C | 73 lines | 32 code | 11 blank | 30 comment | 6 complexity | 8784e0c950107e56ae3dd7df4b62014a MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.0, BSD-3-Clause-No-Nuclear-License-2014, AGPL-1.0, AGPL-3.0, BSD-3-Clause, GPL-3.0, LGPL-2.1, BSD-2-Clause, MPL-2.0-no-copyleft-exception, GPL-2.0, 0BSD
  1. /*
  2. * CDDL HEADER START
  3. *
  4. * The contents of this file are subject to the terms of the
  5. * Common Development and Distribution License (the "License").
  6. * You may not use this file except in compliance with the License.
  7. *
  8. * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  9. * or http://www.opensolaris.org/os/licensing.
  10. * See the License for the specific language governing permissions
  11. * and limitations under the License.
  12. *
  13. * When distributing Covered Code, include this CDDL HEADER in each
  14. * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15. * If applicable, add the following below this CDDL HEADER, with the
  16. * fields enclosed by brackets "[]" replaced with your own identifying
  17. * information: Portions Copyright [yyyy] [name of copyright owner]
  18. *
  19. * CDDL HEADER END
  20. */
  21. /*
  22. * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
  23. * Use is subject to license terms.
  24. */
  25. /* Copyright (c) 1988 AT&T */
  26. /* All Rights Reserved */
  27. #pragma ident "%Z%%M% %I% %E% SMI"
  28. #pragma weak _ftok = ftok
  29. #include "lint.h"
  30. #include "libc.h"
  31. #include <sys/types.h>
  32. #include <sys/stat.h>
  33. #include <sys/mkdev.h>
  34. #include <sys/nvpair.h>
  35. #include <fcntl.h>
  36. #include <attr.h>
  37. key_t
  38. ftok(const char *path, int id)
  39. {
  40. struct stat64 st;
  41. nvlist_t *nvp;
  42. uint32_t devpiece;
  43. int error;
  44. if (stat64(path, &st) < 0)
  45. return ((key_t)-1);
  46. /*
  47. * if getattrat works then extract the FSID from the nvlist
  48. * otherwise, just fall back and use the value from the stat data
  49. */
  50. if ((error = getattrat(AT_FDCWD, XATTR_VIEW_READONLY,
  51. path, &nvp)) == 0) {
  52. uint64_t value;
  53. if ((error = libc_nvlist_lookup_uint64(nvp,
  54. A_FSID, &value)) == 0)
  55. devpiece = value & 0xfff;
  56. libc_nvlist_free(nvp);
  57. }
  58. if (error)
  59. devpiece = st.st_dev & 0xfff;
  60. return ((key_t)((key_t)id << 24 | devpiece << 12 |
  61. ((uint32_t)st.st_ino & 0x0fff)));
  62. }