47 #include <linux/slab.h>
48 #include <linux/acct.h>
49 #include <linux/capability.h>
51 #include <linux/tty.h>
58 #include <asm/uaccess.h>
59 #include <asm/div64.h>
71 #define RESUME (acct_parm[0])
72 #define SUSPEND (acct_parm[1])
73 #define ACCT_TIMEOUT (acct_parm[2])
108 spin_lock(&acct_lock);
112 spin_unlock(&acct_lock);
117 suspend = sbuf.f_blocks *
SUSPEND;
118 resume = sbuf.f_blocks *
RESUME;
123 if (sbuf.f_bavail <= suspend)
125 else if (sbuf.f_bavail >= resume)
134 spin_lock(&acct_lock);
135 if (file != acct->
file) {
156 spin_unlock(&acct_lock);
166 static void acct_file_reopen(
struct bsd_acct_struct *acct,
struct file *file,
169 struct file *old_acct =
NULL;
173 old_acct = acct->
file;
185 list_add(&acct->
list, &acct_list);
189 spin_unlock(&acct_lock);
190 do_acct_process(acct, old_ns, old_acct);
192 spin_lock(&acct_lock);
206 return PTR_ERR(file);
213 if (!file->
f_op->write) {
219 if (ns->bacct ==
NULL) {
227 spin_lock(&acct_lock);
228 if (ns->bacct ==
NULL) {
235 acct_file_reopen(ns->bacct, file, ns);
236 spin_unlock(&acct_lock);
265 return (PTR_ERR(tmp));
266 error = acct_on(tmp);
275 spin_lock(&acct_lock);
277 spin_unlock(&acct_lock);
294 spin_lock(&acct_lock);
297 if (acct->
file && acct->
file->f_path.mnt == m) {
301 spin_unlock(&acct_lock);
315 spin_lock(&acct_lock);
318 if (acct->
file && acct->
file->f_path.dentry->d_sb == sb) {
322 spin_unlock(&acct_lock);
332 spin_lock(&acct_lock);
335 spin_unlock(&acct_lock);
350 #define MAXFRACT ((1 << MANTSIZE) - 1)
358 rnd = value & (1 << (
EXPSIZE - 1));
379 #if ACCT_VERSION==1 || ACCT_VERSION==2
391 #define MAXFRACT2 ((1ul << MANTSIZE2) - 1)
392 #define MAXEXP2 ((1 <<EXPSIZE2) - 1)
398 exp = (value > (MAXFRACT2>>1));
400 while (value > MAXFRACT2) {
409 if (rnd && (++value > MAXFRACT2)) {
416 return (1ul << (MANTSIZE2+EXPSIZE2-1)) - 1;
418 return (value & (MAXFRACT2>>1)) | (exp << (MANTSIZE2-1));
427 static u32 encode_float(
u64 value)
432 if (value==0)
return 0;
433 while ((
s64)value > 0){
437 u = (
u32)(value >> 40) & 0x7fffff
u;
438 return u | (exp << 23);
465 const struct cred *orig_cred;
474 if (!check_free_space(acct, file))
490 +
current->group_leader->start_time.tv_nsec;
492 elapsed = nsec_to_AHZ(run_time);
494 ac.
ac_etime = encode_float(elapsed);
496 ac.
ac_etime = encode_comp_t(elapsed < (
unsigned long) -1
l ?
497 (
unsigned long) elapsed : (
unsigned long) -1
l);
499 #if ACCT_VERSION==1 || ACCT_VERSION==2
502 comp2_t etime = encode_comp2_t(elapsed);
515 #if ACCT_VERSION==1 || ACCT_VERSION==2
527 spin_lock_irq(&
current->sighand->siglock);
537 spin_unlock_irq(&
current->sighand->siglock);
538 ac.
ac_io = encode_comp_t(0 );
553 file->
f_op->write(file, (
char *)&ac,
569 unsigned long vsize = 0;
571 if (group_dead &&
current->mm) {
582 spin_lock_irq(&
current->sighand->siglock);
584 pacct->
ac_mem = vsize / 1024;
585 if (thread_group_leader(
current)) {
600 spin_unlock_irq(&
current->sighand->siglock);
605 struct file *file =
NULL;
612 if (!acct || !acct->
file)
615 spin_lock(&acct_lock);
618 spin_unlock(&acct_lock);
622 spin_unlock(&acct_lock);
624 do_acct_process(acct, ns, file);
644 acct_process_in_ns(ns);