/* vi: set sw=4 ts=4: */
/*
 * ionice implementation for busybox based on linux-utils-ng 2.14
 *
 * Copyright (C) 2008 by  <u173034@informatik.uni-oldenburg.de>
 *
 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
 */

#include <sys/syscall.h>
#include <asm/unistd.h>
#include "libbb.h"

static int ioprio_set(int which, int who, int ioprio)
{
	return syscall(SYS_ioprio_set, which, who, ioprio);
}

static int ioprio_get(int which, int who)
{
	return syscall(SYS_ioprio_get, which, who);
}

enum {
	IOPRIO_WHO_PROCESS = 1,
	IOPRIO_WHO_PGRP,
	IOPRIO_WHO_USER
};

enum {
	IOPRIO_CLASS_NONE,
	IOPRIO_CLASS_RT,
	IOPRIO_CLASS_BE,
	IOPRIO_CLASS_IDLE
};

static const char to_prio[] = "none\0realtime\0best-effort\0idle";

#define IOPRIO_CLASS_SHIFT      13

int ionice_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int ionice_main(int argc UNUSED_PARAM, char **argv)
{
	/* Defaults */
	int ioclass = 0;
	int pri = 0;
	int pid = 0; /* affect own porcess */
	int opt;
	enum {
		OPT_n = 1,
		OPT_c = 2,
		OPT_p = 4,
	};

	/* Numeric params */
	opt_complementary = "n+:c+:p+";
	/* '+': stop at first non-option */
	opt = getopt32(argv, "+n:c:p:", &pri, &ioclass, &pid);
	argv += optind;
	
	if (opt & OPT_c) {
		if (ioclass > 3)
			bb_error_msg_and_die("bad class %d", ioclass);
// Do we need this (compat?)?
//		if (ioclass == IOPRIO_CLASS_NONE)
//			ioclass = IOPRIO_CLASS_BE;
//		if (ioclass == IOPRIO_CLASS_IDLE) {
//			//if (opt & OPT_n)
//			//	bb_error_msg("ignoring priority for idle class");
//			pri = 7;
//		}
	}
	
	if (!(opt & (OPT_n|OPT_c))) {
		if (!(opt & OPT_p) && *argv)
			pid = xatoi_u(*argv);

		pri = ioprio_get(IOPRIO_WHO_PROCESS, pid);
		if (pri == -1)
			bb_perror_msg_and_die("ioprio_%cet", 'g');

		ioclass = (pri >> IOPRIO_CLASS_SHIFT) & 0x3;
		pri &= 0xff;
		printf((ioclass == IOPRIO_CLASS_IDLE) ? "%s\n" : "%s: prio %d\n",
				nth_string(to_prio, ioclass), pri);
	} else {
//printf("pri=%d class=%d val=%x\n",
//pri, ioclass, pri | (ioclass << IOPRIO_CLASS_SHIFT));
		pri |= (ioclass << IOPRIO_CLASS_SHIFT);
		if (ioprio_set(IOPRIO_WHO_PROCESS, pid, pri) == -1)
			bb_perror_msg_and_die("ioprio_%cet", 's');
		if (*argv) {
			BB_EXECVP(*argv, argv);
			bb_simple_perror_msg_and_die(*argv);
		}
	}

	return EXIT_SUCCESS;
}
