Home | History | Annotate | Download | only in e2p
      1 /*
      2  * setflags.c		- Set 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  * 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 
     17 #if HAVE_ERRNO_H
     18 #include <errno.h>
     19 #endif
     20 #include <sys/types.h>
     21 #include <sys/stat.h>
     22 #if HAVE_EXT2_IOCTLS
     23 #include <sys/ioctl.h>
     24 #endif
     25 
     26 #include "e2p.h"
     27 
     28 /*
     29  * Deal with lame glibc's that define this function without actually
     30  * implementing it.  Can you say "attractive nuisance", boys and girls?
     31  * I knew you could!
     32  */
     33 #ifdef __linux__
     34 #undef HAVE_CHFLAGS
     35 #endif
     36 
     37 int setflags (int fd, unsigned long flags)
     38 {
     39 	struct stat buf;
     40 #if HAVE_CHFLAGS
     41 	unsigned long bsd_flags = 0;
     42 
     43 #ifdef UF_IMMUTABLE
     44 	if (flags & EXT2_IMMUTABLE_FL)
     45 		bsd_flags |= UF_IMMUTABLE;
     46 #endif
     47 #ifdef UF_APPEND
     48 	if (flags & EXT2_APPEND_FL)
     49 		bsd_flags |= UF_APPEND;
     50 #endif
     51 #ifdef UF_NODUMP
     52 	if (flags & EXT2_NODUMP_FL)
     53 		bsd_flags |= UF_NODUMP;
     54 #endif
     55 
     56 	return fchflags (fd, bsd_flags);
     57 #else
     58 #if HAVE_EXT2_IOCTLS
     59 	int	f;
     60 
     61 	if (!fstat(fd, &buf) &&
     62 	    !S_ISREG(buf.st_mode) && !S_ISDIR(buf.st_mode)) {
     63 		errno = EOPNOTSUPP;
     64 		return -1;
     65 	}
     66 	f = (int) flags;
     67 	return ioctl (fd, EXT2_IOC_SETFLAGS, &f);
     68 #endif /* HAVE_EXT2_IOCTLS */
     69 #endif
     70 	errno = EOPNOTSUPP;
     71 	return -1;
     72 }
     73