patch by Tito which unifies common get/set functions into 1 get/set function and cuts down on the size used significantly :)
This commit is contained in:
parent
ba3a01f5e0
commit
548ffd49a3
@ -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,
|
||||
|
@ -1,5 +1,6 @@
|
||||
/*
|
||||
* 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 <card@masi.ibp.fr>
|
||||
* Laboratoire MASI, Institut Blaise Pascal
|
||||
@ -35,57 +36,33 @@
|
||||
#define OPEN_FLAGS (O_RDONLY|O_NONBLOCK)
|
||||
#endif
|
||||
|
||||
int fgetflags (const char * name, unsigned long * flags)
|
||||
int fgetsetflags (const char * name, unsigned long * get_flags, unsigned long set_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
|
||||
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;
|
||||
}
|
||||
#if !APPLE_DARWIN
|
||||
fd = open (name, OPEN_FLAGS);
|
||||
if (fd == -1)
|
||||
return -1;
|
||||
r = ioctl (fd, EXT2_IOC_GETFLAGS, &f);
|
||||
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;
|
||||
*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;
|
@ -1,5 +1,7 @@
|
||||
/*
|
||||
* 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 <card@masi.ibp.fr>
|
||||
* Laboratoire MASI, Institut Blaise Pascal
|
||||
@ -31,31 +33,36 @@
|
||||
#define OPEN_FLAGS (O_RDONLY|O_NONBLOCK)
|
||||
#endif
|
||||
|
||||
int fgetversion (const char * name, unsigned long * version)
|
||||
/*
|
||||
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
|
||||
#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 (!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;
|
||||
*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 */
|
@ -1,96 +0,0 @@
|
||||
/*
|
||||
* fsetflags.c - Set a file flags on an ext2 file system
|
||||
*
|
||||
* Copyright (C) 1993, 1994 Remy Card <card@masi.ibp.fr>
|
||||
* 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 <errno.h>
|
||||
#endif
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#if HAVE_EXT2_IOCTLS
|
||||
#include <fcntl.h>
|
||||
#include <sys/ioctl.h>
|
||||
#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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user