blob: 477cb9bd283f9a5fdcef429978c08e620ed51d03 [file] [log] [blame]
Theodore Ts'o3839e651997-04-26 13:21:57 +00001/*
2 * getflags.c - Get a file flags on an ext2 file system
3 *
4 * Copyright (C) 1993, 1994 Remy Card <card@masi.ibp.fr>
5 * Laboratoire MASI, Institut Blaise Pascal
6 * Universite Pierre et Marie Curie (Paris VI)
7 *
8 * This file can be redistributed under the terms of the GNU Library General
9 * Public License
10 */
11
12/*
13 * History:
14 * 93/10/30 - Creation
15 */
16
Theodore Ts'o50e1e101997-04-26 13:58:21 +000017#if HAVE_ERRNO_H
Theodore Ts'o3839e651997-04-26 13:21:57 +000018#include <errno.h>
Theodore Ts'o50e1e101997-04-26 13:58:21 +000019#endif
20#if HAVE_STAT_FLAGS
21#include <sys/stat.h>
22#else
Theodore Ts'o3839e651997-04-26 13:21:57 +000023#include <sys/ioctl.h>
Theodore Ts'o50e1e101997-04-26 13:58:21 +000024#endif
Theodore Ts'o3839e651997-04-26 13:21:57 +000025
Theodore Ts'o3839e651997-04-26 13:21:57 +000026#include "e2p.h"
27
28int getflags (int fd, unsigned long * flags)
29{
Theodore Ts'o50e1e101997-04-26 13:58:21 +000030#if HAVE_STAT_FLAGS
Theodore Ts'occe382b1998-03-09 13:07:09 +000031 struct stat buf;
Theodore Ts'o50e1e101997-04-26 13:58:21 +000032
Theodore Ts'occe382b1998-03-09 13:07:09 +000033 if (fstat (fd, &buf) == -1)
34 return -1;
Theodore Ts'o50e1e101997-04-26 13:58:21 +000035
Theodore Ts'occe382b1998-03-09 13:07:09 +000036 *flags = 0;
Theodore Ts'o50e1e101997-04-26 13:58:21 +000037#ifdef UF_IMMUTABLE
Theodore Ts'occe382b1998-03-09 13:07:09 +000038 if (buf.st_flags & UF_IMMUTABLE)
39 *flags |= EXT2_IMMUTABLE_FL;
Theodore Ts'o50e1e101997-04-26 13:58:21 +000040#endif
41#ifdef UF_APPEND
Theodore Ts'occe382b1998-03-09 13:07:09 +000042 if (buf.st_flags & UF_APPEND)
43 *flags |= EXT2_APPEND_FL;
Theodore Ts'o50e1e101997-04-26 13:58:21 +000044#endif
45#ifdef UF_NODUMP
Theodore Ts'occe382b1998-03-09 13:07:09 +000046 if (buf.st_flags & UF_NODUMP)
47 *flags |= EXT2_NODUMP_FL;
Theodore Ts'o50e1e101997-04-26 13:58:21 +000048#endif
49
Theodore Ts'occe382b1998-03-09 13:07:09 +000050 return 0;
Theodore Ts'o50e1e101997-04-26 13:58:21 +000051#else
52#if HAVE_EXT2_IOCTLS
Theodore Ts'occe382b1998-03-09 13:07:09 +000053 int r, f;
54
55 r = ioctl (fd, EXT2_IOC_GETFLAGS, &f);
56 *flags = f;
57 return r;
Theodore Ts'o50e1e101997-04-26 13:58:21 +000058#else /* ! HAVE_EXT2_IOCTLS */
59 extern int errno;
60 errno = EOPNOTSUPP;
61 return -1;
62#endif /* ! HAVE_EXT2_IOCTLS */
63#endif
Theodore Ts'o3839e651997-04-26 13:21:57 +000064}