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 #include "config.h"
     20 #if HAVE_ERRNO_H
     21 #include <errno.h>
     22 #endif
     23 #include <sys/types.h>
     24 #include <sys/stat.h>
     25 #if HAVE_EXT2_IOCTLS
     26 #include <sys/ioctl.h>
     27 #endif
     28 
     29 #include "e2p.h"
     30 
     31 int getflags (int fd, unsigned long * flags)
     32 {
     33 	struct stat buf;
     34 #if HAVE_STAT_FLAGS
     35 
     36 	if (fstat (fd, &buf) == -1)
     37 		return -1;
     38 
     39 	*flags = 0;
     40 #ifdef UF_IMMUTABLE
     41 	if (buf.st_flags & UF_IMMUTABLE)
     42 		*flags |= EXT2_IMMUTABLE_FL;
     43 #endif
     44 #ifdef UF_APPEND
     45 	if (buf.st_flags & UF_APPEND)
     46 		*flags |= EXT2_APPEND_FL;
     47 #endif
     48 #ifdef UF_NODUMP
     49 	if (buf.st_flags & UF_NODUMP)
     50 		*flags |= EXT2_NODUMP_FL;
     51 #endif
     52 
     53 	return 0;
     54 #else
     55 #if HAVE_EXT2_IOCTLS
     56 	int r, f;
     57 
     58 	if (!fstat(fd, &buf) &&
     59 	    !S_ISREG(buf.st_mode) && !S_ISDIR(buf.st_mode))
     60 		goto notsupp;
     61 	r = ioctl(fd, EXT2_IOC_GETFLAGS, &f);
     62 	*flags = f;
     63 
     64 	return r;
     65 notsupp:
     66 #endif /* HAVE_EXT2_IOCTLS */
     67 #endif
     68 	errno = EOPNOTSUPP;
     69 	return -1;
     70 }
     71