{
bool res = false;
int fd = open(name, O_RDONLY);
+ int rc;
if (fd==-1) {
perror("open()");
return false;
}
+ // this is still needed... the file must be open so that vc_set_iattr()
+ // operates on a known file/inode
if (!exp_st ||
!checkForRace(fd, name, exp_st))
goto err;
- if (vc_X_set_filecontext(fd, global_args->ctx)==-1) {
- //perror("vc_X_set_filecontext()");
+ rc = vc_set_iattr_compat(name, exp_st->st_dev, exp_st->st_ino,
+ global_args->ctx, 0, VC_IATTR_XID);
+
+ if (rc==-1) {
perror(display_name);
goto err;
}
exit(1);
}
- args->ctx = resolveCtx(args->ctx_str);
+ args->ctx = resolveCtx(args->ctx_str);
+ args->do_display_dir = false;
}
.do_set = false,
.do_unset = false,
.local_fs = false,
+ .set_mask = 0,
+ .del_mask = 0
};
global_args = &args;
switch (c) {
case CMD_HELP : showHelp(1, argv[0], 0);
case CMD_VERSION : showVersion();
- case CMD_IMMUTABLE : args.immutable = true; break;
- case CMD_IMMULINK : args.immulink = true; break;
- case CMD_LEGACY : args.is_legacy = true; break;
+ case CMD_IMMU : args.set_mask |= VC_IATTR_IUNLINK; break;
+ case CMD_ADMIN : args.set_mask |= VC_IATTR_ADMIN; break;
+ case CMD_WATCH : args.set_mask |= VC_IATTR_WATCH; break;
+ case CMD_HIDE : args.set_mask |= VC_IATTR_HIDE; break;
+ case CMD_BARRIER : args.set_mask |= VC_IATTR_BARRIER; break;
+ case CMD_UNSET_IMMU : args.del_mask |= VC_IATTR_IUNLINK; break;
+ case CMD_UNSET_ADMIN : args.del_mask |= VC_IATTR_ADMIN; break;
+ case CMD_UNSET_WATCH : args.del_mask |= VC_IATTR_WATCH; break;
+ case CMD_UNSET_HIDE : args.del_mask |= VC_IATTR_HIDE; break;
+ case CMD_UNSET_BARRIER : args.del_mask |= VC_IATTR_BARRIER; break;
case 'R' : args.do_recurse = true; break;
case 'a' : args.do_display_dot = true; break;
case 'd' : args.do_display_dir = true; break;
#include <getopt.h>
#include <stdbool.h>
-#define CMD_HELP 0x8000
-#define CMD_VERSION 0x8001
-#define CMD_IMMUTABLE 0x8002
-#define CMD_IMMULINK 0x8003
-#define CMD_LEGACY 0x8004
+#define CMD_HELP 0x8000
+#define CMD_VERSION 0x8001
+#define CMD_IMMUTABLE 0x8002
+#define CMD_IMMULINK 0x8003
+#define CMD_LEGACY 0x8004
+#define CMD_IMMU 0x8010
+#define CMD_ADMIN 0x8011
+#define CMD_WATCH 0x8012
+#define CMD_HIDE 0x8013
+#define CMD_BARRIER 0x8014
+#define CMD_UNSET_IMMU 0x8020
+#define CMD_UNSET_ADMIN 0x8021
+#define CMD_UNSET_WATCH 0x8022
+#define CMD_UNSET_HIDE 0x8023
+#define CMD_UNSET_BARRIER 0x8024
+
struct stat;
bool do_set;
bool do_unset;
bool local_fs;
+
+ uint32_t set_mask;
+ uint32_t del_mask;
};
extern struct option const CMDLINE_OPTIONS[];
static xid_t
getFileContext(char const *name, struct stat const *exp_st)
{
- int fd = open(name, O_RDONLY);
xid_t res;
+ uint32_t mask = VC_IATTR_XID;
- if (fd==-1) {
- perror("open()");
- return VC_NOCTX;
- }
-
- if (exp_st)
- checkForRace(fd, name, exp_st);
-
- res = vc_X_get_filecontext(fd);
- if (res==VC_NOCTX)
- perror("vc_X_get_filecontext()");
-
- close(fd);
+ if (vc_get_iattr_compat(name, exp_st->st_dev, exp_st->st_ino,
+ &res, 0, &mask)==-1)
+ perror("vc_get_iattr_compat()");
- return res;
+ return (mask&VC_IATTR_XID) ? res : VC_NOCTX;
}
bool
CMDLINE_OPTIONS[] = {
{ "help", no_argument, 0, CMD_HELP },
{ "version", no_argument, 0, CMD_VERSION },
- { "immutable", no_argument, 0, CMD_IMMUTABLE },
- { "immulink", no_argument, 0, CMD_IMMULINK },
+ { "immu", no_argument, 0, CMD_IMMU },
+ { "admin", no_argument, 0, CMD_ADMIN },
+ { "watch", no_argument, 0, CMD_WATCH },
+ { "hide", no_argument, 0, CMD_HIDE },
+ { "barrier", no_argument, 0, CMD_BARRIER },
+ { "~immu", no_argument, 0, CMD_UNSET_IMMU },
+ { "~admin", no_argument, 0, CMD_UNSET_ADMIN },
+ { "~watch", no_argument, 0, CMD_UNSET_WATCH },
+ { "~hide", no_argument, 0, CMD_UNSET_HIDE },
+ { "~barrier", no_argument, 0, CMD_UNSET_BARRIER },
{ 0,0,0,0 }
};
-char const CMDLINE_OPTIONS_SHORT[] = "Rsux";
-
-static long set_mask = 0;
-static long del_mask = VC_IMMUTABLE_ALL;
+char const CMDLINE_OPTIONS_SHORT[] = "Rx";
void
showHelp(int fd, char const *cmd, int res)
WRITE_MSG(fd, "Usage: ");
WRITE_STR(fd, cmd);
WRITE_MSG(fd,
- " [-Rsux] [--immutable] [--immulink] [--] <file>+\n\n"
+ " [-Rx] [--[~]immu] [--[~]admin] [--[~]watch] [--[~]hide] [--] <file>+\n\n"
" Options:\n"
" -R ... recurse through directories\n"
- " -s ... set flag only; when only one of the '--immu*' options\n"
- " is given, do not delete the other ones\n"
- " -u ... revert operation and unset the given flags\n"
" -x ... do not cross filesystems\n\n"
"Please report bugs to " PACKAGE_BUGREPORT "\n");
exit(res);
exit(1);
}
- set_mask = 0;
- if (args->immutable) set_mask |= VC_IMMUTABLE_FILE_FL;
- if (args->immulink) set_mask |= VC_IMMUTABLE_LINK_FL;
-
- if (args->do_set) del_mask = 0;
- else del_mask = VC_IMMUTABLE_ALL;
-
- if (args->do_unset) {
- del_mask = set_mask;
- set_mask = 0;
- }
+ args->do_display_dir = false;
}
static bool
{
int fd = open(name, O_RDONLY);
int res = false;
-
+ int rc;
+
if (fd==-1) {
perror("open()");
return false;
}
+ // this is still needed... the file must be open so that vc_set_iattr()
+ // operates on a known file/inode
if (!exp_st ||
!checkForRace(fd, name, exp_st))
goto err;
- if (vc_X_set_ext2flags(fd, set_mask, del_mask)==-1) {
+ rc = vc_set_iattr_compat(name, exp_st->st_dev, exp_st->st_ino,
+ 0,
+ global_args->set_mask & ~global_args->del_mask,
+ global_args->set_mask|global_args->del_mask);
+
+ if (rc==-1) {
perror(display_name);
goto err;
}
handleFile(char const *name, char const * display_name,
struct stat const *exp_st)
{
- if (!S_ISREG(exp_st->st_mode)) return true;
+ if (!(S_ISREG(exp_st->st_mode) || S_ISDIR(exp_st->st_mode))) return true;
return setFlags(name, display_name, exp_st);
}
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
+#include <ctype.h>
struct option const
CMDLINE_OPTIONS[] = {
}
static bool
-getFlags(char const *name, struct stat const *exp_st, long *flags)
+getFlags(char const *name, struct stat const *exp_st, uint32_t *flags, uint32_t *mask)
{
- int fd = open(name, O_RDONLY);
- int rc;
+ xid_t xid;
+ *mask = ~0;
- if (fd==-1) {
- perror("open()");
+ if (vc_get_iattr_compat(name, exp_st->st_dev, exp_st->st_ino,
+ &xid, flags, mask)==-1) {
+ perror("vc_get_iattr_compat()");
return false;
}
- if (exp_st)
- checkForRace(fd, name, exp_st);
-
- rc = vc_X_get_ext2flags(fd, flags);
- *flags &= VC_IMMUTABLE_ALL;
-
- if (rc==-1)
- perror("vc_X_get_ext2flags()");
-
- close(fd);
- return rc!=-1;
-}
-
-static void
-writePadded(long num)
-{
- char buf[sizeof(num)*2+1];
- size_t l = utilvserver_fmt_xulong(buf, num);
-
- if (l<8) write(1, "00000000", 8-l);
- write(1, buf, l);
-}
-
-#ifdef VC_ENABLE_API_LEGACY
-static bool
-handleFileLegacy(char const *name, char const *display_name,
- struct stat const *exp_st)
-{
- long flags;
-
- if (!S_ISREG(exp_st->st_mode)) {
- write(1, display_name, strlen(display_name));
- write(1, " -\n", 2);
- return true;
- }
-
- if (!getFlags(name, exp_st, &flags)) {
- perror(display_name);
- return false;
- }
-
- write(1, display_name, strlen(display_name));
- write(1, "\t", 1);
- writePadded(flags);
- write(1, "\n", 1);
-
return true;
}
-#endif
bool
handleFile(char const *name, char const *display_name,
struct stat const *exp_st)
{
bool res = true;
-#ifdef VC_ENABLE_API_LEGACY
- if (global_args->is_legacy)
- return handleFileLegacy(name, display_name, exp_st);
-#endif
-
- if (!S_ISREG(exp_st->st_mode)) {
- write(1, "--------", 8);
+ char buf[40];
+ char *ptr = buf;
+
+ memset(buf, ' ', sizeof buf);
+ if (!(S_ISREG(exp_st->st_mode) || S_ISDIR(exp_st->st_mode))) {
+ memcpy(ptr, "------", 6);
}
else {
- long flags;
-
- if (getFlags(name, exp_st, &flags))
- writePadded(flags);
+ uint32_t flags;
+ uint32_t mask;
+
+ if (getFlags(name, exp_st, &flags, &mask)) {
+ // 1 1 0 0
+ // fedcba9876543210fedcba9876543210
+ static char const MARKER[33] = ".......x......ib.............hwa";
+ int i;
+ uint32_t used_flags = (VC_IATTR_XID|VC_IATTR_ADMIN|
+ VC_IATTR_WATCH|VC_IATTR_HIDE|
+ VC_IATTR_BARRIER|VC_IATTR_IUNLINK);
+
+ for (i=0; i<32; ++i) {
+ if (used_flags & 1) {
+ if (! (mask & 1) ) *ptr++ = '-';
+ else if (flags & 1) *ptr++ = toupper(MARKER[31-i]);
+ else *ptr++ = MARKER[31-i];
+ }
+
+ used_flags >>= 1;
+ flags >>= 1;
+ mask >>= 1;
+ }
+ }
else {
- write(1, "ERR ", 8);
+ memcpy(buf, "ERR ", 6);
res = false;
}
}
- write(1, " ", 2);
+ write(1, buf, 8);
write(1, display_name, strlen(display_name));
write(1, "\n", 1);