- int ret = -1;
- if (argc <= 1){
- fprintf (stderr
- ,"showattr file ...\n"
- "\n"
- "Presents extended file attribute.\n"
- "\n"
- "setattr --immutable --immulink file ...\n"
- "\n"
- "Sets the extended file attributes.\n"
- "\n"
- "These utilities exist as an interim until lsattr and\n"
- "chattr are updated.\n"
- );
- }else if (strstr(argv[0],"showattr")!=NULL){
- int i;
- for (i=1; i<argc; i++){
- long flags;
- ret = getext2flags (argv[i],&flags);
- if (ret == -1){
- break;
- }else{
- printf ("%s\t%08lx\n",argv[i],flags);
- }
- }
- }else if (strstr(argv[0],"setattr")!=NULL){
- long flags, add_flags = 0, remove_flags = 0;
- int i;
- ret = 0;
- for (i=1; i<argc; i++){
- const char *arg = argv[i];
- if (strncmp(arg,"--",2)==0){
- if (strcmp(arg,"--immutable")==0){
- add_flags |= EXT2_IMMUTABLE_FL;
- }else if (strcmp(arg,"--!immutable")==0 || strcmp(arg,"--~immutable")==0){
- remove_flags |= EXT2_IMMUTABLE_FL;
- }else if (strcmp(arg,"--immulink")==0){
- add_flags |= EXT2_IUNLINK_FL;
- }else if (strcmp(arg,"--!immulink")==0 || strcmp(arg,"--~immulink")==0){
- remove_flags |= EXT2_IUNLINK_FL;
- }else if (strcmp(arg,"--barrier")==0){
- add_flags |= EXT2_BARRIER_FL;
- }else if (strcmp(arg,"--!barrier")==0 || strcmp(arg,"--~barrier")==0){
- remove_flags |= EXT2_BARRIER_FL;
- }else{
- fprintf (stderr,"Invalid option %s\n",arg);
- ret = -1;
- break;
- }
- }else{
- ret = getext2flags (arg,&flags);
- if (ret == -1){
- break;
- }
- flags |= add_flags;
- flags &= ~remove_flags;
- ret = setext2flags (arg,flags);
- if (ret == -1){
- break;
- }
- }
- }
- }
- return ret;