xref: /haiku/src/tests/system/kernel/disk_device_manager/DiskDeviceManagerTest.cpp (revision 17889a8c70dbb3d59c1412f6431968753c767bab)
1 //----------------------------------------------------------------------
2 //  This software is part of the Haiku distribution and is covered
3 //  by the MIT License.
4 //---------------------------------------------------------------------
5 
6 #include <stdio.h>
7 #include <string.h>
8 
9 #include <OS.h>
10 
11 #include <KDiskDevice.h>
12 #include <KFileDiskDevice.h>
13 #include <KDiskDeviceManager.h>
14 #include <KDiskDeviceUtils.h>
15 
16 const char *kTestFileDevice = "/boot/home/tmp/test-file-device";
17 
18 // main
19 int
20 main(int argc, char **argv)
21 {
22 	const char *testFileDevice = kTestFileDevice;
23 
24 	if (argc > 1)
25 		testFileDevice = argv[1];
26 
27 	KDiskDeviceManager::CreateDefault();
28 	KDiskDeviceManager *manager = KDiskDeviceManager::Default();
29 	manager->InitialDeviceScan();
30 	partition_id id = manager->CreateFileDevice(testFileDevice);
31 	if (id < B_OK)
32 		printf("creating the file device failed: %s\n", strerror(id));
33 
34 	// wait for scanning jobs to finish
35 	// (that's hopefully a hack :-))
36 	for (;;) {
37 		if (ManagerLocker locker = manager) {
38 			if (manager->CountJobs() == 0)
39 				break;
40 		}
41 		snooze(50000);
42 	}
43 
44 	// print devices
45 	for (int32 cookie = 0;
46 		 KDiskDevice *device = manager->RegisterNextDevice(&cookie); ) {
47 		PartitionRegistrar _(device, true);
48 		if (DeviceReadLocker locker = device) {
49 			device->Dump();
50 			printf("\n");
51 		}
52 	}
53 
54 //	error = manager->DeleteFileDevice(kTestFileDevice);
55 //	if (error != B_OK)
56 //		printf("deleting the file device failed: %s\n", strerror(error));
57 
58 
59 	KDiskDeviceManager::DeleteDefault();
60 	return 0;
61 }
62 
63