/* *************************************************************************** * Read stats from the sysfs filesystem for the devices entered on the * command line. * * IN: * @curr Index in array for current sample statistics. *************************************************************************** */ void read_sysfs_dlist_stat(int curr) { int dev, ok; char filename[MAX_PF_NAME]; char *slash; struct io_dlist *st_dev_list_i; /* Every I/O device (or partition) is potentially unregistered */ set_entries_unregistered(iodev_nr, st_hdr_iodev); for (dev = 0; dev < dlist_idx; dev++) { st_dev_list_i = st_dev_list + dev; /* Some devices may have a slash in their name (eg. cciss/c0d0...) */ while ((slash = strchr(st_dev_list_i->dev_name, '/'))) { *slash = '!'; } snprintf(filename, MAX_PF_NAME, "%s/%s/%s", SYSFS_BLOCK, st_dev_list_i->dev_name, S_STAT); filename[MAX_PF_NAME - 1] = '\0'; /* Read device stats */ ok = read_sysfs_file_stat(curr, filename, st_dev_list_i->dev_name); if (ok && st_dev_list_i->disp_part) { /* Also read stats for its partitions */ read_sysfs_dlist_part_stat(curr, st_dev_list_i->dev_name); } } /* Free structures corresponding to unregistered devices */ free_unregistered_entries(iodev_nr, st_hdr_iodev); }
/* *************************************************************************** * Read stats from the sysfs filesystem * for the devices entered on the command line *************************************************************************** */ void read_sysfs_dlist_stat(int curr, int flags) { int dev, ok; char filename[MAX_PF_NAME]; struct io_dlist *st_dev_list_i; /* Every I/O device (or partition) is potentially unregistered */ set_entries_inactive(iodev_nr); for (dev = 0; dev < dlist_idx; dev++) { st_dev_list_i = st_dev_list + dev; sprintf(filename, "%s/%s/%s", SYSFS_BLOCK, st_dev_list_i->dev_name, S_STAT); /* Read device stats */ ok = read_sysfs_file_stat(curr, filename, st_dev_list_i->dev_name, DT_DEVICE); if (ok && st_dev_list_i->disp_part) /* Also read stats for its partitions */ read_sysfs_dlist_part_stat(curr, st_dev_list_i->dev_name); } /* Free structures corresponding to unregistered devices */ free_inactive_entries(iodev_nr); }
/* *************************************************************************** * Read stats from the sysfs filesystem for every block devices found. * * IN: * @curr Index in array for current sample statistics. *************************************************************************** */ void read_sysfs_stat(int curr) { DIR *dir; struct dirent *drd; char filename[MAX_PF_NAME]; int ok; /* Every I/O device entry is potentially unregistered */ set_entries_unregistered(iodev_nr, st_hdr_iodev); /* Open /sys/block directory */ if ((dir = opendir(SYSFS_BLOCK)) != NULL) { /* Get current entry */ while ((drd = readdir(dir)) != NULL) { if (!strcmp(drd->d_name, ".") || !strcmp(drd->d_name, "..")) continue; snprintf(filename, MAX_PF_NAME, "%s/%s/%s", SYSFS_BLOCK, drd->d_name, S_STAT); filename[MAX_PF_NAME - 1] = '\0'; /* If current entry is a directory, try to read its stat file */ ok = read_sysfs_file_stat(curr, filename, drd->d_name); /* * If '-p ALL' was entered on the command line, * also try to read stats for its partitions */ if (ok && DISPLAY_PART_ALL(flags)) { read_sysfs_dlist_part_stat(curr, drd->d_name); } } /* Close /sys/block directory */ closedir(dir); } /* Free structures corresponding to unregistered devices */ free_unregistered_entries(iodev_nr, st_hdr_iodev); }