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 <cstdint>
35#include <cstring>
36#include <fcntl.h>
37
38#if defined(__linux__) || defined(__GNU__)
39#include <sys/sysmacros.h>
40using XrdSysStatx = struct statx;
41#define HAVE_STATX
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
57public:
63 static void Stat2Statx(const struct stat & stat, XrdSysStatx & statx);
64
70 static void Statx2Stat(const XrdSysStatx & statx, struct stat & stat);
71
77 static void StatxT2StatT(const statx_timestamp & stx_T, struct timespec & sta_T);
78
84 static void StatT2StatxT(const struct timespec & sta_T, statx_timestamp & stx_T);
85
90 static size_t GetSize(const XrdSysStatx & buf) {
91#ifdef HAVE_STATX
92 return buf.stx_size;
93#else
94 return buf.statx.st_size;
95#endif
96 }
97};
98
99inline void XrdSysStatxHelpers::StatxT2StatT(const statx_timestamp & stx_T, struct timespec & sta_T) {
100 sta_T.tv_sec = stx_T.tv_sec;
101 sta_T.tv_nsec = stx_T.tv_nsec;
102}
103
104inline void XrdSysStatxHelpers::StatT2StatxT(const struct timespec & sta_T, statx_timestamp & stx_T) {
105 stx_T.tv_sec = sta_T.tv_sec;
106 stx_T.tv_nsec = sta_T.tv_nsec;
107}
108
109inline void XrdSysStatxHelpers::Stat2Statx(const struct stat & st, XrdSysStatx & stx) {
110#ifdef HAVE_STATX
111 memset(&stx, 0, sizeof(stx));
113 stx.stx_blksize = st.st_blksize;
114 stx.stx_nlink = st.st_nlink;
115 stx.stx_uid = st.st_uid;
116 stx.stx_gid = st.st_gid;
117 stx.stx_mode = st.st_mode;
118 stx.stx_ino = st.st_ino;
119 stx.stx_size = st.st_size;
120 stx.stx_blocks = st.st_blocks;
121 StatT2StatxT(st.st_atim, stx.stx_atime);
122 StatT2StatxT(st.st_mtim, stx.stx_mtime);
123 StatT2StatxT(st.st_ctim, stx.stx_ctime);
124 stx.stx_dev_major = major(st.st_dev);
125 stx.stx_dev_minor = minor(st.st_dev);
126 stx.stx_rdev_major = major(st.st_rdev);
127 stx.stx_rdev_minor = minor(st.st_rdev);
128#else
129 // In that case, stx.statx and st are identical definition. See XrdSysStatx.hh
131 stx.statx = st;
132#endif
133}
134
135inline void XrdSysStatxHelpers::Statx2Stat(const XrdSysStatx & stx, struct stat & st) {
136#ifdef HAVE_STATX
137 memset(&st, 0, sizeof(st));
138
144
145 if (stx.stx_mask & STATX_NLINK)
146 st.st_nlink = stx.stx_nlink;
147 if (stx.stx_mask & STATX_UID)
148 st.st_uid = stx.stx_uid;
149 if (stx.stx_mask & STATX_GID)
150 st.st_gid = stx.stx_gid;
151 if (stx.stx_mask & STATX_MODE)
152 st.st_mode = stx.stx_mode;
153 if (stx.stx_mask & STATX_INO)
154 st.st_ino = stx.stx_ino;
155 if (stx.stx_mask & STATX_SIZE)
156 st.st_size = stx.stx_size;
157 if (stx.stx_mask & STATX_BLOCKS)
158 st.st_blocks = stx.stx_blocks;
159 if (stx.stx_mask & STATX_ATIME)
160 StatxT2StatT(stx.stx_atime, st.st_atim);
161 if (stx.stx_mask & STATX_MTIME)
162 StatxT2StatT(stx.stx_mtime, st.st_mtim);
163 if (stx.stx_mask & STATX_CTIME)
164 StatxT2StatT(stx.stx_ctime, st.st_ctim);
165 if (stx.stx_mask & STATX_BASIC_STATS) {
166 // There is no mask for those three attributes, so let's use the STATX_BASIC_STATS one
167 st.st_dev = makedev(stx.stx_dev_major, stx.stx_dev_minor);
168 st.st_rdev = makedev(stx.stx_rdev_major, stx.stx_rdev_minor);
169 st.st_blksize = stx.stx_blksize;
170 }
171
172#else
173 // In that case, stx.statx and st are identical definition. See XrdSysStatx.hh
174 st = stx.statx;
175#endif
176}
177
178#endif //XROOTD_XRDSYSSTATX_HH
#define stat(a, b)
Definition XrdPosix.hh:101
#define statx(d, p, f, m, b)
Definition XrdPosix.hh:119
struct timespec statx_timestamp
uint32_t stx_mask
#define STATX_BASIC_STATS
struct stat statx
static void Statx2Stat(const XrdSysStatx &statx, struct stat &stat)
static void Stat2Statx(const struct stat &stat, XrdSysStatx &statx)
static size_t GetSize(const XrdSysStatx &buf)
static void StatxT2StatT(const statx_timestamp &stx_T, struct timespec &sta_T)
static void StatT2StatxT(const struct timespec &sta_T, statx_timestamp &stx_T)