initial checkin
authorEnrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
Sun, 7 Mar 2004 19:35:59 +0000 (19:35 +0000)
committerEnrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
Sun, 7 Mar 2004 19:35:59 +0000 (19:35 +0000)
git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/trunk@1132 94cd875c-1c1d-0410-91d2-eb244daf1a30

13 files changed:
util-vserver/lib/bcaps-v13.c [new file with mode: 0644]
util-vserver/lib/bcaps_list-v13.c [new file with mode: 0644]
util-vserver/lib/ccaps-v13.c [new file with mode: 0644]
util-vserver/lib/ccaps_list-v13.c [new file with mode: 0644]
util-vserver/lib/syscall_getccaps-v13.hc [new file with mode: 0644]
util-vserver/lib/syscall_getccaps.c [new file with mode: 0644]
util-vserver/lib/syscall_setccaps-v13.hc [new file with mode: 0644]
util-vserver/lib/syscall_setccaps.c [new file with mode: 0644]
util-vserver/lib/val2text-t2v-uint32.c [new file with mode: 0644]
util-vserver/lib/val2text-t2v-uint64.c [new file with mode: 0644]
util-vserver/lib/val2text-v2t-uint32.c [new file with mode: 0644]
util-vserver/lib/val2text-v2t-uint64.c [new file with mode: 0644]
util-vserver/lib/val2text.hc [new file with mode: 0644]

diff --git a/util-vserver/lib/bcaps-v13.c b/util-vserver/lib/bcaps-v13.c
new file mode 100644 (file)
index 0000000..607d5e3
--- /dev/null
@@ -0,0 +1,53 @@
+// $Id$    --*- c -*--
+
+// Copyright (C) 2004 Enrico Scholz <ensc@delenn.intern.sigma-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 "internal.h"
+#include <lib_internal/util-dimof.h>
+
+#include <string.h>
+#include <assert.h>
+
+#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 (file)
index 0000000..e62bbd1
--- /dev/null
@@ -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 <config.h>
+#endif
+
+#include "vserver.h"
+#include "internal.h"
+
+#include <string.h>
+
+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 (file)
index 0000000..822b3b6
--- /dev/null
@@ -0,0 +1,53 @@
+// $Id$    --*- c -*--
+
+// Copyright (C) 2004 Enrico Scholz <ensc@delenn.intern.sigma-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 "internal.h"
+#include <lib_internal/util-dimof.h>
+
+#include <string.h>
+#include <assert.h>
+
+#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 (file)
index 0000000..f52bfe7
--- /dev/null
@@ -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 <config.h>
+#endif
+
+#include "vserver.h"
+#include "internal.h"
+
+#include <string.h>
+
+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 (file)
index 0000000..a0708c3
--- /dev/null
@@ -0,0 +1,35 @@
+// $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
+
+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 (file)
index 0000000..e5f867e
--- /dev/null
@@ -0,0 +1,42 @@
+// $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 "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 (file)
index 0000000..f37b9c7
--- /dev/null
@@ -0,0 +1,33 @@
+// $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
+
+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 (file)
index 0000000..f8691df
--- /dev/null
@@ -0,0 +1,42 @@
+// $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 "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 (file)
index 0000000..da72ff5
--- /dev/null
@@ -0,0 +1,26 @@
+// $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 "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 (file)
index 0000000..194fa62
--- /dev/null
@@ -0,0 +1,26 @@
+// $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 "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 (file)
index 0000000..8c206de
--- /dev/null
@@ -0,0 +1,26 @@
+// $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 "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 (file)
index 0000000..5701ba0
--- /dev/null
@@ -0,0 +1,26 @@
+// $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 "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 (file)
index 0000000..ecac1b4
--- /dev/null
@@ -0,0 +1,75 @@
+// $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 <stdlib.h>
+#include <string.h>
+
+#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<map_len; ++i)                                          \
+      if (len==map[i].len &&                                           \
+         strncmp(map[i].id, str, len)==0)                              \
+       return i;                                                       \
+                                                                       \
+    return -1;                                                         \
+  }
+
+#define TEXT2VAL(TYPE,SHORT)                                           \
+  static ssize_t                                                       \
+  searchValue(TYPE val,                                                        \
+             struct Mapping_##SHORT const *map,  size_t map_len)       \
+  {                                                                    \
+    size_t             i;                                              \
+    for (i=0; i<map_len; ++i)                                          \
+      if (val == map[i].val) return i;                                 \
+    return -1;                                                         \
+  }                                                                    \
+                                                                       \
+  ssize_t                                                              \
+  utilvserver_text2value_##SHORT(TYPE *val,                            \
+                                struct Mapping_##SHORT const *map,     \
+                                size_t map_len)                        \
+  {                                                                    \
+    ssize_t    idx;                                                    \
+    TYPE       del_val;                                                \
+    if (*val==0)                                                       \
+      return -1;                                                       \
+                                                                       \
+    del_val = *val;                                                    \
+    idx     = searchValue(del_val, map, map_len);                      \
+                                                                       \
+    if (idx==-1) {                                                     \
+      size_t   i;                                                      \
+      for (i=0; i<sizeof(*val)*8 && (*val&(1<<i))==0; ++i) {}          \
+      del_val = (1<<i);                                                        \
+      idx     = searchValue(del_val, map, map_len);                    \
+    }                                                                  \
+    *val &= ~del_val;                                                  \
+    return idx;                                                                \
+  }