XRootD
Loading...
Searching...
No Matches
XrdSysStatx.hh
Go to the documentation of this file.
1/******************************************************************************/
2/* */
3/* X r d S y s S t a t x . h h */
4/* */
5/* (c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University */
6/* Produced by Andrew Hanushevsky for Stanford University under contract */
7/* DE-AC02-76-SFO0515 with the Department of Energy */
8/* */
9/* This file is part of the XRootD software suite. */
10/* */
11/* XRootD is free software: you can redistribute it and/or modify it under */
12/* the terms of the GNU Lesser General Public License as published by the */
13/* Free Software Foundation, either version 3 of the License, or (at your */
14/* option) any later version. */
15/* */
16/* XRootD is distributed in the hope that it will be useful, but WITHOUT */
17/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
18/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
19/* License for more details. */
20/* */
21/* You should have received a copy of the GNU Lesser General Public License */
22/* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
23/* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
24/* */
25/* The copyright holder's institutional names and contributor's names may not */
26/* be used to endorse or promote products derived from this software without */
27/* specific prior written permission of the institution or contributor. */
28/******************************************************************************/
29
30#ifndef XROOTD_XRDSYSSTATX_HH
31#define XROOTD_XRDSYSSTATX_HH
32
33#include <sys/stat.h>
34#include <stdint.h>
35#include <string.h>
36#include <fcntl.h>
37
38#if defined(__linux__) || defined(__GNU__)
39#include <sys/sysmacros.h>
40typedef struct statx XrdSysStatx;
41#define HAVE_STATX 1
42#else
44{uint32_t stx_mask;
45 struct stat statx;
46};
47
48#define STATX_BASIC_STATS 0x0000003f
49#define STATX_ALL 0x0000013f
50#define STATX_BTIME 0x00000100
51
52typedef struct timespec statx_timestamp;
53
54#endif // __linux__
55
56#ifdef __cplusplus
57
58class XrdSysStatxHelpers {
59public:
65 static void Stat2Statx(const struct stat & stat, XrdSysStatx & statx);
66
72 static void Statx2Stat(const XrdSysStatx & statx, struct stat & stat);
73
79 static void StatxT2StatT(const statx_timestamp & stx_T, struct timespec & sta_T);
80
86 static void StatT2StatxT(const struct timespec & sta_T, statx_timestamp & stx_T);
87
92 static size_t GetSize(const XrdSysStatx & buf) {
93#ifdef HAVE_STATX
94 return buf.stx_size;
95#else
96 return buf.statx.st_size;
97#endif
98 }
99};
100
101inline void XrdSysStatxHelpers::StatxT2StatT(const statx_timestamp & stx_T, struct timespec & sta_T) {
102 sta_T.tv_sec = stx_T.tv_sec;
103 sta_T.tv_nsec = stx_T.tv_nsec;
104}
105
106inline void XrdSysStatxHelpers::StatT2StatxT(const struct timespec & sta_T, statx_timestamp & stx_T) {
107 stx_T.tv_sec = sta_T.tv_sec;
108 stx_T.tv_nsec = sta_T.tv_nsec;
109}
110
111inline void XrdSysStatxHelpers::Stat2Statx(const struct stat & st, XrdSysStatx & stx) {
112#ifdef HAVE_STATX
113 memset(&stx, 0, sizeof(stx));
115 stx.stx_blksize = st.st_blksize;
116 stx.stx_nlink = st.st_nlink;
117 stx.stx_uid = st.st_uid;
118 stx.stx_gid = st.st_gid;
119 stx.stx_mode = st.st_mode;
120 stx.stx_ino = st.st_ino;
121 stx.stx_size = st.st_size;
122 stx.stx_blocks = st.st_blocks;
123 StatT2StatxT(st.st_atim, stx.stx_atime);
124 StatT2StatxT(st.st_mtim, stx.stx_mtime);
125 StatT2StatxT(st.st_ctim, stx.stx_ctime);
126 stx.stx_dev_major = major(st.st_dev);
127 stx.stx_dev_minor = minor(st.st_dev);
128 stx.stx_rdev_major = major(st.st_rdev);
129 stx.stx_rdev_minor = minor(st.st_rdev);
130#else
131 // In that case, stx.statx and st are identical definition. See XrdSysStatx.hh
133 stx.statx = st;
134#endif
135}
136
137inline void XrdSysStatxHelpers::Statx2Stat(const XrdSysStatx & stx, struct stat & st) {
138#ifdef HAVE_STATX
139 memset(&st, 0, sizeof(st));
140
146
147 if (stx.stx_mask & STATX_NLINK)
148 st.st_nlink = stx.stx_nlink;
149 if (stx.stx_mask & STATX_UID)
150 st.st_uid = stx.stx_uid;
151 if (stx.stx_mask & STATX_GID)
152 st.st_gid = stx.stx_gid;
153 if (stx.stx_mask & STATX_MODE)
154 st.st_mode = stx.stx_mode;
155 if (stx.stx_mask & STATX_INO)
156 st.st_ino = stx.stx_ino;
157 if (stx.stx_mask & STATX_SIZE)
158 st.st_size = stx.stx_size;
159 if (stx.stx_mask & STATX_BLOCKS)
160 st.st_blocks = stx.stx_blocks;
161 if (stx.stx_mask & STATX_ATIME)
162 StatxT2StatT(stx.stx_atime, st.st_atim);
163 if (stx.stx_mask & STATX_MTIME)
164 StatxT2StatT(stx.stx_mtime, st.st_mtim);
165 if (stx.stx_mask & STATX_CTIME)
166 StatxT2StatT(stx.stx_ctime, st.st_ctim);
167 if (stx.stx_mask & STATX_BASIC_STATS) {
168 // There is no mask for those three attributes, so let's use the STATX_BASIC_STATS one
169 st.st_dev = makedev(stx.stx_dev_major, stx.stx_dev_minor);
170 st.st_rdev = makedev(stx.stx_rdev_major, stx.stx_rdev_minor);
171 st.st_blksize = stx.stx_blksize;
172 }
173
174#else
175 // In that case, stx.statx and st are identical definition. See XrdSysStatx.hh
176 st = stx.statx;
177#endif
178}
179
180#endif // __cplusplus
181
182#endif //XROOTD_XRDSYSSTATX_HH
#define stat(a, b)
Definition XrdPosix.hh:105
#define statx(d, p, f, m, b)
Definition XrdPosix.hh:125
struct timespec statx_timestamp
uint32_t stx_mask
#define STATX_BASIC_STATS
struct stat statx