/* * comp_t.c * * Routine per la manipolazione dei record di accounting di Linux. * * decode_comp_t() converte le quantita` codificate in comp_t * nel semplice numero che codifica. * * Martin Guy, FreakNet Medialab, Luglio 2001 */ #include "comp_t.h" #if 0 /* Da /usr/src/linux/kernel/acct.c */ /* * encode an unsigned long into a comp_t * * This routine has been adopted from the encode_comp_t() function in * the kern_acct.c file of the FreeBSD operating system. The encoding * is a 13-bit fraction with a 3-bit (base 8) exponent. */ #define MANTSIZE 13 /* 13 bit mantissa. */ #define EXPSIZE 3 /* Base 8 (3 bit) exponent. */ #define MAXFRACT ((1 << MANTSIZE) - 1) /* Maximum fractional value. */ static comp_t encode_comp_t(unsigned long value) { int exp, rnd; exp = rnd = 0; while (value > MAXFRACT) { rnd = value & (1 << (EXPSIZE - 1)); /* Round up? */ value >>= EXPSIZE; /* Base 8 exponent == 3 bit shift. */ exp++; } /* * If we need to round up, do it (and handle overflow correctly). */ if (rnd && (++value > MAXFRACT)) { value >>= EXPSIZE; exp++; } /* * Clean it up and polish it off. */ exp <<= MANTSIZE; /* Shift the exponent into place */ exp += value; /* and add on the mantissa. */ return exp; } #endif /* Convertita nella funzione inversa... */ #define MANTSIZE 13 /* 13 bit mantissa. */ #define EXPSIZE 3 /* Base 8 (3 bit) exponent. */ unsigned long decode_comp_t(comp_t comp) { unsigned long value; int exp; exp = comp >> MANTSIZE; /* Sappiamo che comp_t e` unsigned */ value = comp & ((1<