MCPcopy Create free account
hub / github.com/CloverHackyColor/CloverBootloader / queryDevice

Function queryDevice

CloverPackage/utils/partutil/partutil.c:207–330  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

205}
206
207static
208bool queryDevice(char const* deviceName, queryType query, char *answer, size_t answer_maxsize)
209{
210 struct stat buf;
211 DADiskRef disk;
212 CFDictionaryRef descDict;
213 CFBooleanRef b_ref;
214 bool result = false;
215 int isMediaWhole = 0;
216
217 assert(deviceName);
218
219 char devFilePath[ MAXPATHLEN ];
220 char *deviceFilePath = &devFilePath[0];
221
222 strlcpy( deviceFilePath, _PATH_DEV, sizeof( devFilePath ) );
223 strlcat( deviceFilePath, deviceName, sizeof( devFilePath ) );
224
225 if (stat(deviceFilePath, &buf) < 0) {
226 fprintf(stderr, "Error: stat failed on %s: %s\n", deviceFilePath, strerror(errno));
227 return false;
228 }
229 if (!(buf.st_mode & (S_IFCHR | S_IFBLK))) {
230 fprintf(stderr, "Error: %s is not a block or character special device\n", deviceFilePath);
231 return false;
232 }
233
234 if (getDASessionAndDisk(deviceName, NULL, &disk) < 0)
235 return false;
236
237 descDict = DADiskCopyDescription(disk);
238 CFRelease(disk);
239
240 if (!descDict) {
241 return false;
242 }
243
244 if (CFDictionaryGetValueIfPresent(descDict, kDADiskDescriptionMediaWholeKey, (void const**) &b_ref) &&
245 CFBooleanGetValue(b_ref))
246 isMediaWhole = 1;
247
248 // If query partition scheme, the device must be a whole disk
249 if (query == query_partitionscheme && !isMediaWhole) {
250 fprintf(stderr, "Error: device must be a whole disk to query about partition scheme !\n");
251 CFRelease(descDict);
252 return false;
253 }
254
255 CFStringRef key = NULL;
256 switch (query) {
257 case query_fstype:
258 key = kDADiskDescriptionVolumeKindKey;
259 break;
260 case query_bsdname:
261 key = kDADiskDescriptionMediaBSDNameKey;
262 break;
263 case query_mountpoint:
264 key = kDADiskDescriptionVolumePathKey;

Callers 1

mainFunction · 0.85

Calls 5

fprintfFunction · 0.85
snprintfFunction · 0.85
getFSTypeFromPBRFunction · 0.85
statClass · 0.70
getDASessionAndDiskFunction · 0.70

Tested by

no test coverage detected