static int get_emmc0_cid(void) { struct device *emmc_disk; /* * Automation people are needing proper serial number for ADB * lets derivate from the serial number of the emmc card. */ emmc_disk = class_find_device(&block_class, NULL, NULL, mmcblk0_match); if (emmc_disk) { struct gendisk *disk = dev_to_disk(emmc_disk); struct mmc_card *card = mmc_dev_to_card(disk->driverfs_dev); if (card) { cid_legacy.manfid = card->cid.manfid; cid_legacy.prod_name[0] = card->cid.prod_name[0]; cid_legacy.prod_name[1] = card->cid.prod_name[1]; cid_legacy.prod_name[2] = card->cid.prod_name[2]; cid_legacy.prod_name[3] = card->cid.prod_name[3]; cid_legacy.prod_name[4] = card->cid.prod_name[4]; cid_legacy.prod_name[5] = card->cid.prod_name[5]; cid_legacy.prod_name[6] = card->cid.prod_name[6]; cid_legacy.prod_name[7] = card->cid.prod_name[7]; cid_legacy.serial = card->cid.serial; cid_legacy.oemid = card->cid.oemid; cid_legacy.year = card->cid.year; cid_legacy.hwrev = card->cid.hwrev; cid_legacy.fwrev = card->cid.fwrev; cid_legacy.month = card->cid.month; snprintf(emmc0_id, sizeof(emmc0_id), "Medfield%08X", jhash(&cid_legacy, sizeof(cid_legacy), 0)); return 1; } } return 0; }
static struct block_device *get_emmc_bdev(void) { struct block_device *bdev; struct device *emmc_disk; emmc_disk = class_find_device(&block_class, NULL, NULL, mmcblk0boot0_match); if (emmc_disk == 0) { pr_err("emmc not found!\n"); return NULL; } /* partition 0 means raw disk */ bdev = bdget_disk(dev_to_disk(emmc_disk), 0); if (bdev == NULL) { dev_err(emmc_disk, "unable to get disk\n"); return NULL; } /* Note: this bdev ref will be freed after first * bdev_get/bdev_put cycle */ return bdev; }
/******************************************************************** * /sys/block/srb?/ * srb_debug Sets verbosity * srb_urls Gets device CDMI url * srb_name Gets device's on-storage filename * srb_size Gets device size *******************************************************************/ static ssize_t attr_debug_store(struct device *dv, struct device_attribute *attr, const char *buff, size_t count) { struct gendisk *disk = dev_to_disk(dv); struct srb_device_s *dev = disk->private_data; long int val; int ret; ret = kstrtol(buff, 10, &val); if (ret < 0) { SRBDEV_LOG_WARN(dev, "Invalid debug value"); return ret; } if ((int)val < 0 || (int)val > 7) { SRBDEV_LOG_WARN(dev, "Invalid debug value (%d) for device %s in sysfs", (int)val, dev->name); return -EINVAL; } dev->debug.level = (int)val; SRBDEV_LOG_DEBUG(dev, "Setting Log level to %d for device %s", (int)val, dev->name); return count; }
/* firmware version */ static ssize_t aoedisk_show_fwver(struct device *dev, struct device_attribute *attr, char *page) { struct gendisk *disk = dev_to_disk(dev); struct aoedev *d = disk->private_data; return snprintf(page, PAGE_SIZE, "0x%04x\n", (unsigned int) d->fw_ver); }
ssize_t part_timeout_show(struct device *dev, struct device_attribute *attr, char *buf) { struct gendisk *disk = dev_to_disk(dev); int set = test_bit(QUEUE_FLAG_FAIL_IO, &disk->queue->queue_flags); return sprintf(buf, "%d\n", set != 0); }
static ssize_t aoedisk_show_payload(struct device *dev, struct device_attribute *attr, char *page) { struct gendisk *disk = dev_to_disk(dev); struct aoedev *d = disk->private_data; return snprintf(page, PAGE_SIZE, "%lu\n", d->maxbcnt); }
static ssize_t attr_disk_size_show(struct device *dv, struct device_attribute *attr, char *buff) { struct gendisk *disk = dev_to_disk(dv); struct srb_device_s *dev = disk->private_data; return scnprintf(buff, PAGE_SIZE, "%llu\n", dev->disk_size); }
static ssize_t attr_disk_name_show(struct device *dv, struct device_attribute *attr, char *buff) { struct gendisk *disk = dev_to_disk(dv); struct srb_device_s *dev = disk->private_data; //snprintf(buff, PAGE_SIZE, "%s\n", kbasename(dev->thread_cdmi_desc[0].url)); return scnprintf(buff, PAGE_SIZE, "%s\n", kbasename(dev->thread_cdmi_desc[0]->url)); }
static ssize_t aoedisk_show_mac(struct device *dev, struct device_attribute *attr, char *page) { struct gendisk *disk = dev_to_disk(dev); struct aoedev *d = disk->private_data; struct aoetgt *t = d->targets[0]; if (t == NULL) return snprintf(page, PAGE_SIZE, "none\n"); return snprintf(page, PAGE_SIZE, "%pm\n", t->addr); }
static ssize_t aoedisk_show_state(struct device *dev, struct device_attribute *attr, char *page) { struct gendisk *disk = dev_to_disk(dev); struct aoedev *d = disk->private_data; return snprintf(page, PAGE_SIZE, "%s%s\n", (d->flags & DEVFL_UP) ? "up" : "down", (d->flags & DEVFL_KICKME) ? ",kickme" : (d->nopen && !(d->flags & DEVFL_UP)) ? ",closewait" : ""); /* I'd rather see nopen exported so we can ditch closewait */ }
ssize_t part_timeout_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct gendisk *disk = dev_to_disk(dev); int val; if (count) { struct request_queue *q = disk->queue; char *p = (char *) buf; val = simple_strtoul(p, &p, 10); spin_lock_irq(q->queue_lock); if (val) queue_flag_set(QUEUE_FLAG_FAIL_IO, q); else queue_flag_clear(QUEUE_FLAG_FAIL_IO, q); spin_unlock_irq(q->queue_lock); } return count; }
static ssize_t aoedisk_show_netif(struct device *dev, struct device_attribute *attr, char *page) { struct gendisk *disk = dev_to_disk(dev); struct aoedev *d = disk->private_data; struct net_device *nds[8], **nd, **nnd, **ne; struct aoetgt **t, **te; struct aoeif *ifp, *e; char *p; memset(nds, 0, sizeof nds); nd = nds; ne = nd + ARRAY_SIZE(nds); t = d->targets; te = t + NTARGETS; for (; t < te && *t; t++) { ifp = (*t)->ifs; e = ifp + NAOEIFS; for (; ifp < e && ifp->nd; ifp++) { for (nnd = nds; nnd < nd; nnd++) if (*nnd == ifp->nd) break; if (nnd == nd && nd != ne) *nd++ = ifp->nd; } } ne = nd; nd = nds; if (*nd == NULL) return snprintf(page, PAGE_SIZE, "none\n"); for (p = page; nd < ne; nd++) p += snprintf(p, PAGE_SIZE - (p-page), "%s%s", p == page ? "" : ",", (*nd)->name); p += snprintf(p, PAGE_SIZE - (p-page), "\n"); return p-page; }
void show_gend(void) { struct class_dev_iter iter; struct device *dev; class_dev_iter_init(&iter, my_block_class, NULL, my_disk_type); // struct class_dev_iter { // [0] struct klist_iter ki; // [16] const struct device_type *type; //} //printk("iter %p iter.ki %p i_klist %p i_cur %p\n", // &iter, iter.ki, iter.ki.i_klist, iter.ki.i_cur); while ((dev = my_class_dev_iter_next(&iter))) { struct gendisk *disk = dev_to_disk(dev); struct disk_part_iter piter; struct hd_struct *part; char name_buf[BDEVNAME_SIZE]; char devt_buf[BDEVT_SIZE]; char uuid_buf[PARTITION_META_INFO_UUIDLTH * 2 + 5]; // printk("gen %p name %s\n", disk, disk->disk_name); /* * Don't show empty devices or things that have been * suppressed */ if (get_capacity(disk) == 0 || (disk->flags & GENHD_FL_SUPPRESS_PARTITION_INFO)) continue; // James: we only want to verify 'sda' if (strcmp(disk->disk_name, "sda") != 0) continue; /* * Note, unlike /proc/partitions, I am showing the * numbers in hex - the same format as the root= * option takes. */ disk_part_iter_init(&piter, disk, DISK_PITER_INCL_PART0); printk("gen %p name %s\n disk_part_tbl %p ", disk, disk->disk_name, disk->part_tbl); while ((part = disk_part_iter_next(&piter))) { bool is_part0 = part == &disk->part0; printk("part %p\n", part); uuid_buf[0] = '\0'; if (part->info) snprintf(uuid_buf, sizeof(uuid_buf), "%pU", part->info->uuid); printk("%s%s %10llu %s %s", is_part0 ? "" : " ", bdevt_str(part_devt(part), devt_buf), (unsigned long long)part->nr_sects >> 1, disk_name(disk, part->partno, name_buf), uuid_buf); if (is_part0) { if (disk->driverfs_dev != NULL && disk->driverfs_dev->driver != NULL) printk(" driver: %s\n", disk->driverfs_dev->driver->name); else printk(" (driver?)\n"); } else printk("\n"); } disk_part_iter_exit(&piter); } class_dev_iter_exit(&iter); }
static inline struct zram *dev_to_zram(struct device *dev) { return (struct zram *)dev_to_disk(dev)->private_data; }