From 1c010b3d5c9603345a6c2f27aa5e8cab5ff6b28d Mon Sep 17 00:00:00 2001 From: Enrico Scholz Date: Sun, 7 Mar 2004 19:35:59 +0000 Subject: [PATCH] initial checkin git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/trunk@1132 94cd875c-1c1d-0410-91d2-eb244daf1a30 --- util-vserver/lib/bcaps-v13.c | 53 ++++++++++++++++++++++ util-vserver/lib/bcaps_list-v13.c | 40 +++++++++++++++++ util-vserver/lib/ccaps-v13.c | 53 ++++++++++++++++++++++ util-vserver/lib/ccaps_list-v13.c | 38 ++++++++++++++++ util-vserver/lib/syscall_getccaps-v13.hc | 35 +++++++++++++++ util-vserver/lib/syscall_getccaps.c | 42 ++++++++++++++++++ util-vserver/lib/syscall_setccaps-v13.hc | 33 ++++++++++++++ util-vserver/lib/syscall_setccaps.c | 42 ++++++++++++++++++ util-vserver/lib/val2text-t2v-uint32.c | 26 +++++++++++ util-vserver/lib/val2text-t2v-uint64.c | 26 +++++++++++ util-vserver/lib/val2text-v2t-uint32.c | 26 +++++++++++ util-vserver/lib/val2text-v2t-uint64.c | 26 +++++++++++ util-vserver/lib/val2text.hc | 75 ++++++++++++++++++++++++++++++++ 13 files changed, 515 insertions(+) create mode 100644 util-vserver/lib/bcaps-v13.c create mode 100644 util-vserver/lib/bcaps_list-v13.c create mode 100644 util-vserver/lib/ccaps-v13.c create mode 100644 util-vserver/lib/ccaps_list-v13.c create mode 100644 util-vserver/lib/syscall_getccaps-v13.hc create mode 100644 util-vserver/lib/syscall_getccaps.c create mode 100644 util-vserver/lib/syscall_setccaps-v13.hc create mode 100644 util-vserver/lib/syscall_setccaps.c create mode 100644 util-vserver/lib/val2text-t2v-uint32.c create mode 100644 util-vserver/lib/val2text-t2v-uint64.c create mode 100644 util-vserver/lib/val2text-v2t-uint32.c create mode 100644 util-vserver/lib/val2text-v2t-uint64.c create mode 100644 util-vserver/lib/val2text.hc diff --git a/util-vserver/lib/bcaps-v13.c b/util-vserver/lib/bcaps-v13.c new file mode 100644 index 0000000..607d5e3 --- /dev/null +++ b/util-vserver/lib/bcaps-v13.c @@ -0,0 +1,53 @@ +// $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 "internal.h" +#include + +#include +#include + +#define DECL(STR, VAL) { STR, sizeof(STR)-1, VAL } + +static struct Mapping_uint64 const VALUES[] = { +#warning Add the 'bcap' values here +}; + +uint_least64_t +vc_text2bcap(char const *str, size_t len) +{ + ssize_t idx = utilvserver_value2text_uint64(str, len, + VALUES, DIM_OF(VALUES)); + if (idx==-1) return 0; + else return VALUES[idx].val; +} + +char const * +vc_lobcap2text(uint_least64_t *val) +{ + ssize_t idx = utilvserver_text2value_uint64(val, + VALUES, DIM_OF(VALUES)); + + if (idx==-1) return 0; + else return VALUES[idx].id; +} diff --git a/util-vserver/lib/bcaps_list-v13.c b/util-vserver/lib/bcaps_list-v13.c new file mode 100644 index 0000000..e62bbd1 --- /dev/null +++ b/util-vserver/lib/bcaps_list-v13.c @@ -0,0 +1,40 @@ +// $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 "internal.h" + +#include + +int +vc_list2bcap(char const *str, size_t len, + struct vc_err_listparser *err, + struct vc_ctx_caps *caps) +{ + uint_least64_t tmp=0; + + return utilvserver_listparser_uint64(str, len, + err ? &err->ptr : 0, + err ? &err->len : 0, + &caps->bcaps, &tmp, + vc_text2bcap); +} diff --git a/util-vserver/lib/ccaps-v13.c b/util-vserver/lib/ccaps-v13.c new file mode 100644 index 0000000..822b3b6 --- /dev/null +++ b/util-vserver/lib/ccaps-v13.c @@ -0,0 +1,53 @@ +// $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 "internal.h" +#include + +#include +#include + +#define DECL(STR, VAL) { STR, sizeof(STR)-1, VAL } + +static struct Mapping_uint64 const VALUES[] = { +#warning Add the 'ccap' values here +}; + +uint_least64_t +vc_text2ccap(char const *str, size_t len) +{ + ssize_t idx = utilvserver_value2text_uint64(str, len, + VALUES, DIM_OF(VALUES)); + if (idx==-1) return 0; + else return VALUES[idx].val; +} + +char const * +vc_loccap2text(uint_least64_t *val) +{ + ssize_t idx = utilvserver_text2value_uint64(val, + VALUES, DIM_OF(VALUES)); + + if (idx==-1) return 0; + else return VALUES[idx].id; +} diff --git a/util-vserver/lib/ccaps_list-v13.c b/util-vserver/lib/ccaps_list-v13.c new file mode 100644 index 0000000..f52bfe7 --- /dev/null +++ b/util-vserver/lib/ccaps_list-v13.c @@ -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 "internal.h" + +#include + +int +vc_list2ccap(char const *str, size_t len, + struct vc_err_listparser *err, + struct vc_ctx_caps *caps) +{ + return utilvserver_listparser_uint64(str, len, + err ? &err->ptr : 0, + err ? &err->len : 0, + &caps->ccaps, &caps->cmask, + vc_text2ccap); +} diff --git a/util-vserver/lib/syscall_getccaps-v13.hc b/util-vserver/lib/syscall_getccaps-v13.hc new file mode 100644 index 0000000..a0708c3 --- /dev/null +++ b/util-vserver/lib/syscall_getccaps-v13.hc @@ -0,0 +1,35 @@ +// $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 + +static inline ALWAYSINLINE int +vc_get_ccaps_v13(xid_t xid, struct vc_ctx_caps *caps) +{ + struct vcmd_ctx_caps_v0 k_caps; + int res; + + res = vserver(VCMD_get_ccaps, CTX_USER2KERNEL(xid), &k_caps); + caps->bcaps = k_caps.bcaps; + caps->ccaps = k_caps.ccaps; + caps->cmask = k_caps.cmask; + + return res; +} diff --git a/util-vserver/lib/syscall_getccaps.c b/util-vserver/lib/syscall_getccaps.c new file mode 100644 index 0000000..e5f867e --- /dev/null +++ b/util-vserver/lib/syscall_getccaps.c @@ -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" +#include "linuxvirtual.h" + +#if defined(VC_ENABLE_API_V13) +# include "syscall_getccaps-v13.hc" +#endif + +#if defined(VC_ENABLE_API_V13) +int +vc_get_ccaps(xid_t xid, struct vc_ctx_caps *caps) +{ + if (caps==0) { + errno = EFAULT; + return -1; + } + + CALL_VC(CALL_VC_V13A(vc_get_ccaps, xid, caps)); +} +#endif diff --git a/util-vserver/lib/syscall_setccaps-v13.hc b/util-vserver/lib/syscall_setccaps-v13.hc new file mode 100644 index 0000000..f37b9c7 --- /dev/null +++ b/util-vserver/lib/syscall_setccaps-v13.hc @@ -0,0 +1,33 @@ +// $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 + +static inline ALWAYSINLINE int +vc_set_ccaps_v13(xid_t xid, struct vc_ctx_caps const *caps) +{ + struct vcmd_ctx_caps_v0 k_caps; + + k_caps.bcaps = caps->bcaps; + k_caps.ccaps = caps->ccaps; + k_caps.cmask = caps->cmask; + + return vserver(VCMD_set_ccaps, CTX_USER2KERNEL(xid), &k_caps); +} diff --git a/util-vserver/lib/syscall_setccaps.c b/util-vserver/lib/syscall_setccaps.c new file mode 100644 index 0000000..f8691df --- /dev/null +++ b/util-vserver/lib/syscall_setccaps.c @@ -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" +#include "linuxvirtual.h" + +#if defined(VC_ENABLE_API_V13) +# include "syscall_setccaps-v13.hc" +#endif + +#if defined(VC_ENABLE_API_V13) +int +vc_set_ccaps(xid_t xid, struct vc_ctx_caps const *caps) +{ + if (caps==0) { + errno = EFAULT; + return -1; + } + + CALL_VC(CALL_VC_V13A(vc_set_ccaps, xid, caps)); +} +#endif diff --git a/util-vserver/lib/val2text-t2v-uint32.c b/util-vserver/lib/val2text-t2v-uint32.c new file mode 100644 index 0000000..da72ff5 --- /dev/null +++ b/util-vserver/lib/val2text-t2v-uint32.c @@ -0,0 +1,26 @@ +// $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 "internal.h" +#include "val2text.hc" + +TEXT2VAL(uint_least32_t, uint32) diff --git a/util-vserver/lib/val2text-t2v-uint64.c b/util-vserver/lib/val2text-t2v-uint64.c new file mode 100644 index 0000000..194fa62 --- /dev/null +++ b/util-vserver/lib/val2text-t2v-uint64.c @@ -0,0 +1,26 @@ +// $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 "internal.h" +#include "val2text.hc" + +TEXT2VAL(uint_least64_t, uint64) diff --git a/util-vserver/lib/val2text-v2t-uint32.c b/util-vserver/lib/val2text-v2t-uint32.c new file mode 100644 index 0000000..8c206de --- /dev/null +++ b/util-vserver/lib/val2text-v2t-uint32.c @@ -0,0 +1,26 @@ +// $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 "internal.h" +#include "val2text.hc" + +VAL2TEXT(uint_least32_t, uint32) diff --git a/util-vserver/lib/val2text-v2t-uint64.c b/util-vserver/lib/val2text-v2t-uint64.c new file mode 100644 index 0000000..5701ba0 --- /dev/null +++ b/util-vserver/lib/val2text-v2t-uint64.c @@ -0,0 +1,26 @@ +// $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 "internal.h" +#include "val2text.hc" + +VAL2TEXT(uint_least64_t, uint64) diff --git a/util-vserver/lib/val2text.hc b/util-vserver/lib/val2text.hc new file mode 100644 index 0000000..ecac1b4 --- /dev/null +++ b/util-vserver/lib/val2text.hc @@ -0,0 +1,75 @@ +// $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 +#include + +#define VAL2TEXT(TYPE,SHORT) \ + ssize_t \ + utilvserver_value2text_##SHORT(char const *str, size_t len, \ + struct Mapping_ ##SHORT const *map, \ + size_t map_len) \ + { \ + size_t i; \ + if (len==0) len=strlen(str); \ + \ + for (i=0; i