コード例 #1
0
ファイル: genhd.c プロジェクト: andreiw/mkunity
static void add_partition (struct gendisk *hd, int minor, int start, int size)
{
	char buf[8];
	hd->part[minor].start_sect = start;
	hd->part[minor].nr_sects   = size;
	printk(" %s", disk_name(hd, minor, buf));
}
コード例 #2
0
ファイル: ahci-alpm.c プロジェクト: XVilka/powertop
static char *model_name(char *path, char *shortname)
{

	DIR *dir;
	struct dirent *dirent;
	char pathname[PATH_MAX];

	sprintf(pathname, "%s/device", path);

	dir = opendir(pathname);
	if (!dir)
		return strdup(shortname);
		
	while ((dirent = readdir(dir))) {
		if (dirent->d_name[0]=='.')
			continue;

		if (!strchr(dirent->d_name, ':'))
			continue;
		if (!strstr(dirent->d_name, "target"))
			continue;
		return disk_name(pathname, dirent->d_name, shortname);
	}
	closedir(dir);
	
	return strdup(shortname);
}
コード例 #3
0
struct parsed_partitions *
check_partition(struct gendisk *hd, struct block_device *bdev)
{
	struct parsed_partitions *state;
	int i, res, err;

	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);
	snprintf(state->pp_buf, PAGE_SIZE, " %s:", state->name);
	if (isdigit(state->name[strlen(state->name)-1]))
		sprintf(state->name, "p");

	state->limit = disk_max_parts(hd);
	i = res = err = 0;
	while (!res && check_part[i]) {
		memset(&state->parts, 0, sizeof(state->parts));
		res = check_part[i++](state);
		if (res < 0) {
			/* We have hit an I/O error which we don't report now.
		 	* But record it, and let the others do their job.
		 	*/
			err = res;
			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)
		strlcat(state->pp_buf, " unknown partition table\n", PAGE_SIZE);
	else if (warn_no_part)
		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);
}
コード例 #4
0
ファイル: msdos.c プロジェクト: liexusong/Linux-2.4.16
	*partition_name (struct gendisk *hd, int minor, char *buf)
{
#ifdef CONFIG_DEVFS_FS
	sprintf(buf, "p%d", (minor & ((1 << hd->minor_shift) - 1)));
	return buf;
#else
	return disk_name(hd, minor, buf);
#endif
}
コード例 #5
0
ファイル: check.c プロジェクト: xricson/knoppix
/*
 * NOTE: this cannot be called from interrupt context.
 *
 * But in interrupt context you should really have a struct
 * block_device anyway and use bdevname() above.
 */
