VirtualBox

source: vbox/trunk/src/VBox/Runtime/r3/posix/fs2-posix.cpp@ 104635

Last change on this file since 104635 was 98103, checked in by vboxsync, 22 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 6.4 KB
Line 
1/* $Id: fs2-posix.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * IPRT - File System Helpers, POSIX, Part 2.
4 */
5
6/*
7 * Copyright (C) 2006-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * The contents of this file may alternatively be used under the terms
26 * of the Common Development and Distribution License Version 1.0
27 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
28 * in the VirtualBox distribution, in which case the provisions of the
29 * CDDL are applicable instead of those of the GPL.
30 *
31 * You may elect to license modified versions of this file under the
32 * terms and conditions of either the GPL or the CDDL or both.
33 *
34 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
35 */
36
37
38/*********************************************************************************************************************************
39* Header Files *
40*********************************************************************************************************************************/
41#define RTTIME_INCL_TIMESPEC
42#include <sys/time.h>
43#include <sys/param.h>
44#ifndef DEV_BSIZE
45# include <sys/stat.h>
46# if defined(RT_OS_HAIKU) && !defined(S_BLKSIZE)
47# define S_BLKSIZE 512
48# endif
49# define DEV_BSIZE S_BLKSIZE /** @todo bird: add DEV_BSIZE to sys/param.h on OS/2. */
50#endif
51
52#include <iprt/fs.h>
53#include "internal/iprt.h"
54
55#include <iprt/assert.h>
56#include <iprt/time.h>
57#include "internal/fs.h"
58
59
60/**
61 * Internal worker function which setups RTFSOBJINFO based on a UNIX stat struct.
62 *
63 * @param pObjInfo The file system object info structure to setup.
64 * @param pStat The stat structure to use.
65 * @param pszName The filename which this applies to (exe/hidden check).
66 * @param cbName The length of that filename. (optional, set 0)
67 */
68void rtFsConvertStatToObjInfo(PRTFSOBJINFO pObjInfo, const struct stat *pStat, const char *pszName, unsigned cbName)
69{
70 pObjInfo->cbObject = pStat->st_size;
71 pObjInfo->cbAllocated = pStat->st_blocks * DEV_BSIZE;
72
73#ifdef HAVE_STAT_NSEC
74 RTTimeSpecAddNano(RTTimeSpecSetSeconds(&pObjInfo->AccessTime, pStat->st_atime), pStat->st_atimensec);
75 RTTimeSpecAddNano(RTTimeSpecSetSeconds(&pObjInfo->ModificationTime, pStat->st_mtime), pStat->st_mtimensec);
76 RTTimeSpecAddNano(RTTimeSpecSetSeconds(&pObjInfo->ChangeTime, pStat->st_ctime), pStat->st_ctimensec);
77# ifdef HAVE_STAT_BIRTHTIME
78 RTTimeSpecAddNano(RTTimeSpecSetSeconds(&pObjInfo->BirthTime, pStat->st_birthtime), pStat->st_birthtimensec);
79# endif
80
81#elif defined(HAVE_STAT_TIMESPEC_BRIEF)
82 RTTimeSpecSetTimespec(&pObjInfo->AccessTime, &pStat->st_atim);
83 RTTimeSpecSetTimespec(&pObjInfo->ModificationTime, &pStat->st_mtim);
84 RTTimeSpecSetTimespec(&pObjInfo->ChangeTime, &pStat->st_ctim);
85# ifdef HAVE_STAT_BIRTHTIME
86 RTTimeSpecSetTimespec(&pObjInfo->BirthTime, &pStat->st_birthtim);
87# endif
88
89#elif defined(HAVE_STAT_TIMESPEC)
90 RTTimeSpecSetTimespec(&pObjInfo->AccessTime, pStat->st_atimespec);
91 RTTimeSpecSetTimespec(&pObjInfo->ModificationTime, pStat->st_mtimespec);
92 RTTimeSpecSetTimespec(&pObjInfo->ChangeTime, pStat->st_ctimespec);
93# ifdef HAVE_STAT_BIRTHTIME
94 RTTimeSpecSetTimespec(&pObjInfo->BirthTime, pStat->st_birthtimespec);
95# endif
96
97#else /* just the normal stuff */
98 RTTimeSpecSetSeconds(&pObjInfo->AccessTime, pStat->st_atime);
99 RTTimeSpecSetSeconds(&pObjInfo->ModificationTime, pStat->st_mtime);
100 RTTimeSpecSetSeconds(&pObjInfo->ChangeTime, pStat->st_ctime);
101# ifdef HAVE_STAT_BIRTHTIME
102 RTTimeSpecSetSeconds(&pObjInfo->BirthTime, pStat->st_birthtime);
103# endif
104#endif
105#ifndef HAVE_STAT_BIRTHTIME
106 pObjInfo->BirthTime = pObjInfo->ChangeTime;
107#endif
108
109 /* the file mode */
110 RTFMODE fMode = pStat->st_mode & RTFS_UNIX_MASK;
111 Assert(RTFS_UNIX_ISUID == S_ISUID);
112 Assert(RTFS_UNIX_ISGID == S_ISGID);
113#ifdef S_ISTXT
114 Assert(RTFS_UNIX_ISTXT == S_ISTXT);
115#elif defined(S_ISVTX)
116 Assert(RTFS_UNIX_ISTXT == S_ISVTX);
117#else
118#error "S_ISVTX / S_ISTXT isn't defined"
119#endif
120 Assert(RTFS_UNIX_IRWXU == S_IRWXU);
121 Assert(RTFS_UNIX_IRUSR == S_IRUSR);
122 Assert(RTFS_UNIX_IWUSR == S_IWUSR);
123 Assert(RTFS_UNIX_IXUSR == S_IXUSR);
124 Assert(RTFS_UNIX_IRWXG == S_IRWXG);
125 Assert(RTFS_UNIX_IRGRP == S_IRGRP);
126 Assert(RTFS_UNIX_IWGRP == S_IWGRP);
127 Assert(RTFS_UNIX_IXGRP == S_IXGRP);
128 Assert(RTFS_UNIX_IRWXO == S_IRWXO);
129 Assert(RTFS_UNIX_IROTH == S_IROTH);
130 Assert(RTFS_UNIX_IWOTH == S_IWOTH);
131 Assert(RTFS_UNIX_IXOTH == S_IXOTH);
132 Assert(RTFS_TYPE_FIFO == S_IFIFO);
133 Assert(RTFS_TYPE_DEV_CHAR == S_IFCHR);
134 Assert(RTFS_TYPE_DIRECTORY == S_IFDIR);
135 Assert(RTFS_TYPE_DEV_BLOCK == S_IFBLK);
136 Assert(RTFS_TYPE_FILE == S_IFREG);
137 Assert(RTFS_TYPE_SYMLINK == S_IFLNK);
138 Assert(RTFS_TYPE_SOCKET == S_IFSOCK);
139#ifdef S_IFWHT
140 Assert(RTFS_TYPE_WHITEOUT == S_IFWHT);
141#endif
142 Assert(RTFS_TYPE_MASK == S_IFMT);
143
144 pObjInfo->Attr.fMode = rtFsModeFromUnix(fMode, pszName, cbName, 0);
145
146 /* additional unix attribs */
147 pObjInfo->Attr.enmAdditional = RTFSOBJATTRADD_UNIX;
148 pObjInfo->Attr.u.Unix.uid = pStat->st_uid;
149 pObjInfo->Attr.u.Unix.gid = pStat->st_gid;
150 pObjInfo->Attr.u.Unix.cHardlinks = pStat->st_nlink;
151 pObjInfo->Attr.u.Unix.INodeIdDevice = pStat->st_dev;
152 pObjInfo->Attr.u.Unix.INodeId = pStat->st_ino;
153#ifdef HAVE_STAT_FLAGS
154 pObjInfo->Attr.u.Unix.fFlags = pStat->st_flags;
155#else
156 pObjInfo->Attr.u.Unix.fFlags = 0;
157#endif
158#ifdef HAVE_STAT_GEN
159 pObjInfo->Attr.u.Unix.GenerationId = pStat->st_gen;
160#else
161 pObjInfo->Attr.u.Unix.GenerationId = 0;
162#endif
163 pObjInfo->Attr.u.Unix.Device = pStat->st_rdev;
164}
165
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette