aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/staging/zram/zram_sysfs.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/staging/zram/zram_sysfs.c')
-rw-r--r--drivers/staging/zram/zram_sysfs.c40
1 files changed, 38 insertions, 2 deletions
diff --git a/drivers/staging/zram/zram_sysfs.c b/drivers/staging/zram/zram_sysfs.c
index a70cc01..8a23554 100644
--- a/drivers/staging/zram/zram_sysfs.c
+++ b/drivers/staging/zram/zram_sysfs.c
@@ -35,7 +35,7 @@ static struct zram *dev_to_zram(struct device *dev)
struct zram *zram = NULL;
for (i = 0; i < num_devices; i++) {
- zram = &devices[i];
+ zram = &zram_devices[i];
if (disk_to_dev(zram->disk) == dev)
break;
}
@@ -80,6 +80,42 @@ static ssize_t initstate_show(struct device *dev,
return sprintf(buf, "%u\n", zram->init_done);
}
+#ifdef CONFIG_ZRAM_FOR_ANDROID
+extern int swapon(const char*specialfile, int swap_flags);
+
+static ssize_t initstate_store(struct device *dev,
+ struct device_attribute *attr, const char *buf,
+ size_t len)
+{
+ int ret;
+ unsigned long do_init;
+ struct zram *zram = dev_to_zram(dev);
+
+ if (zram->init_done) {
+ pr_info("the device is initialized device\n");
+ return -EBUSY;
+ }
+
+ ret = strict_strtoul(buf, 10, &do_init);
+ if (ret)
+ return ret;
+ if (!do_init)
+ return -EINVAL;
+
+ zram_init_device(zram);
+ swapon("/dev/block/zram0", 0);
+ return len;
+}
+#else
+static inline ssize_t initstate_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t len)
+{
+ return 0;
+}
+#endif /* CONFIG_ZRAM_FOR_ANDROID */
+
+
static ssize_t reset_store(struct device *dev,
struct device_attribute *attr, const char *buf, size_t len)
{
@@ -190,7 +226,7 @@ static ssize_t mem_used_total_show(struct device *dev,
static DEVICE_ATTR(disksize, S_IRUGO | S_IWUSR,
disksize_show, disksize_store);
-static DEVICE_ATTR(initstate, S_IRUGO, initstate_show, NULL);
+static DEVICE_ATTR(initstate, S_IRUGO | S_IWUSR, initstate_show, initstate_store);
static DEVICE_ATTR(reset, S_IWUSR, NULL, reset_store);
static DEVICE_ATTR(num_reads, S_IRUGO, num_reads_show, NULL);
static DEVICE_ATTR(num_writes, S_IRUGO, num_writes_show, NULL);