From: Enrico Scholz Date: Wed, 21 Jan 2004 01:14:26 +0000 (+0000) Subject: initial checkin X-Git-Tag: VERSION_0_10~879 X-Git-Url: http://git.linux-vserver.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b9a57c2e5e4db7d8ff9f9feea2b59ccc89161cbc;p=util-vserver.git initial checkin git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/trunk@651 94cd875c-1c1d-0410-91d2-eb244daf1a30 --- diff --git a/util-vserver/lib/fscompat_getiattr-v11.hc b/util-vserver/lib/fscompat_getiattr-v11.hc new file mode 100644 index 0000000..c7204ed --- /dev/null +++ b/util-vserver/lib/fscompat_getiattr-v11.hc @@ -0,0 +1,90 @@ +// $Id$ --*- c -*-- + +// Copyright (C) 2004 Enrico Scholz +// +// 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 +#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; + } +} diff --git a/util-vserver/lib/fscompat_getiattr.c b/util-vserver/lib/fscompat_getiattr.c new file mode 100644 index 0000000..4d6ae59 --- /dev/null +++ b/util-vserver/lib/fscompat_getiattr.c @@ -0,0 +1,62 @@ +// $Id$ --*- c -*-- + +// Copyright (C) 2004 Enrico Scholz +// +// 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 +#endif + +#include "vserver.h" +#include "vserver-internal.h" +#include + +#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; +} diff --git a/util-vserver/lib/fscompat_setiattr-v11.hc b/util-vserver/lib/fscompat_setiattr-v11.hc new file mode 100644 index 0000000..0ef3eb5 --- /dev/null +++ b/util-vserver/lib/fscompat_setiattr-v11.hc @@ -0,0 +1,85 @@ +// $Id$ --*- c -*-- + +// Copyright (C) 2004 Enrico Scholz +// +// 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 +#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; + } +} diff --git a/util-vserver/lib/fscompat_setiattr.c b/util-vserver/lib/fscompat_setiattr.c new file mode 100644 index 0000000..e4f937b --- /dev/null +++ b/util-vserver/lib/fscompat_setiattr.c @@ -0,0 +1,49 @@ +// $Id$ --*- c -*-- + +// Copyright (C) 2004 Enrico Scholz +// +// 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 +#endif + +#include "vserver.h" +#include "vserver-internal.h" +#include + +#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; +} diff --git a/util-vserver/lib/ioctl-getxflg.hc b/util-vserver/lib/ioctl-getxflg.hc new file mode 100644 index 0000000..3d50c6f --- /dev/null +++ b/util-vserver/lib/ioctl-getxflg.hc @@ -0,0 +1,39 @@ +// $Id$ --*- c -*-- + +// Copyright (C) 2004 Enrico Scholz +// +// 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 +#endif + +#include "vserver.h" +#include "vserver-internal.h" +#include "ext2fs.h" + +#include + +#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; +} diff --git a/util-vserver/lib/ioctl-setxflg.hc b/util-vserver/lib/ioctl-setxflg.hc new file mode 100644 index 0000000..6563136 --- /dev/null +++ b/util-vserver/lib/ioctl-setxflg.hc @@ -0,0 +1,38 @@ +// $Id$ --*- c -*-- + +// Copyright (C) 2004 Enrico Scholz +// +// 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 +#endif + +#include "vserver.h" +#include "vserver-internal.h" +#include "ext2fs.h" + +#include + +#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; +} diff --git a/util-vserver/lib/syscall_getiattr-v13.hc b/util-vserver/lib/syscall_getiattr-v13.hc new file mode 100644 index 0000000..efdeff3 --- /dev/null +++ b/util-vserver/lib/syscall_getiattr-v13.hc @@ -0,0 +1,42 @@ +// $Id$ --*- c -*-- + +// Copyright (C) 2004 Enrico Scholz +// +// 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 +#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; +} diff --git a/util-vserver/lib/syscall_getiattr.c b/util-vserver/lib/syscall_getiattr.c new file mode 100644 index 0000000..9a75717 --- /dev/null +++ b/util-vserver/lib/syscall_getiattr.c @@ -0,0 +1,35 @@ +// $Id$ --*- c++ -*-- + +// Copyright (C) 2003 Enrico Scholz +// +// 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 +#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)); +} diff --git a/util-vserver/lib/syscall_setiattr-v13.hc b/util-vserver/lib/syscall_setiattr-v13.hc new file mode 100644 index 0000000..32768e7 --- /dev/null +++ b/util-vserver/lib/syscall_setiattr-v13.hc @@ -0,0 +1,37 @@ +// $Id$ --*- c -*-- + +// Copyright (C) 2004 Enrico Scholz +// +// 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 +#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); +} diff --git a/util-vserver/lib/syscall_setiattr.c b/util-vserver/lib/syscall_setiattr.c new file mode 100644 index 0000000..ffda4d2 --- /dev/null +++ b/util-vserver/lib/syscall_setiattr.c @@ -0,0 +1,35 @@ +// $Id$ --*- c++ -*-- + +// Copyright (C) 2003 Enrico Scholz +// +// 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 +#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)); +}