aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/ABI/testing/sysfs-fs-nilfs214
-rw-r--r--fs/nilfs2/sysfs.c113
-rw-r--r--fs/nilfs2/sysfs.h61
3 files changed, 188 insertions, 0 deletions
diff --git a/Documentation/ABI/testing/sysfs-fs-nilfs2 b/Documentation/ABI/testing/sysfs-fs-nilfs2
new file mode 100644
index 000000000000..71b4fd39f74d
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-fs-nilfs2
@@ -0,0 +1,14 @@
1
2What: /sys/fs/nilfs2/features/revision
3Date: April 2014
4Contact: "Vyacheslav Dubeyko" <slava@dubeyko.com>
5Description:
6 Show current revision of NILFS file system driver.
7 This value informs about file system revision that
8 driver is ready to support.
9
10What: /sys/fs/nilfs2/features/README
11Date: April 2014
12Contact: "Vyacheslav Dubeyko" <slava@dubeyko.com>
13Description:
14 Describe attributes of /sys/fs/nilfs2/features group.
diff --git a/fs/nilfs2/sysfs.c b/fs/nilfs2/sysfs.c
new file mode 100644
index 000000000000..41b8f7039657
--- /dev/null
+++ b/fs/nilfs2/sysfs.c
@@ -0,0 +1,113 @@
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>/ */
29static 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
48static 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
55static 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
60static 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
67NILFS_FEATURE_RO_ATTR(revision);
68NILFS_FEATURE_RO_ATTR(README);
69
70static struct attribute *nilfs_feature_attrs[] = {
71 NILFS_FEATURE_ATTR_LIST(revision),
72 NILFS_FEATURE_ATTR_LIST(README),
73 NULL,
74};
75
76static const struct attribute_group nilfs_feature_attr_group = {
77 .name = "features",
78 .attrs = nilfs_feature_attrs,
79};
80
81int __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
102cleanup_sysfs_init:
103 kset_unregister(nilfs_kset);
104
105failed_sysfs_init:
106 return err;
107}
108
109void nilfs_sysfs_exit(void)
110{
111 sysfs_remove_group(&nilfs_kset->kobj, &nilfs_feature_attr_group);
112 kset_unregister(nilfs_kset);
113}
diff --git a/fs/nilfs2/sysfs.h b/fs/nilfs2/sysfs.h
new file mode 100644
index 000000000000..0aed24661052
--- /dev/null
+++ b/fs/nilfs2/sysfs.h
@@ -0,0 +1,61 @@
1/*
2 * sysfs.h - sysfs support declarations.
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#ifndef _NILFS_SYSFS_H
21#define _NILFS_SYSFS_H
22
23#include <linux/sysfs.h>
24
25#define NILFS_ROOT_GROUP_NAME "nilfs2"
26
27#define NILFS_COMMON_ATTR_STRUCT(name) \
28struct nilfs_##name##_attr { \
29 struct attribute attr; \
30 ssize_t (*show)(struct kobject *, struct attribute *, \
31 char *); \
32 ssize_t (*store)(struct kobject *, struct attribute *, \
33 const char *, size_t); \
34};
35
36NILFS_COMMON_ATTR_STRUCT(feature);
37
38#define NILFS_ATTR(type, name, mode, show, store) \
39 static struct nilfs_##type##_attr nilfs_##type##_attr_##name = \
40 __ATTR(name, mode, show, store)
41
42#define NILFS_INFO_ATTR(type, name) \
43 NILFS_ATTR(type, name, 0444, NULL, NULL)
44#define NILFS_RO_ATTR(type, name) \
45 NILFS_ATTR(type, name, 0444, nilfs_##type##_##name##_show, NULL)
46#define NILFS_RW_ATTR(type, name) \
47 NILFS_ATTR(type, name, 0644, \
48 nilfs_##type##_##name##_show, \
49 nilfs_##type##_##name##_store)
50
51#define NILFS_FEATURE_INFO_ATTR(name) \
52 NILFS_INFO_ATTR(feature, name)
53#define NILFS_FEATURE_RO_ATTR(name) \
54 NILFS_RO_ATTR(feature, name)
55#define NILFS_FEATURE_RW_ATTR(name) \
56 NILFS_RW_ATTR(feature, name)
57
58#define NILFS_FEATURE_ATTR_LIST(name) \
59 (&nilfs_feature_attr_##name.attr)
60
61#endif /* _NILFS_SYSFS_H */