Debian Codegraph @

file_io/unix/filestat.c

raw symbols SCIP
1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include "apr_arch_file_io.h"cxx . . $ `<file>/include/arch/unix/apr_arch_file_io.h`/
18 #include "apr_file_io.h"cxx . . $ `<file>/include/apr_file_io.h`/
19 #include "apr_general.h"cxx . . $ `<file>/include/apr_general.h`/
20 #include "apr_strings.h"cxx . . $ `<file>/include/apr_strings.h`/
21 #include "apr_errno.h"cxx . . $ `<file>/include/apr_errno.h`/
22
23 #ifdef HAVE_UTIMEcxx . . $ `include/arch/unix/apr_private.h:742:9`!
24 #include <utime.h>
25 #endif
26
27 static apr_filetype_ecxx . . $ apr_filetype_e# filetype_from_modecxx . . $ filetype_from_mode(c3b635c5423a3d67).(mode_tcxx . . $ mode_t# mode)
28 {
29 apr_filetype_ecxx . . $ apr_filetype_e# type;
30
31 switch (mode & S_IFMTcxx . . $ `<external>/531885356569766532/stat.h:104:10`!) {
32 case S_IFREGcxx . . $ `<external>/531885356569766532/stat.h:108:10`!:
33 type = APR_REGcxx . . $ APR_REG.; break;
34 case S_IFDIRcxx . . $ `<external>/531885356569766532/stat.h:105:10`!:
35 type = APR_DIRcxx . . $ APR_DIR.; break;
36 case S_IFLNKcxx . . $ `<external>/531885356569766532/stat.h:113:11`!:
37 type = APR_LNKcxx . . $ APR_LNK.; break;
38 case S_IFCHRcxx . . $ `<external>/531885356569766532/stat.h:106:10`!:
39 type = APR_CHRcxx . . $ APR_CHR.; break;
40 case S_IFBLKcxx . . $ `<external>/531885356569766532/stat.h:107:10`!:
41 type = APR_BLKcxx . . $ APR_BLK.; break;
42 #if defined(S_IFFIFO)
43 case S_IFFIFO:
44 type = APR_PIPE; break;
45 #endif
46 #if !defined(BEOS) && defined(S_IFSOCKcxx . . $ `<external>/531885356569766532/stat.h:117:11`!)
47 case S_IFSOCKcxx . . $ `<external>/531885356569766532/stat.h:117:11`!:
48 type = APR_SOCKcxx . . $ APR_SOCK.; break;
49 #endif
50
51 default:
52 /* Work around missing S_IFxxx values above
53 * for Linux et al.
54 */
55 #if !defined(S_IFFIFO) && defined(S_ISFIFOcxx . . $ `<external>/531885356569766532/stat.h:130:10`!)
56 if (S_ISFIFOcxx . . $ `<external>/531885356569766532/stat.h:130:10`!(mode)) {
57 type = APR_PIPEcxx . . $ APR_PIPE.;
58 } else
59 #endif
60 #if !defined(BEOS) && !defined(S_IFSOCKcxx . . $ `<external>/531885356569766532/stat.h:117:11`!) && defined(S_ISSOCKcxx . . $ `<external>/531885356569766532/stat.h:142:10`!)
61 if (S_ISSOCK(mode)) {
62 type = APR_SOCK;
63 } else
64 #endif
65 type = APR_UNKFILEcxx . . $ APR_UNKFILE.;
66 }
67 return type;
68 }
69
70 static void fill_out_finfocxx . . $ fill_out_finfo(dbd7381422d9dfe7).(apr_finfo_tcxx . . $ apr_finfo_t# *finfo, struct_statcxx . . $ struct_stat# *info,
71 apr_int32_tcxx . . $ apr_int32_t# wanted)
72 {
73 finfo->validcxx . . $ apr_finfo_t#valid. = APR_FINFO_MINcxx . . $ `include/apr_file_info.h:163:9`! | APR_FINFO_IDENTcxx . . $ `include/apr_file_info.h:164:9`! | APR_FINFO_NLINKcxx . . $ `include/apr_file_info.h:153:9`!
74 | APR_FINFO_OWNERcxx . . $ `include/apr_file_info.h:165:9`! | APR_FINFO_PROTcxx . . $ `include/apr_file_info.h:166:9`!;
75 finfo->protectioncxx . . $ apr_finfo_t#protection. = apr_unix_mode2permscxx . . $ apr_unix_mode2perms(4c679297bf94b9eb).(info->st_modecxx . . $ stat#st_mode.);
76 finfo->filetypecxx . . $ apr_finfo_t#filetype. = filetype_from_modecxx . . $ filetype_from_mode(c3b635c5423a3d67).(info->st_modecxx . . $ stat#st_mode.);
77 finfo->usercxx . . $ apr_finfo_t#user. = info->st_uidcxx . . $ stat#st_uid.;
78 finfo->groupcxx . . $ apr_finfo_t#group. = info->st_gidcxx . . $ stat#st_gid.;
79 finfo->sizecxx . . $ apr_finfo_t#size. = info->st_sizecxx . . $ stat#st_size.;
80 finfo->devicecxx . . $ apr_finfo_t#device. = info->st_devcxx . . $ stat#st_dev.;
81 finfo->nlinkcxx . . $ apr_finfo_t#nlink. = info->st_nlinkcxx . . $ stat#st_nlink.;
82
83 /* Check for overflow if storing a 64-bit st_ino in a 32-bit
84 * apr_ino_t for LFS builds: */
85 if (sizeof(apr_ino_tcxx . . $ apr_ino_t#) >= sizeof(info->st_inocxx . . $ stat#st_ino.)
86 || (apr_ino_tcxx . . $ apr_ino_t#)info->st_inocxx . . $ stat#st_ino. == info->st_inocxx . . $ stat#st_ino.) {
87 finfo->inodecxx . . $ apr_finfo_t#inode. = info->st_inocxx . . $ stat#st_ino.;
88 } else {
89 finfo->validcxx . . $ apr_finfo_t#valid. &= ~APR_FINFO_INODEcxx . . $ `include/apr_file_info.h:152:9`!;
90 }
91
92 apr_time_ansi_putcxx . . $ apr_time_ansi_put(6887c1c60e1d20d8).(&finfo->atimecxx . . $ apr_finfo_t#atime., info->st_atimecxx . . $ `<external>/16045971866008360577/struct_stat.h:77:11`!);
93 #ifdef HAVE_STRUCT_STAT_ST_ATIM_TV_NSECcxx . . $ `include/arch/unix/apr_private.h:595:9`!
94 finfo->atimecxx . . $ apr_finfo_t#atime. += info->st_atimcxx . . $ stat#st_atim..tv_nseccxx . . $ timespec#tv_nsec. / APR_TIME_Ccxx . . $ `include/apr_time.h:49:9`!(1000);
95 #elif defined(HAVE_STRUCT_STAT_ST_ATIMENSEC)
96 finfo->atime += info->st_atimensec / APR_TIME_C(1000);
97 #elif defined(HAVE_STRUCT_STAT_ST_ATIME_N)
98 finfo->atime += info->st_atime_n / APR_TIME_C(1000);
99 #endif
100
101 apr_time_ansi_putcxx . . $ apr_time_ansi_put(6887c1c60e1d20d8).(&finfo->mtimecxx . . $ apr_finfo_t#mtime., info->st_mtimecxx . . $ `<external>/16045971866008360577/struct_stat.h:78:11`!);
102 #ifdef HAVE_STRUCT_STAT_ST_MTIM_TV_NSECcxx . . $ `include/arch/unix/apr_private.h:616:9`!
103 finfo->mtimecxx . . $ apr_finfo_t#mtime. += info->st_mtimcxx . . $ stat#st_mtim..tv_nseccxx . . $ timespec#tv_nsec. / APR_TIME_Ccxx . . $ `include/apr_time.h:49:9`!(1000);
104 #elif defined(HAVE_STRUCT_STAT_ST_MTIMENSEC)
105 finfo->mtime += info->st_mtimensec / APR_TIME_C(1000);
106 #elif defined(HAVE_STRUCT_STAT_ST_MTIME_N)
107 finfo->mtime += info->st_mtime_n / APR_TIME_C(1000);
108 #endif
109
110 apr_time_ansi_putcxx . . $ apr_time_ansi_put(6887c1c60e1d20d8).(&finfo->ctimecxx . . $ apr_finfo_t#ctime., info->st_ctimecxx . . $ `<external>/16045971866008360577/struct_stat.h:79:11`!);
111 #ifdef HAVE_STRUCT_STAT_ST_CTIM_TV_NSECcxx . . $ `include/arch/unix/apr_private.h:607:9`!
112 finfo->ctimecxx . . $ apr_finfo_t#ctime. += info->st_ctimcxx . . $ stat#st_ctim..tv_nseccxx . . $ timespec#tv_nsec. / APR_TIME_Ccxx . . $ `include/apr_time.h:49:9`!(1000);
113 #elif defined(HAVE_STRUCT_STAT_ST_CTIMENSEC)
114 finfo->ctime += info->st_ctimensec / APR_TIME_C(1000);
115 #elif defined(HAVE_STRUCT_STAT_ST_CTIME_N)
116 finfo->ctime += info->st_ctime_n / APR_TIME_C(1000);
117 #endif
118
119 #ifdef HAVE_STRUCT_STAT_ST_BLOCKScxx . . $ `include/arch/unix/apr_private.h:598:9`!
120 #ifdef DEV_BSIZEcxx . . $ `<external>/1231830743887005719/param.h:78:10`!
121 finfo->csizecxx . . $ apr_finfo_t#csize. = (apr_off_tcxx . . $ apr_off_t#)info->st_blockscxx . . $ stat#st_blocks. * (apr_off_tcxx . . $ apr_off_t#)DEV_BSIZEcxx . . $ `<external>/1231830743887005719/param.h:78:10`!;
122 #else
123 finfo->csize = (apr_off_t)info->st_blocks * (apr_off_t)512;
124 #endif
125 finfo->validcxx . . $ apr_finfo_t#valid. |= APR_FINFO_CSIZEcxx . . $ `include/apr_file_info.h:150:9`!;
126 #endif
127 }
128
129 apr_status_tcxx . . $ apr_status_t# apr_file_info_get_lockedcxx . . $ apr_file_info_get_locked(379442b21185e16e).(apr_finfo_tcxx . . $ apr_finfo_t# *finfo, apr_int32_tcxx . . $ apr_int32_t# wanted,
130 apr_file_tcxx . . $ apr_file_t# *thefile)
131 {
132 struct_statcxx . . $ struct_stat# info;
133
134 if (thefile->bufferedcxx . . $ apr_file_t#buffered.) {
135 apr_status_tcxx . . $ apr_status_t# rv = apr_file_flush_lockedcxx . . $ apr_file_flush_locked(ac1f877fcad40383).(thefile);
136 if (rv != APR_SUCCESScxx . . $ `include/apr_errno.h:225:9`!)
137 return rv;
138 }
139
140 if (fstatcxx . . $ fstat(a43660ce2f600cb5).(thefile->filedescxx . . $ apr_file_t#filedes., &info) == 0) {
141 finfo->poolcxx . . $ apr_finfo_t#pool. = thefile->poolcxx . . $ apr_file_t#pool.;
142 finfo->fnamecxx . . $ apr_finfo_t#fname. = thefile->fnamecxx . . $ apr_file_t#fname.;
143 fill_out_finfocxx . . $ fill_out_finfo(dbd7381422d9dfe7).(finfo, &info, wanted);
144 return (wanted & ~finfo->validcxx . . $ apr_finfo_t#valid.) ? APR_INCOMPLETEcxx . . $ `include/apr_errno.h:452:9`! : APR_SUCCESScxx . . $ `include/apr_errno.h:225:9`!;
145 }
146 else {
147 return errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!;
148 }
149 }
150
151 APR_DECLAREcxx . . $ `include/apr.h:507:9`!(apr_status_t) apr_file_info_getcxx . . $ apr_file_info_get(379442b21185e16e).(apr_finfo_tcxx . . $ apr_finfo_t# *finfo,
152 apr_int32_tcxx . . $ apr_int32_t# wanted,
153 apr_file_tcxx . . $ apr_file_t# *thefile)
154 {
155 struct_statcxx . . $ struct_stat# info;
156
157 if (thefile->bufferedcxx . . $ apr_file_t#buffered.) {
158 apr_status_tcxx . . $ apr_status_t# rv = apr_file_flushcxx . . $ apr_file_flush(ac1f877fcad40383).(thefile);
159 if (rv != APR_SUCCESScxx . . $ `include/apr_errno.h:225:9`!)
160 return rv;
161 }
162
163 if (fstatcxx . . $ fstat(a43660ce2f600cb5).(thefile->filedescxx . . $ apr_file_t#filedes., &info) == 0) {
164 finfo->poolcxx . . $ apr_finfo_t#pool. = thefile->poolcxx . . $ apr_file_t#pool.;
165 finfo->fnamecxx . . $ apr_finfo_t#fname. = thefile->fnamecxx . . $ apr_file_t#fname.;
166 fill_out_finfocxx . . $ fill_out_finfo(dbd7381422d9dfe7).(finfo, &info, wanted);
167 return (wanted & ~finfo->validcxx . . $ apr_finfo_t#valid.) ? APR_INCOMPLETEcxx . . $ `include/apr_errno.h:452:9`! : APR_SUCCESScxx . . $ `include/apr_errno.h:225:9`!;
168 }
169 else {
170 return errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!;
171 }
172 }
173
174 APR_DECLAREcxx . . $ `include/apr.h:507:9`!(apr_status_t) apr_file_perms_setcxx . . $ apr_file_perms_set(cb7559238bb26814).(const char *fname,
175 apr_fileperms_tcxx . . $ apr_fileperms_t# perms)
176 {
177 mode_tcxx . . $ mode_t# mode = apr_unix_perms2modecxx . . $ apr_unix_perms2mode(46cc46841198e427).(perms);
178
179 if (chmodcxx . . $ chmod(1df18506ef0a631b).(fname, mode) == -1)
180 return errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!;
181 return APR_SUCCESScxx . . $ `include/apr_errno.h:225:9`!;
182 }
183
184 APR_DECLAREcxx . . $ `include/apr.h:507:9`!(apr_status_t) apr_file_attrs_setcxx . . $ apr_file_attrs_set(4215efd1ccdd88fe).(const char *fname,
185 apr_fileattrs_tcxx . . $ apr_fileattrs_t# attributes,
186 apr_fileattrs_tcxx . . $ apr_fileattrs_t# attr_mask,
187 apr_pool_tcxx . . $ apr_pool_t# *pool)
188 {
189 apr_status_tcxx . . $ apr_status_t# status;
190 apr_finfo_tcxx . . $ apr_finfo_t# finfo;
191
192 /* Don't do anything if we can't handle the requested attributes */
193 if (!(attr_mask & (APR_FILE_ATTR_READONLYcxx . . $ `include/apr_file_io.h:158:9`!
194 | APR_FILE_ATTR_EXECUTABLEcxx . . $ `include/apr_file_io.h:159:9`!)))
195 return APR_SUCCESScxx . . $ `include/apr_errno.h:225:9`!;
196
197 status = apr_statcxx . . $ apr_stat(9cb7fb18475a4672).(&finfo, fname, APR_FINFO_PROTcxx . . $ `include/apr_file_info.h:166:9`!, pool);
198 if (status)
199 return status;
200
201 /* ### TODO: should added bits be umask'd? */
202 if (attr_mask & APR_FILE_ATTR_READONLYcxx . . $ `include/apr_file_io.h:158:9`!)
203 {
204 if (attributes & APR_FILE_ATTR_READONLYcxx . . $ `include/apr_file_io.h:158:9`!)
205 {
206 finfo.protectioncxx . . $ apr_finfo_t#protection. &= ~APR_UWRITEcxx . . $ `include/apr_file_info.h:102:9`!;
207 finfo.protectioncxx . . $ apr_finfo_t#protection. &= ~APR_GWRITEcxx . . $ `include/apr_file_info.h:106:9`!;
208 finfo.protectioncxx . . $ apr_finfo_t#protection. &= ~APR_WWRITEcxx . . $ `include/apr_file_info.h:110:9`!;
209 }
210 else
211 {
212 /* ### umask this! */
213 finfo.protectioncxx . . $ apr_finfo_t#protection. |= APR_UWRITEcxx . . $ `include/apr_file_info.h:102:9`!;
214 finfo.protectioncxx . . $ apr_finfo_t#protection. |= APR_GWRITEcxx . . $ `include/apr_file_info.h:106:9`!;
215 finfo.protectioncxx . . $ apr_finfo_t#protection. |= APR_WWRITEcxx . . $ `include/apr_file_info.h:110:9`!;
216 }
217 }
218
219 if (attr_mask & APR_FILE_ATTR_EXECUTABLEcxx . . $ `include/apr_file_io.h:159:9`!)
220 {
221 if (attributes & APR_FILE_ATTR_EXECUTABLEcxx . . $ `include/apr_file_io.h:159:9`!)
222 {
223 /* ### umask this! */
224 finfo.protectioncxx . . $ apr_finfo_t#protection. |= APR_UEXECUTEcxx . . $ `include/apr_file_info.h:103:9`!;
225 finfo.protectioncxx . . $ apr_finfo_t#protection. |= APR_GEXECUTEcxx . . $ `include/apr_file_info.h:107:9`!;
226 finfo.protectioncxx . . $ apr_finfo_t#protection. |= APR_WEXECUTEcxx . . $ `include/apr_file_info.h:111:9`!;
227 }
228 else
229 {
230 finfo.protectioncxx . . $ apr_finfo_t#protection. &= ~APR_UEXECUTEcxx . . $ `include/apr_file_info.h:103:9`!;
231 finfo.protectioncxx . . $ apr_finfo_t#protection. &= ~APR_GEXECUTEcxx . . $ `include/apr_file_info.h:107:9`!;
232 finfo.protectioncxx . . $ apr_finfo_t#protection. &= ~APR_WEXECUTEcxx . . $ `include/apr_file_info.h:111:9`!;
233 }
234 }
235
236 return apr_file_perms_setcxx . . $ apr_file_perms_set(cb7559238bb26814).(fname, finfo.protectioncxx . . $ apr_finfo_t#protection.);
237 }
238
239
240 APR_DECLAREcxx . . $ `include/apr.h:507:9`!(apr_status_t) apr_file_mtime_setcxx . . $ apr_file_mtime_set(904575e58cd69bbf).(const char *fname,
241 apr_time_tcxx . . $ apr_time_t# mtime,
242 apr_pool_tcxx . . $ apr_pool_t# *pool)
243 {
244 apr_status_tcxx . . $ apr_status_t# status;
245 apr_finfo_tcxx . . $ apr_finfo_t# finfo;
246
247 status = apr_statcxx . . $ apr_stat(9cb7fb18475a4672).(&finfo, fname, APR_FINFO_ATIMEcxx . . $ `include/apr_file_info.h:148:9`!, pool);
248 if (status) {
249 return status;
250 }
251
252 #ifdef HAVE_UTIMEScxx . . $ `include/arch/unix/apr_private.h:745:9`!
253 {
254 struct timevalcxx . . $ timeval# tvp[2];
255
256 tvp[0].tv_seccxx . . $ timeval#tv_sec. = apr_time_seccxx . . $ `include/apr_time.h:63:9`!(finfo.atime);
257 tvp[0].tv_useccxx . . $ timeval#tv_usec. = apr_time_useccxx . . $ `include/apr_time.h:66:9`!(finfo.atime);
258 tvp[1].tv_seccxx . . $ timeval#tv_sec. = apr_time_seccxx . . $ `include/apr_time.h:63:9`!(mtime);
259 tvp[1].tv_useccxx . . $ timeval#tv_usec. = apr_time_useccxx . . $ `include/apr_time.h:66:9`!(mtime);
260
261 if (utimescxx . . $ utimes(6ed4149773030879).(fname, tvp) == -1) {
262 return errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!;
263 }
264 }
265 #elif defined(HAVE_UTIME)
266 {
267 struct utimbuf buf;
268
269 buf.actime = (time_t) (finfo.atime / APR_USEC_PER_SEC);
270 buf.modtime = (time_t) (mtime / APR_USEC_PER_SEC);
271
272 if (utime(fname, &buf) == -1) {
273 return errno;
274 }
275 }
276 #else
277 return APR_ENOTIMPL;
278 #endif
279
280 return APR_SUCCESScxx . . $ `include/apr_errno.h:225:9`!;
281 }
282
283
284 APR_DECLAREcxx . . $ `include/apr.h:507:9`!(apr_status_t) apr_statcxx . . $ apr_stat(9cb7fb18475a4672).(apr_finfo_tcxx . . $ apr_finfo_t# *finfo,
285 const char *fname,
286 apr_int32_tcxx . . $ apr_int32_t# wanted, apr_pool_tcxx . . $ apr_pool_t# *pool)
287 {
288 struct_statcxx . . $ struct_stat# info;
289 int srv;
290
291 if (wanted & APR_FINFO_LINKcxx . . $ `include/apr_file_info.h:145:9`!)
292 srv = lstatcxx . . $ lstat(a9cd1e23e96f423c).(fname, &info);
293 else
294 srv = statcxx . . $ stat(a9cd1e23e96f423c).(fname, &info);
295
296 if (srv == 0) {
297 finfo->poolcxx . . $ apr_finfo_t#pool. = pool;
298 finfo->fnamecxx . . $ apr_finfo_t#fname. = fname;
299 fill_out_finfocxx . . $ fill_out_finfo(dbd7381422d9dfe7).(finfo, &info, wanted);
300 if (wanted & APR_FINFO_LINKcxx . . $ `include/apr_file_info.h:145:9`!)
301 wanted &= ~APR_FINFO_LINKcxx . . $ `include/apr_file_info.h:145:9`!;
302 return (wanted & ~finfo->validcxx . . $ apr_finfo_t#valid.) ? APR_INCOMPLETEcxx . . $ `include/apr_errno.h:452:9`! : APR_SUCCESScxx . . $ `include/apr_errno.h:225:9`!;
303 }
304 else {
305 #if !defined(ENOENTcxx . . $ `<external>/8987895939074593727/errno-base.h:6:9`!) || !defined(ENOTDIRcxx . . $ `<external>/8987895939074593727/errno-base.h:24:9`!)
306 #error ENOENT || ENOTDIR not defined; please see the
307 #error comments at this line in the source for a workaround.
308 /*
309 * If ENOENT || ENOTDIR is not defined in one of the your OS's
310 * include files, APR cannot report a good reason why the stat()
311 * of the file failed; there are cases where it can fail even though
312 * the file exists. This opens holes in Apache, for example, because
313 * it becomes possible for someone to get a directory listing of a
314 * directory even though there is an index (eg. index.html) file in
315 * it. If you do not have a problem with this, delete the above
316 * #error lines and start the compile again. If you need to do this,
317 * please submit a bug report to http://www.apache.org/bug_report.html
318 * letting us know that you needed to do this. Please be sure to
319 * include the operating system you are using.
320 */
321 /* WARNING: All errors will be handled as not found
322 */
323 #if !defined(ENOENT)
324 return APR_ENOENT;
325 #else
326 /* WARNING: All errors but not found will be handled as not directory
327 */
328 if (errno != ENOENT)
329 return APR_ENOENT;
330 else
331 return errno;
332 #endif
333 #else /* All was defined well, report the usual: */
334 return errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!;
335 #endif
336 }
337 }
338
339