diff options
Diffstat (limited to 'lib/e2p/fsetflags.c')
-rw-r--r-- | lib/e2p/fsetflags.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/e2p/fsetflags.c b/lib/e2p/fsetflags.c index 6455e386..d865d243 100644 --- a/lib/e2p/fsetflags.c +++ b/lib/e2p/fsetflags.c @@ -80,14 +80,26 @@ int fsetflags (const char * name, unsigned long flags) int f = (int) flags; return syscall(SYS_fsctl, name, EXT2_IOC_SETFLAGS, &f, 0); #elif HAVE_EXT2_IOCTLS + struct stat buf; int fd, r, f, save_errno = 0; + if (!stat(name, &buf) && + !S_ISREG(buf.st_mode) && !S_ISDIR(buf.st_mode)) { + errno = EOPNOTSUPP; + return -1; + } fd = open(name, OPEN_FLAGS); if (fd == -1) { if (errno == ELOOP || errno == ENXIO) errno = EOPNOTSUPP; return -1; } + if (!fstat(fd, &buf) && + !S_ISREG(buf.st_mode) && !S_ISDIR(buf.st_mode)) { + close(fd); + errno = EOPNOTSUPP; + return -1; + } f = (int) flags; r = ioctl(fd, EXT2_IOC_SETFLAGS, &f); if (r == -1) { |