Commit | Line | Data |
---|---|---|
aebe17f6 VD |
1 | /* |
2 | * sysfs.c - sysfs support implementation. | |
3 | * | |
4 | * Copyright (C) 2005-2014 Nippon Telegraph and Telephone Corporation. | |
5 | * Copyright (C) 2014 HGST, Inc., a Western Digital Company. | |
6 | * | |
7 | * This program is free software; you can redistribute it and/or modify | |
8 | * it under the terms of the GNU General Public License as published by | |
9 | * the Free Software Foundation; either version 2 of the License, or | |
10 | * (at your option) any later version. | |
11 | * | |
12 | * This program is distributed in the hope that it will be useful, | |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | * GNU General Public License for more details. | |
16 | * | |
17 | * Written by Vyacheslav Dubeyko <Vyacheslav.Dubeyko@hgst.com> | |
18 | */ | |
19 | ||
20 | #include <linux/kobject.h> | |
21 | ||
22 | #include "nilfs.h" | |
23 | #include "mdt.h" | |
24 | #include "sufile.h" | |
25 | #include "cpfile.h" | |
26 | #include "sysfs.h" | |
27 | ||
28 | /* /sys/fs/<nilfs>/ */ | |
29 | static struct kset *nilfs_kset; | |
30 | ||
31 | #define NILFS_SHOW_TIME(time_t_val, buf) ({ \ | |
32 | struct tm res; \ | |
33 | int count = 0; \ | |
34 | time_to_tm(time_t_val, 0, &res); \ | |
35 | res.tm_year += 1900; \ | |
36 | res.tm_mon += 1; \ | |
37 | count = scnprintf(buf, PAGE_SIZE, \ | |
38 | "%ld-%.2d-%.2d %.2d:%.2d:%.2d\n", \ | |
39 | res.tm_year, res.tm_mon, res.tm_mday, \ | |
40 | res.tm_hour, res.tm_min, res.tm_sec);\ | |
41 | count; \ | |
42 | }) | |
43 | ||
44 | /************************************************************************ | |
45 | * NILFS feature attrs * | |
46 | ************************************************************************/ | |
47 | ||
48 | static ssize_t nilfs_feature_revision_show(struct kobject *kobj, | |
49 | struct attribute *attr, char *buf) | |
50 | { | |
51 | return snprintf(buf, PAGE_SIZE, "%d.%d\n", | |
52 | NILFS_CURRENT_REV, NILFS_MINOR_REV); | |
53 | } | |
54 | ||
55 | static const char features_readme_str[] = | |
56 | "The features group contains attributes that describe NILFS file\n" | |
57 | "system driver features.\n\n" | |
58 | "(1) revision\n\tshow current revision of NILFS file system driver.\n"; | |
59 | ||
60 | static ssize_t nilfs_feature_README_show(struct kobject *kobj, | |
61 | struct attribute *attr, | |
62 | char *buf) | |
63 | { | |
64 | return snprintf(buf, PAGE_SIZE, features_readme_str); | |
65 | } | |
66 | ||
67 | NILFS_FEATURE_RO_ATTR(revision); | |
68 | NILFS_FEATURE_RO_ATTR(README); | |
69 | ||
70 | static struct attribute *nilfs_feature_attrs[] = { | |
71 | NILFS_FEATURE_ATTR_LIST(revision), | |
72 | NILFS_FEATURE_ATTR_LIST(README), | |
73 | NULL, | |
74 | }; | |
75 | ||
76 | static const struct attribute_group nilfs_feature_attr_group = { | |
77 | .name = "features", | |
78 | .attrs = nilfs_feature_attrs, | |
79 | }; | |
80 | ||
81 | int __init nilfs_sysfs_init(void) | |
82 | { | |
83 | int err; | |
84 | ||
85 | nilfs_kset = kset_create_and_add(NILFS_ROOT_GROUP_NAME, NULL, fs_kobj); | |
86 | if (!nilfs_kset) { | |
87 | err = -ENOMEM; | |
88 | printk(KERN_ERR "NILFS: unable to create sysfs entry: err %d\n", | |
89 | err); | |
90 | goto failed_sysfs_init; | |
91 | } | |
92 | ||
93 | err = sysfs_create_group(&nilfs_kset->kobj, &nilfs_feature_attr_group); | |
94 | if (unlikely(err)) { | |
95 | printk(KERN_ERR "NILFS: unable to create feature group: err %d\n", | |
96 | err); | |
97 | goto cleanup_sysfs_init; | |
98 | } | |
99 | ||
100 | return 0; | |
101 | ||
102 | cleanup_sysfs_init: | |
103 | kset_unregister(nilfs_kset); | |
104 | ||
105 | failed_sysfs_init: | |
106 | return err; | |
107 | } | |
108 | ||
109 | void nilfs_sysfs_exit(void) | |
110 | { | |
111 | sysfs_remove_group(&nilfs_kset->kobj, &nilfs_feature_attr_group); | |
112 | kset_unregister(nilfs_kset); | |
113 | } |