tree-wide: port various places over to new stat_inode_same() helper

This commit is contained in:
Lennart Poettering
2022-02-14 17:27:14 +01:00
parent 38db6211b5
commit a9dac7a6dd
10 changed files with 20 additions and 37 deletions
+3 -8
View File
@@ -446,7 +446,7 @@ int same_fd(int a, int b) {
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
@@ -456,13 +456,8 @@ int same_fd(int a, int b) {
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;
+1 -2
View File
@@ -856,8 +856,7 @@ int conservative_renameat(
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 ||
+2 -4
View File
@@ -298,10 +298,8 @@ fallback_fstat:
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);
+1 -2
View File
@@ -185,8 +185,7 @@ int files_same(const char *filea, const char *fileb, int flags) {
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) {