From: Enrico Scholz Date: Thu, 28 Apr 2005 17:51:43 +0000 (+0000) Subject: added personality* files X-Git-Tag: version_0_30_210~226 X-Git-Url: http://git.linux-vserver.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1259f90633496ded2135b015c98b501953110789;p=util-vserver.git added personality* files git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/trunk@2055 94cd875c-1c1d-0410-91d2-eb244daf1a30 --- diff --git a/util-vserver/lib/Makefile-files b/util-vserver/lib/Makefile-files index fe82880..588bd9d 100644 --- a/util-vserver/lib/Makefile-files +++ b/util-vserver/lib/Makefile-files @@ -135,6 +135,9 @@ lib_SRCS = lib/syscall.c \ lib/issupportedstring.c \ lib/listparser_uint32.c \ lib/listparser_uint64.c \ + lib/personalityflag.c \ + lib/personalityflag_list.c \ + lib/personalitytype.c \ lib/syscall-syscall.c \ lib/val2text-t2v-uint32.c \ lib/val2text-t2v-uint64.c \ diff --git a/util-vserver/lib/personalityflag.c b/util-vserver/lib/personalityflag.c new file mode 100644 index 0000000..2cb6b11 --- /dev/null +++ b/util-vserver/lib/personalityflag.c @@ -0,0 +1,59 @@ +// $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 + +#define DECL(VAL) { #VAL, sizeof(#VAL)-1, (VAL) } + +static struct Mapping_uint32 const VALUES[] = { + DECL(MMAP_PAGE_ZERO), + DECL(ADDR_LIMIT_32BIT), + DECL(SHORT_INODE), + DECL(WHOLE_SECONDS), + DECL(STICKY_TIMEOUTS), + DECL(ADDR_LIMIT_3GB) +}; + +uint_least32_t +vc_text2personalityflag(char const *str, size_t len) +{ + ssize_t idx = utilvserver_value2text_uint32(str, len, + VALUES, DIM_OF(VALUES)); + + if (idx==-1) return 0; + else return VALUES[idx].val; +} + +char const * +vc_lopersonality2text(uint_least32_t *val) +{ + ssize_t idx = utilvserver_text2value_uint32(val, VALUES, + DIM_OF(VALUES)); + + if (idx==-1) return 0; + else return VALUES[idx].id; +} + + diff --git a/util-vserver/lib/personalityflag_list.c b/util-vserver/lib/personalityflag_list.c new file mode 100644 index 0000000..fc42d7b --- /dev/null +++ b/util-vserver/lib/personalityflag_list.c @@ -0,0 +1,50 @@ +// $Id$ --*- c -*-- + +// Copyright (C) 2005 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 + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include "vserver.h" +#include "internal.h" + + +static uint_least32_t +text2personalityflag_err(char const *str, + size_t len, bool *failed) +{ + uint_least32_t res = vc_text2personalityflag(str, len); + if (res==0) *failed = true; + return res; +} + +int +vc_list2personalityflag(char const *str, size_t len, + uint_least32_t *personality, + struct vc_err_listparser *err) +{ + return utilvserver_listparser_uint32(str, len, + err ? &err->ptr : 0, + err ? &err->len : 0, + personality, 0, + text2personalityflag_err); +} diff --git a/util-vserver/lib/personalitytype.c b/util-vserver/lib/personalitytype.c new file mode 100644 index 0000000..731948e --- /dev/null +++ b/util-vserver/lib/personalitytype.c @@ -0,0 +1,79 @@ +// $Id$ --*- c -*-- + +// Copyright (C) 2005 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 +#include +#include + +#define DECL(VAL) { #VAL, sizeof(#VAL)-1, (PER_ ## VAL) } + +static struct Mapping_uint32 const VALUES[] = { + DECL(LINUX), + DECL(LINUX_32BIT), + DECL(SVR4), + DECL(SVR3), + DECL(SCOSVR3), + DECL(OSR5), + DECL(WYSEV386), + DECL(ISCR4), + DECL(BSD), + DECL(SUNOS), + DECL(XENIX), + DECL(LINUX32), + DECL(LINUX32_3GB), + DECL(IRIX32), + DECL(IRIXN32), + DECL(IRIX64), + DECL(RISCOS), + DECL(SOLARIS), + DECL(UW7), + DECL(HPUX), + DECL(OSF4) +}; + +static char const * +removePrefix(char const *str, size_t *len) +{ + if ((len==0 || *len==0 || *len>4) && + strncasecmp("per_", str, 4)==0) { + if (len && *len>4) *len -= 4; + return str+4; + } + else + return str; +} + +uint_least32_t +vc_str2personalitytype(char const *str, size_t len) +{ + char const *tmp = removePrefix(str, &len); + ssize_t idx = utilvserver_value2text_uint32(tmp, len, + VALUES, DIM_OF(VALUES)); + + if (idx==-1) return VC_BAD_PERSONALITY; + else return VALUES[idx].val; +}