summaryrefslogtreecommitdiff
path: root/lib/e2p
diff options
context:
space:
mode:
authorTheodore Ts'o <tytso@mit.edu>2002-08-17 14:44:56 -0400
committerTheodore Ts'o <tytso@mit.edu>2002-08-17 14:44:56 -0400
commit023d111e92195624463e870146d0f386ba5c2d87 (patch)
treee29003c4e19f7785a2c94cc85e653426c1821c08 /lib/e2p
parentf044b4d8a02ef9f95e27b8bdf6adc6548e5dc4a9 (diff)
downloade2fsprogs-023d111e92195624463e870146d0f386ba5c2d87.tar.gz
chattr.1.in: Document the compression attribute flags E, X, and
Z, and explain that chattr can't set or set these flags. (Addresses Debian Bug #151990) fsetflags.c (fsetflags), fgetflags.c (fgetflags.c), setflags.c (setflags), getflags.c (getflags): Check to make sure the file is a regular file or a directory before attempting to use the ext2 ioctls. Otherwise, return EOPNOTSUPP. (Addresses Debian Bug #152029).
Diffstat (limited to 'lib/e2p')
-rw-r--r--lib/e2p/ChangeLog8
-rw-r--r--lib/e2p/fgetflags.c18
-rw-r--r--lib/e2p/fsetflags.c19
-rw-r--r--lib/e2p/getflags.c16
-rw-r--r--lib/e2p/setflags.c17
5 files changed, 50 insertions, 28 deletions
diff --git a/lib/e2p/ChangeLog b/lib/e2p/ChangeLog
index 5dfc86d1..e2b1ebca 100644
--- a/lib/e2p/ChangeLog
+++ b/lib/e2p/ChangeLog
@@ -1,3 +1,11 @@
+2002-08-17 Theodore Ts'o <tytso@mit.edu>
+
+ * fsetflags.c (fsetflags), fgetflags.c (fgetflags.c), setflags.c
+ (setflags), getflags.c (getflags): Check to make sure the
+ file is a regular file or a directory before attempting to
+ use the ext2 ioctls. Otherwise, return EOPNOTSUPP.
+ (Addresses Debian Bug #152029).
+
2002-07-14 Theodore Ts'o <tytso@mit.edu>
* fsetflags.c (fsetflags), fgetflags.c (fgetflags,
diff --git a/lib/e2p/fgetflags.c b/lib/e2p/fgetflags.c
index ed4ade9d..f2d0399e 100644
--- a/lib/e2p/fgetflags.c
+++ b/lib/e2p/fgetflags.c
@@ -23,9 +23,9 @@
#if HAVE_UNISTD_H
#include <unistd.h>
#endif
-#if HAVE_STAT_FLAGS
+#include <sys/types.h>
#include <sys/stat.h>
-#else
+#if HAVE_EXT2_IOCTLS
#include <fcntl.h>
#include <sys/ioctl.h>
#endif
@@ -40,8 +40,8 @@
int fgetflags (const char * name, unsigned long * flags)
{
-#if HAVE_STAT_FLAGS
struct stat buf;
+#if HAVE_STAT_FLAGS
if (stat (name, &buf) == -1)
return -1;
@@ -65,6 +65,11 @@ int fgetflags (const char * name, unsigned long * flags)
#if HAVE_EXT2_IOCTLS
int fd, r, f, save_errno = 0;
+ if (!stat(name, &buf) &&
+ !S_ISREG(buf.st_mode) && !S_ISDIR(buf.st_mode)) {
+ close(fd);
+ goto notsupp;
+ }
fd = open (name, OPEN_FLAGS);
if (fd == -1)
return -1;
@@ -76,10 +81,9 @@ int fgetflags (const char * name, unsigned long * flags)
if (save_errno)
errno = save_errno;
return r;
-#else /* ! HAVE_EXT2_IOCTLS */
- extern int errno;
+#endif /* HAVE_EXT2_IOCTLS */
+#endif
+notsupp:
errno = EOPNOTSUPP;
return -1;
-#endif /* ! HAVE_EXT2_IOCTLS */
-#endif
}
diff --git a/lib/e2p/fsetflags.c b/lib/e2p/fsetflags.c
index 6942c045..f12af1c8 100644
--- a/lib/e2p/fsetflags.c
+++ b/lib/e2p/fsetflags.c
@@ -23,9 +23,9 @@
#if HAVE_UNISTD_H
#include <unistd.h>
#endif
-#if HAVE_CHFLAGS
-#include <sys/stat.h> /* For the flag values. */
-#else
+#include <sys/types.h>
+#include <sys/stat.h>
+#if HAVE_EXT2_IOCTLS
#include <fcntl.h>
#include <sys/ioctl.h>
#endif
@@ -40,6 +40,7 @@
int fsetflags (const char * name, unsigned long flags)
{
+ struct stat buf;
#if HAVE_CHFLAGS
unsigned long bsd_flags = 0;
@@ -61,6 +62,11 @@ int fsetflags (const char * name, unsigned long flags)
#if HAVE_EXT2_IOCTLS
int fd, r, f, save_errno = 0;
+ if (!stat(name, &buf) &&
+ !S_ISREG(buf.st_mode) && !S_ISDIR(buf.st_mode)) {
+ close(fd);
+ goto notsupp;
+ }
fd = open (name, OPEN_FLAGS);
if (fd == -1)
return -1;
@@ -72,10 +78,9 @@ int fsetflags (const char * name, unsigned long flags)
if (save_errno)
errno = save_errno;
return r;
-#else /* ! HAVE_EXT2_IOCTLS */
- extern int errno;
+#endif /* HAVE_EXT2_IOCTLS */
+#endif
+notsupp:
errno = EOPNOTSUPP;
return -1;
-#endif /* ! HAVE_EXT2_IOCTLS */
-#endif
}
diff --git a/lib/e2p/getflags.c b/lib/e2p/getflags.c
index 477cb9bd..acf7a122 100644
--- a/lib/e2p/getflags.c
+++ b/lib/e2p/getflags.c
@@ -17,9 +17,9 @@
#if HAVE_ERRNO_H
#include <errno.h>
#endif
-#if HAVE_STAT_FLAGS
+#include <sys/types.h>
#include <sys/stat.h>
-#else
+#if HAVE_EXT2_IOCTLS
#include <sys/ioctl.h>
#endif
@@ -27,8 +27,8 @@
int getflags (int fd, unsigned long * flags)
{
-#if HAVE_STAT_FLAGS
struct stat buf;
+#if HAVE_STAT_FLAGS
if (fstat (fd, &buf) == -1)
return -1;
@@ -52,13 +52,15 @@ int getflags (int fd, unsigned long * flags)
#if HAVE_EXT2_IOCTLS
int r, f;
+ if (!fstat(fd, &buf) &&
+ !S_ISREG(buf.st_mode) && !S_ISDIR(buf.st_mode))
+ goto notsupp;
r = ioctl (fd, EXT2_IOC_GETFLAGS, &f);
*flags = f;
return r;
-#else /* ! HAVE_EXT2_IOCTLS */
- extern int errno;
+#endif /* HAVE_EXT2_IOCTLS */
+#endif
+notsupp:
errno = EOPNOTSUPP;
return -1;
-#endif /* ! HAVE_EXT2_IOCTLS */
-#endif
}
diff --git a/lib/e2p/setflags.c b/lib/e2p/setflags.c
index 2bf47fa2..16930357 100644
--- a/lib/e2p/setflags.c
+++ b/lib/e2p/setflags.c
@@ -17,10 +17,9 @@
#if HAVE_ERRNO_H
#include <errno.h>
#endif
-#if HAVE_CHFLAGS
#include <sys/types.h>
-#include <sys/stat.h> /* For the flag values. */
-#else
+#include <sys/stat.h>
+#if HAVE_EXT2_IOCTLS
#include <sys/ioctl.h>
#endif
@@ -28,6 +27,7 @@
int setflags (int fd, unsigned long flags)
{
+ struct stat buf;
#if HAVE_CHFLAGS
unsigned long bsd_flags = 0;
@@ -49,12 +49,15 @@ int setflags (int fd, unsigned long flags)
#if HAVE_EXT2_IOCTLS
int f;
+ if (!fstat(fd, &buf) &&
+ !S_ISREG(buf.st_mode) && !S_ISDIR(buf.st_mode)) {
+ errno = EOPNOTSUPP;
+ return -1;
+ }
f = (int) flags;
return ioctl (fd, EXT2_IOC_SETFLAGS, &f);
-#else /* ! HAVE_EXT2_IOCTLS */
- extern int errno;
+#endif /* HAVE_EXT2_IOCTLS */
+#endif
errno = EOPNOTSUPP;
return -1;
-#endif /* ! HAVE_EXT2_IOCTLS */
-#endif
}