uuid.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
  3. * All Rights Reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it would be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write the Free Software Foundation,
  16. * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #include <xfs.h>
  19. /* IRIX interpretation of an uuid_t */
  20. typedef struct {
  21. __be32 uu_timelow;
  22. __be16 uu_timemid;
  23. __be16 uu_timehi;
  24. __be16 uu_clockseq;
  25. __be16 uu_node[3];
  26. } xfs_uu_t;
  27. /*
  28. * uuid_getnodeuniq - obtain the node unique fields of a UUID.
  29. *
  30. * This is not in any way a standard or condoned UUID function;
  31. * it just something that's needed for user-level file handles.
  32. */
  33. void
  34. uuid_getnodeuniq(uuid_t *uuid, int fsid [2])
  35. {
  36. xfs_uu_t *uup = (xfs_uu_t *)uuid;
  37. fsid[0] = (be16_to_cpu(uup->uu_clockseq) << 16) |
  38. be16_to_cpu(uup->uu_timemid);
  39. fsid[1] = be32_to_cpu(uup->uu_timelow);
  40. }
  41. int
  42. uuid_is_nil(uuid_t *uuid)
  43. {
  44. int i;
  45. char *cp = (char *)uuid;
  46. if (uuid == NULL)
  47. return 0;
  48. /* implied check of version number here... */
  49. for (i = 0; i < sizeof *uuid; i++)
  50. if (*cp++) return 0; /* not nil */
  51. return 1; /* is nil */
  52. }
  53. int
  54. uuid_equal(uuid_t *uuid1, uuid_t *uuid2)
  55. {
  56. return memcmp(uuid1, uuid2, sizeof(uuid_t)) ? 0 : 1;
  57. }