VirtualBox

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

Last change on this file since 4337 was 4071, checked in by vboxsync, 17 years ago

Biggest check-in ever. New source code headers for all (C) innotek files.

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