--- /dev/null
+// $Id$ --*- c -*--
+
+// Copyright (C) 2004 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "ioctl-getext2flags.hc"
+#include "ioctl-getfilecontext.hc"
+#include "ioctl-getxflg.hc"
+
+static inline int
+vc_get_iattr_compat_v11(char const *filename,
+ dev_t dev, ino_t ino,
+ xid_t * /*@null@*/ xid,
+ uint32_t * /*@null@*/ flags,
+ uint32_t * mask)
+{
+ int fd = open(filename, O_RDONLY);
+ struct stat st;
+ int stat_rc;
+ int old_mask = *mask;
+
+ if (fd==-1) return -1;
+ *mask = 0;
+
+ stat_rc = fstat(fd, &st);
+ if (stat_rc==-1) goto err;
+
+ if (st.st_dev!=dev || st.st_ino!=ino) {
+ errno = EINVAL;
+ goto err;
+ }
+
+ if ( old_mask&VC_IATTR_XID ) {
+ *xid = vc_X_get_filecontext(fd);
+ if (*xid!=VC_NOCTX) *mask |= VC_IATTR_XID;
+ }
+
+ if ( old_mask&VC_IATTR_IUNLINK ) {
+ long tmp;
+ int rc = vc_X_get_ext2flags(fd, &tmp);
+
+ if (rc!=-1) {
+ *mask |= VC_IATTR_IUNLINK;
+ if (tmp & (VC_IMMUTABLE_FILE_FL|VC_IMMUTABLE_LINK_FL))
+ *flags |= VC_IATTR_IUNLINK;
+ }
+ }
+
+ if ( (old_mask&VC_IATTR_BARRIER) && S_ISDIR(st.st_mode)) {
+ *mask |= VC_IATTR_BARRIER;
+ if ((st.st_mode&0777) == 0) *flags |= VC_IATTR_BARRIER;
+ }
+
+ if ( (old_mask&(VC_IATTR_WATCH|VC_IATTR_HIDE)) ){
+ long tmp;
+ int rc = vc_X_get_xflg(fd, &tmp);
+ if (rc!=-1) {
+ *mask |= (VC_IATTR_WATCH|VC_IATTR_HIDE);
+ if (tmp&1) *flags |= VC_IATTR_HIDE;
+ if (tmp&2) *flags |= VC_IATTR_WATCH;
+ }
+ }
+
+ close(fd);
+ return 0;
+ err:
+ {
+ int old_errno = errno;
+ close(fd);
+ errno = old_errno;
+ return -1;
+ }
+}
--- /dev/null
+// $Id$ --*- c -*--
+
+// Copyright (C) 2004 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "vserver.h"
+#include "vserver-internal.h"
+#include <fcntl.h>
+
+#ifdef VC_ENABLE_API_FSCOMPAT
+# include "fscompat_getiattr-v11.hc"
+#endif
+
+int
+vc_get_iattr_compat(char const *filename,
+ dev_t dev, ino_t ino,
+ xid_t * /*@null@*/ xid,
+ uint32_t * /*@null@*/ flags,
+ uint32_t * mask)
+{
+#ifdef VC_ENABLE_API_FSCOMPAT
+ int ver = utilvserver_checkCompatVersion();
+ if (ver==-1) return -1;
+#endif
+
+ if ( (mask==0) ||
+ ((*mask&VC_IATTR_XID) && xid==0) ||
+ ((*mask&~VC_IATTR_XID) && flags==0) ) {
+ errno = EINVAL;
+ return -1;
+ }
+ if ( flags ) *flags &= ~*mask;
+
+#ifdef VC_ENABLE_API_FSCOMPAT
+ if ((ver&0xffff)<=4)
+ return vc_get_iattr_compat_v11(filename, dev, ino, xid, flags, mask);
+#endif
+
+#ifdef VC_ENABLE_API_V13
+ return vc_get_iattr(dev, ino, xid, flags, mask);
+#endif
+
+ errno = ENOSYS;
+ return -1;
+}
--- /dev/null
+// $Id$ --*- c -*--
+
+// Copyright (C) 2004 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "ioctl-setext2flags.hc"
+#include "ioctl-setfilecontext.hc"
+#include "ioctl-setxflg.hc"
+#include "ioctl-getxflg.hc"
+
+static inline ALWAYSINLINE int
+vc_set_iattr_compat_v11(char const *filename,
+ dev_t dev, ino_t ino, xid_t xid,
+ uint32_t flags, uint32_t mask)
+{
+ int fd = open(filename, O_RDONLY);
+ struct stat st;
+ int stat_rc;
+
+ if (fd==-1) return -1;
+
+ stat_rc = fstat(fd, &st);
+ if (stat_rc==-1) goto err;
+
+ if (st.st_dev!=dev || st.st_ino!=ino) {
+ errno = EINVAL;
+ goto err;
+ }
+
+ if ( (mask&VC_IATTR_IUNLINK) ) {
+ int const tmp = VC_IMMUTABLE_FILE_FL|VC_IMMUTABLE_LINK_FL;
+ if (vc_X_set_ext2flags(fd,
+ (flags&VC_IATTR_IUNLINK) ? tmp : 0,
+ (flags&VC_IATTR_IUNLINK) ? 0 : tmp)==-1)
+ goto err;
+ }
+
+ if ( (mask&VC_IATTR_BARRIER) ) {
+ if (fchmod(fd, (flags&VC_IATTR_BARRIER) ? 0 : (st.st_mode|0500))==-1)
+ goto err;
+ }
+
+ if ( (mask&VC_IATTR_XID) &&
+ vc_X_set_filecontext(fd, xid)==-1)
+ goto err;
+
+ if ( (mask&(VC_IATTR_HIDE|VC_IATTR_WATCH)) ) {
+ long tmp;
+ if (vc_X_get_xflg(fd, &tmp)==-1) goto err;
+
+ tmp &= ~( ((mask&VC_IATTR_HIDE) ? 1 : 0) |
+ ((mask&VC_IATTR_WATCH) ? 2 : 0) );
+ tmp |= ( ((flags&VC_IATTR_HIDE) ? 1 : 0) |
+ ((flags&VC_IATTR_WATCH) ? 2 : 0) );
+
+ if (vc_X_set_xflg(fd, tmp)==-1) goto err;
+ }
+
+ close(fd);
+ return 0;
+ err:
+ {
+ int old_errno = errno;
+ close(fd);
+ errno = old_errno;
+ return -1;
+ }
+}
--- /dev/null
+// $Id$ --*- c -*--
+
+// Copyright (C) 2004 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "vserver.h"
+#include "vserver-internal.h"
+#include <fcntl.h>
+
+#ifdef VC_ENABLE_API_FSCOMPAT
+# include "fscompat_setiattr-v11.hc"
+#endif
+
+int
+vc_set_iattr_compat(char const *filename,
+ dev_t dev, ino_t ino, xid_t xid,
+ uint32_t flags, uint32_t mask)
+{
+#ifdef VC_ENABLE_API_FSCOMPAT
+ int ver = utilvserver_checkCompatVersion();
+ if (ver==-1) return -1;
+ if ((ver&0xffff)<=4)
+ return vc_set_iattr_compat_v11(filename, dev, ino, xid, flags, mask);
+#endif
+
+#ifdef VC_ENABLE_API_V13
+ return vc_set_iattr(dev, ino, xid, flags, mask);
+#endif
+
+ errno = ENOSYS;
+ return -1;
+}
--- /dev/null
+// $Id$ --*- c -*--
+
+// Copyright (C) 2004 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "vserver.h"
+#include "vserver-internal.h"
+#include "ext2fs.h"
+
+#include <sys/ioctl.h>
+
+#define FIOC_GETXFLG _IOR('x', 5, long)
+
+static inline ALWAYSINLINE int
+vc_X_get_xflg(int fd, long *flags)
+{
+ int rc;
+ *flags = 0;
+ rc = ioctl(fd, FIOC_GETXFLG, flags);
+
+ return rc;
+}
--- /dev/null
+// $Id$ --*- c -*--
+
+// Copyright (C) 2004 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "vserver.h"
+#include "vserver-internal.h"
+#include "ext2fs.h"
+
+#include <sys/ioctl.h>
+
+#define FIOC_SETXFLG _IOW('x', 6, long)
+
+static inline ALWAYSINLINE int
+vc_X_set_xflg(int fd, long flags)
+{
+ int rc;
+ rc = ioctl(fd, FIOC_SETXFLG, &flags);
+
+ return rc;
+}
--- /dev/null
+// $Id$ --*- c -*--
+
+// Copyright (C) 2004 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "vserver.h"
+#include "vserver-internal.h"
+
+static inline ALWAYSINLINE int
+vc_get_iattr_v13(dev_t dev, ino_t ino, xid_t *xid,
+ uint32_t *flags, uint32_t *mask)
+{
+ struct vcmd_ctx_iattr_v0 attr;
+ int rc;
+
+ attr.dev = dev;
+ attr.ino = ino;
+
+ rc = vserver(VC_CMD(INODE, 2, 0), 0, &attr);
+ if (xid) *xid = attr.xid;
+ if (flags) *flags = attr.flags;
+ if (mask) *mask = attr.mask;
+
+ return rc;
+}
--- /dev/null
+// $Id$ --*- c++ -*--
+
+// Copyright (C) 2003 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "vserver.h"
+#include "vserver-internal.h"
+#include "linuxvirtual.h"
+
+#ifdef VC_ENABLE_API_V13
+# include "syscall_getiattr-v13.hc"
+#endif
+
+int
+vc_get_iattr(dev_t dev, ino_t ino, xid_t *xid, uint32_t *flags, uint32_t *mask)
+{
+ CALL_VC(CALL_VC_V13(vc_get_iattr, dev, ino, xid, flags, mask));
+}
--- /dev/null
+// $Id$ --*- c -*--
+
+// Copyright (C) 2004 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "vserver.h"
+#include "vserver-internal.h"
+
+static inline ALWAYSINLINE int
+vc_set_iattr_v13(dev_t dev, ino_t ino, xid_t xid, uint32_t flags, uint32_t mask)
+{
+ struct vcmd_ctx_iattr_v0 attr;
+
+ attr.dev = dev;
+ attr.ino = ino;
+ attr.xid = xid;
+ attr.flags = flags;
+ attr.mask = mask;
+ return vserver(VC_CMD(INODE, 1, 0), 0, &attr);
+}
--- /dev/null
+// $Id$ --*- c++ -*--
+
+// Copyright (C) 2003 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "vserver.h"
+#include "vserver-internal.h"
+#include "linuxvirtual.h"
+
+#ifdef VC_ENABLE_API_V13
+# include "syscall_setiattr-v13.hc"
+#endif
+
+int
+vc_set_iattr(dev_t dev, ino_t ino, xid_t xid, uint32_t flags, uint32_t mask)
+{
+ CALL_VC(CALL_VC_V13(vc_set_iattr, dev, ino, xid, flags, mask));
+}