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)
|
|
|
|
*
|
2010-05-18 09:31:56 +08:00
|
|
|
* %Begin-Header%
|
|
|
|
* This file may be redistributed under the terms of the GNU Library
|
|
|
|
* General Public License, version 2.
|
|
|
|
* %End-Header%
|
1997-04-26 21:21:57 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
2002-08-18 02:44:56 +08:00
|
|
|
#include <sys/types.h>
|
1997-04-26 21:58:21 +08:00
|
|
|
#include <sys/stat.h>
|
2002-08-18 02:44:56 +08:00
|
|
|
#if HAVE_EXT2_IOCTLS
|
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)
|
|
|
|
{
|
1998-03-09 21:07:09 +08:00
|
|
|
struct stat buf;
|
2002-08-18 02:44:56 +08:00
|
|
|
#if HAVE_STAT_FLAGS
|
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;
|
2008-08-28 11:07:54 +08:00
|
|
|
|
2002-08-18 02:44:56 +08:00
|
|
|
if (!fstat(fd, &buf) &&
|
|
|
|
!S_ISREG(buf.st_mode) && !S_ISDIR(buf.st_mode))
|
|
|
|
goto notsupp;
|
2011-06-11 23:50:01 +08:00
|
|
|
r = ioctl(fd, EXT2_IOC_GETFLAGS, &f);
|
1998-03-09 21:07:09 +08:00
|
|
|
*flags = f;
|
2011-06-11 23:50:01 +08:00
|
|
|
|
1998-03-09 21:07:09 +08:00
|
|
|
return r;
|
2011-06-11 23:50:01 +08:00
|
|
|
notsupp:
|
2002-08-18 02:44:56 +08:00
|
|
|
#endif /* HAVE_EXT2_IOCTLS */
|
|
|
|
#endif
|
1997-04-26 21:58:21 +08:00
|
|
|
errno = EOPNOTSUPP;
|
|
|
|
return -1;
|
1997-04-26 21:21:57 +08:00
|
|
|
}
|