KVM: Avoid corrupting tr in real mode
[deliverable/linux.git] / fs / sysfs / group.c
CommitLineData
1da177e4
LT
1/*
2 * fs/sysfs/group.c - Operations for adding/removing multiple files at once.
3 *
4 * Copyright (c) 2003 Patrick Mochel
5 * Copyright (c) 2003 Open Source Development Lab
6 *
7 * This file is released undert the GPL v2.
8 *
9 */
10
11#include <linux/kobject.h>
12#include <linux/module.h>
13#include <linux/dcache.h>
5f45f1a7 14#include <linux/namei.h>
1da177e4 15#include <linux/err.h>
b592fcfe 16#include <linux/fs.h>
94bebf4d 17#include <asm/semaphore.h>
1da177e4
LT
18#include "sysfs.h"
19
20
608e266a
TH
21static void remove_files(struct sysfs_dirent *dir_sd,
22 const struct attribute_group *grp)
1da177e4
LT
23{
24 struct attribute *const* attr;
25
26 for (attr = grp->attrs; *attr; attr++)
608e266a 27 sysfs_hash_and_remove(dir_sd, (*attr)->name);
1da177e4
LT
28}
29
608e266a
TH
30static int create_files(struct sysfs_dirent *dir_sd,
31 const struct attribute_group *grp)
1da177e4
LT
32{
33 struct attribute *const* attr;
34 int error = 0;
35
608e266a
TH
36 for (attr = grp->attrs; *attr && !error; attr++)
37 error = sysfs_add_file(dir_sd, *attr, SYSFS_KOBJ_ATTR);
1da177e4 38 if (error)
608e266a 39 remove_files(dir_sd, grp);
1da177e4
LT
40 return error;
41}
42
43
44int sysfs_create_group(struct kobject * kobj,
45 const struct attribute_group * grp)
46{
608e266a 47 struct sysfs_dirent *sd;
1da177e4
LT
48 int error;
49
608e266a 50 BUG_ON(!kobj || !kobj->sd);
1da177e4
LT
51
52 if (grp->name) {
608e266a 53 error = sysfs_create_subdir(kobj, grp->name, &sd);
1da177e4
LT
54 if (error)
55 return error;
56 } else
608e266a
TH
57 sd = kobj->sd;
58 sysfs_get(sd);
59 error = create_files(sd, grp);
60 if (error) {
1da177e4 61 if (grp->name)
608e266a 62 sysfs_remove_subdir(sd);
1da177e4 63 }
608e266a 64 sysfs_put(sd);
1da177e4
LT
65 return error;
66}
67
68void sysfs_remove_group(struct kobject * kobj,
69 const struct attribute_group * grp)
70{
608e266a
TH
71 struct sysfs_dirent *dir_sd = kobj->sd;
72 struct sysfs_dirent *sd;
1da177e4 73
057f6c01 74 if (grp->name) {
608e266a
TH
75 sd = sysfs_get_dirent(dir_sd, grp->name);
76 BUG_ON(!sd);
77 } else
78 sd = sysfs_get(dir_sd);
1da177e4 79
608e266a 80 remove_files(sd, grp);
1da177e4 81 if (grp->name)
608e266a
TH
82 sysfs_remove_subdir(sd);
83
84 sysfs_put(sd);
1da177e4
LT
85}
86
87
88EXPORT_SYMBOL_GPL(sysfs_create_group);
89EXPORT_SYMBOL_GPL(sysfs_remove_group);
This page took 0.235355 seconds and 5 git commands to generate.