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.
30 #include <sys/ioctl.h>
35 // Patch to help compile this utility on unpatched kernel source
36 #ifndef EXT2_IMMUTABLE_FILE_FL
37 #define EXT2_IMMUTABLE_FILE_FL 0x00000010
38 #define EXT2_IMMUTABLE_LINK_FL 0x00008000
42 Get the extended attributes of a file
44 static int getext2flags (const char *fname, long *flags)
47 int fd = open (fname,O_RDONLY);
49 fprintf (stderr,"Can't open file %s (%s)\n",fname,strerror(errno));
52 ret = ioctl (fd,EXT2_IOC_GETFLAGS,flags);
55 fprintf (stderr,"Can't get ext2 flags on file %s (%s)\n"
56 ,fname,strerror(errno));
63 Set the extended attributes of a file
65 static int setext2flags (const char *fname, long flags)
68 int fd = open (fname,O_RDONLY);
70 fprintf (stderr,"Can't open file %s (%s)\n",fname,strerror(errno));
72 ret = ioctl (fd,EXT2_IOC_SETFLAGS,&flags);
75 fprintf (stderr,"Can't set ext2 flags on file %s (%s)\n"
76 ,fname,strerror(errno));
83 int main (int argc, char *argv[])
88 ,"showattr file ...\n"
90 "Presents extended file attribute.\n"
92 "setattr --immutable --immulink file ...\n"
94 "Sets the extended file attributes.\n"
96 "These utilities exist as an interim until lsattr and\n"
97 "chattr are updated.\n"
99 }else if (strstr(argv[0],"showattr")!=NULL){
101 for (i=1; i<argc; i++){
103 ret = getext2flags (argv[i],&flags);
107 printf ("%s\t%08lx\n",argv[i],flags);
110 }else if (strstr(argv[0],"setattr")!=NULL){
114 for (i=1; i<argc; i++){
115 const char *arg = argv[i];
116 if (strncmp(arg,"--",2)==0){
117 if (strcmp(arg,"--immutable")==0){
118 flags |= EXT2_IMMUTABLE_FILE_FL;
119 }else if (strcmp(arg,"--immulink")==0){
120 flags |= EXT2_IMMUTABLE_LINK_FL;
122 fprintf (stderr,"Invalid option %s\n",arg);
127 ret = setext2flags (arg,flags);