VirtualBox

source: vbox/trunk/src/VBox/Runtime/testcase/tstDir.cpp@ 1532

Last change on this file since 1532 was 1, checked in by vboxsync, 55 years ago

import

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 8.2 KB
Line 
1/* $Id: tstDir.cpp 1 1970-01-01 00:00:00Z vboxsync $ */
2/** @file
3 * InnoTek Portable Runtime Testcase - Directory listing.
4 */
5
6/*
7 * Copyright (C) 2006 InnoTek Systemberatung GmbH
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 as published by the Free Software Foundation,
13 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
14 * distribution. VirtualBox OSE is distributed in the hope that it will
15 * be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * If you received this file as part of a commercial VirtualBox
18 * distribution, then only the terms of your commercial VirtualBox
19 * license agreement apply instead of the previous paragraph.
20 */
21
22#include <iprt/dir.h>
23#include <iprt/runtime.h>
24#include <iprt/stream.h>
25#include <iprt/err.h>
26//#include <iprt/
27
28int main(int argc, char **argv)
29{
30 int rcRet = 0;
31 RTR3Init();
32
33 /*
34 * Iterate arguments.
35 */
36 bool fLong = false;
37 bool fShortName = false;
38 for (int i = 1; i < argc; i++)
39 {
40 if (argv[i][0] == '-')
41 {
42 for (int j = 1; argv[i][j]; j++)
43 {
44 switch (argv[i][j])
45 {
46 case 'l':
47 fLong = true;
48 break;
49 case 's':
50 fShortName = true;
51 break;
52 default:
53 RTPrintf("Unknown option '%c' ignored!\n", argv[i][j]);
54 break;
55 }
56 }
57 }
58 else
59 {
60 /* open */
61 PRTDIR pDir;
62 int rc = RTDirOpen(&pDir, argv[i]);
63 if (RT_SUCCESS(rc))
64 {
65 /* list */
66 if (!fLong)
67 {
68 for (;;)
69 {
70 RTDIRENTRY DirEntry;
71 rc = RTDirRead(pDir, &DirEntry, NULL);
72 if (RT_FAILURE(rc))
73 break;
74 switch (DirEntry.enmType)
75 {
76 case RTDIRENTRYTYPE_UNKNOWN: RTPrintf("u"); break;
77 case RTDIRENTRYTYPE_FIFO: RTPrintf("f"); break;
78 case RTDIRENTRYTYPE_DEV_CHAR: RTPrintf("c"); break;
79 case RTDIRENTRYTYPE_DIRECTORY: RTPrintf("d"); break;
80 case RTDIRENTRYTYPE_DEV_BLOCK: RTPrintf("b"); break;
81 case RTDIRENTRYTYPE_FILE: RTPrintf("-"); break;
82 case RTDIRENTRYTYPE_SYMLINK: RTPrintf("l"); break;
83 case RTDIRENTRYTYPE_SOCKET: RTPrintf("s"); break;
84 case RTDIRENTRYTYPE_WHITEOUT: RTPrintf("w"); break;
85 default:
86 rcRet = 1;
87 RTPrintf("?");
88 break;
89 }
90 RTPrintf(" %#18llx %3d %s\n", (uint64_t)DirEntry.INodeId,
91 DirEntry.cbName, DirEntry.szName);
92 }
93 }
94 else
95 {
96 for (;;)
97 {
98 RTDIRENTRYEX DirEntry;
99 rc = RTDirReadEx(pDir, &DirEntry, NULL, RTFSOBJATTRADD_UNIX);
100 if (RT_FAILURE(rc))
101 break;
102
103 RTFMODE fMode = DirEntry.Info.Attr.fMode;
104 switch (fMode & RTFS_TYPE_MASK)
105 {
106 case RTFS_TYPE_FIFO: RTPrintf("f"); break;
107 case RTFS_TYPE_DEV_CHAR: RTPrintf("c"); break;
108 case RTFS_TYPE_DIRECTORY: RTPrintf("d"); break;
109 case RTFS_TYPE_DEV_BLOCK: RTPrintf("b"); break;
110 case RTFS_TYPE_FILE: RTPrintf("-"); break;
111 case RTFS_TYPE_SYMLINK: RTPrintf("l"); break;
112 case RTFS_TYPE_SOCKET: RTPrintf("s"); break;
113 case RTFS_TYPE_WHITEOUT: RTPrintf("w"); break;
114 default:
115 rcRet = 1;
116 RTPrintf("?");
117 break;
118 }
119 /** @todo sticy bits++ */
120 RTPrintf("%c%c%c",
121 fMode & RTFS_UNIX_IRUSR ? 'r' : '-',
122 fMode & RTFS_UNIX_IWUSR ? 'w' : '-',
123 fMode & RTFS_UNIX_IXUSR ? 'x' : '-');
124 RTPrintf("%c%c%c",
125 fMode & RTFS_UNIX_IRGRP ? 'r' : '-',
126 fMode & RTFS_UNIX_IWGRP ? 'w' : '-',
127 fMode & RTFS_UNIX_IXGRP ? 'x' : '-');
128 RTPrintf("%c%c%c",
129 fMode & RTFS_UNIX_IROTH ? 'r' : '-',
130 fMode & RTFS_UNIX_IWOTH ? 'w' : '-',
131 fMode & RTFS_UNIX_IXOTH ? 'x' : '-');
132 RTPrintf(" %c%c%c%c%c%c%c%c%c%c%c%c%c%c",
133 fMode & RTFS_DOS_READONLY ? 'R' : '-',
134 fMode & RTFS_DOS_HIDDEN ? 'H' : '-',
135 fMode & RTFS_DOS_SYSTEM ? 'S' : '-',
136 fMode & RTFS_DOS_DIRECTORY ? 'D' : '-',
137 fMode & RTFS_DOS_ARCHIVED ? 'A' : '-',
138 fMode & RTFS_DOS_NT_DEVICE ? 'd' : '-',
139 fMode & RTFS_DOS_NT_NORMAL ? 'N' : '-',
140 fMode & RTFS_DOS_NT_TEMPORARY ? 'T' : '-',
141 fMode & RTFS_DOS_NT_SPARSE_FILE ? 'P' : '-',
142 fMode & RTFS_DOS_NT_REPARSE_POINT ? 'J' : '-',
143 fMode & RTFS_DOS_NT_COMPRESSED ? 'C' : '-',
144 fMode & RTFS_DOS_NT_OFFLINE ? 'O' : '-',
145 fMode & RTFS_DOS_NT_NOT_CONTENT_INDEXED ? 'I' : '-',
146 fMode & RTFS_DOS_NT_ENCRYPTED ? 'E' : '-');
147 RTPrintf(" %d %4d %4d %10lld %10lld %#llx %#llx %#llx %#llx",
148 DirEntry.Info.Attr.u.Unix.cHardlinks,
149 DirEntry.Info.Attr.u.Unix.uid,
150 DirEntry.Info.Attr.u.Unix.gid,
151 DirEntry.Info.cbObject,
152 DirEntry.Info.cbAllocated,
153 DirEntry.Info.BirthTime,
154 DirEntry.Info.ChangeTime,
155 DirEntry.Info.ModificationTime,
156 DirEntry.Info.AccessTime);
157 if (fShortName && DirEntry.cucShortName)
158 RTPrintf(" %2d %lS\n", DirEntry.cucShortName, DirEntry.uszShortName);
159 else
160 RTPrintf(" %2d %s\n", DirEntry.cbName, DirEntry.szName);
161 if (rc != VINF_SUCCESS)
162 RTPrintf("^^ %Rrc\n", rc);
163 }
164 }
165
166 if (rc != VERR_NO_MORE_FILES)
167 {
168 RTPrintf("tstDir: Enumeration failed! rc=%Rrc\n", rc);
169 rcRet = 1;
170 }
171
172 /* close up */
173 rc = RTDirClose(pDir);
174 if (RT_FAILURE(rc))
175 {
176 RTPrintf("tstDir: Failed to close dir! rc=%Rrc\n", rc);
177 rcRet = 1;
178 }
179 }
180 else
181 {
182 RTPrintf("tstDir: Failed to open '%s', rc=%Rrc\n", argv[i], rc);
183 rcRet = 1;
184 }
185 }
186 }
187
188 return rcRet;
189}
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