int main(int argc, char **argv)
{
	int fd, ret;
	struct sched_param param;

	if (argc == 1)
		ret = set_unload_heads_path("/dev/sda");
	else if (argc == 2)
		ret = set_unload_heads_path(argv[1]);
	else
		ret = -EINVAL;

	if (ret || !valid_disk()) {
		fprintf(stderr, "usage: %s <device> (default: /dev/sda)\n",
				argv[0]);
		exit(1);
	}

	fd = open("/dev/freefall", O_RDONLY);
	if (fd < 0) {
		perror("/dev/freefall");
		return EXIT_FAILURE;
	}

	daemon(0, 0);
	param.sched_priority = sched_get_priority_max(SCHED_FIFO);
	sched_setscheduler(0, SCHED_FIFO, &param);
	mlockall(MCL_CURRENT|MCL_FUTURE);

	signal(SIGALRM, ignore_me);

	for (;;) {
		unsigned char count;

		ret = read(fd, &count, sizeof(count));
		alarm(0);
		if ((ret == -1) && (errno == EINTR)) {
			/* Alarm expired, time to unpark the heads */
			continue;
		}

		if (ret != sizeof(count)) {
			perror("read");
			break;
		}

		protect(21);
		set_led(1);
		if (1 || on_ac() || lid_open())
			alarm(2);
		else
			alarm(20);
	}

	close(fd);
	return EXIT_SUCCESS;
}
/* registers disks (can also work with partitions, but we don't use it here) */
void init_partition_info(char **wanted_partitions, int wanted_partitions_n)
{
  const char *scan_fmt = NULL;
  char * buf;

  debug_msg("initializing partition info for mod_iostat");

  // supposedly older kernels don't have this file
  if(access("/proc/diskstats", R_OK)) {
    kernel_type = 4;
    scan_fmt = "%4d %4d %*d %31s %u";
  } else {
    kernel_type = 6;
    scan_fmt = "%4d %4d %31s %u";
  }

  if(!scan_fmt)
    err_msg("logic error in initialize(). cannot set scan_fmt");

  buf = update_file_iostat(kernel_type);

  while ( buf != NULL ) {
    unsigned int reads = 0;
    struct part_info curr;

    if (sscanf(buf, scan_fmt, &curr.major, &curr.minor,
         curr.name, &reads) == 4) {
      unsigned int p;

      // skip invalid device types
      if (!valid_disk(curr.major)) {
        buf = index(buf, '\n');
        if(buf != NULL) buf++;
        debug_msg("Skipping %s", curr.name);
        continue;
      }

      // to skip over the ones that exist and register a new one
      for (p = 0; p < n_partitions
             && (partition[p].major != curr.major
           || partition[p].minor != curr.minor);
           p++);

      if (p == n_partitions && p < MAX_PARTITIONS) {
        // if user specified the partition names
        if (wanted_partitions_n) {
          unsigned int j;

          for (j = 0;
            j < wanted_partitions_n && wanted_partitions[j]; j++) {
            if (!strcmp(curr.name, wanted_partitions[j])) { // if they match
              partition[p] = curr;
              n_partitions = p + 1;
            }
          }
        } else if (reads && printable(curr.major, curr.minor)) {
          partition[p] = curr;
          n_partitions = p + 1;
        }
      }
    } // sscanf
    // printf("looping with buf:\n%s\n", buf);

    // buf = index(buf, '\n')+1; // next line
    buf = index(buf, '\n');
    if(buf != NULL) buf++;
  }
}