1 | /** $Id: VBoxSFUtil.cpp 75337 2018-11-09 01:39:01Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBoxSF - OS/2 Shared Folders, Utility for attaching and testing.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (c) 2016-2018 knut st. osmundsen <[email protected]>
|
---|
8 | *
|
---|
9 | * Permission is hereby granted, free of charge, to any person
|
---|
10 | * obtaining a copy of this software and associated documentation
|
---|
11 | * files (the "Software"), to deal in the Software without
|
---|
12 | * restriction, including without limitation the rights to use,
|
---|
13 | * copy, modify, merge, publish, distribute, sublicense, and/or sell
|
---|
14 | * copies of the Software, and to permit persons to whom the
|
---|
15 | * Software is furnished to do so, subject to the following
|
---|
16 | * conditions:
|
---|
17 | *
|
---|
18 | * The above copyright notice and this permission notice shall be
|
---|
19 | * included in all copies or substantial portions of the Software.
|
---|
20 | *
|
---|
21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
---|
22 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
---|
23 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
---|
24 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
---|
25 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
---|
26 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
---|
27 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
---|
28 | * OTHER DEALINGS IN THE SOFTWARE.
|
---|
29 | */
|
---|
30 |
|
---|
31 |
|
---|
32 | /*********************************************************************************************************************************
|
---|
33 | * Header Files *
|
---|
34 | *********************************************************************************************************************************/
|
---|
35 | #include <string.h>
|
---|
36 | #include <stdio.h>
|
---|
37 | #include <stdint.h>
|
---|
38 | #include <stdlib.h>
|
---|
39 | #define INCL_BASE
|
---|
40 | #include <os2.h>
|
---|
41 |
|
---|
42 |
|
---|
43 | /*********************************************************************************************************************************
|
---|
44 | * Internal Functions *
|
---|
45 | *********************************************************************************************************************************/
|
---|
46 | extern "C" APIRET __cdecl CallDosQFileMode(const char *pszFilename, PUSHORT pfAttr, ULONG ulReserved);
|
---|
47 |
|
---|
48 |
|
---|
49 |
|
---|
50 | int vboxSfOs2UtilUse(int argc, char **argv)
|
---|
51 | {
|
---|
52 | /*
|
---|
53 | * Continue parsing.
|
---|
54 | */
|
---|
55 | if (argc != 3)
|
---|
56 | {
|
---|
57 | fprintf(stderr, "syntax error: Expected three arguments to 'use' command\n");
|
---|
58 | return 2;
|
---|
59 | }
|
---|
60 |
|
---|
61 | /* The drive letter. */
|
---|
62 | const char *pszDrive = argv[1];
|
---|
63 | if ( ( (pszDrive[0] >= 'A' && pszDrive[0] <= 'Z')
|
---|
64 | || (pszDrive[0] >= 'a' && pszDrive[0] <= 'z'))
|
---|
65 | && pszDrive[1] == ':'
|
---|
66 | && pszDrive[2] == '\0')
|
---|
67 | { /* likely */ }
|
---|
68 | else
|
---|
69 | {
|
---|
70 | fprintf(stderr, "syntax error: Invalid drive specification '%s', expected something like 'K:'.\n", pszDrive);
|
---|
71 | return 2;
|
---|
72 | }
|
---|
73 |
|
---|
74 | /* The shared folder. */
|
---|
75 | const char *pszFolder = argv[2];
|
---|
76 | size_t cchFolder = strlen(pszFolder);
|
---|
77 | if (cchFolder <= 80 && cchFolder != 0)
|
---|
78 | { /* likely */ }
|
---|
79 | else
|
---|
80 | {
|
---|
81 | fprintf(stderr, "syntax error: Shared folder name '%s' is too %s!\n", cchFolder >= 1 ? "long" : "short");
|
---|
82 | return 2;
|
---|
83 | }
|
---|
84 |
|
---|
85 | /*
|
---|
86 | * Try attach it.
|
---|
87 | */
|
---|
88 | APIRET rc = DosFSAttach(pszDrive, "VBOXSF", (void *)pszFolder, cchFolder + 1, FS_ATTACH);
|
---|
89 | if (rc == NO_ERROR)
|
---|
90 | {
|
---|
91 | printf("done\n");
|
---|
92 | return 0;
|
---|
93 | }
|
---|
94 | fprintf(stderr, "error: DosFSAttach failed: %u\n", rc);
|
---|
95 | return 1;
|
---|
96 | }
|
---|
97 |
|
---|
98 |
|
---|
99 | int vboxSfOs2UtilQPathInfo(int argc, char **argv)
|
---|
100 | {
|
---|
101 | for (int i = 1; i < argc; i++)
|
---|
102 | {
|
---|
103 | union
|
---|
104 | {
|
---|
105 | USHORT fAttribs;
|
---|
106 | FILESTATUS Lvl1r1;
|
---|
107 | FILESTATUS3 Lvl1r3;
|
---|
108 | FILESTATUS3L Lvl11;
|
---|
109 | FILESTATUS2 Lvl2r2;
|
---|
110 | FILESTATUS4 Lvl2r4;
|
---|
111 | FILESTATUS4L Lvl12;
|
---|
112 | FEA2LIST FeaList;
|
---|
113 | char szFullName[260];
|
---|
114 | //char szTest1[sizeof(FILESTATUS3) == sizeof(FILESTATUS)];
|
---|
115 | //char szTest2[sizeof(FILESTATUS4) == sizeof(FILESTATUS2)];
|
---|
116 | } u;
|
---|
117 |
|
---|
118 | u.fAttribs = 0xffff;
|
---|
119 | int rc = CallDosQFileMode(argv[i], &u.fAttribs, 0 /* reserved */);
|
---|
120 | printf("%s: DosQFileMode -> %u, %#x\n", argv[i], rc, u.fAttribs);
|
---|
121 |
|
---|
122 | memset(&u, 0xaa, sizeof(u));
|
---|
123 | rc = DosQueryPathInfo(argv[i], FIL_STANDARD, &u.Lvl1r1, sizeof(u.Lvl1r1));
|
---|
124 | printf("%s: FIL_STANDARD/%#x -> %u\n", argv[i], sizeof(u.Lvl1r1), rc);
|
---|
125 | if (rc == NO_ERROR)
|
---|
126 | {
|
---|
127 | printf(" Lvl1r1: creation=%u:%u write=%u:%u access=%u:%u\n",
|
---|
128 | u.Lvl1r1.fdateCreation, u.Lvl1r1.ftimeCreation, u.Lvl1r1.fdateLastWrite, u.Lvl1r1.ftimeLastWrite,
|
---|
129 | u.Lvl1r1.fdateLastAccess, u.Lvl1r1.ftimeLastAccess);
|
---|
130 | printf(" Lvl1r1: attrib=%#x size=%u alloc=%u\n", u.Lvl1r1.attrFile, u.Lvl1r1.cbFile, u.Lvl1r1.cbFileAlloc);
|
---|
131 |
|
---|
132 | }
|
---|
133 |
|
---|
134 | memset(&u, 0xbb, sizeof(u));
|
---|
135 | rc = DosQueryPathInfo(argv[i], FIL_STANDARD, &u.Lvl1r3, sizeof(u.Lvl1r3));
|
---|
136 | printf("%s: FIL_STANDARD/%#x-> %u\n", argv[i], sizeof(u.Lvl1r3), rc);
|
---|
137 | if (rc == NO_ERROR)
|
---|
138 | {
|
---|
139 | printf(" Lvl1r3: creation=%u:%u write=%u:%u access=%u:%u\n",
|
---|
140 | u.Lvl1r3.fdateCreation, u.Lvl1r3.ftimeCreation, u.Lvl1r3.fdateLastWrite, u.Lvl1r3.ftimeLastWrite,
|
---|
141 | u.Lvl1r3.fdateLastAccess, u.Lvl1r3.ftimeLastAccess);
|
---|
142 | printf(" Lvl1r3: attrib=%#x size=%u alloc=%u\n", u.Lvl1r3.attrFile, u.Lvl1r3.cbFile, u.Lvl1r3.cbFileAlloc);
|
---|
143 |
|
---|
144 | }
|
---|
145 |
|
---|
146 | memset(&u, 0xdd, sizeof(u));
|
---|
147 | rc = DosQueryPathInfo(argv[i], FIL_STANDARDL, &u.Lvl11, sizeof(u.Lvl11));
|
---|
148 | printf("%s: FIL_STANDARDL/%#x -> %u\n", argv[i], sizeof(u.Lvl11), rc);
|
---|
149 | if (rc == NO_ERROR)
|
---|
150 | {
|
---|
151 | printf(" Lvl11: creation=%u:%u write=%u:%u access=%u:%u\n",
|
---|
152 | u.Lvl11.fdateCreation, u.Lvl11.ftimeCreation, u.Lvl11.fdateLastWrite, u.Lvl11.ftimeLastWrite,
|
---|
153 | u.Lvl11.fdateLastAccess, u.Lvl11.ftimeLastAccess);
|
---|
154 | printf(" Lvl11: attrib=%#x size=%llu alloc=%llu\n", u.Lvl11.attrFile, u.Lvl11.cbFile, u.Lvl11.cbFileAlloc);
|
---|
155 | }
|
---|
156 |
|
---|
157 | memset(&u, 0xee, sizeof(u));
|
---|
158 | rc = DosQueryPathInfo(argv[i], FIL_QUERYEASIZE, &u.Lvl2r2, sizeof(u.Lvl2r2));
|
---|
159 | printf("%s: FIL_QUERYEASIZE/%#x -> %u\n", argv[i], sizeof(u.Lvl2r2), rc);
|
---|
160 | if (rc == NO_ERROR)
|
---|
161 | {
|
---|
162 | printf(" Lvl2: creation=%u:%u write=%u:%u access=%u:%u\n",
|
---|
163 | u.Lvl2r2.fdateCreation, u.Lvl2r2.ftimeCreation, u.Lvl2r2.fdateLastWrite, u.Lvl2r2.ftimeLastWrite,
|
---|
164 | u.Lvl2r2.fdateLastAccess, u.Lvl2r2.ftimeLastAccess);
|
---|
165 | printf(" Lvl2: attrib=%#x size=%u alloc=%u cbList=%#x\n",
|
---|
166 | u.Lvl2r2.attrFile, u.Lvl2r2.cbFile, u.Lvl2r2.cbFileAlloc, u.Lvl2r4.cbList);
|
---|
167 | }
|
---|
168 |
|
---|
169 | memset(&u, 0x55, sizeof(u));
|
---|
170 | rc = DosQueryPathInfo(argv[i], FIL_QUERYEASIZE, &u.Lvl2r4, sizeof(u.Lvl2r4));
|
---|
171 | printf("%s: FIL_QUERYEASIZE/%#x -> %u\n", argv[i], sizeof(u.Lvl2r4), rc);
|
---|
172 | if (rc == NO_ERROR)
|
---|
173 | {
|
---|
174 | printf(" Lvl2: creation=%u:%u write=%u:%u access=%u:%u\n",
|
---|
175 | u.Lvl2r4.fdateCreation, u.Lvl2r4.ftimeCreation, u.Lvl2r4.fdateLastWrite, u.Lvl2r4.ftimeLastWrite,
|
---|
176 | u.Lvl2r4.fdateLastAccess, u.Lvl2r4.ftimeLastAccess);
|
---|
177 | printf(" Lvl2: attrib=%#x size=%u alloc=%u cbList=%#x\n",
|
---|
178 | u.Lvl2r4.attrFile, u.Lvl2r4.cbFile, u.Lvl2r4.cbFileAlloc, u.Lvl2r4.cbList);
|
---|
179 | }
|
---|
180 |
|
---|
181 | memset(&u, 0x99, sizeof(u));
|
---|
182 | rc = DosQueryPathInfo(argv[i], FIL_QUERYEASIZEL, &u.Lvl12, sizeof(u.Lvl12));
|
---|
183 | printf("%s: FIL_QUERYEASIZEL/%#x -> %u\n", argv[i], sizeof(u.Lvl12), rc);
|
---|
184 | if (rc == NO_ERROR)
|
---|
185 | {
|
---|
186 | printf(" Lvl12: creation=%u:%u write=%u:%u access=%u:%u\n",
|
---|
187 | u.Lvl12.fdateCreation, u.Lvl12.ftimeCreation, u.Lvl12.fdateLastWrite, u.Lvl12.ftimeLastWrite,
|
---|
188 | u.Lvl12.fdateLastAccess, u.Lvl12.ftimeLastAccess);
|
---|
189 | printf(" Lvl12: attrib=%#x size=%llu alloc=%llu cbList=%#x\n",
|
---|
190 | u.Lvl12.attrFile, u.Lvl12.cbFile, u.Lvl12.cbFileAlloc, u.Lvl12.cbList);
|
---|
191 | }
|
---|
192 |
|
---|
193 | memset(&u, 0x44, sizeof(u));
|
---|
194 | rc = DosQueryPathInfo(argv[i], FIL_QUERYFULLNAME, &u.szFullName[0], sizeof(u.szFullName));
|
---|
195 | printf("%s: FIL_QUERYFULLNAME -> %u\n", argv[i], rc);
|
---|
196 | if (rc == NO_ERROR)
|
---|
197 | printf(" Lvl5: %s<eol>\n", u.szFullName);
|
---|
198 |
|
---|
199 | size_t cchInput = strlen(argv[i]);
|
---|
200 | if (cchInput >= sizeof(u.szFullName))
|
---|
201 | cchInput = sizeof(u.szFullName) - 1;
|
---|
202 |
|
---|
203 | /** @todo Cannot get to level 6 thru 32-bit, need 16-bit. DOSCALL1.DLL
|
---|
204 | * chickens out on us. Sigh. */
|
---|
205 | memcpy(u.szFullName, argv[i], cchInput);
|
---|
206 | u.szFullName[0] = '\0';
|
---|
207 | rc = DosQueryPathInfo(argv[i], 6 /*FIL_VERIFY_SYNTAX*/, &u.szFullName[0], sizeof(u.szFullName));
|
---|
208 | printf("%s: FIL_VERIFY_SYNTAX -> %u\n", argv[i], rc);
|
---|
209 | if (rc == NO_ERROR)
|
---|
210 | printf(" Lvl6: %s<eol>\n", u.szFullName);
|
---|
211 |
|
---|
212 | memcpy(u.szFullName, argv[i], cchInput);
|
---|
213 | u.szFullName[0] = '\0';
|
---|
214 | rc = DosQueryPathInfo(argv[i], 16 /*FIL_VERIFY_SYNTAX_L*/, &u.szFullName[0], sizeof(u.szFullName));
|
---|
215 | printf("%s: FIL_VERIFY_SYNTAX_L -> %u\n", argv[i], rc);
|
---|
216 | if (rc == NO_ERROR)
|
---|
217 | printf(" Lvl6L: %s<eol>\n", u.szFullName);
|
---|
218 |
|
---|
219 | memcpy(u.szFullName, argv[i], cchInput);
|
---|
220 | u.szFullName[0] = '\0';
|
---|
221 | rc = DosQueryPathInfo(argv[i], 7 /*FIL_FIX_CASE*/, &u.szFullName[0], sizeof(u.szFullName));
|
---|
222 | printf("%s: FIL_FIX_CASE -> %u\n", argv[i], rc);
|
---|
223 | if (rc == NO_ERROR)
|
---|
224 | printf(" Lvl7: %s<eol>\n", u.szFullName);
|
---|
225 |
|
---|
226 | memcpy(u.szFullName, argv[i], cchInput);
|
---|
227 | u.szFullName[0] = '\0';
|
---|
228 | rc = DosQueryPathInfo(argv[i], 17 /*FIL_FIX_CASE_L*/, &u.szFullName[0], sizeof(u.szFullName));
|
---|
229 | printf("%s: FIL_FIX_CASE_L -> %u\n", argv[i], rc);
|
---|
230 | if (rc == NO_ERROR)
|
---|
231 | printf(" Lvl17: %s<eol>\n", u.szFullName);
|
---|
232 |
|
---|
233 | struct
|
---|
234 | {
|
---|
235 | ULONG cbList;
|
---|
236 | ULONG oNext;
|
---|
237 | BYTE cchName;
|
---|
238 | char szName[10];
|
---|
239 | } Gea2List, const Gea2ListOrg = { sizeof(Gea2List), 0, sizeof(".LONGNAME") - 1, ".LONGNAME" };
|
---|
240 | EAOP2 EaOp;
|
---|
241 | EaOp.fpGEA2List = (PGEA2LIST)memcpy(&Gea2List, &Gea2ListOrg, sizeof(Gea2List));
|
---|
242 | EaOp.fpFEA2List = &u.FeaList;
|
---|
243 | EaOp.oError = 0;
|
---|
244 | memset(&u, '\0', sizeof(u));
|
---|
245 | u.FeaList.cbList = sizeof(u);
|
---|
246 | rc = DosQueryPathInfo(argv[i], FIL_QUERYEASFROMLIST, &EaOp, sizeof(EaOp));
|
---|
247 | printf("%s: FIL_QUERYEASFROMLIST -> %u\n", argv[i], rc);
|
---|
248 | if (rc == NO_ERROR)
|
---|
249 | printf(" Lvl3: FeaList.cbList=%#x oError=%#x\n", u.FeaList.cbList, EaOp.oError);
|
---|
250 |
|
---|
251 | EaOp.fpGEA2List = (PGEA2LIST)memcpy(&Gea2List, &Gea2ListOrg, sizeof(Gea2List));
|
---|
252 | EaOp.fpFEA2List = &u.FeaList;
|
---|
253 | EaOp.oError = 0;
|
---|
254 | memset(&u, '\0', sizeof(u));
|
---|
255 | u.FeaList.cbList = sizeof(u);
|
---|
256 | rc = DosQueryPathInfo(argv[i], FIL_QUERYEASFROMLISTL, &EaOp, sizeof(EaOp));
|
---|
257 | if (rc != ERROR_INVALID_LEVEL)
|
---|
258 | printf("%s: FIL_QUERYEASFROMLISTL -> %u\n", argv[i], rc);
|
---|
259 |
|
---|
260 | EaOp.fpGEA2List = (PGEA2LIST)memcpy(&Gea2List, &Gea2ListOrg, sizeof(Gea2List));
|
---|
261 | EaOp.fpFEA2List = &u.FeaList;
|
---|
262 | EaOp.oError = 0;
|
---|
263 | memset(&u, '\0', sizeof(u));
|
---|
264 | u.FeaList.cbList = sizeof(u);
|
---|
265 | rc = DosQueryPathInfo(argv[i], 4, &EaOp, sizeof(EaOp));
|
---|
266 | printf("%s: FIL_QUERYALLEAS/4 -> %u\n", argv[i], rc);
|
---|
267 | if (rc == NO_ERROR)
|
---|
268 | printf(" Lvl4: FeaList.cbList=%#x oError=%#x\n", u.FeaList.cbList, EaOp.oError);
|
---|
269 |
|
---|
270 | EaOp.fpGEA2List = (PGEA2LIST)memcpy(&Gea2List, &Gea2ListOrg, sizeof(Gea2List));
|
---|
271 | EaOp.fpFEA2List = &u.FeaList;
|
---|
272 | EaOp.oError = 0;
|
---|
273 | memset(&u, '\0', sizeof(u));
|
---|
274 | u.FeaList.cbList = sizeof(u);
|
---|
275 | rc = DosQueryPathInfo(argv[i], 14, &EaOp, sizeof(EaOp));
|
---|
276 | if (rc != ERROR_INVALID_LEVEL)
|
---|
277 | printf("%s: FIL_QUERYALLEASL/14 -> %u\n", argv[i], rc);
|
---|
278 |
|
---|
279 | EaOp.fpGEA2List = (PGEA2LIST)memcpy(&Gea2List, &Gea2ListOrg, sizeof(Gea2List));
|
---|
280 | EaOp.fpFEA2List = &u.FeaList;
|
---|
281 | EaOp.oError = 0;
|
---|
282 | memset(&u, '\0', sizeof(u));
|
---|
283 | u.FeaList.cbList = sizeof(u);
|
---|
284 | rc = DosQueryPathInfo(argv[i], 8, &EaOp, sizeof(EaOp));
|
---|
285 | printf("%s: FIL_QUERYALLEAS/8 -> %u\n", argv[i], rc);
|
---|
286 | if (rc == NO_ERROR)
|
---|
287 | printf(" Lvl8: FeaList.cbList=%#x oError=%#x\n", u.FeaList.cbList, EaOp.oError);
|
---|
288 |
|
---|
289 | EaOp.fpGEA2List = (PGEA2LIST)memcpy(&Gea2List, &Gea2ListOrg, sizeof(Gea2List));
|
---|
290 | EaOp.fpFEA2List = &u.FeaList;
|
---|
291 | EaOp.oError = 0;
|
---|
292 | memset(&u, '\0', sizeof(u));
|
---|
293 | u.FeaList.cbList = sizeof(u);
|
---|
294 | rc = DosQueryPathInfo(argv[i], 18, &EaOp, sizeof(EaOp));
|
---|
295 | if (rc != ERROR_INVALID_LEVEL)
|
---|
296 | printf("%s: FIL_QUERYALLEASL/18 -> %u\n", argv[i], rc);
|
---|
297 |
|
---|
298 | EaOp.fpGEA2List = (PGEA2LIST)memcpy(&Gea2List, &Gea2ListOrg, sizeof(Gea2List));
|
---|
299 | EaOp.fpFEA2List = &u.FeaList;
|
---|
300 | EaOp.oError = 0;
|
---|
301 | memset(&u, '\0', sizeof(u));
|
---|
302 | u.FeaList.cbList = sizeof(u);
|
---|
303 | rc = DosQueryPathInfo(argv[i], 15, &EaOp, sizeof(EaOp));
|
---|
304 | if (rc != ERROR_INVALID_LEVEL)
|
---|
305 | printf("%s: FIL_QUERYALLEASL/15 -> %u\n", argv[i], rc);
|
---|
306 |
|
---|
307 | memset(&u, '\0', sizeof(u));
|
---|
308 | rc = DosQueryPathInfo(argv[i], 0, &u, sizeof(u));
|
---|
309 | if (rc != ERROR_INVALID_LEVEL)
|
---|
310 | printf("%s: 0 -> %u\n", argv[i], rc);
|
---|
311 | }
|
---|
312 | return 0;
|
---|
313 | }
|
---|
314 |
|
---|
315 |
|
---|
316 | int vboxSfOs2UtilFindFile(int argc, char **argv)
|
---|
317 | {
|
---|
318 | unsigned cMaxMatches = 1;
|
---|
319 | unsigned cbBuf = 1024;
|
---|
320 | unsigned uLevel = FIL_STANDARDL;
|
---|
321 | unsigned fAttribs = FILE_DIRECTORY | FILE_HIDDEN | FILE_SYSTEM;
|
---|
322 | bool fOptions = true;
|
---|
323 |
|
---|
324 | uint8_t *pbBuf = NULL;
|
---|
325 | for (int i = 1; i < argc; i++)
|
---|
326 | {
|
---|
327 | const char *pszArg = argv[i];
|
---|
328 |
|
---|
329 | /*
|
---|
330 | * Deal with options.
|
---|
331 | */
|
---|
332 | if (fOptions && *pszArg == '-')
|
---|
333 | {
|
---|
334 | pszArg++;
|
---|
335 | if (*pszArg == '-')
|
---|
336 | {
|
---|
337 | pszArg++;
|
---|
338 | if (!*pszArg)
|
---|
339 | {
|
---|
340 | fOptions = false;
|
---|
341 | continue;
|
---|
342 | }
|
---|
343 | if (strcmp(pszArg, "attribs") == 0)
|
---|
344 | pszArg = "a";
|
---|
345 | else if (strcmp(pszArg, "buffer-size") == 0)
|
---|
346 | pszArg = "b";
|
---|
347 | else if (strcmp(pszArg, "level") == 0)
|
---|
348 | pszArg = "l";
|
---|
349 | else if (strcmp(pszArg, "matches") == 0)
|
---|
350 | pszArg = "m";
|
---|
351 | else if (strcmp(pszArg, "help") == 0)
|
---|
352 | pszArg = "h";
|
---|
353 | else
|
---|
354 | {
|
---|
355 | fprintf(stderr, "syntax error: Unknown option: %s\n", argv[i]);
|
---|
356 | return 2;
|
---|
357 | }
|
---|
358 | }
|
---|
359 | do
|
---|
360 | {
|
---|
361 | const char *pszValue = NULL;
|
---|
362 | char chOpt = *pszArg++;
|
---|
363 | if (strchr("ablm", chOpt) != NULL)
|
---|
364 | {
|
---|
365 | if (*pszArg != '\0')
|
---|
366 | pszValue = *pszArg == ':' || *pszArg == '=' ? ++pszArg : pszArg;
|
---|
367 | else if (i + 1 < argc)
|
---|
368 | pszValue = argv[++i];
|
---|
369 | else
|
---|
370 | {
|
---|
371 | fprintf(stderr, "syntax error: -%c takes a value\n", chOpt);
|
---|
372 | return 2;
|
---|
373 | }
|
---|
374 | pszArg = "";
|
---|
375 | }
|
---|
376 | switch (chOpt)
|
---|
377 | {
|
---|
378 | case 'a':
|
---|
379 | fAttribs = atoi(pszValue);
|
---|
380 | break;
|
---|
381 | case 'b':
|
---|
382 | cbBuf = atoi(pszValue);
|
---|
383 | free(pbBuf);
|
---|
384 | pbBuf = NULL;
|
---|
385 | break;
|
---|
386 | case 'l':
|
---|
387 | uLevel = atoi(pszValue);
|
---|
388 | break;
|
---|
389 | case 'm':
|
---|
390 | cMaxMatches = atoi(pszValue);
|
---|
391 | break;
|
---|
392 | case 'h':
|
---|
393 | printf("usage: findfile [-a|--attribs <mask>] [-b|--buffer-size <bytes>]\n"
|
---|
394 | " [-l|--level <num>] [-m|--matches <num>] [--] <dir1> [dir2..N]\n");
|
---|
395 | return 0;
|
---|
396 | default:
|
---|
397 | fprintf(stderr, "syntax error: Unknown option '%c' (%s)\n", chOpt, argv[i - (pszValue != NULL)]);
|
---|
398 | return 2;
|
---|
399 | }
|
---|
400 |
|
---|
401 | } while (pszArg && *pszArg != '\0');
|
---|
402 | }
|
---|
403 | else
|
---|
404 | {
|
---|
405 | /*
|
---|
406 | * Search the specified directory/whatever.
|
---|
407 | */
|
---|
408 | if (!pbBuf)
|
---|
409 | {
|
---|
410 | pbBuf = (uint8_t *)malloc(cbBuf);
|
---|
411 | if (!pbBuf)
|
---|
412 | {
|
---|
413 | fprintf(stderr, "error: out of memory (cbBuf=%#x)\n", cbBuf);
|
---|
414 | return 1;
|
---|
415 | }
|
---|
416 | }
|
---|
417 |
|
---|
418 | HDIR hDir = HDIR_CREATE;
|
---|
419 | ULONG cMatches = cMaxMatches;
|
---|
420 | memset(pbBuf, 0xf6, cbBuf);
|
---|
421 | APIRET rc = DosFindFirst(pszArg, &hDir, fAttribs, pbBuf, cbBuf, &cMatches, uLevel);
|
---|
422 | printf("DosFindFirst -> %u hDir=%p cMatches=%#x\n", rc, hDir, cMatches);
|
---|
423 | if (rc == NO_ERROR)
|
---|
424 | {
|
---|
425 | do
|
---|
426 | {
|
---|
427 | uint8_t *pbTmp = pbBuf;
|
---|
428 | for (uint32_t iMatch = 0; iMatch < cMatches; iMatch++)
|
---|
429 | {
|
---|
430 | uint32_t offNext = *(uint32_t *)pbTmp;
|
---|
431 | switch (uLevel)
|
---|
432 | {
|
---|
433 | case FIL_STANDARD:
|
---|
434 | {
|
---|
435 | PFILEFINDBUF3 pBuf = (PFILEFINDBUF3)pbTmp;
|
---|
436 | printf("#%u: nx=%#x sz=%#x at=%#x nm=%#x:%s\n",
|
---|
437 | iMatch, pBuf->oNextEntryOffset, pBuf->cbFile, pBuf->attrFile, pBuf->cchName, pBuf->achName);
|
---|
438 | if (strlen(pBuf->achName) != pBuf->cchName)
|
---|
439 | printf("Bad name length!\n");
|
---|
440 | break;
|
---|
441 | }
|
---|
442 | case FIL_STANDARDL:
|
---|
443 | {
|
---|
444 | PFILEFINDBUF3L pBuf = (PFILEFINDBUF3L)pbTmp;
|
---|
445 | printf("#%u: nx=%#x sz=%#llx at=%#x nm=%#x:%s\n",
|
---|
446 | iMatch, pBuf->oNextEntryOffset, pBuf->cbFile, pBuf->attrFile, pBuf->cchName, pBuf->achName);
|
---|
447 | if (strlen(pBuf->achName) != pBuf->cchName)
|
---|
448 | printf("Bad name length!\n");
|
---|
449 | break;
|
---|
450 | }
|
---|
451 | case FIL_QUERYEASIZE:
|
---|
452 | {
|
---|
453 | PFILEFINDBUF4 pBuf = (PFILEFINDBUF4)pbTmp;
|
---|
454 | printf("#%u: nx=%#x sz=%#x at=%#x nm=%#x:%s\n",
|
---|
455 | iMatch, pBuf->oNextEntryOffset, pBuf->cbFile, pBuf->attrFile, pBuf->cchName, pBuf->achName);
|
---|
456 | if (strlen(pBuf->achName) != pBuf->cchName)
|
---|
457 | printf("Bad name length!\n");
|
---|
458 | break;
|
---|
459 | }
|
---|
460 | case FIL_QUERYEASIZEL:
|
---|
461 | {
|
---|
462 | PFILEFINDBUF4L pBuf = (PFILEFINDBUF4L)pbTmp;
|
---|
463 | printf("#%u: nx=%#x sz=%#llx at=%#x nm=%#x:%s\n",
|
---|
464 | iMatch, pBuf->oNextEntryOffset, pBuf->cbFile, pBuf->attrFile, pBuf->cchName, pBuf->achName);
|
---|
465 | if (strlen(pBuf->achName) != pBuf->cchName)
|
---|
466 | printf("Bad name length!\n");
|
---|
467 | break;
|
---|
468 | }
|
---|
469 |
|
---|
470 | }
|
---|
471 |
|
---|
472 | pbTmp += offNext;
|
---|
473 | }
|
---|
474 |
|
---|
475 | /* Next bunch. */
|
---|
476 | memset(pbBuf, 0xf6, cbBuf);
|
---|
477 | cMatches = cMaxMatches;
|
---|
478 | rc = DosFindNext(hDir, pbBuf, cbBuf, &cMatches);
|
---|
479 | printf("DosFindNext -> %u hDir=%p cMatches=%#x\n", rc, hDir, cMatches);
|
---|
480 | } while (rc == NO_ERROR);
|
---|
481 |
|
---|
482 | rc = DosFindClose(hDir);
|
---|
483 | printf("DosFindClose -> %u\n", rc);
|
---|
484 | }
|
---|
485 | }
|
---|
486 | }
|
---|
487 | return 0;
|
---|
488 | }
|
---|
489 |
|
---|
490 |
|
---|
491 | static int vboxSfOs2UtilMkDir(int argc, char **argv)
|
---|
492 | {
|
---|
493 | for (int i = 1; i < argc; i++)
|
---|
494 | {
|
---|
495 | APIRET rc = DosCreateDir(argv[i], NULL);
|
---|
496 | printf("DosCreateDir -> %u for '%s'\n", rc, argv[i]);
|
---|
497 | }
|
---|
498 | return 0;
|
---|
499 | }
|
---|
500 |
|
---|
501 |
|
---|
502 | int main(int argc, char **argv)
|
---|
503 | {
|
---|
504 | /*
|
---|
505 | * Parse input.
|
---|
506 | */
|
---|
507 | for (int i = 1; i < argc; i++)
|
---|
508 | {
|
---|
509 | const char *pszArg = argv[i];
|
---|
510 | if (strcmp(pszArg, "use") == 0)
|
---|
511 | return vboxSfOs2UtilUse(argc - i, argv + i);
|
---|
512 | if (strcmp(pszArg, "qpathinfo") == 0)
|
---|
513 | return vboxSfOs2UtilQPathInfo(argc - i, argv + i);
|
---|
514 | if (strcmp(pszArg, "findfile") == 0)
|
---|
515 | return vboxSfOs2UtilFindFile(argc - i, argv + i);
|
---|
516 | if (strcmp(pszArg, "mkdir") == 0)
|
---|
517 | return vboxSfOs2UtilMkDir(argc - i, argv + i);
|
---|
518 |
|
---|
519 | fprintf(stderr, "Unknown command/option: %u\n", pszArg);
|
---|
520 | return 2;
|
---|
521 | }
|
---|
522 | fprintf(stderr,
|
---|
523 | "usage: VBoxSFUtil.exe use [drive] [shared-folder]\n"
|
---|
524 | " or VBoxSFUtil.exe unuse [drive|shared-folder] [..]\n"
|
---|
525 | " or VBoxSFUtil.exe list\n");
|
---|
526 | return 2;
|
---|
527 | }
|
---|
528 |
|
---|