block: export 'ro' sysfs attribute for partitions
[pandora-kernel.git] / fs / partitions / check.c
index 72c5265..861ae84 100644 (file)
@@ -164,10 +164,16 @@ check_partition(struct gendisk *hd, struct block_device *bdev)
        state = kzalloc(sizeof(struct parsed_partitions), GFP_KERNEL);
        if (!state)
                return NULL;
+       state->pp_buf = (char *)__get_free_page(GFP_KERNEL);
+       if (!state->pp_buf) {
+               kfree(state);
+               return NULL;
+       }
+       state->pp_buf[0] = '\0';
 
        state->bdev = bdev;
        disk_name(hd, 0, state->name);
-       printk(KERN_INFO " %s:", state->name);
+       snprintf(state->pp_buf, PAGE_SIZE, " %s:", state->name);
        if (isdigit(state->name[strlen(state->name)-1]))
                sprintf(state->name, "p");
 
@@ -185,17 +191,25 @@ check_partition(struct gendisk *hd, struct block_device *bdev)
                }
 
        }
-       if (res > 0)
+       if (res > 0) {
+               printk(KERN_INFO "%s", state->pp_buf);
+
+               free_page((unsigned long)state->pp_buf);
                return state;
+       }
        if (state->access_beyond_eod)
                err = -ENOSPC;
        if (err)
        /* The partition is unrecognized. So report I/O errors if there were any */
                res = err;
        if (!res)
-               printk(" unknown partition table\n");
+               strlcat(state->pp_buf, " unknown partition table\n", PAGE_SIZE);
        else if (warn_no_part)
-               printk(" unable to read partition table\n");
+               strlcat(state->pp_buf, " unable to read partition table\n", PAGE_SIZE);
+
+       printk(KERN_INFO "%s", state->pp_buf);
+
+       free_page((unsigned long)state->pp_buf);
        kfree(state);
        return ERR_PTR(res);
 }
@@ -223,6 +237,13 @@ ssize_t part_size_show(struct device *dev,
        return sprintf(buf, "%llu\n",(unsigned long long)p->nr_sects);
 }
 
+ssize_t part_ro_show(struct device *dev,
+                      struct device_attribute *attr, char *buf)
+{
+       struct hd_struct *p = dev_to_part(dev);
+       return sprintf(buf, "%d\n", p->policy ? 1 : 0);
+}
+
 ssize_t part_alignment_offset_show(struct device *dev,
                                   struct device_attribute *attr, char *buf)
 {
@@ -298,6 +319,7 @@ ssize_t part_fail_store(struct device *dev,
 static DEVICE_ATTR(partition, S_IRUGO, part_partition_show, NULL);
 static DEVICE_ATTR(start, S_IRUGO, part_start_show, NULL);
 static DEVICE_ATTR(size, S_IRUGO, part_size_show, NULL);
+static DEVICE_ATTR(ro, S_IRUGO, part_ro_show, NULL);
 static DEVICE_ATTR(alignment_offset, S_IRUGO, part_alignment_offset_show, NULL);
 static DEVICE_ATTR(discard_alignment, S_IRUGO, part_discard_alignment_show,
                   NULL);
@@ -312,6 +334,7 @@ static struct attribute *part_attrs[] = {
        &dev_attr_partition.attr,
        &dev_attr_start.attr,
        &dev_attr_size.attr,
+       &dev_attr_ro.attr,
        &dev_attr_alignment_offset.attr,
        &dev_attr_discard_alignment.attr,
        &dev_attr_stat.attr,