3 // Copyright (C) 2003 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
4 // based on showattr.cc by Jacques Gelinas
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2, or (at your option)
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 #include <sys/ioctl.h>
26 #include <linux/ext2_fs.h>
28 // Patch to help compile this utility on unpatched kernel source
29 #ifndef EXT2_IMMUTABLE_FILE_FL
30 #define EXT2_IMMUTABLE_FILE_FL 0x00000010
31 #define EXT2_IMMUTABLE_LINK_FL 0x00008000
35 Get the extended attributes of a file
37 static int getext2flags (const char *fname, long *flags)
40 int fd = open (fname,O_RDONLY);
42 fprintf (stderr,"Can't open file %s (%s)\n",fname,strerror(errno));
45 ret = ioctl (fd,EXT2_IOC_GETFLAGS,flags);
48 fprintf (stderr,"Can't get ext2 flags on file %s (%s)\n"
49 ,fname,strerror(errno));
56 Set the extended attributes of a file
58 static int setext2flags (const char *fname, long flags)
61 int fd = open (fname,O_RDONLY);
63 fprintf (stderr,"Can't open file %s (%s)\n",fname,strerror(errno));
65 ret = ioctl (fd,EXT2_IOC_SETFLAGS,&flags);
68 fprintf (stderr,"Can't set ext2 flags on file %s (%s)\n"
69 ,fname,strerror(errno));
76 int main (int argc, char *argv[])
81 ,"showattr file ...\n"
83 "Presents extended file attribute.\n"
85 "setattr --immutable --immulink file ...\n"
87 "Sets the extended file attributes.\n"
89 "These utilities exist as an interim until lsattr and\n"
90 "chattr are updated.\n"
92 }else if (strstr(argv[0],"showattr")!=NULL){
94 for (i=1; i<argc; i++){
96 ret = getext2flags (argv[i],&flags);
100 printf ("%s\t%08lx\n",argv[i],flags);
103 }else if (strstr(argv[0],"setattr")!=NULL){
107 for (i=1; i<argc; i++){
108 const char *arg = argv[i];
109 if (strncmp(arg,"--",2)==0){
110 if (strcmp(arg,"--immutable")==0){
111 flags |= EXT2_IMMUTABLE_FILE_FL;
112 }else if (strcmp(arg,"--immulink")==0){
113 flags |= EXT2_IMMUTABLE_LINK_FL;
115 fprintf (stderr,"Invalid option %s\n",arg);
120 ret = setext2flags (arg,flags);