Hi. In sysfs there are already default attributes provided by the block layer (see drivers/block/genhd.c and fs/partitions/check.c). root@makki root# cat /sys/block/etherd\!e6.0/size 781422768 Those are sectors. Anyway, I can add more attributes, like this "state" attribute, which is either "up", "up,closewait", "down", or "down,closewait". root@makki root# cat /sys/block/etherd\!e6.0/state up I'm adding the attribute as shown below, but it means using a struct disk_attribute that is defined in genhd.c, which seems strange, since if this is the right way, I'd expect that struct to be in a header file. What is The Right Way to add attributes in sysfs to block devices? #include <linux/genhd.h> #include "aoe.h" /* add attributes for our block devices in sysfs */ struct disk_attribute { /* shouldn't this be in a kernel header? */ struct attribute attr; ssize_t (*show)(struct gendisk *, char *); }; static ssize_t aoedisk_show_state(struct gendisk * disk, char *page) { struct aoedev *d = disk->private_data; return snprintf(page, PAGE_SIZE, "%s%s\n", (d->flags & DEVFL_UP) ? "up" : "down", (d->flags & DEVFL_CLOSEWAIT) ? ",closewait" : ""); } static struct disk_attribute disk_attr_state = { .attr = {.name = "state", .mode = S_IRUGO }, .show = aoedisk_show_state }; /* called after add_disk */ static void aoeblk_add_sysfs(struct aoedev *d) { /* create all the sysfs files (just one now) */ sysfs_create_file(&d->gd->kobj, &disk_attr_state.attr); } /* called before del_gendisk */ void aoeblk_rm_sysfs(struct aoedev *d) { /* remove all the sysfs files (just one now) */ sysfs_remove_link(&d->gd->kobj, "state"); } -- Ed L Cashin <ecashin@xxxxxxxxxx> -- Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ FAQ: http://kernelnewbies.org/faq/