staging: gma500: Set the TWOD base
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / kernel / utsname.c
blob44646179eabae8e8fd848174869f7d1782c90be8
1 /*
2 * Copyright (C) 2004 IBM Corporation
4 * Author: Serge Hallyn <serue@us.ibm.com>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation, version 2 of the
9 * License.
12 #include <linux/module.h>
13 #include <linux/uts.h>
14 #include <linux/utsname.h>
15 #include <linux/err.h>
16 #include <linux/slab.h>
17 #include <linux/user_namespace.h>
19 static struct uts_namespace *create_uts_ns(void)
21 struct uts_namespace *uts_ns;
23 uts_ns = kmalloc(sizeof(struct uts_namespace), GFP_KERNEL);
24 if (uts_ns)
25 kref_init(&uts_ns->kref);
26 return uts_ns;
30 * Clone a new ns copying an original utsname, setting refcount to 1
31 * @old_ns: namespace to clone
32 * Return NULL on error (failure to kmalloc), new ns otherwise
34 static struct uts_namespace *clone_uts_ns(struct task_struct *tsk,
35 struct uts_namespace *old_ns)
37 struct uts_namespace *ns;
39 ns = create_uts_ns();
40 if (!ns)
41 return ERR_PTR(-ENOMEM);
43 down_read(&uts_sem);
44 memcpy(&ns->name, &old_ns->name, sizeof(ns->name));
45 ns->user_ns = get_user_ns(task_cred_xxx(tsk, user)->user_ns);
46 up_read(&uts_sem);
47 return ns;
51 * Copy task tsk's utsname namespace, or clone it if flags
52 * specifies CLONE_NEWUTS. In latter case, changes to the
53 * utsname of this process won't be seen by parent, and vice
54 * versa.
56 struct uts_namespace *copy_utsname(unsigned long flags,
57 struct task_struct *tsk)
59 struct uts_namespace *old_ns = tsk->nsproxy->uts_ns;
60 struct uts_namespace *new_ns;
62 BUG_ON(!old_ns);
63 get_uts_ns(old_ns);
65 if (!(flags & CLONE_NEWUTS))
66 return old_ns;
68 new_ns = clone_uts_ns(tsk, old_ns);
70 put_uts_ns(old_ns);
71 return new_ns;
74 void free_uts_ns(struct kref *kref)
76 struct uts_namespace *ns;
78 ns = container_of(kref, struct uts_namespace, kref);
79 put_user_ns(ns->user_ns);
80 kfree(ns);