MCPcopy Create free account
hub / github.com/coreutils/coreutils / get_device

Function get_device

src/df.c:1264–1339  ·  view source on GitHub ↗

If DEVICE corresponds to a mount point, show its usage and return true. Otherwise, return false. */

Source from the content-addressed store, hash-verified

1262/* If DEVICE corresponds to a mount point, show its usage
1263 and return true. Otherwise, return false. */
1264static bool
1265get_device (char const *device)
1266{
1267 struct mount_entry const *best_match = NULL;
1268 bool best_match_accessible = false;
1269 bool eclipsed_device = false;
1270 char const *file = device;
1271
1272 char *resolved = canonicalize_file_name (device);
1273 if (resolved && IS_ABSOLUTE_FILE_NAME (resolved))
1274 device = resolved;
1275
1276 size_t best_match_len = SIZE_MAX;
1277 for (struct mount_entry const *me = mount_list; me; me = me->me_next)
1278 {
1279 /* TODO: Should cache canon_dev in the mount_entry struct. */
1280 char *devname = me->me_devname;
1281 char *canon_dev = canonicalize_file_name (me->me_devname);
1282 if (canon_dev && IS_ABSOLUTE_FILE_NAME (canon_dev))
1283 devname = canon_dev;
1284
1285 if (streq (device, devname))
1286 {
1287 char *last_device = last_device_for_mount (me->me_mountdir);
1288 eclipsed_device = last_device && ! streq (last_device, devname);
1289 size_t len = strlen (me->me_mountdir);
1290
1291 if (! eclipsed_device
1292 && (! best_match_accessible || len < best_match_len))
1293 {
1294 struct stat device_stats;
1295 bool this_match_accessible = false;
1296
1297 if (stat (me->me_mountdir, &device_stats) == 0)
1298 best_match_accessible = this_match_accessible = true;
1299
1300 if (this_match_accessible
1301 || (! best_match_accessible && len < best_match_len))
1302 {
1303 best_match = me;
1304 if (len == 1) /* Traditional root. */
1305 {
1306 free (last_device);
1307 free (canon_dev);
1308 break;
1309 }
1310 else
1311 best_match_len = len;
1312 }
1313 }
1314
1315 free (last_device);
1316 }
1317
1318 free (canon_dev);
1319 }
1320
1321 free (resolved);

Callers 1

get_entryFunction · 0.85

Calls 3

last_device_for_mountFunction · 0.85
get_devFunction · 0.85
statClass · 0.70

Tested by

no test coverage detected