2 * sysfs.c - sysfs support implementation.
4 * Copyright (C) 2005-2014 Nippon Telegraph and Telephone Corporation.
5 * Copyright (C) 2014 HGST, Inc., a Western Digital Company.
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.
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.
17 * Written by Vyacheslav Dubeyko <Vyacheslav.Dubeyko@hgst.com>
20 #include <linux/kobject.h>
28 /* /sys/fs/<nilfs>/ */
29 static struct kset *nilfs_kset;
31 #define NILFS_SHOW_TIME(time_t_val, buf) ({ \
34 time_to_tm(time_t_val, 0, &res); \
35 res.tm_year += 1900; \
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);\
44 /************************************************************************
45 * NILFS feature attrs *
46 ************************************************************************/
48 static ssize_t nilfs_feature_revision_show(struct kobject *kobj,
49 struct attribute *attr, char *buf)
51 return snprintf(buf, PAGE_SIZE, "%d.%d\n",
52 NILFS_CURRENT_REV, NILFS_MINOR_REV);
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";
60 static ssize_t nilfs_feature_README_show(struct kobject *kobj,
61 struct attribute *attr,
64 return snprintf(buf, PAGE_SIZE, features_readme_str);
67 NILFS_FEATURE_RO_ATTR(revision);
68 NILFS_FEATURE_RO_ATTR(README);
70 static struct attribute *nilfs_feature_attrs[] = {
71 NILFS_FEATURE_ATTR_LIST(revision),
72 NILFS_FEATURE_ATTR_LIST(README),
76 static const struct attribute_group nilfs_feature_attr_group = {
78 .attrs = nilfs_feature_attrs,
81 int __init nilfs_sysfs_init(void)
85 nilfs_kset = kset_create_and_add(NILFS_ROOT_GROUP_NAME, NULL, fs_kobj);
88 printk(KERN_ERR "NILFS: unable to create sysfs entry: err %d\n",
90 goto failed_sysfs_init;
93 err = sysfs_create_group(&nilfs_kset->kobj, &nilfs_feature_attr_group);
95 printk(KERN_ERR "NILFS: unable to create feature group: err %d\n",
97 goto cleanup_sysfs_init;
103 kset_unregister(nilfs_kset);
109 void nilfs_sysfs_exit(void)
111 sysfs_remove_group(&nilfs_kset->kobj, &nilfs_feature_attr_group);
112 kset_unregister(nilfs_kset);