VirtualBox

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

Last change on this file since 78253 was 77754, checked in by vboxsync, 6 years ago

IPRT: Some st_birthtime experimentation for FreeBSD.

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