statx_cp.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /* Struct statx to stat/stat64 conversion for Linux.
  2. Copyright (C) 2018 Free Software Foundation, Inc.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library. If not, see
  13. <http://www.gnu.org/licenses/>. */
  14. #include <stddef.h>
  15. #include <string.h>
  16. #include <sys/stat.h>
  17. #include <statx_cp.h>
  18. #if !defined(__NR_fstat64) || !defined(__NR_fstatat64)
  19. void
  20. __cp_stat64_statx (struct stat64 *to, struct statx *from)
  21. {
  22. memset (to, 0, sizeof (struct stat64));
  23. to->st_dev = ((from->stx_dev_minor & 0xff) | (from->stx_dev_major << 8)
  24. | ((from->stx_dev_minor & ~0xff) << 12));
  25. to->st_rdev = ((from->stx_rdev_minor & 0xff) | (from->stx_rdev_major << 8)
  26. | ((from->stx_rdev_minor & ~0xff) << 12));
  27. to->st_ino = from->stx_ino;
  28. to->st_mode = from->stx_mode;
  29. to->st_nlink = from->stx_nlink;
  30. to->st_uid = from->stx_uid;
  31. to->st_gid = from->stx_gid;
  32. to->st_atime = from->stx_atime.tv_sec;
  33. to->st_atim.tv_nsec = from->stx_atime.tv_nsec;
  34. to->st_mtime = from->stx_mtime.tv_sec;
  35. to->st_mtim.tv_nsec = from->stx_mtime.tv_nsec;
  36. to->st_ctime = from->stx_ctime.tv_sec;
  37. to->st_ctim.tv_nsec = from->stx_ctime.tv_nsec;
  38. to->st_size = from->stx_size;
  39. to->st_blocks = from->stx_blocks;
  40. to->st_blksize = from->stx_blksize;
  41. }
  42. void
  43. __cp_stat_statx (struct stat *to, struct statx *from)
  44. {
  45. memset (to, 0, sizeof (struct stat));
  46. to->st_dev = ((from->stx_dev_minor & 0xff) | (from->stx_dev_major << 8)
  47. | ((from->stx_dev_minor & ~0xff) << 12));
  48. to->st_rdev = ((from->stx_rdev_minor & 0xff) | (from->stx_rdev_major << 8)
  49. | ((from->stx_rdev_minor & ~0xff) << 12));
  50. to->st_ino = from->stx_ino;
  51. to->st_mode = from->stx_mode;
  52. to->st_nlink = from->stx_nlink;
  53. to->st_uid = from->stx_uid;
  54. to->st_gid = from->stx_gid;
  55. to->st_atime = from->stx_atime.tv_sec;
  56. to->st_atim.tv_nsec = from->stx_atime.tv_nsec;
  57. to->st_mtime = from->stx_mtime.tv_sec;
  58. to->st_mtim.tv_nsec = from->stx_mtime.tv_nsec;
  59. to->st_ctime = from->stx_ctime.tv_sec;
  60. to->st_ctim.tv_nsec = from->stx_ctime.tv_nsec;
  61. to->st_size = from->stx_size;
  62. to->st_blocks = from->stx_blocks;
  63. to->st_blksize = from->stx_blksize;
  64. }
  65. #endif