2 #include <proto/exec.h>
5 #include <exec/memory.h>
7 #include <aros/debug.h>
11 int deleteDirContents(char *startpath
, int depth
, int dnum
, int fnum
) {
12 struct ExAllControl
*eac
;
13 struct TagItem ti
={TAG_DONE
};
14 struct ExAllData
*ead
;
15 struct ExAllData
*next
;
17 struct FileInfoBlock fib
;
23 size
=(dnum
+(fnum
*32))*(sizeof(struct ExAllData
)+32);
24 eac
= AllocDosObject(DOS_EXALLCONTROL
, &ti
);
27 printf("\nFailed to allocated dos object!\n");
31 ead
= AllocVec(size
, MEMF_ANY
| MEMF_CLEAR
);
34 FreeDosObject(DOS_EXALLCONTROL
, eac
);
35 printf("\nFailed to allocated memory!\n");
38 lock
= Lock(startpath
, SHARED_LOCK
);
42 FreeDosObject(DOS_EXALLCONTROL
, eac
);
43 printf("\nFailed to lock %s!\n", startpath
);
44 printf("I/O Error is %ld\n", (long)IoErr());
45 PrintFault(IoErr(), NULL
);
49 if (fib
.fib_DirEntryType
!= ST_USERDIR
)
53 FreeDosObject(DOS_EXALLCONTROL
, eac
);
54 printf("\nEntry %s is not directory!\n", startpath
);
55 printf("I/O Error is %ld\n", (long)IoErr());
56 PrintFault(IoErr(), NULL
);
59 if (ExAll(lock
, ead
, size
, ED_TYPE
, eac
) != 0)
61 kprintf("entries = %ld\n", eac
->eac_Entries
);
62 ExAllEnd(lock
, ead
, size
, ED_TYPE
, eac
);
65 FreeDosObject(DOS_EXALLCONTROL
, eac
);
66 printf("\nNot enough memory for %s when doing ExamineAll()!\n", startpath
);
67 printf("I/O Error is %ld\n", (long)IoErr());
68 PrintFault(IoErr(), NULL
);
72 if (IoErr() != ERROR_NO_MORE_ENTRIES
)
74 FreeDosObject(DOS_EXALLCONTROL
, eac
);
76 printf("\nExAll() returned error on %s!\n", startpath
);
77 printf("I/O Error is %ld\n", (long)IoErr());
78 PrintFault(IoErr(), NULL
);
81 if (eac
->eac_Entries
== 0)
87 AddPart(dpath
, startpath
, 512);
88 AddPart(dpath
, next
->ed_Name
, 512);
89 if (next
->ed_Type
== ST_FILE
)
92 if (DeleteFile(dpath
) == 0)
94 FreeDosObject(DOS_EXALLCONTROL
, eac
);
96 printf("\nFailed to delete file %s\n", dpath
);
97 printf("I/O Error is %ld\n", (long)IoErr());
98 PrintFault(IoErr(), NULL
);
103 else if (next
->ed_Type
== ST_USERDIR
)
105 if (deleteDirContents(dpath
, depth
-1, dnum
-1, fnum
== 0 ? fnum
: fnum
-1) != 0)
107 FreeDosObject(DOS_EXALLCONTROL
, eac
);
114 FreeDosObject(DOS_EXALLCONTROL
, eac
);
116 printf("\nFailed to identify %s - it is no directory or file!\n", dpath
);
119 next
= next
->ed_Next
;
121 FreeDosObject(DOS_EXALLCONTROL
, eac
);
124 if (DeleteFile(startpath
) == 0)
126 printf("\nFailed to delete directory %s\n", startpath
);
127 printf("I/O Error is %ld\n", (long)IoErr());
128 PrintFault(IoErr(), NULL
);
135 int deleteAll(char *startpath
, int depth
, int dnum
, int fnum
) {
140 for (i
=0; i
<dnum
; i
++)
142 sprintf(name
, "d-%03d-%03d", depth
, i
);
143 AddPart(path
, startpath
, 512);
144 AddPart(path
, name
, 512);
145 if (deleteDirContents(path
, depth
, dnum
, fnum
) != 0)
151 int specificParentCheck(BPTR lock
, BPTR dlock
, char *path
) {
154 plock
= ParentDir(dlock
);
157 printf("\nFailed to get parent of %s!\n", path
);
158 printf("I/O Error is %ld\n", (long)IoErr());
159 PrintFault(IoErr(), NULL
);
162 if (!SameLock(lock
, plock
))
165 printf("\nParent of %s is not correct!\n", path
);
172 int checkParent(char *startpath
, int depth
, int dnum
, int fnum
, int size
) {
183 lock
= Lock(startpath
, SHARED_LOCK
);
186 printf("\nFailed to get lock on %s!\n", startpath
);
187 printf("I/O Error is %ld\n", (long)IoErr());
188 PrintFault(IoErr(), NULL
);
191 for (i
=0; i
<dnum
; i
++)
193 sprintf(name
, "d-%03d-%03d", depth
, i
);
194 AddPart(path
, startpath
, 512);
195 AddPart(path
, name
, 512);
196 dlock
= Lock(path
, SHARED_LOCK
);
200 printf("\nFailed to get lock on %s!\n", path
);
201 printf("I/O Error is %ld\n", (long)IoErr());
202 PrintFault(IoErr(), NULL
);
205 if (specificParentCheck(lock
, dlock
, path
) != 0)
211 for (j
=0; j
<fnum
; j
++)
213 sprintf(name
, "f-%03d-%03d-%03d-%08d", depth
, i
, j
, size
);
214 AddPart(fpath
, path
, 512);
215 AddPart(fpath
, name
, 512);
216 flock
= Lock(fpath
, SHARED_LOCK
);
221 printf("\nFailed to get lock on %s!\n", fpath
);
222 printf("I/O Error is %ld\n", (long)IoErr());
223 PrintFault(IoErr(), NULL
);
226 if (specificParentCheck(dlock
, flock
, fpath
) != 0)
236 if (checkParent(path
, depth
-1, dnum
-1, fnum
== 0 ? fnum
: fnum
-1, size
) != 0)
243 int checkFile(char *path
, int depth
, int dnum
, int fnum
, int size
) {
245 unsigned int buffer
[512];
248 fh
= Open(path
, MODE_OLDFILE
);
251 printf("\nFailed to open file %s!\n", path
);
252 printf("I/O Error is %ld\n", (long)IoErr());
253 PrintFault(IoErr(), NULL
);
256 for (i
=0;i
<(size
/512);i
++)
258 if (Read(fh
, buffer
, 512) != 512)
260 printf("\nFailed to read from file %s\n", path
);
261 printf("I/O Error is %ld\n", (long)IoErr());
262 PrintFault(IoErr(), NULL
);
265 for (j
=0;j
<(512>>4); j
+=4)
268 (buffer
[j
+0] != depth
) ||
269 (buffer
[j
+1] != dnum
) ||
270 (buffer
[j
+2] != fnum
) ||
271 (buffer
[j
+3] != size
)
274 printf("\nFailed to verify file %s at offset %d\n", path
, j
*4);
275 printf("Expected: %08x %08x %0x %08x\n", depth
, dnum
, fnum
, size
);
276 printf("Got : %08x %08x %0x %08x\n", buffer
[j
+0], buffer
[j
+1], buffer
[j
+2], buffer
[j
+3]);
285 int checkFiles(char *startpath
, int depth
, int dnum
, int fnum
, int size
) {
293 for (i
=0; i
<dnum
; i
++)
295 sprintf(name
, "d-%03d-%03d", depth
, i
);
296 AddPart(path
, startpath
, 512);
297 AddPart(path
, name
, 512);
298 for (j
=0; j
<fnum
; j
++)
300 sprintf(name
, "f-%03d-%03d-%03d-%08d", depth
, i
, j
, size
);
301 AddPart(fpath
, path
, 512);
302 AddPart(fpath
, name
, 512);
303 if (checkFile(fpath
, depth
, dnum
, fnum
, size
) != 0)
307 if (checkFiles(path
, depth
-1, dnum
-1, fnum
== 0 ? fnum
: fnum
-1, size
) != 0)
313 int writeFile(char *path
, int size
, int depth
, int dnum
, int fnum
) {
315 unsigned int buffer
[512];
318 fh
= Open(path
, MODE_NEWFILE
);
321 printf("\nFailed to create file %s!\n", path
);
322 printf("I/O Error is %ld\n", (long)IoErr());
323 PrintFault(IoErr(), NULL
);
326 for (i
=0;i
<(512>>4); i
+=4)
333 for (i
=0;i
<(size
/512);i
++)
335 if (Write(fh
, buffer
, 512) != 512)
338 printf("Failed to write to file %s\n", path
);
339 printf("I/O Error is %ld\n", (long)IoErr());
340 PrintFault(IoErr(), NULL
);
345 // printf("Verifying ...");
346 if (checkFile(path
, size
, depth
, dnum
, fnum
) != 0)
352 int createFiles(char *startpath
, int depth
, int dnum
, int fnum
, int size
) {
360 for (i
=0; i
<dnum
; i
++)
362 sprintf(name
, "d-%03d-%03d", depth
, i
);
363 AddPart(path
, startpath
, 512);
364 AddPart(path
, name
, 512);
365 for (j
=0; j
<fnum
; j
++)
367 sprintf(name
, "f-%03d-%03d-%03d-%08d", depth
, i
, j
, size
);
368 AddPart(fpath
, path
, 512);
369 AddPart(fpath
, name
, 512);
370 if (writeFile(fpath
, size
, depth
, dnum
, fnum
) != 0)
374 if (createFiles(path
, depth
-1, dnum
-1, fnum
== 0 ? fnum
: fnum
-1, size
) != 0)
380 int checkDirs(char *startpath
, int depth
, int num
) {
388 for (i
=0; i
<num
; i
++)
390 sprintf(name
, "d-%03d-%03d", depth
, i
);
391 AddPart(path
, startpath
, 512);
392 AddPart(path
, name
, 512);
393 dir
= Lock(path
, SHARED_LOCK
);
396 printf("\nFailed locking %s!\n",path
);
397 printf("I/O Error is %ld\n", (long)IoErr());
398 PrintFault(IoErr(), NULL
);
403 if (checkDirs(path
, depth
-1, num
-1) != 0)
409 int createDirs(char *startpath
, int depth
, int num
) {
417 for (i
=0; i
<num
; i
++)
419 sprintf(name
, "d-%03d-%03d", depth
, i
);
420 AddPart(path
, startpath
, 512);
421 AddPart(path
, name
, 512);
422 dir
= CreateDir(path
);
425 printf("\nFailed to create %s!\n", path
);
426 printf("I/O Error is %ld\n", (long)IoErr());
427 PrintFault(IoErr(), NULL
);
432 if (createDirs(path
, depth
-1, num
-1) != 0)
438 int verifyFiles(char *startpath
, int depth
, int dnum
, int fnum
, int size
) {
439 printf("Verifying %d files per depth with size of %d bytes ...", fnum
, size
);
440 if (checkFiles(startpath
, depth
, dnum
, fnum
, size
) != 0)
446 int getDiskInfo(char *device
, struct InfoData
*id
) {
449 lock
= Lock(device
, SHARED_LOCK
);
452 printf("Failed to get lock on %s!\n", device
);
460 int fileTest(char *startpath
, int depth
, int dnum
, int fnum
, int isize
) {
468 printf("Creating %d files per depth with size of %d bytes ...", fnum
, size
);
469 if (createFiles(startpath
, depth
, dnum
, fnum
, size
) != 0)
476 if (verifyFiles(startpath
, depth
, dnum
, cfnum
, csize
) != 0)
488 #define TEST_PARENT 0
490 int main(int argc
, char *argv
[]) {
491 int isize
=1; /* initial size in 1024 byte */
492 int depth
=10; /* directory depth */
493 int dnum
=6; /* number of directories per depth*/
494 int fnum
=16; /* number of files per depth (the bigger the files the lesser are created) */
502 printf("Usage: %s <device>\n", argv
[0]);
506 if (getDiskInfo(argv
[1], &sid
) != 0)
508 printf("Directory test\n");
509 printf("==============\n");
510 printf("Creating directories ...");
511 if (createDirs(argv
[1], depth
, dnum
) != 0)
514 printf("Checking directories ...");
515 if (checkDirs(argv
[1], depth
, dnum
) != 0)
519 printf("File test\n");
520 printf("=========\n");
521 if (fileTest(argv
[1], depth
, dnum
, fnum
, isize
) != 0)
524 printf("Doing a parent check ...");
525 if (checkParent(argv
[1], depth
, dnum
, fnum
,) != 0)
529 if (getDiskInfo(argv
[1], &mid
) != 0)
532 printf("Deleting files and directories created by this test ...");
533 if (deleteAll(argv
[1], depth
, dnum
, fnum
) != 0)
537 printf("Used blocks before test: %ld\n", (long)sid
.id_NumBlocksUsed
);
539 printf("Used blocks using test: %ld\n", (long)mid
.id_NumBlocksUsed
);
540 if (getDiskInfo(argv
[1], &eid
) == 0)
541 printf("Used blocks after test: %ld\n", (long)eid
.id_NumBlocksUsed
);