blob: a2584432a1109039633244aae178e98cb6cfa821 [file] [log] [blame]
Theodore Ts'o3839e651997-04-26 13:21:57 +00001/*
2 * fsetflags.c - Set 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_UNISTD_H
Theodore Ts'o3839e651997-04-26 13:21:57 +000021#include <unistd.h>
Theodore Ts'o50e1e101997-04-26 13:58:21 +000022#endif
23#if HAVE_CHFLAGS
24#include <sys/stat.h> /* For the flag values. */
25#else
26#include <fcntl.h>
Theodore Ts'o3839e651997-04-26 13:21:57 +000027#include <sys/ioctl.h>
Theodore Ts'o50e1e101997-04-26 13:58:21 +000028#endif
Theodore Ts'o3839e651997-04-26 13:21:57 +000029
30#include <linux/ext2_fs.h>
31
32#include "e2p.h"
33
34int fsetflags (const char * name, unsigned long flags)
35{
Theodore Ts'o50e1e101997-04-26 13:58:21 +000036#if HAVE_CHFLAGS
37 unsigned long bsd_flags = 0;
38
39#ifdef UF_IMMUTABLE
40 if (flags & EXT2_IMMUTABLE_FL)
41 bsd_flags |= UF_IMMUTABLE;
42#endif
43#ifdef UF_APPEND
44 if (flags & EXT2_APPEND_FL)
45 bsd_flags |= UF_APPEND;
46#endif
47#ifdef UF_NODUMP
48 if (flags & EXT2_NODUMP_FL)
49 bsd_flags |= UF_NODUMP;
50#endif
51
52 return chflags (name, bsd_flags);
53#else
54#if HAVE_EXT2_IOCTLS
Theodore Ts'o3839e651997-04-26 13:21:57 +000055 int fd;
56 int r;
57
58 fd = open (name, O_RDONLY);
59 if (fd == -1)
60 return -1;
61 r = ioctl (fd, EXT2_IOC_SETFLAGS, &flags);
62 close (fd);
63 return r;
Theodore Ts'o50e1e101997-04-26 13:58:21 +000064#else /* ! HAVE_EXT2_IOCTLS */
65 extern int errno;
66 errno = EOPNOTSUPP;
67 return -1;
68#endif /* ! HAVE_EXT2_IOCTLS */
69#endif
Theodore Ts'o3839e651997-04-26 13:21:57 +000070}