const char *__bdevname(dev_t dev, char *buffer)
{
	struct gendisk *disk;
	int part;

	disk = get_gendisk(dev, &part);
	if (disk) {
		buffer = disk_name(disk, part, buffer);
		put_disk(disk);
	} else {
		snprintf(buffer, BDEVNAME_SIZE, "unknown-block(%u,%u)",
				MAJOR(dev), MINOR(dev));
	}

	return buffer;
}
コード例 #6
0
ファイル: check.c プロジェクト: NikhilNJ/screenplay-dx
static struct parsed_partitions *
check_partition(struct gendisk *hd, struct block_device *bdev)
{
	struct parsed_partitions *state;
	int i, res, err;

	state = kmalloc(sizeof(struct parsed_partitions), GFP_KERNEL);
	if (!state)
		return NULL;

	disk_name(hd, 0, state->name);
	printk(KERN_INFO " %s:", state->name);
	if (isdigit(state->name[strlen(state->name)-1]))
		sprintf(state->name, "p");

	state->limit = hd->minors;
	i = res = err = 0;
	while (!res && check_part[i]) {
		memset(&state->parts, 0, sizeof(state->parts));
		res = check_part[i++](state, bdev);
		if (res < 0) {
			/* We have hit an I/O error which we don't report now.
		 	* But record it, and let the others do their job.
		 	*/
			err = res;
			res = 0;
		}

	}
	if (res > 0)
		return state;
	if (err)
	/* The partition is unrecognized. So report I/O errors if there were any */
		res = err;
	if (!res)
		printk(" unknown partition table\n");
	else if (warn_no_part)
		printk(" unable to read partition table\n");
	kfree(state);
	return ERR_PTR(res);
}
コード例 #7
0
ファイル: genhd.c プロジェクト: andreiw/mkunity
static void check_partition(struct gendisk *hd, kdev_t dev)
{
	static int first_time = 1;
	unsigned long first_sector;
	char buf[8];

	if (first_time)
		printk("Partition check:\n");
	first_time = 0;
	first_sector = hd->part[MINOR(dev)].start_sect;

	/*
	 * This is a kludge to allow the partition check to be
	 * skipped for specific drives (e.g. IDE cd-rom drives)
	 */
	if ((int)first_sector == -1) {
		hd->part[MINOR(dev)].start_sect = 0;
		return;
	}

	printk(" %s:", disk_name(hd, MINOR(dev), buf));
#ifdef CONFIG_MSDOS_PARTITION
	if (msdos_partition(hd, dev, first_sector))
		return;
#endif
#ifdef CONFIG_OSF_PARTITION
	if (osf_partition(hd, dev, first_sector))
		return;
#endif
#ifdef CONFIG_SUN_PARTITION
	if(sun_partition(hd, dev, first_sector))
		return;
#endif
#ifdef CONFIG_AMIGA_PARTITION
	if(amiga_partition(hd, dev, first_sector))
		return;
#endif
	printk(" unknown partition table\n");
}
コード例 #8
0
ファイル: check.c プロジェクト: xricson/knoppix
static struct parsed_partitions *
check_partition(struct gendisk *hd, struct block_device *bdev)
{
	struct parsed_partitions *state;
	int i, res;

	state = kmalloc(sizeof(struct parsed_partitions), GFP_KERNEL);
	if (!state)
		return NULL;

#ifdef CONFIG_DEVFS_FS
	if (hd->devfs_name[0] != '\0') {
		printk(KERN_INFO " /dev/%s:", hd->devfs_name);
		sprintf(state->name, "p");
	}
#endif
	else {
		disk_name(hd, 0, state->name);
		printk(KERN_INFO " %s:", state->name);
		if (isdigit(state->name[strlen(state->name)-1]))
			sprintf(state->name, "p");
	}
	state->limit = hd->minors;
	i = res = 0;
	while (!res && check_part[i]) {
		memset(&state->parts, 0, sizeof(state->parts));
		res = check_part[i++](state, bdev);
	}
	if (res > 0)
		return state;
	if (!res)
		printk(" unknown partition table\n");
	else if (warn_no_part)
		printk(" unable to read partition table\n");
	kfree(state);
	return NULL;
}
コード例 #9
0
ファイル: genhd.c プロジェクト: niubl/camera_project
int
get_partition_list(char *page, char **start, off_t offset, int count)
{
    struct gendisk *gp;
    struct hd_struct *hd;
    char buf[64];
    int len, n;

    len = sprintf(page, "major minor  #blocks  name\n\n");

    read_lock(&gendisk_lock);
    for (gp = gendisk_head; gp; gp = gp->next) {
        for (n = 0; n < (gp->nr_real << gp->minor_shift); n++) {
            if (gp->part[n].nr_sects == 0)
                continue;

            hd = &gp->part[n];
            disk_round_stats(hd);
            len += sprintf(page + len,
                           "%4d  %4d %10d %s\n", gp->major,
                           n, gp->sizes[n], disk_name(gp, n, buf));

            if (len < offset)
                offset -= len, len = 0;
            else if (len >= offset + count)
                goto out;
        }
    }

out:
    read_unlock(&gendisk_lock);
    *start = page + offset;
    len -= offset;
    if (len < 0)
        len = 0;
    return len > count ? count : len;
}
コード例 #10
0
ファイル: check.c プロジェクト: xricson/knoppix
const char *bdevname(struct block_device *bdev, char *buf)
{
	int part = MINOR(bdev->bd_dev) - bdev->bd_disk->first_minor;
	return disk_name(bdev->bd_disk, part, buf);
}
コード例 #11
0
ファイル: hd-idle.c プロジェクト: Duckbox-Developers/apps
/* main function */
int main(int argc, char *argv[])
{
	IDLE_TIME *it;
	int have_logfile = 0;
	int min_idle_time;
	int sleep_time;
	int opt;

	/* create default idle-time parameter entry */
	if ((it = malloc(sizeof(*it))) == NULL)
	{
		fprintf(stderr, "out of memory\n");
		exit(1);
	}
	it->next = NULL;
	it->name = NULL;
	it->idle_time = DEFAULT_IDLE_TIME;
	it_root = it;

	/* process command line options */
	while ((opt = getopt(argc, argv, "t:a:i:l:dh")) != -1)
	{
		switch (opt)
		{

			case 't':
				/* just spin-down the specified disk and exit */
				spindown_disk(optarg);
				return (0);

			case 'a':
				/* add a new set of idle-time parameters for this particular disk */
				if ((it = malloc(sizeof(*it))) == NULL)
				{
					fprintf(stderr, "out of memory\n");
					return (2);
				}
				it->name = disk_name(optarg);
				it->idle_time = DEFAULT_IDLE_TIME;
				it->next = it_root;
				it_root = it;
				break;

			case 'i':
				/* set idle-time parameters for current (or default) disk */
				it->idle_time = atoi(optarg);
				break;

			case 'l':
				logfile = optarg;
				have_logfile = 1;
				break;

			case 'd':
				debug = 1;
				break;

			case 'h':
				printf("usage: hd-idle [-t <disk>] [-a <name>] [-i <idle_time>] [-l <logfile>] [-d] [-h]\n");
				return (0);

			case ':':
				fprintf(stderr, "error: option -%c requires an argument\n", optopt);
				return (1);

			case '?':
				fprintf(stderr, "error: unknown option -%c\n", optopt);
				return (1);
		}
	}

	/* set sleep time to 1/10th of the shortest idle time */
	min_idle_time = 1 << 30;
	for (it = it_root; it != NULL; it = it->next)
	{
		if (it->idle_time != 0 && it->idle_time < min_idle_time)
		{
			min_idle_time = it->idle_time;
		}
	}
	if ((sleep_time = min_idle_time / 10) == 0)
	{
		sleep_time = 1;
	}

	/* daemonize unless we're running in debug mode */
	if (!debug)
	{
		daemonize();
	}

	/* main loop: probe for idle disks and stop them */
	for (;;)
	{
		DISKSTATS tmp;
		FILE *fp;
		char buf[200];

		if ((fp = fopen(STAT_FILE, "r")) == NULL)
		{
			perror(STAT_FILE);
			return (2);
		}

		memset(&tmp, 0x00, sizeof(tmp));

		while (fgets(buf, sizeof(buf), fp) != NULL)
		{
			if (sscanf(buf, "%*d %*d %s %*u %*u %u %*u %*u %*u %u %*u %*u %*u %*u",
					tmp.name, &tmp.reads, &tmp.writes) == 3)
			{
				DISKSTATS *ds;
				time_t now = time(NULL);

				/* make sure this is a SCSI disk (sd[a-z]) */
				if (tmp.name[0] != 's' ||
						tmp.name[1] != 'd' ||
						!isalpha(tmp.name[2]) ||
						tmp.name[3] != '\0')
				{
					continue;
				}

				dprintf("probing %s: reads: %u, writes: %u\n", tmp.name, tmp.reads, tmp.writes);

				/* get previous statistics for this disk */
				ds = get_diskstats(tmp.name);

				if (ds == NULL)
				{
					/* new disk; just add it to the linked list */
					if ((ds = malloc(sizeof(*ds))) == NULL)
					{
						fprintf(stderr, "out of memory\n");
						return (2);
					}
					memcpy(ds, &tmp, sizeof(*ds));
					ds->last_io = now;
					ds->spinup = ds->last_io;
					ds->next = ds_root;
					ds_root = ds;

					/* find idle time for this disk (falling-back to default; default means
					 * 'it->name == NULL' and this entry will always be the last due to the
					 * way this single-linked list is built when parsing command line
					 * arguments)
					 */
					for (it = it_root; it != NULL; it = it->next)
					{
						if (it->name == NULL || !strcmp(ds->name, it->name))
						{
							ds->idle_time = it->idle_time;
							break;
						}
					}

				}
				else if (ds->reads == tmp.reads && ds->writes == tmp.writes)
				{
					if (!ds->spun_down)
					{
						/* no activity on this disk and still running */
						if (ds->idle_time != 0 && now - ds->last_io >= ds->idle_time)
						{
							spindown_disk(ds->name);
							ds->spindown = now;
							ds->spun_down = 1;
						}
					}

				}
				else
				{
					/* disk had some activity */
					if (ds->spun_down)
					{
						/* disk was spun down, thus it has just spun up */
						if (have_logfile)
						{
							log_spinup(ds);
						}
						ds->spinup = now;
					}
					ds->reads = tmp.reads;
					ds->writes = tmp.writes;
					ds->last_io = now;
					ds->spun_down = 0;
				}
			}
		}

		fclose(fp);
		sleep(sleep_time);
	}

	return (0);
}
コード例 #12
0
ファイル: hdidle.c プロジェクト: fededim/openwrt-witi
int main(int argc, char *argv[])
{
	IDLE_TIME *it;
	int min_idle_time;
	int sleep_time;
	int opt;

	if ((it = malloc(sizeof(*it))) == NULL) {
		fprintf(stderr, "out of memory\n");
		exit(1);
	}
	it->next = NULL;
	it->name = NULL;
	it->idle_time = DEFAULT_IDLE_TIME;
	it_root = it;

	while ((opt = getopt(argc, argv, "t:a:i:l:dnhI")) != -1) {
		switch (opt) {

		case 't':
			spindown_disk(optarg);
			return(0);

		case 'a':
			if ((it = malloc(sizeof(*it))) == NULL) {
			fprintf(stderr, "out of memory\n");
			return(2);
			}
			it->name = disk_name(optarg);
			it->idle_time = DEFAULT_IDLE_TIME;
			it->next = it_root;
			it_root = it;
			break;

		case 'i':
			it->idle_time = atoi(optarg);
			break;

		case 'd':
			loglevel = LOG_DEBUG;
			break;

		case 'n':
			asdaemon = 0;
			break;

		case 'I':
			loglevel = LOG_DEBUG;
			usesyslog = 0;
			break;

		case 'h':
			printf("usage: hd-idle [-t <disk>] [-a <name>] [-i <idle_time>] [-d (debug) ]\n"
			       "               [-n (no daemon)] [-I (interactive)] [-h]\n");
			return(0);

		case ':':
			fprintf(stderr, "error: option -%c requires an argument\n", optopt);
			return(1);

		case '?':
			fprintf(stderr, "error: unknown option -%c\n", optopt);
			return(1);
		}
	}

	/* set sleep time to 1/10th of the shortest idle time */
	min_idle_time = 1 << 30;
	for (it = it_root; it != NULL; it = it->next) {
		if (it->idle_time != 0 && it->idle_time < min_idle_time) {
			min_idle_time = it->idle_time;
		}
	}
	if ((sleep_time = min_idle_time / 10) == 0) {
		sleep_time = 1;
	}

	if (asdaemon)
		daemonize();

	if (usesyslog)
		openlog("hdidle", LOG_PID, LOG_DAEMON);

	for (;;) {
		DISKSTATS tmp;
		char buf[200];
		FILE *fp;

		if ((fp = fopen(STAT_FILE, "r")) == NULL) {
			perror(STAT_FILE);
			return(2);
		}

		memset(&tmp, 0x00, sizeof(tmp));

		while (fgets(buf, sizeof(buf), fp) != NULL) {
			if (!(sscanf(buf, "%*d %*d %s %*u %*u %u %*u %*u %*u %u %*u %*u %*u %*u",
					tmp.name, &tmp.reads, &tmp.writes) == 3))
				continue;

			DISKSTATS *ds;
			time_t now = time(NULL);

			/* make sure this is a SCSI disk (sd[a-z]) */
			if (tmp.name[0] != 's' || tmp.name[1] != 'd' ||
				!isalpha(tmp.name[2]) || tmp.name[3] != '\0')
				continue;

			write_log(LOG_DEBUG, "probing %s: reads: %u, writes: %u",
					tmp.name, tmp.reads, tmp.writes);

			/* get previous statistics for this disk */
			ds = get_diskstats(tmp.name);

			if (ds == NULL) {
			/* new disk; just add it to the linked list */
				if ((ds = malloc(sizeof(*ds))) == NULL) {
					fprintf(stderr, "out of memory\n");
					return(2);
				}
				memcpy(ds, &tmp, sizeof(*ds));
				ds->last_io = now;
				ds->spinup = ds->last_io;
				ds->next = ds_root;
				ds_root = ds;

				/* find idle time for this disk (falling-back to default; default means
				* 'it->name == NULL' and this entry will always be the last due to the
				* way this single-linked list is built when parsing command line
				* arguments)
				*/
				for (it = it_root; it != NULL; it = it->next)
					if (it->name == NULL || !strcmp(ds->name, it->name)) {
						ds->idle_time = it->idle_time;
						write_log(LOG_INFO, "disk %s: standby timeout %u seconds",
									ds->name, ds->idle_time);
						break;
					}
				continue;
			}

			/* no activity */
			if (ds->reads == tmp.reads && ds->writes == tmp.writes) {
				if (ds->spun_down)
					continue;

				/* no activity on this disk and still running */
				if (ds->idle_time != 0 && now - ds->last_io >= ds->idle_time) {
					spindown_disk(ds->name);
					ds->spindown = now;
					ds->spun_down = 1;
				}
				continue;
			}


			ds->reads = tmp.reads;
			ds->writes = tmp.writes;
			ds->last_io = now;
			ds->spun_down = 0;
			if (!ds->spun_down)
				continue;

			/* disk was spun down, thus it has just spun up */
			write_log(LOG_INFO, "disk %s: spinup (running: %ld, stopped: %ld)",
			ds->name,
			(long) ds->spindown - (long) ds->spinup,
			(long) time(NULL) - (long) ds->spindown);
			ds->spinup = now;
		}

		fclose(fp);
		sleep(sleep_time);
	}

	return(0);
}
コード例 #13
0
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);
}
コード例 #14
0
ファイル: partition-generic.c プロジェクト: J0ngKwanPak/linux
const char *bdevname(struct block_device *bdev, char *buf)
{
	return disk_name(bdev->bd_disk, bdev->bd_part->partno, buf);
}