#ifdef HAVE_SYS_IOCTL_H
#include <sys/ioctl.h>
#endif
-#ifdef HAVE_EXT2FS_EXT2_FS_H
-#include <ext2fs/ext2_fs.h>
-#endif
-#if defined(FS_IOC_GETFLAGS) && defined(FS_IOC_SETFLAGS) \
- && defined(HAVE_EXT2FS_EXT2_FS_H)
+#if defined(FS_IOC_GETFLAGS) && defined(FS_IOC_SETFLAGS)
#define BUP_HAVE_FILE_ATTRS 1
#endif
+#ifndef FS_NOCOW_FL
+// Of course, this assumes it's a bitfield value.
+#define FS_NOCOW_FL 0
+#endif
+
static int istty2 = 0;
// Probably we should use autoconf or something and set HAVE_PY_GETARGCARGV...
}
-static PyObject *open_noatime(PyObject *self, PyObject *args)
+static int _open_noatime(const char *filename, int attrs)
{
- char *filename = NULL;
- int attrs, attrs_noatime, fd;
- if (!PyArg_ParseTuple(args, "s", &filename))
- return NULL;
- attrs = O_RDONLY;
+ int attrs_noatime, fd;
+ attrs |= O_RDONLY;
#ifdef O_NOFOLLOW
attrs |= O_NOFOLLOW;
#endif
// just harmlessly ignore it, so this branch won't trigger)
fd = open(filename, attrs);
}
+ return fd;
+}
+
+
+static PyObject *open_noatime(PyObject *self, PyObject *args)
+{
+ char *filename = NULL;
+ int fd;
+ if (!PyArg_ParseTuple(args, "s", &filename))
+ return NULL;
+ fd = _open_noatime(filename, 0);
if (fd < 0)
return PyErr_SetFromErrnoWithFilename(PyExc_OSError, filename);
return Py_BuildValue("i", fd);
if (!PyArg_ParseTuple(args, "s", &path))
return NULL;
- fd = open(path, O_RDONLY | O_NONBLOCK | O_LARGEFILE | O_NOFOLLOW);
+ fd = _open_noatime(path, O_NONBLOCK);
if (fd == -1)
return PyErr_SetFromErrnoWithFilename(PyExc_OSError, path);
static PyObject *bup_set_linux_file_attr(PyObject *self, PyObject *args)
{
int rc;
- unsigned long attr;
+ unsigned long orig_attr, attr;
char *path;
int fd;
// Restrict attr to modifiable flags acdeijstuADST -- see
// chattr(1) and the e2fsprogs source. Letter to flag mapping is
// in pf.c flags_array[].
- attr &= EXT2_APPEND_FL | EXT2_COMPR_FL | EXT2_NODUMP_FL | EXT4_EXTENTS_FL
- | EXT2_IMMUTABLE_FL | EXT3_JOURNAL_DATA_FL | EXT2_SECRM_FL | EXT2_NOTAIL_FL
- | EXT2_UNRM_FL | EXT2_NOATIME_FL | EXT2_DIRSYNC_FL | EXT2_SYNC_FL
- | EXT2_TOPDIR_FL;
+ attr &= FS_APPEND_FL | FS_COMPR_FL | FS_NODUMP_FL | FS_EXTENT_FL
+ | FS_IMMUTABLE_FL | FS_JOURNAL_DATA_FL | FS_SECRM_FL | FS_NOTAIL_FL
+ | FS_UNRM_FL | FS_NOATIME_FL | FS_DIRSYNC_FL | FS_SYNC_FL
+ | FS_TOPDIR_FL | FS_NOCOW_FL;
+
+ // The extents flag can't be removed, so don't (see chattr(1) and chattr.c).
+ rc = ioctl(fd, FS_IOC_GETFLAGS, &orig_attr);
+ if (rc == -1)
+ {
+ close(fd);
+ return PyErr_SetFromErrnoWithFilename(PyExc_OSError, path);
+ }
+ attr |= (orig_attr & FS_EXTENT_FL);
rc = ioctl(fd, FS_IOC_SETFLAGS, &attr);
if (rc == -1)