vbox的更動 34015 路徑 trunk/src/VBox/Runtime/r3/fs.cpp
- 時間撮記:
- 2010-11-12 上午12:15:05 (14 年 以前)
- 檔案:
-
- 修改 1 筆資料
圖例:
- 未更動
- 新增
- 刪除
-
trunk/src/VBox/Runtime/r3/fs.cpp
r34002 r34015 29 29 * Header Files * 30 30 *******************************************************************************/ 31 #ifndef RT_OS_WINDOWS32 # define RTTIME_INCL_TIMESPEC33 # include <sys/time.h>34 # include <sys/param.h>35 # ifndef DEV_BSIZE36 # include <sys/stat.h>37 # define DEV_BSIZE S_BLKSIZE /** @todo bird: add DEV_BSIZE to sys/param.h on OS/2. */38 # endif39 # include <grp.h>40 # include <pwd.h>41 #endif42 43 31 #include <iprt/fs.h> 44 32 #include "internal/iprt.h" … … 194 182 } 195 183 196 #ifndef RT_OS_WINDOWS197 198 /**199 * Internal worker function which setups RTFSOBJINFO based on a UNIX stat struct.200 *201 * @param pObjInfo The file system object info structure to setup.202 * @param pStat The stat structure to use.203 * @param pszName The filename which this applies to (exe/hidden check).204 * @param cbName The length of that filename. (optional, set 0)205 */206 void rtFsConvertStatToObjInfo(PRTFSOBJINFO pObjInfo, const struct stat *pStat, const char *pszName, unsigned cbName)207 {208 pObjInfo->cbObject = pStat->st_size;209 pObjInfo->cbAllocated = pStat->st_blocks * DEV_BSIZE;210 211 #ifdef HAVE_STAT_NSEC212 RTTimeSpecAddNano(RTTimeSpecSetSeconds(&pObjInfo->AccessTime, pStat->st_atime), pStat->st_atimensec);213 RTTimeSpecAddNano(RTTimeSpecSetSeconds(&pObjInfo->ModificationTime, pStat->st_mtime), pStat->st_mtimensec);214 RTTimeSpecAddNano(RTTimeSpecSetSeconds(&pObjInfo->ChangeTime, pStat->st_ctime), pStat->st_ctimensec);215 #ifdef HAVE_STAT_BIRTHTIME216 RTTimeSpecAddNano(RTTimeSpecSetSeconds(&pObjInfo->BirthTime, pStat->st_birthtime), pStat->st_birthtimensec);217 #endif218 219 #elif defined(HAVE_STAT_TIMESPEC_BRIEF)220 RTTimeSpecSetTimespec(&pObjInfo->AccessTime, &pStat->st_atim);221 RTTimeSpecSetTimespec(&pObjInfo->ModificationTime, &pStat->st_mtim);222 RTTimeSpecSetTimespec(&pObjInfo->ChangeTime, &pStat->st_ctim);223 # ifdef HAVE_STAT_BIRTHTIME224 RTTimeSpecSetTimespec(&pObjInfo->BirthTime, &pStat->st_birthtim);225 # endif226 227 #elif defined(HAVE_STAT_TIMESPEC)228 RTTimeSpecSetTimespec(&pObjInfo->AccessTime, pStat->st_atimespec);229 RTTimeSpecSetTimespec(&pObjInfo->ModificationTime, pStat->st_mtimespec);230 RTTimeSpecSetTimespec(&pObjInfo->ChangeTime, pStat->st_ctimespec);231 # ifdef HAVE_STAT_BIRTHTIME232 RTTimeSpecSetTimespec(&pObjInfo->BirthTime, pStat->st_birthtimespec);233 # endif234 235 #else /* just the normal stuff */236 RTTimeSpecSetSeconds(&pObjInfo->AccessTime, pStat->st_atime);237 RTTimeSpecSetSeconds(&pObjInfo->ModificationTime, pStat->st_mtime);238 RTTimeSpecSetSeconds(&pObjInfo->ChangeTime, pStat->st_ctime);239 # ifdef HAVE_STAT_BIRTHTIME240 RTTimeSpecSetSeconds(&pObjInfo->BirthTime, pStat->st_birthtime);241 # endif242 #endif243 #ifndef HAVE_STAT_BIRTHTIME244 pObjInfo->BirthTime = pObjInfo->ChangeTime;245 #endif246 247 248 /* the file mode */249 RTFMODE fMode = pStat->st_mode & RTFS_UNIX_MASK;250 Assert(RTFS_UNIX_ISUID == S_ISUID);251 Assert(RTFS_UNIX_ISGID == S_ISGID);252 #ifdef S_ISTXT253 Assert(RTFS_UNIX_ISTXT == S_ISTXT);254 #elif defined(S_ISVTX)255 Assert(RTFS_UNIX_ISTXT == S_ISVTX);256 #else257 #error "S_ISVTX / S_ISTXT isn't defined"258 #endif259 Assert(RTFS_UNIX_IRWXU == S_IRWXU);260 Assert(RTFS_UNIX_IRUSR == S_IRUSR);261 Assert(RTFS_UNIX_IWUSR == S_IWUSR);262 Assert(RTFS_UNIX_IXUSR == S_IXUSR);263 Assert(RTFS_UNIX_IRWXG == S_IRWXG);264 Assert(RTFS_UNIX_IRGRP == S_IRGRP);265 Assert(RTFS_UNIX_IWGRP == S_IWGRP);266 Assert(RTFS_UNIX_IXGRP == S_IXGRP);267 Assert(RTFS_UNIX_IRWXO == S_IRWXO);268 Assert(RTFS_UNIX_IROTH == S_IROTH);269 Assert(RTFS_UNIX_IWOTH == S_IWOTH);270 Assert(RTFS_UNIX_IXOTH == S_IXOTH);271 Assert(RTFS_TYPE_FIFO == S_IFIFO);272 Assert(RTFS_TYPE_DEV_CHAR == S_IFCHR);273 Assert(RTFS_TYPE_DIRECTORY == S_IFDIR);274 Assert(RTFS_TYPE_DEV_BLOCK == S_IFBLK);275 Assert(RTFS_TYPE_FILE == S_IFREG);276 Assert(RTFS_TYPE_SYMLINK == S_IFLNK);277 Assert(RTFS_TYPE_SOCKET == S_IFSOCK);278 #ifdef S_IFWHT279 Assert(RTFS_TYPE_WHITEOUT == S_IFWHT);280 #endif281 Assert(RTFS_TYPE_MASK == S_IFMT);282 283 pObjInfo->Attr.fMode = rtFsModeFromUnix(fMode, pszName, cbName);284 285 /* additional unix attribs */286 pObjInfo->Attr.enmAdditional = RTFSOBJATTRADD_UNIX;287 pObjInfo->Attr.u.Unix.uid = pStat->st_uid;288 pObjInfo->Attr.u.Unix.gid = pStat->st_gid;289 pObjInfo->Attr.u.Unix.cHardlinks = pStat->st_nlink;290 pObjInfo->Attr.u.Unix.INodeIdDevice = pStat->st_dev;291 pObjInfo->Attr.u.Unix.INodeId = pStat->st_ino;292 #ifdef HAVE_STAT_FLAGS293 pObjInfo->Attr.u.Unix.fFlags = pStat->st_flags;294 #else295 pObjInfo->Attr.u.Unix.fFlags = 0;296 #endif297 #ifdef HAVE_STAT_GEN298 pObjInfo->Attr.u.Unix.GenerationId = pStat->st_gen;299 #else300 pObjInfo->Attr.u.Unix.GenerationId = 0;301 #endif302 pObjInfo->Attr.u.Unix.Device = pStat->st_rdev;303 }304 305 306 /**307 * Set user-owner additional attributes.308 *309 * @param pObjInfo The object info to fill add attrs for.310 * @param uid The user id.311 */312 void rtFsObjInfoAttrSetUnixOwner(PRTFSOBJINFO pObjInfo, RTUID uid)313 {314 pObjInfo->Attr.enmAdditional = RTFSOBJATTRADD_UNIX_OWNER;315 pObjInfo->Attr.u.UnixOwner.uid = uid;316 pObjInfo->Attr.u.UnixOwner.szName[0] = '\0';317 318 char achBuf[_4K];319 struct passwd Pwd;320 struct passwd *pPwd;321 int rc = getpwuid_r(uid, &Pwd, achBuf, sizeof(achBuf), &pPwd);322 if (!rc && pPwd)323 RTStrCopy(pObjInfo->Attr.u.UnixOwner.szName, sizeof(pObjInfo->Attr.u.UnixOwner.szName), pPwd->pw_name);324 }325 326 327 /**328 * Set user-group additional attributes.329 *330 * @param pObjInfo The object info to fill add attrs for.331 * @param gid The group id.332 */333 void rtFsObjInfoAttrSetUnixGroup(PRTFSOBJINFO pObjInfo, RTUID gid)334 {335 pObjInfo->Attr.enmAdditional = RTFSOBJATTRADD_UNIX_GROUP;336 pObjInfo->Attr.u.UnixGroup.gid = gid;337 pObjInfo->Attr.u.UnixGroup.szName[0] = '\0';338 339 char achBuf[_4K];340 struct group Grp;341 struct group *pGrp;342 343 int rc = getgrgid_r(gid, &Grp, achBuf, sizeof(achBuf), &pGrp);344 if (!rc && pGrp)345 RTStrCopy(pObjInfo->Attr.u.UnixGroup.szName, sizeof(pObjInfo->Attr.u.UnixGroup.szName), pGrp->gr_name);346 }347 348 #endif /* !RT_OS_WINDOWS */349 350 184 351 185 RTDECL(const char *) RTFsTypeName(RTFSTYPE enmType)
注意:
瀏覽 TracChangeset
來幫助您使用更動檢視器