if (fstat(b, &stb) < 0)
return -errno;
- if ((sta.st_mode & S_IFMT) != (stb.st_mode & S_IFMT))
+ if (!stat_inode_same(&sta, &stb))
return false;
/* We consider all device fds different, since two device fds
if (S_ISCHR(sta.st_mode) || S_ISBLK(sta.st_mode))
return false;
- if (sta.st_dev != stb.st_dev || sta.st_ino != stb.st_ino)
- return false;
-
- /* The fds refer to the same inode on disk, let's also check
- * if they have the same fd flags. This is useful to
- * distinguish the read and write side of a pipe created with
- * pipe(). */
+ /* The fds refer to the same inode on disk, let's also check if they have the same fd flags. This is
+ * useful to distinguish the read and write side of a pipe created with pipe(). */
fa = fcntl(a, F_GETFL);
if (fa < 0)
return -errno;
if (fstat(new_fd, &new_stat) < 0)
goto do_rename;
- if (new_stat.st_ino == old_stat.st_ino &&
- new_stat.st_dev == old_stat.st_dev)
+ if (stat_inode_same(&new_stat, &old_stat))
goto is_same;
if (old_stat.st_mode != new_stat.st_mode ||
if (fstatat(fd, "", &b, AT_EMPTY_PATH) < 0)
return -errno;
- /* A directory with same device and inode as its parent? Must
- * be the root directory */
- if (a.st_dev == b.st_dev &&
- a.st_ino == b.st_ino)
+ /* A directory with same device and inode as its parent? Must be the root directory */
+ if (stat_inode_same(&a, &b))
return 1;
return check_st_dev && (a.st_dev != b.st_dev);
if (fstatat(AT_FDCWD, fileb, &b, flags) < 0)
return -errno;
- return a.st_dev == b.st_dev &&
- a.st_ino == b.st_ino;
+ return stat_inode_same(&a, &b);
}
bool is_fs_type(const struct statfs *s, statfs_f_type_t magic_value) {
#include "hashmap.h"
#include "macro.h"
#include "memory-util.h"
+#include "stat-util.h"
#include "string-util.h"
#include "time-util.h"
#include "user-util.h"
if (!S_ISREG(st.st_mode))
continue;
- if (exclude_fd >= 0 &&
- exclude_st.st_dev == st.st_dev &&
- exclude_st.st_ino == st.st_ino)
+ if (exclude_fd >= 0 && stat_inode_same(&exclude_st, &st))
continue;
r = hashmap_ensure_allocated(&h, NULL);
#include "path-util.h"
#include "process-util.h"
#include "socket-util.h"
+#include "stat-util.h"
#include "strv.h"
#include "time-util.h"
#include "util.h"
return -errno;
}
- return
- st_path.st_dev == st_fd.st_dev &&
- st_path.st_ino == st_fd.st_ino;
+ return stat_inode_same(&st_path, &st_fd);
}
return 1;
}
if (S_ISREG(st_fd.st_mode) && S_ISREG(st_path.st_mode))
- return
- st_path.st_dev == st_fd.st_dev &&
- st_path.st_ino == st_fd.st_ino;
+ return stat_inode_same(&st_path, &st_fd);
else if (S_ISCHR(st_fd.st_mode) && S_ISCHR(st_path.st_mode))
return st_path.st_rdev == st_fd.st_rdev;
else
if (stat(fpath, &b) < 0)
return -errno;
- if (a.st_dev != b.st_dev ||
- a.st_ino != b.st_ino)
+ if (!stat_inode_same(&a, &b))
return 0;
}
#include "mountpoint-util.h"
#include "set.h"
#include "socket-util.h"
+#include "stat-util.h"
#include "string-util.h"
#include "strv.h"
else
log_debug_errno(errno, "sd-device-monitor: Failed to stat PID1's netns, ignoring: %m");
- } else if (a.st_dev != b.st_dev || a.st_ino != b.st_ino)
+ } else if (!stat_inode_same(&a, &b))
log_debug("sd-device-monitor: Netlink socket we listen on is not from host netns, we won't see device events.");
}
}
f = ordered_hashmap_get(j->files, path);
if (f) {
- if (f->last_stat.st_dev == st.st_dev &&
- f->last_stat.st_ino == st.st_ino) {
+ if (stat_inode_same(&f->last_stat, &st)) {
/* We already track this file, under the same path and with the same device/inode numbers, it's
* hence really the same. Mark this file as seen in this generation. This is used to GC old
/* Is it symlinked to our own uplink file? */
if (stat(PRIVATE_STATIC_RESOLV_CONF, &own) >= 0 &&
- st.st_dev == own.st_dev &&
- st.st_ino == own.st_ino)
+ stat_inode_same(&st, &own))
return log_warning_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
"DNSStubListener= is disabled, but /etc/resolv.conf is a symlink to "
PRIVATE_STATIC_RESOLV_CONF " which expects DNSStubListener= to be enabled.");
/* Is it symlinked to our own uplink file? */
if (stat(path, &own) >= 0 &&
- st->st_dev == own.st_dev &&
- st->st_ino == own.st_ino)
+ stat_inode_same(st, &own))
return true;
}
continue;
}
- if (system_st.st_dev == our_st.st_dev &&
- system_st.st_ino == our_st.st_ino)
+ if (stat_inode_same(&system_st, &our_st))
return m;
}
return log_debug_errno(errno, "Failed to fstat mount namespace FD of systemd: %m");
/* We can't add new mounts at runtime if the process wasn't started in a namespace */
- if (st.st_ino == self_mntns_st.st_ino && st.st_dev == self_mntns_st.st_dev)
+ if (stat_inode_same(&st, &self_mntns_st))
return log_debug_errno(SYNTHETIC_ERRNO(EINVAL), "Failed to activate bind mount in target, not running in a mount namespace");
/* One day, when bind mounting /proc/self/fd/n works across namespace boundaries we should rework