VirtualBox

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

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

The Giant CDDL Dual-License Header Change.

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