3 * Scanning disk for btrfs multi-devices
6 * Copyright (c) 2013 Tencent, Inc.
9 #ifdef __MAKEWITH_GNUEFI
10 #include "edk2/DriverBinding.h"
11 #include "edk2/ComponentName.h"
13 #include "../include/refit_call_wrapper.h"
15 extern struct fsw_host_table fsw_efi_host_table
;
16 static void dummy_volume_free(struct fsw_volume
*vol
) { }
17 static struct fsw_fstype_table dummy_fstype
= {
18 { FSW_STRING_TYPE_UTF8
, 4, 4, "dummy" },
19 sizeof(struct fsw_volume
),
20 sizeof(struct fsw_dnode
),
23 dummy_volume_free
, //volume_free,
34 static struct fsw_volume
*create_dummy_volume(EFI_DISK_IO
*diskio
, UINT32 mediaid
)
37 struct fsw_volume
*vol
;
38 FSW_VOLUME_DATA
*Volume
;
40 err
= fsw_alloc_zero(sizeof(struct fsw_volume
), (void **)&vol
);
43 err
= fsw_alloc_zero(sizeof(FSW_VOLUME_DATA
), (void **)&Volume
);
48 /* fstype_table->volume_free for fsw_unmount */
49 vol
->fstype_table
= &dummy_fstype
;
50 /* host_data needded to fsw_block_get()/fsw_efi_read_block() */
51 Volume
->DiskIo
= diskio
;
52 Volume
->MediaId
= mediaid
;
54 vol
->host_data
= Volume
;
55 vol
->host_table
= &fsw_efi_host_table
;
59 static struct fsw_volume
*clone_dummy_volume(struct fsw_volume
*vol
)
61 FSW_VOLUME_DATA
*Volume
= (FSW_VOLUME_DATA
*)vol
->host_data
;
62 return create_dummy_volume(Volume
->DiskIo
, Volume
->MediaId
);
65 static void free_dummy_volume(struct fsw_volume
*vol
)
67 fsw_free(vol
->host_data
);
71 static int scan_disks(int (*hook
)(struct fsw_volume
*, struct fsw_volume
*), struct fsw_volume
*master
)
75 UINTN HandleCount
= 0;
79 // Driver hangs if compiled with GNU-EFI unless there's a Print() statement somewhere.
80 // I'm still trying to track that down; in the meantime, work around it....
81 #if defined(__MAKEWITH_GNUEFI)
84 DPRINT(L
"Scanning disks\n");
85 Status
= refit_call5_wrapper(BS
->LocateHandleBuffer
, ByProtocol
, &PROTO_NAME(DiskIoProtocol
), NULL
, &HandleCount
, &Handles
);
86 if (Status
== EFI_NOT_FOUND
)
87 return -1; // no filesystems. strange, but true...
88 for (i
= 0; i
< HandleCount
; i
++) {
90 EFI_BLOCK_IO
*blockio
;
91 Status
= refit_call3_wrapper(BS
->HandleProtocol
, Handles
[i
], &PROTO_NAME(DiskIoProtocol
), (VOID
**) &diskio
);
94 Status
= refit_call3_wrapper(BS
->HandleProtocol
, Handles
[i
], &PROTO_NAME(BlockIoProtocol
), (VOID
**) &blockio
);
97 struct fsw_volume
*vol
= create_dummy_volume(diskio
, blockio
->Media
->MediaId
);
99 DPRINT(L
"Checking disk %d\n", i
);
100 if(hook(master
, vol
) == FSW_SUCCESS
)
102 free_dummy_volume(vol
);