VirtualBox

source: vbox/trunk/src/VBox/Runtime/testcase/tstRTPathQueryInfo.cpp@ 83743

Last change on this file since 83743 was 82968, checked in by vboxsync, 5 years ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.8 KB
Line 
1/* $Id: tstRTPathQueryInfo.cpp 82968 2020-02-04 10:35:17Z vboxsync $ */
2/** @file
3 * IPRT Testcase - RTPathQueryInfoEx testcase
4 */
5
6/*
7 * Copyright (C) 2006-2020 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#include <iprt/path.h>
32#include <iprt/initterm.h>
33#include <iprt/errcore.h>
34#include <iprt/stream.h>
35#include <iprt/message.h>
36#include <iprt/time.h>
37
38
39int main(int argc, char **argv)
40{
41 int rc = RTR3InitExe(argc, &argv, 0);
42 if (RT_FAILURE(rc))
43 return RTMsgInitFailure(rc);
44
45 /*
46 * Iterate arguments.
47 */
48 RTEXITCODE rcExit = RTEXITCODE_SUCCESS;
49 uint32_t fFlags = RTPATH_F_ON_LINK;
50 RTFSOBJATTRADD enmAdditionalAttribs = RTFSOBJATTRADD_NOTHING;
51 for (int i = 1; i < argc; i++)
52 {
53 if (argv[i][0] == '-')
54 {
55 for (int j = 1; argv[i][j]; j++)
56 {
57 switch (argv[i][j])
58 {
59 case 'H':
60 fFlags = RTPATH_F_FOLLOW_LINK;
61 break;
62 case 'l':
63 enmAdditionalAttribs = RTFSOBJATTRADD_UNIX;
64 break;
65 default:
66 RTPrintf("Unknown option '%c' ignored!\n", argv[i][j]);
67 break;
68 }
69 }
70 }
71 else
72 {
73 RTFSOBJINFO ObjInfo;
74 rc = RTPathQueryInfoEx(argv[i], &ObjInfo, enmAdditionalAttribs, fFlags);
75 if (RT_SUCCESS(rc))
76 {
77 RTPrintf(" File: '%s'\n", argv[i]);
78 RTPrintf(" Size: %'RTfoff Allocated: %'RTfoff\n", ObjInfo.cbObject, ObjInfo.cbAllocated);
79
80 RTPrintf(" Mode: ");
81 RTFMODE fMode = ObjInfo.Attr.fMode;
82 switch (fMode & RTFS_TYPE_MASK)
83 {
84 case RTFS_TYPE_FIFO: RTPrintf("f"); break;
85 case RTFS_TYPE_DEV_CHAR: RTPrintf("c"); break;
86 case RTFS_TYPE_DIRECTORY: RTPrintf("d"); break;
87 case RTFS_TYPE_DEV_BLOCK: RTPrintf("b"); break;
88 case RTFS_TYPE_FILE: RTPrintf("-"); break;
89 case RTFS_TYPE_SYMLINK: RTPrintf("l"); break;
90 case RTFS_TYPE_SOCKET: RTPrintf("s"); break;
91 case RTFS_TYPE_WHITEOUT: RTPrintf("w"); break;
92 default:
93 rcExit = RTEXITCODE_FAILURE;
94 RTPrintf("?");
95 break;
96 }
97 /** @todo sticy bits++ */
98 RTPrintf("%c%c%c",
99 fMode & RTFS_UNIX_IRUSR ? 'r' : '-',
100 fMode & RTFS_UNIX_IWUSR ? 'w' : '-',
101 fMode & RTFS_UNIX_IXUSR ? 'x' : '-');
102 RTPrintf("%c%c%c",
103 fMode & RTFS_UNIX_IRGRP ? 'r' : '-',
104 fMode & RTFS_UNIX_IWGRP ? 'w' : '-',
105 fMode & RTFS_UNIX_IXGRP ? 'x' : '-');
106 RTPrintf("%c%c%c",
107 fMode & RTFS_UNIX_IROTH ? 'r' : '-',
108 fMode & RTFS_UNIX_IWOTH ? 'w' : '-',
109 fMode & RTFS_UNIX_IXOTH ? 'x' : '-');
110
111 RTPrintf(" Attributes: %c%c%c%c%c%c%c%c%c%c%c%c%c%c",
112 fMode & RTFS_DOS_READONLY ? 'R' : '-',
113 fMode & RTFS_DOS_HIDDEN ? 'H' : '-',
114 fMode & RTFS_DOS_SYSTEM ? 'S' : '-',
115 fMode & RTFS_DOS_DIRECTORY ? 'D' : '-',
116 fMode & RTFS_DOS_ARCHIVED ? 'A' : '-',
117 fMode & RTFS_DOS_NT_DEVICE ? 'd' : '-',
118 fMode & RTFS_DOS_NT_NORMAL ? 'N' : '-',
119 fMode & RTFS_DOS_NT_TEMPORARY ? 'T' : '-',
120 fMode & RTFS_DOS_NT_SPARSE_FILE ? 'P' : '-',
121 fMode & RTFS_DOS_NT_REPARSE_POINT ? 'J' : '-',
122 fMode & RTFS_DOS_NT_COMPRESSED ? 'C' : '-',
123 fMode & RTFS_DOS_NT_OFFLINE ? 'O' : '-',
124 fMode & RTFS_DOS_NT_NOT_CONTENT_INDEXED ? 'I' : '-',
125 fMode & RTFS_DOS_NT_ENCRYPTED ? 'E' : '-');
126 RTPrintf("\n");
127
128 if (enmAdditionalAttribs == RTFSOBJATTRADD_UNIX)
129 {
130 RTPrintf(" Inode: %#llx InodeDevice: %#x Links: %u\n",
131 ObjInfo.Attr.u.Unix.INodeId,
132 ObjInfo.Attr.u.Unix.INodeIdDevice,
133 ObjInfo.Attr.u.Unix.cHardlinks);
134 RTPrintf(" Uid: %d Gid: %d\n",
135 ObjInfo.Attr.u.Unix.uid,
136 ObjInfo.Attr.u.Unix.gid);
137 }
138
139 char szTmp[80];
140 RTPrintf(" Birth: %s\n", RTTimeSpecToString(&ObjInfo.BirthTime, szTmp, sizeof(szTmp)));
141 RTPrintf("Access: %s\n", RTTimeSpecToString(&ObjInfo.AccessTime, szTmp, sizeof(szTmp)));
142 RTPrintf("Modify: %s\n", RTTimeSpecToString(&ObjInfo.ModificationTime, szTmp, sizeof(szTmp)));
143 RTPrintf("Change: %s\n", RTTimeSpecToString(&ObjInfo.ChangeTime, szTmp, sizeof(szTmp)));
144
145 }
146 else
147 {
148 RTPrintf("RTPathQueryInfoEx(%s,,%d,%#x) -> %Rrc\n", argv[i], enmAdditionalAttribs, fFlags, rc);
149 rcExit = RTEXITCODE_FAILURE;
150 }
151 }
152 }
153
154 return rcExit;
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