From 548ffd49a346a699ab64bd2659420d3ddbaeea6b Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Sat, 7 May 2005 07:14:41 +0000 Subject: patch by Tito which unifies common get/set functions into 1 get/set function and cuts down on the size used significantly :) --- e2fsprogs/e2p/e2p.h | 15 +++++-- e2fsprogs/e2p/fgetflags.c | 92 ---------------------------------------- e2fsprogs/e2p/fgetsetflags.c | 69 ++++++++++++++++++++++++++++++ e2fsprogs/e2p/fgetsetversion.c | 69 ++++++++++++++++++++++++++++++ e2fsprogs/e2p/fgetversion.c | 62 --------------------------- e2fsprogs/e2p/fsetflags.c | 96 ------------------------------------------ 6 files changed, 149 insertions(+), 254 deletions(-) delete mode 100644 e2fsprogs/e2p/fgetflags.c create mode 100644 e2fsprogs/e2p/fgetsetflags.c create mode 100644 e2fsprogs/e2p/fgetsetversion.c delete mode 100644 e2fsprogs/e2p/fgetversion.c delete mode 100644 e2fsprogs/e2p/fsetflags.c (limited to 'e2fsprogs') diff --git a/e2fsprogs/e2p/e2p.h b/e2fsprogs/e2p/e2p.h index d208b46..78930ec 100644 --- a/e2fsprogs/e2p/e2p.h +++ b/e2fsprogs/e2p/e2p.h @@ -13,11 +13,18 @@ #define PFOPT_LONG 1 /* Must be 1 for compatibility with `int long_format'. */ +/*int fgetversion (const char * name, unsigned long * version);*/ +/*int fsetversion (const char * name, unsigned long version);*/ +int fgetsetversion(const char * name, unsigned long * get_version, unsigned long set_version); +#define fgetversion(name, version) fgetsetversion(name, version, 0) +#define fsetversion(name, version) fgetsetversion(name, NULL, version) + +/*int fgetflags (const char * name, unsigned long * flags);*/ +/*int fsetflags (const char * name, unsigned long flags);*/ +int fgetsetflags(const char * name, unsigned long * get_flags, unsigned long set_flags); +#define fgetflags(name, flags) fgetsetflags(name, flags, 0) +#define fsetflags(name, flags) fgetsetflags(name, NULL, flags) -int fgetflags (const char * name, unsigned long * flags); -int fgetversion (const char * name, unsigned long * version); -int fsetflags (const char * name, unsigned long flags); -int fsetversion (const char * name, unsigned long version); int getflags (int fd, unsigned long * flags); int getversion (int fd, unsigned long * version); int iterate_on_dir (const char * dir_name, diff --git a/e2fsprogs/e2p/fgetflags.c b/e2fsprogs/e2p/fgetflags.c deleted file mode 100644 index 6db729e..0000000 --- a/e2fsprogs/e2p/fgetflags.c +++ /dev/null @@ -1,92 +0,0 @@ -/* - * fgetflags.c - Get a file flags on an ext2 file system - * - * Copyright (C) 1993, 1994 Remy Card - * Laboratoire MASI, Institut Blaise Pascal - * Universite Pierre et Marie Curie (Paris VI) - * - * This file can be redistributed under the terms of the GNU Library General - * Public License - */ - -/* - * History: - * 93/10/30 - Creation - */ - -#if HAVE_ERRNO_H -#include -#endif -#if HAVE_UNISTD_H -#include -#endif -#include -#include -#if HAVE_EXT2_IOCTLS -#include -#include -#endif - -#include "e2p.h" - -#ifdef O_LARGEFILE -#define OPEN_FLAGS (O_RDONLY|O_NONBLOCK|O_LARGEFILE) -#else -#define OPEN_FLAGS (O_RDONLY|O_NONBLOCK) -#endif - -int fgetflags (const char * name, unsigned long * flags) -{ - struct stat buf; -#if HAVE_STAT_FLAGS && !(APPLE_DARWIN && HAVE_EXT2_IOCTLS) - - if (stat (name, &buf) == -1) - return -1; - - *flags = 0; -#ifdef UF_IMMUTABLE - if (buf.st_flags & UF_IMMUTABLE) - *flags |= EXT2_IMMUTABLE_FL; -#endif -#ifdef UF_APPEND - if (buf.st_flags & UF_APPEND) - *flags |= EXT2_APPEND_FL; -#endif -#ifdef UF_NODUMP - if (buf.st_flags & UF_NODUMP) - *flags |= EXT2_NODUMP_FL; -#endif - - return 0; -#else -#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)) { - goto notsupp; - } -#if !APPLE_DARWIN - fd = open (name, OPEN_FLAGS); - if (fd == -1) - return -1; - r = ioctl (fd, EXT2_IOC_GETFLAGS, &f); - if (r == -1) - save_errno = errno; - *flags = f; - close (fd); - if (save_errno) - errno = save_errno; - return r; -#else - f = -1; - save_errno = syscall(SYS_fsctl, name, EXT2_IOC_GETFLAGS, &f, 0); - *flags = f; - return (save_errno); -#endif -#endif /* HAVE_EXT2_IOCTLS */ -#endif -notsupp: - errno = EOPNOTSUPP; - return -1; -} diff --git a/e2fsprogs/e2p/fgetsetflags.c b/e2fsprogs/e2p/fgetsetflags.c new file mode 100644 index 0000000..0a9f535 --- /dev/null +++ b/e2fsprogs/e2p/fgetsetflags.c @@ -0,0 +1,69 @@ +/* + * fgetflags.c - Get a file flags on an ext2 file system + * fsetflags.c - Set a file flags on an ext2 file system + * + * Copyright (C) 1993, 1994 Remy Card + * Laboratoire MASI, Institut Blaise Pascal + * Universite Pierre et Marie Curie (Paris VI) + * + * This file can be redistributed under the terms of the GNU Library General + * Public License + */ + +/* + * History: + * 93/10/30 - Creation + */ + +#if HAVE_ERRNO_H +#include +#endif +#if HAVE_UNISTD_H +#include +#endif +#include +#include +#if HAVE_EXT2_IOCTLS +#include +#include +#endif + +#include "e2p.h" + +#ifdef O_LARGEFILE +#define OPEN_FLAGS (O_RDONLY|O_NONBLOCK|O_LARGEFILE) +#else +#define OPEN_FLAGS (O_RDONLY|O_NONBLOCK) +#endif + +int fgetsetflags (const char * name, unsigned long * get_flags, unsigned long set_flags) +{ +#if 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)) { + goto notsupp; + } + fd = open (name, OPEN_FLAGS); + if (fd == -1) + return -1; + if (!get_flags) { + f = (int) set_flags; + r = ioctl (fd, EXT2_IOC_SETFLAGS, &f); + } else { + r = ioctl (fd, EXT2_IOC_GETFLAGS, &f); + *get_flags = f; + } + if (r == -1) + save_errno = errno; + close (fd); + if (save_errno) + errno = save_errno; + return r; +#endif /* HAVE_EXT2_IOCTLS */ +notsupp: + errno = EOPNOTSUPP; + return -1; +} diff --git a/e2fsprogs/e2p/fgetsetversion.c b/e2fsprogs/e2p/fgetsetversion.c new file mode 100644 index 0000000..dcf127c --- /dev/null +++ b/e2fsprogs/e2p/fgetsetversion.c @@ -0,0 +1,69 @@ +/* + * fgetversion.c - Get a file version on an ext2 file system + * fsetversion.c - Set a file version on an ext2 file system + * + * + * Copyright (C) 1993, 1994 Remy Card + * Laboratoire MASI, Institut Blaise Pascal + * Universite Pierre et Marie Curie (Paris VI) + * + * This file can be redistributed under the terms of the GNU Library General + * Public License + */ + +/* + * History: + * 93/10/30 - Creation + */ + +#if HAVE_ERRNO_H +#include +#endif +#if HAVE_UNISTD_H +#include +#endif +#include +#include + +#include "e2p.h" + +#ifdef O_LARGEFILE +#define OPEN_FLAGS (O_RDONLY|O_NONBLOCK|O_LARGEFILE) +#else +#define OPEN_FLAGS (O_RDONLY|O_NONBLOCK) +#endif + +/* + To do fsetversion: unsigned long *ptr_version must be set to NULL. + and unsigned long version must be set to a value + To do fgetversion: unsigned long *ptr_version must NOT be set to NULL + and unsigned long version is ignored. + TITO. +*/ + +int fgetsetversion (const char * name, unsigned long * get_version, unsigned long set_version) +{ +#if HAVE_EXT2_IOCTLS + int fd, r, ver, save_errno = 0; + + fd = open (name, OPEN_FLAGS); + if (fd == -1) + return -1; + if (!get_version) { + ver = (int) set_version; + r = ioctl (fd, EXT2_IOC_SETVERSION, &ver); + } else { + r = ioctl (fd, EXT2_IOC_GETVERSION, &ver); + *get_version = ver; + } + if (r == -1) + save_errno = errno; + close (fd); + if (save_errno) + errno = save_errno; + return r; +#else /* ! HAVE_EXT2_IOCTLS */ + errno = EOPNOTSUPP; + return -1; +#endif /* ! HAVE_EXT2_IOCTLS */ +} diff --git a/e2fsprogs/e2p/fgetversion.c b/e2fsprogs/e2p/fgetversion.c deleted file mode 100644 index 351a7d5..0000000 --- a/e2fsprogs/e2p/fgetversion.c +++ /dev/null @@ -1,62 +0,0 @@ -/* - * fgetversion.c - Get a file version on an ext2 file system - * - * Copyright (C) 1993, 1994 Remy Card - * Laboratoire MASI, Institut Blaise Pascal - * Universite Pierre et Marie Curie (Paris VI) - * - * This file can be redistributed under the terms of the GNU Library General - * Public License - */ - -/* - * History: - * 93/10/30 - Creation - */ - -#if HAVE_ERRNO_H -#include -#endif -#if HAVE_UNISTD_H -#include -#endif -#include -#include - -#include "e2p.h" - -#ifdef O_LARGEFILE -#define OPEN_FLAGS (O_RDONLY|O_NONBLOCK|O_LARGEFILE) -#else -#define OPEN_FLAGS (O_RDONLY|O_NONBLOCK) -#endif - -int fgetversion (const char * name, unsigned long * version) -{ -#if HAVE_EXT2_IOCTLS -#if !APPLE_DARWIN - int fd, r, ver, save_errno = 0; - - fd = open (name, OPEN_FLAGS); - if (fd == -1) - return -1; - r = ioctl (fd, EXT2_IOC_GETVERSION, &ver); - if (r == -1) - save_errno = errno; - *version = ver; - close (fd); - if (save_errno) - errno = save_errno; - return r; -#else - int ver=-1, err; - err = syscall(SYS_fsctl, name, EXT2_IOC_GETVERSION, &ver, 0); - *version = ver; - return(err); -#endif -#else /* ! HAVE_EXT2_IOCTLS */ - extern int errno; - errno = EOPNOTSUPP; - return -1; -#endif /* ! HAVE_EXT2_IOCTLS */ -} diff --git a/e2fsprogs/e2p/fsetflags.c b/e2fsprogs/e2p/fsetflags.c deleted file mode 100644 index 40e7292..0000000 --- a/e2fsprogs/e2p/fsetflags.c +++ /dev/null @@ -1,96 +0,0 @@ -/* - * fsetflags.c - Set a file flags on an ext2 file system - * - * Copyright (C) 1993, 1994 Remy Card - * Laboratoire MASI, Institut Blaise Pascal - * Universite Pierre et Marie Curie (Paris VI) - * - * This file can be redistributed under the terms of the GNU Library General - * Public License - */ - -/* - * History: - * 93/10/30 - Creation - */ - -#if HAVE_ERRNO_H -#include -#endif -#if HAVE_UNISTD_H -#include -#endif -#include -#include -#if HAVE_EXT2_IOCTLS -#include -#include -#endif - -#include "e2p.h" - -/* - * Deal with lame glibc's that define this function without actually - * implementing it. Can you say "attractive nuisance", boys and girls? - * I knew you could! - */ -#ifdef __linux__ -#undef HAVE_CHFLAGS -#endif - -#ifdef O_LARGEFILE -#define OPEN_FLAGS (O_RDONLY|O_NONBLOCK|O_LARGEFILE) -#else -#define OPEN_FLAGS (O_RDONLY|O_NONBLOCK) -#endif - -int fsetflags (const char * name, unsigned long flags) -{ - struct stat buf; -#if HAVE_CHFLAGS && !(APPLE_DARWIN && HAVE_EXT2_IOCTLS) - unsigned long bsd_flags = 0; - -#ifdef UF_IMMUTABLE - if (flags & EXT2_IMMUTABLE_FL) - bsd_flags |= UF_IMMUTABLE; -#endif -#ifdef UF_APPEND - if (flags & EXT2_APPEND_FL) - bsd_flags |= UF_APPEND; -#endif -#ifdef UF_NODUMP - if (flags & EXT2_NODUMP_FL) - bsd_flags |= UF_NODUMP; -#endif - - return chflags (name, bsd_flags); -#else -#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)) { - goto notsupp; - } -#if !APPLE_DARWIN - fd = open (name, OPEN_FLAGS); - if (fd == -1) - return -1; - f = (int) flags; - r = ioctl (fd, EXT2_IOC_SETFLAGS, &f); - if (r == -1) - save_errno = errno; - close (fd); - if (save_errno) - errno = save_errno; -#else - f = (int) flags; - return syscall(SYS_fsctl, name, EXT2_IOC_SETFLAGS, &f, 0); -#endif - return r; -#endif /* HAVE_EXT2_IOCTLS */ -#endif -notsupp: - errno = EOPNOTSUPP; - return -1; -} -- cgit v1.1