e2fsprogs/lib/e2p/getflags.c

70 lines
1.3 KiB
C
Raw Normal View History

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)
*
* %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
#include <sys/types.h>
1997-04-26 21:58:21 +08:00
#include <sys/stat.h>
#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)
{
struct stat buf;
#if HAVE_STAT_FLAGS
1997-04-26 21:58:21 +08:00
if (fstat (fd, &buf) == -1)
return -1;
1997-04-26 21:58:21 +08:00
*flags = 0;
1997-04-26 21:58:21 +08:00
#ifdef UF_IMMUTABLE
if (buf.st_flags & UF_IMMUTABLE)
*flags |= EXT2_IMMUTABLE_FL;
1997-04-26 21:58:21 +08:00
#endif
#ifdef UF_APPEND
if (buf.st_flags & UF_APPEND)
*flags |= EXT2_APPEND_FL;
1997-04-26 21:58:21 +08:00
#endif
#ifdef UF_NODUMP
if (buf.st_flags & UF_NODUMP)
*flags |= EXT2_NODUMP_FL;
1997-04-26 21:58:21 +08:00
#endif
return 0;
1997-04-26 21:58:21 +08:00
#else
#if HAVE_EXT2_IOCTLS
int r, f;
if (!fstat(fd, &buf) &&
!S_ISREG(buf.st_mode) && !S_ISDIR(buf.st_mode))
goto notsupp;
r = ioctl(fd, EXT2_IOC_GETFLAGS, &f);
*flags = f;
return r;
notsupp:
#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
}