summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-04-08 20:47:35 +0200
committerLennart Poettering <lennart@poettering.net>2015-04-08 20:47:35 +0200
commit1ed8f8c16da99551c6731764759878a0bc243fde (patch)
treee374c9701d1f6217e77b056b52401c02d59755eb
parent171181bcd64d5a128f6678107d18ffa1c9388b94 (diff)
util: merge change_attr_fd() and chattr_fd()
-rw-r--r--src/import/import-raw.c4
-rw-r--r--src/import/pull-raw.c6
-rw-r--r--src/journal/journal-file.c4
-rw-r--r--src/journal/journalctl.c2
-rw-r--r--src/shared/copy.c2
-rw-r--r--src/shared/util.c36
-rw-r--r--src/shared/util.h5
-rw-r--r--src/tmpfiles/tmpfiles.c3
8 files changed, 17 insertions, 45 deletions
diff --git a/src/import/import-raw.c b/src/import/import-raw.c
index ad8f806aff..97e1254f09 100644
--- a/src/import/import-raw.c
+++ b/src/import/import-raw.c
@@ -188,7 +188,7 @@ static int raw_import_maybe_convert_qcow2(RawImport *i) {
if (converted_fd < 0)
return log_error_errno(errno, "Failed to create %s: %m", t);
- r = chattr_fd(converted_fd, true, FS_NOCOW_FL);
+ r = chattr_fd(converted_fd, FS_NOCOW_FL, FS_NOCOW_FL);
if (r < 0)
log_warning_errno(errno, "Failed to set file attributes on %s: %m", t);
@@ -277,7 +277,7 @@ static int raw_import_open_disk(RawImport *i) {
if (i->output_fd < 0)
return log_error_errno(errno, "Failed to open destination %s: %m", i->temp_path);
- r = chattr_fd(i->output_fd, true, FS_NOCOW_FL);
+ r = chattr_fd(i->output_fd, FS_NOCOW_FL, FS_NOCOW_FL);
if (r < 0)
log_warning_errno(errno, "Failed to set file attributes on %s: %m", i->temp_path);
diff --git a/src/import/pull-raw.c b/src/import/pull-raw.c
index ebbe6a9cd3..b65bb0c034 100644
--- a/src/import/pull-raw.c
+++ b/src/import/pull-raw.c
@@ -216,7 +216,7 @@ static int raw_pull_maybe_convert_qcow2(RawPull *i) {
if (converted_fd < 0)
return log_error_errno(errno, "Failed to create %s: %m", t);
- r = chattr_fd(converted_fd, true, FS_NOCOW_FL);
+ r = chattr_fd(converted_fd, FS_NOCOW_FL, FS_NOCOW_FL);
if (r < 0)
log_warning_errno(errno, "Failed to set file attributes on %s: %m", t);
@@ -292,7 +292,7 @@ static int raw_pull_make_local_copy(RawPull *i) {
* performance on COW file systems like btrfs, since it
* reduces fragmentation caused by not allowing in-place
* writes. */
- r = chattr_fd(dfd, true, FS_NOCOW_FL);
+ r = chattr_fd(dfd, FS_NOCOW_FL, FS_NOCOW_FL);
if (r < 0)
log_warning_errno(errno, "Failed to set file attributes on %s: %m", tp);
@@ -434,7 +434,7 @@ static int raw_pull_job_on_open_disk(PullJob *j) {
if (j->disk_fd < 0)
return log_error_errno(errno, "Failed to create %s: %m", i->temp_path);
- r = chattr_fd(j->disk_fd, true, FS_NOCOW_FL);
+ r = chattr_fd(j->disk_fd, FS_NOCOW_FL, FS_NOCOW_FL);
if (r < 0)
log_warning_errno(errno, "Failed to set file attributes on %s: %m", i->temp_path);
diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c
index 5a4e7cbd7d..6bbcc6d777 100644
--- a/src/journal/journal-file.c
+++ b/src/journal/journal-file.c
@@ -149,7 +149,7 @@ void journal_file_close(JournalFile *f) {
* reenable all the good bits COW usually provides
* (such as data checksumming). */
- (void) chattr_fd(f->fd, false, FS_NOCOW_FL);
+ (void) chattr_fd(f->fd, 0, FS_NOCOW_FL);
(void) btrfs_defrag_fd(f->fd);
}
@@ -2608,7 +2608,7 @@ int journal_file_open(
* the expense of data integrity features (which
* shouldn't be too bad, given that we do our own
* checksumming). */
- r = chattr_fd(f->fd, true, FS_NOCOW_FL);
+ r = chattr_fd(f->fd, FS_NOCOW_FL, FS_NOCOW_FL);
if (r < 0 && r != -ENOTTY)
log_warning_errno(r, "Failed to set file attributes: %m");
diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c
index b4f88bcd0a..40c84b9ba5 100644
--- a/src/journal/journalctl.c
+++ b/src/journal/journalctl.c
@@ -1377,7 +1377,7 @@ static int setup_keys(void) {
/* Enable secure remove, exclusion from dump, synchronous
* writing and in-place updating */
- r = chattr_fd(fd, true, FS_SECRM_FL|FS_NODUMP_FL|FS_SYNC_FL|FS_NOCOW_FL);
+ r = chattr_fd(fd, FS_SECRM_FL|FS_NODUMP_FL|FS_SYNC_FL|FS_NOCOW_FL, FS_SECRM_FL|FS_NODUMP_FL|FS_SYNC_FL|FS_NOCOW_FL);
if (r < 0)
log_warning_errno(errno, "Failed to set file attributes: %m");
diff --git a/src/shared/copy.c b/src/shared/copy.c
index 775a339856..1282cb88be 100644
--- a/src/shared/copy.c
+++ b/src/shared/copy.c
@@ -372,7 +372,7 @@ int copy_file(const char *from, const char *to, int flags, mode_t mode, unsigned
}
if (chattr_flags != 0)
- (void) chattr_fd(fdt, true, chattr_flags);
+ (void) chattr_fd(fdt, chattr_flags, (unsigned) -1);
r = copy_file_fd(from, fdt, true);
if (r < 0) {
diff --git a/src/shared/util.c b/src/shared/util.c
index de56d98feb..da75667c80 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -7678,7 +7678,7 @@ int same_fd(int a, int b) {
return fa == fb;
}
-int chattr_fd(int fd, bool b, unsigned mask) {
+int chattr_fd(int fd, unsigned value, unsigned mask) {
unsigned old_attr, new_attr;
assert(fd >= 0);
@@ -7689,21 +7689,17 @@ int chattr_fd(int fd, bool b, unsigned mask) {
if (ioctl(fd, FS_IOC_GETFLAGS, &old_attr) < 0)
return -errno;
- if (b)
- new_attr = old_attr | mask;
- else
- new_attr = old_attr & ~mask;
-
+ new_attr = (old_attr & ~mask) | (value & mask);
if (new_attr == old_attr)
return 0;
if (ioctl(fd, FS_IOC_SETFLAGS, &new_attr) < 0)
return -errno;
- return 0;
+ return 1;
}
-int chattr_path(const char *p, bool b, unsigned mask) {
+int chattr_path(const char *p, unsigned value, unsigned mask) {
_cleanup_close_ int fd = -1;
assert(p);
@@ -7715,29 +7711,7 @@ int chattr_path(const char *p, bool b, unsigned mask) {
if (fd < 0)
return -errno;
- return chattr_fd(fd, b, mask);
-}
-
-int change_attr_fd(int fd, unsigned value, unsigned mask) {
- unsigned old_attr, new_attr;
-
- assert(fd >= 0);
-
- if (mask == 0)
- return 0;
-
- if (ioctl(fd, FS_IOC_GETFLAGS, &old_attr) < 0)
- return -errno;
-
- new_attr = (old_attr & ~mask) |(value & mask);
-
- if (new_attr == old_attr)
- return 0;
-
- if (ioctl(fd, FS_IOC_SETFLAGS, &new_attr) < 0)
- return -errno;
-
- return 0;
+ return chattr_fd(fd, value, mask);
}
int read_attr_fd(int fd, unsigned *ret) {
diff --git a/src/shared/util.h b/src/shared/util.h
index e7a5d6366e..b41090bf70 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -1058,9 +1058,8 @@ int fd_getcrtime_at(int dirfd, const char *name, usec_t *usec, int flags);
int same_fd(int a, int b);
-int chattr_fd(int fd, bool b, unsigned mask);
-int chattr_path(const char *p, bool b, unsigned mask);
-int change_attr_fd(int fd, unsigned value, unsigned mask);
+int chattr_fd(int fd, unsigned value, unsigned mask);
+int chattr_path(const char *p, unsigned value, unsigned mask);
int read_attr_fd(int fd, unsigned *ret);
int read_attr_path(const char *p, unsigned *ret);
diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c
index 8c89fb33b8..16ed100124 100644
--- a/src/tmpfiles/tmpfiles.c
+++ b/src/tmpfiles/tmpfiles.c
@@ -869,14 +869,13 @@ static int path_set_attrib(Item *item, const char *path) {
}
fd = open(path, O_RDONLY|O_NONBLOCK|O_CLOEXEC);
-
if (fd < 0)
return log_error_errno(errno, "Cannot open \"%s\": %m", path);
f = item->attrib_value & item->attrib_mask;
if (!S_ISDIR(st.st_mode))
f &= ~FS_DIRSYNC_FL;
- r = change_attr_fd(fd, f, item->attrib_mask);
+ r = chattr_fd(fd, f, item->attrib_mask);
if (r < 0)
return log_error_errno(errno,
"Cannot set attrib for \"%s\", value=0x%08lx, mask=0x%08lx: %m",