1997-04-26 21:21:57 +08:00
|
|
|
/*
|
|
|
|
* getflags.c - Get 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
|
|
|
|
*/
|
|
|
|
|
1997-04-26 21:58:21 +08:00
|
|
|
#if HAVE_ERRNO_H
|
1997-04-26 21:21:57 +08:00
|
|
|
#include <errno.h>
|
1997-04-26 21:58:21 +08:00
|
|
|
#endif
|
|
|
|
#if HAVE_STAT_FLAGS
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#else
|
1997-04-26 21:21:57 +08:00
|
|
|
#include <sys/ioctl.h>
|
1997-04-26 21:58:21 +08:00
|
|
|
#endif
|
1997-04-26 21:21:57 +08:00
|
|
|
|
|
|
|
#include "e2p.h"
|
|
|
|
|
|
|
|
int getflags (int fd, unsigned long * flags)
|
|
|
|
{
|
1997-04-26 21:58:21 +08:00
|
|
|
#if HAVE_STAT_FLAGS
|
1998-03-09 21:07:09 +08:00
|
|
|
struct stat buf;
|
1997-04-26 21:58:21 +08:00
|
|
|
|
1998-03-09 21:07:09 +08:00
|
|
|
if (fstat (fd, &buf) == -1)
|
|
|
|
return -1;
|
1997-04-26 21:58:21 +08:00
|
|
|
|
1998-03-09 21:07:09 +08:00
|
|
|
*flags = 0;
|
1997-04-26 21:58:21 +08:00
|
|
|
#ifdef UF_IMMUTABLE
|
1998-03-09 21:07:09 +08:00
|
|
|
if (buf.st_flags & UF_IMMUTABLE)
|
|
|
|
*flags |= EXT2_IMMUTABLE_FL;
|
1997-04-26 21:58:21 +08:00
|
|
|
#endif
|
|
|
|
#ifdef UF_APPEND
|
1998-03-09 21:07:09 +08:00
|
|
|
if (buf.st_flags & UF_APPEND)
|
|
|
|
*flags |= EXT2_APPEND_FL;
|
1997-04-26 21:58:21 +08:00
|
|
|
#endif
|
|
|
|
#ifdef UF_NODUMP
|
1998-03-09 21:07:09 +08:00
|
|
|
if (buf.st_flags & UF_NODUMP)
|
|
|
|
*flags |= EXT2_NODUMP_FL;
|
1997-04-26 21:58:21 +08:00
|
|
|
#endif
|
|
|
|
|
1998-03-09 21:07:09 +08:00
|
|
|
return 0;
|
1997-04-26 21:58:21 +08:00
|
|
|
#else
|
|
|
|
#if HAVE_EXT2_IOCTLS
|
1998-03-09 21:07:09 +08:00
|
|
|
int r, f;
|
|
|
|
|
|
|
|
r = ioctl (fd, EXT2_IOC_GETFLAGS, &f);
|
|
|
|
*flags = f;
|
|
|
|
return r;
|
1997-04-26 21:58:21 +08:00
|
|
|
#else /* ! HAVE_EXT2_IOCTLS */
|
|
|
|
extern int errno;
|
|
|
|
errno = EOPNOTSUPP;
|
|
|
|
return -1;
|
|
|
|
#endif /* ! HAVE_EXT2_IOCTLS */
|
|
|
|
#endif
|
1997-04-26 21:21:57 +08:00
|
|
|
}
|