VirtualBox

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

Last change on this file since 71128 was 69111, checked in by vboxsync, 7 years ago

(C) year

  • 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 69111 2017-10-17 14:26:02Z vboxsync $ */
2/** @file
3 * IPRT - File System Helpers, POSIX, Part 2.
4 */
5
6/*
7 * Copyright (C) 2006-2017 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
100 /* the file mode */
101 RTFMODE fMode = pStat->st_mode & RTFS_UNIX_MASK;
102 Assert(RTFS_UNIX_ISUID == S_ISUID);
103 Assert(RTFS_UNIX_ISGID == S_ISGID);
104#ifdef S_ISTXT
105 Assert(RTFS_UNIX_ISTXT == S_ISTXT);
106#elif defined(S_ISVTX)
107 Assert(RTFS_UNIX_ISTXT == S_ISVTX);
108#else
109#error "S_ISVTX / S_ISTXT isn't defined"
110#endif
111 Assert(RTFS_UNIX_IRWXU == S_IRWXU);
112 Assert(RTFS_UNIX_IRUSR == S_IRUSR);
113 Assert(RTFS_UNIX_IWUSR == S_IWUSR);
114 Assert(RTFS_UNIX_IXUSR == S_IXUSR);
115 Assert(RTFS_UNIX_IRWXG == S_IRWXG);
116 Assert(RTFS_UNIX_IRGRP == S_IRGRP);
117 Assert(RTFS_UNIX_IWGRP == S_IWGRP);
118 Assert(RTFS_UNIX_IXGRP == S_IXGRP);
119 Assert(RTFS_UNIX_IRWXO == S_IRWXO);
120 Assert(RTFS_UNIX_IROTH == S_IROTH);
121 Assert(RTFS_UNIX_IWOTH == S_IWOTH);
122 Assert(RTFS_UNIX_IXOTH == S_IXOTH);
123 Assert(RTFS_TYPE_FIFO == S_IFIFO);
124 Assert(RTFS_TYPE_DEV_CHAR == S_IFCHR);
125 Assert(RTFS_TYPE_DIRECTORY == S_IFDIR);
126 Assert(RTFS_TYPE_DEV_BLOCK == S_IFBLK);
127 Assert(RTFS_TYPE_FILE == S_IFREG);
128 Assert(RTFS_TYPE_SYMLINK == S_IFLNK);
129 Assert(RTFS_TYPE_SOCKET == S_IFSOCK);
130#ifdef S_IFWHT
131 Assert(RTFS_TYPE_WHITEOUT == S_IFWHT);
132#endif
133 Assert(RTFS_TYPE_MASK == S_IFMT);
134
135 pObjInfo->Attr.fMode = rtFsModeFromUnix(fMode, pszName, cbName);
136
137 /* additional unix attribs */
138 pObjInfo->Attr.enmAdditional = RTFSOBJATTRADD_UNIX;
139 pObjInfo->Attr.u.Unix.uid = pStat->st_uid;
140 pObjInfo->Attr.u.Unix.gid = pStat->st_gid;
141 pObjInfo->Attr.u.Unix.cHardlinks = pStat->st_nlink;
142 pObjInfo->Attr.u.Unix.INodeIdDevice = pStat->st_dev;
143 pObjInfo->Attr.u.Unix.INodeId = pStat->st_ino;
144#ifdef HAVE_STAT_FLAGS
145 pObjInfo->Attr.u.Unix.fFlags = pStat->st_flags;
146#else
147 pObjInfo->Attr.u.Unix.fFlags = 0;
148#endif
149#ifdef HAVE_STAT_GEN
150 pObjInfo->Attr.u.Unix.GenerationId = pStat->st_gen;
151#else
152 pObjInfo->Attr.u.Unix.GenerationId = 0;
153#endif
154 pObjInfo->Attr.u.Unix.Device = pStat->st_rdev;
155}
156
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