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

Function get_point

src/df.c:1344–1437  ·  view source on GitHub ↗

Figure out which device file or directory POINT is mounted on and show its device usage. STATP must be the result of 'stat (POINT, STATP)'. */

Source from the content-addressed store, hash-verified

1342 and show its device usage.
1343 STATP must be the result of 'stat (POINT, STATP)'. */
1344static void
1345get_point (char const *point, const struct stat *statp)
1346{
1347 struct stat device_stats;
1348 struct mount_entry const *best_match = NULL;
1349
1350 /* Calculate the real absolute file name for POINT, and use that to find
1351 the mount point. This avoids statting unavailable mount points,
1352 which can hang df. */
1353 char *resolved = canonicalize_file_name (point);
1354 if (resolved && resolved[0] == '/')
1355 {
1356 size_t resolved_len = strlen (resolved);
1357 size_t best_match_len = 0;
1358
1359 for (struct mount_entry *me = mount_list; me; me = me->me_next)
1360 {
1361 if (!streq (me->me_type, "lofs")
1362 && (!best_match || best_match->me_dummy || !me->me_dummy))
1363 {
1364 size_t len = strlen (me->me_mountdir);
1365 if (best_match_len <= len && len <= resolved_len
1366 && (len == 1 /* root file system */
1367 || ((len == resolved_len || resolved[len] == '/')
1368 && STREQ_LEN (me->me_mountdir, resolved, len))))
1369 {
1370 best_match = me;
1371 best_match_len = len;
1372 }
1373 }
1374 }
1375 }
1376 free (resolved);
1377 if (best_match
1378 && (stat (best_match->me_mountdir, &device_stats) != 0
1379 || device_stats.st_dev != statp->st_dev))
1380 best_match = NULL;
1381
1382 if (! best_match)
1383 for (struct mount_entry *me = mount_list; me; me = me->me_next)
1384 {
1385 if (me->me_dev == (dev_t) -1)
1386 {
1387 if (stat (me->me_mountdir, &device_stats) == 0)
1388 me->me_dev = device_stats.st_dev;
1389 else
1390 {
1391 /* Report only I/O errors. Other errors might be
1392 caused by shadowed mount points, which means POINT
1393 can't possibly be on this file system. */
1394 if (errno == EIO)
1395 {
1396 error (0, errno, "%s", quotef (me->me_mountdir));
1397 exit_status = EXIT_FAILURE;
1398 }
1399
1400 /* So we won't try and fail repeatedly. */
1401 me->me_dev = (dev_t) -2;

Callers 1

get_entryFunction · 0.85

Calls 3

get_devFunction · 0.85
find_mount_pointFunction · 0.85
statClass · 0.70

Tested by

no test coverage detected