Home | History | Annotate | Download | only in e2p
      1 /*
      2  * getflags.c		- Get a file flags on an ext2 file system
      3  *
      4  * Copyright (C) 1993, 1994  Remy Card <card (at) masi.ibp.fr>
      5  *                           Laboratoire MASI, Institut Blaise Pascal
      6  *                           Universite Pierre et Marie Curie (Paris VI)
      7  *
      8  * %Begin-Header%
      9  * This file may be redistributed under the terms of the GNU Library
     10  * General Public License, version 2.
     11  * %End-Header%
     12  */
     13 
     14 /*
     15  * History:
     16  * 93/10/30	- Creation
     17  */
     18 
     19 #if HAVE_ERRNO_H
     20 #include <errno.h>
     21 #endif
     22 #include <sys/types.h>
     23 #include <sys/stat.h>
     24 #if HAVE_EXT2_IOCTLS
     25 #include <sys/ioctl.h>
     26 #endif
     27 
     28 #include "e2p.h"
     29 
     30 int getflags (int fd, unsigned long * flags)
     31 {
     32 	struct stat buf;
     33 #if HAVE_STAT_FLAGS
     34 
     35 	if (fstat (fd, &buf) == -1)
     36 		return -1;
     37 
     38 	*flags = 0;
     39 #ifdef UF_IMMUTABLE
     40 	if (buf.st_flags & UF_IMMUTABLE)
     41 		*flags |= EXT2_IMMUTABLE_FL;
     42 #endif
     43 #ifdef UF_APPEND
     44 	if (buf.st_flags & UF_APPEND)
     45 		*flags |= EXT2_APPEND_FL;
     46 #endif
     47 #ifdef UF_NODUMP
     48 	if (buf.st_flags & UF_NODUMP)
     49 		*flags |= EXT2_NODUMP_FL;
     50 #endif
     51 
     52 	return 0;
     53 #else
     54 #if HAVE_EXT2_IOCTLS
     55 	int r, f;
     56 
     57 	if (!fstat(fd, &buf) &&
     58 	    !S_ISREG(buf.st_mode) && !S_ISDIR(buf.st_mode))
     59 		goto notsupp;
     60 	r = ioctl (fd, EXT2_IOC_GETFLAGS, &f);
     61 	*flags = f;
     62 	return r;
     63 #endif /* HAVE_EXT2_IOCTLS */
     64 #endif
     65 notsupp:
     66 	errno = EOPNOTSUPP;
     67 	return -1;
     68 }
     69