diff -ru --new-file linux-1.2.3/arch/i386/config.in linux/arch/i386/config.in --- linux-1.2.3/arch/i386/config.in Tue Mar 7 15:25:26 1995 +++ linux/arch/i386/config.in Sun Apr 2 11:39:55 1995 @@ -217,6 +217,7 @@ fi bool 'OS/2 HPFS filesystem support (read only)' CONFIG_HPFS_FS n bool 'System V and Coherent filesystem support' CONFIG_SYSV_FS n +bool 'Disk QUOTA support' CONFIG_QUOTA y comment 'character devices' diff -ru --new-file linux-1.2.3/drivers/scsi/sr.c linux/drivers/scsi/sr.c --- linux-1.2.3/drivers/scsi/sr.c Sun Mar 19 11:54:09 1995 +++ linux/drivers/scsi/sr.c Sun Apr 2 11:39:55 1995 @@ -24,6 +24,7 @@ #include #include #include +#include #include #define MAJOR_NR SCSI_CDROM_MAJOR diff -ru --new-file linux-1.2.3/fs/Makefile linux/fs/Makefile --- linux-1.2.3/fs/Makefile Mon Jan 23 09:38:28 1995 +++ linux/fs/Makefile Sun Apr 2 11:39:55 1995 @@ -80,9 +80,9 @@ .s.o: $(AS) -o $*.o $< -OBJS= open.o read_write.o inode.o devices.o file_table.o buffer.o super.o \ - block_dev.o stat.o exec.o pipe.o namei.o fcntl.o ioctl.o \ - select.o fifo.o locks.o filesystems.o dcache.o $(BINFMTS) +OBJS= open.o read_write.o inode.o devices.o file_table.o fileio.o buffer.o \ + super.o block_dev.o stat.o exec.o pipe.o namei.o fcntl.o ioctl.o \ + select.o fifo.o locks.o filesystems.o dcache.o dquot.o $(BINFMTS) all: fs.o filesystems.a diff -ru --new-file linux-1.2.3/fs/binfmt_elf.c linux/fs/binfmt_elf.c --- linux-1.2.3/fs/binfmt_elf.c Wed Feb 15 09:51:06 1995 +++ linux/fs/binfmt_elf.c Sun Apr 2 11:39:55 1995 @@ -483,6 +483,8 @@ current->mm->end_code = 0; current->mm->start_mmap = ELF_START_MMAP; current->mm->mmap = NULL; + current->flags &= ~PF_FORKNOEXEC; /* accounting flags */ + current->io_usage = 0; elf_entry = (unsigned int) elf_ex.e_entry; /* Do this so that we can load the interpreter, if need be. We will diff -ru --new-file linux-1.2.3/fs/buffer.c linux/fs/buffer.c --- linux-1.2.3/fs/buffer.c Mon Mar 6 10:22:08 1995 +++ linux/fs/buffer.c Sun Apr 2 11:39:55 1995 @@ -216,6 +216,9 @@ sync_supers(dev); sync_inodes(dev); sync_buffers(dev, 0); +#ifdef CONFIG_QUOTA + sync_dquots(dev, -1); +#endif } int fsync_dev(dev_t dev) @@ -223,6 +226,9 @@ sync_buffers(dev, 0); sync_supers(dev); sync_inodes(dev); +#ifdef CONFIG_QUOTA + sync_dquots(dev, -1); +#endif return sync_buffers(dev, 1); } diff -ru --new-file linux-1.2.3/fs/dquot.c linux/fs/dquot.c --- linux-1.2.3/fs/dquot.c Thu Jan 1 01:00:00 1970 +++ linux/fs/dquot.c Sun Apr 2 11:39:55 1995 @@ -0,0 +1,1003 @@ +/* + * QUOTA An implementation of the diskquota system for the LINUX operating + * system. QUOTA is implemented using the BSD systemcall interface as + * the means of communication with the user level. Should work for all + * filesystems because of integration into the VFS layer of the + * operating system. This is based on the Melbourne quota system wich + * uses both user and group quota files. + * + * Main layer of quota management + * + * Version: $Id: dquot.c,v 3.12 1994/10/30 09:37:48 mvw Exp mvw $ + * + * Authors: Marco van Wieringen + * Edvard Tuinder + * Linus Torvalds + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + */ + +#include +#include +#include +#include + +#ifdef CONFIG_QUOTA +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +static char quotamessage[MAX_QUOTA_MESSAGE]; +static char *quotatypes[] = INITQFNAMES; + +static int nr_dquots = 0, nr_free_dquots = 0; +static struct dquot *hash_table[NR_DQHASH]; +static struct dquot *first_dquot; + +static struct wait_queue *dquot_wait = (struct wait_queue *)NULL; + +extern void add_dquot_ref(dev_t dev, short type); +extern void reset_dquot_ptrs(dev_t dev, short type); +extern void close_fp(struct file *filp, int fd); + +#ifndef min +#define min(a,b) ((a) < (b)) ? (a) : (b) +#endif + +/* + * Functions for management of the hashlist. + */ +static inline int const hashfn(dev_t dev, unsigned int id, short type) +{ + return ((dev ^ id) * (MAXQUOTAS - type)) % NR_DQHASH; +} + +static inline struct dquot **const hash(dev_t dev, unsigned int id, short type) +{ + return hash_table + hashfn(dev, id, type); +} + +static void insert_dquot_free(struct dquot *dquot) +{ + dquot->dq_next = first_dquot; + dquot->dq_prev = first_dquot->dq_prev; + dquot->dq_next->dq_prev = dquot; + dquot->dq_prev->dq_next = dquot; + first_dquot = dquot; +} + +static void remove_dquot_free(struct dquot *dquot) +{ + if (first_dquot == dquot) + first_dquot = first_dquot->dq_next; + if (dquot->dq_next) + dquot->dq_next->dq_prev = dquot->dq_prev; + if (dquot->dq_prev) + dquot->dq_prev->dq_next = dquot->dq_next; + dquot->dq_next = dquot->dq_prev = NODQUOT; +} + +static void insert_dquot_hash(struct dquot *dquot) +{ + struct dquot **h; + + h = hash(dquot->dq_dev, dquot->dq_id, dquot->dq_type); + dquot->dq_hash_next = *h; + dquot->dq_hash_prev = NODQUOT; + if (dquot->dq_hash_next) + dquot->dq_hash_next->dq_hash_prev = dquot; + *h = dquot; +} + +static void remove_dquot_hash(struct dquot *dquot) +{ + struct dquot **h; + + h = hash(dquot->dq_dev, dquot->dq_id, dquot->dq_type); + if (*h == dquot) + *h = dquot->dq_hash_next; + if (dquot->dq_hash_next) + dquot->dq_hash_next->dq_hash_prev = dquot->dq_hash_prev; + if (dquot->dq_hash_prev) + dquot->dq_hash_prev->dq_hash_next = dquot->dq_hash_next; + dquot->dq_hash_prev = dquot->dq_hash_next = NODQUOT; +} + +static void put_last_free(struct dquot *dquot) +{ + remove_dquot_free(dquot); + dquot->dq_prev = first_dquot->dq_prev; + dquot->dq_prev->dq_next = dquot; + dquot->dq_next = first_dquot; + dquot->dq_next->dq_prev = dquot; +} + +static void grow_dquots(void) +{ + struct dquot *dquot; + int i; + + if (!(dquot = (struct dquot*) get_free_page(GFP_KERNEL))) + return; + i = PAGE_SIZE / sizeof(struct dquot); + nr_dquots += i; + nr_free_dquots += i; + if (!first_dquot) + dquot->dq_next = dquot->dq_prev = first_dquot = dquot++, i--; + for ( ; i ; i-- ) + insert_dquot_free(dquot++); +} + +/* + * Functions for locking and waiting on dquots. + */ +static void __wait_on_dquot(struct dquot *dquot) +{ + struct wait_queue wait = {current, NULL}; + + add_wait_queue(&dquot->dq_wait, &wait); +repeat: + current->state = TASK_UNINTERRUPTIBLE; + if (dquot->dq_flags & DQ_LOCKED) { + dquot->dq_flags |= DQ_WANT; + schedule(); + goto repeat; + } + remove_wait_queue(&dquot->dq_wait, &wait); + current->state = TASK_RUNNING; +} + +static inline void wait_on_dquot(struct dquot *dquot) +{ + if (dquot->dq_flags & DQ_LOCKED) + __wait_on_dquot(dquot); +} + +static inline void lock_dquot(struct dquot *dquot) +{ + wait_on_dquot(dquot); + dquot->dq_flags |= DQ_LOCKED; +} + +static inline void unlock_dquot(struct dquot *dquot) +{ + dquot->dq_flags &= ~DQ_LOCKED; + if (dquot->dq_flags & DQ_WANT) { + dquot->dq_flags &= ~DQ_WANT; + wake_up(&dquot->dq_wait); + } +} +/* + * Note that we don't want to disturb any wait-queues when we discard + * an dquot. + * + * FIXME: As soon as we have a nice solution for the inode problem we + * can also fix this one. I.e. the volatile part. + */ +static void clear_dquot(struct dquot * dquot) +{ + struct wait_queue *wait; + + wait_on_dquot(dquot); + remove_dquot_hash(dquot); + remove_dquot_free(dquot); + wait = ((volatile struct dquot *) dquot)->dq_wait; + if (dquot->dq_count) + nr_free_dquots++; + memset(dquot, 0, sizeof(*dquot)); + ((volatile struct dquot *) dquot)->dq_wait = wait; + insert_dquot_free(dquot); +} + +static void write_dquot(struct dquot *dquot) +{ + short type = dquot->dq_type; + struct file *filp = dquot->dq_mnt->mnt_quotas[type]; + unsigned short fs; + + if (!(dquot->dq_flags & DQ_MOD) || (filp == (struct file *)0)) + return; + lock_dquot(dquot); + down(&dquot->dq_mnt->mnt_sem); + if (filp->f_op->lseek) { + if (filp->f_op->lseek(filp->f_inode, filp, + dqoff(dquot->dq_id), 0) != dqoff(dquot->dq_id)) { + up(&dquot->dq_mnt->mnt_sem); + return; + } + } else + filp->f_pos = dqoff(dquot->dq_id); + fs = get_fs(); + set_fs(KERNEL_DS); + if (filp->f_op->write(filp->f_inode, filp, + (char *)&dquot->dq_dqb, sizeof(struct dqblk)) == sizeof(struct dqblk)) + dquot->dq_flags &= ~DQ_MOD; + up(&dquot->dq_mnt->mnt_sem); + set_fs(fs); + unlock_dquot(dquot); +} + +static void read_dquot(struct dquot *dquot) +{ + short type = dquot->dq_type; + struct file *filp = dquot->dq_mnt->mnt_quotas[type]; + unsigned short fs; + + if (filp == (struct file *)0) + return; + lock_dquot(dquot); + down(&dquot->dq_mnt->mnt_sem); + if (filp->f_op->lseek) { + if (filp->f_op->lseek(filp->f_inode, filp, + dqoff(dquot->dq_id),0) != dqoff(dquot->dq_id)) { + up(&dquot->dq_mnt->mnt_sem); + return; + } + } else + filp->f_pos = dqoff(dquot->dq_id); + fs = get_fs(); + set_fs(KERNEL_DS); + filp->f_op->read(filp->f_inode, filp, (char *)&dquot->dq_dqb, sizeof(struct dqblk)); + up(&dquot->dq_mnt->mnt_sem); + set_fs(fs); + if (dquot->dq_bhardlimit == 0 && dquot->dq_bsoftlimit == 0 && + dquot->dq_ihardlimit == 0 && dquot->dq_isoftlimit == 0) + dquot->dq_flags |= DQ_FAKE; + unlock_dquot(dquot); +} + +int sync_dquots(dev_t dev, short type) +{ + struct dquot *dquot = first_dquot; + int i; + + for(i = 0; i < nr_dquots * 2; i++, dquot = dquot->dq_next) { + if (!dquot->dq_count || (dev && dquot->dq_dev != dev)) + continue; + if (type != -1 && dquot->dq_type != type) + continue; + wait_on_dquot(dquot); + if (dquot->dq_flags & DQ_MOD) + write_dquot(dquot); + } + return 0; + /* NOTREACHED */ +} + +/* + * Trash the cache for a certain type on a device. + */ +void invalidate_dquots(dev_t dev, short type) +{ + struct dquot *dquot, *next; + int i; + + next = first_dquot; + for(i = nr_dquots ; i > 0 ; i--) { + dquot = next; + next = dquot->dq_next; + if (dquot->dq_dev != dev || dquot->dq_type != type) + continue; + if (dquot->dq_flags & DQ_LOCKED) { + printk("VFS: dquot busy on removed device %d/%d\n", MAJOR(dev), MINOR(dev)); + continue; + } + if (dquot->dq_flags & DQ_MOD) + write_dquot(dquot); + clear_dquot(dquot); + } +} + +/* + * Check quota for inodes. Returns QUOTA_OK if can allocate and + * NO_QUOTA if it can't. + */ +static int check_idq(struct dquot *dquot, int id, short type, u_long wanted_inodes) +{ + if (wanted_inodes == 0 || dquot->dq_flags & DQ_FAKE) + return QUOTA_OK; + if (dquot->dq_ihardlimit && + (dquot->dq_curinodes + wanted_inodes) >= dquot->dq_ihardlimit) { + if (!(dquot->dq_flags & DQ_INODES)) { + sprintf(quotamessage, + "File LIMIT reached on %s for %s %d. !! NO MORE !!\n\r", + dquot->dq_mnt->mnt_devname, quotatypes[type], id); + tty_write_message(current->tty, quotamessage); + dquot->dq_flags |= DQ_INODES; + } + return NO_QUOTA; + } + if (dquot->dq_isoftlimit && + (dquot->dq_curinodes + wanted_inodes) >= dquot->dq_isoftlimit && + dquot->dq_itime && CURRENT_TIME >= dquot->dq_itime) { + sprintf(quotamessage, + "File QUOTA exceeded TOO long on %s for %s %d. !! NO MORE !!\n\r", + dquot->dq_mnt->mnt_devname, quotatypes[type], id); + tty_write_message(current->tty, quotamessage); + return NO_QUOTA; + } + if (dquot->dq_isoftlimit && + (dquot->dq_curinodes + wanted_inodes) >= dquot->dq_isoftlimit && + dquot->dq_itime == 0) { + sprintf(quotamessage, + "File QUOTA exceeded on %s for %s %d\n\r", + dquot->dq_mnt->mnt_devname, quotatypes[type], id); + tty_write_message(current->tty, quotamessage); + dquot->dq_itime = CURRENT_TIME + dquot->dq_mnt->mnt_iexp[type]; + } + return QUOTA_OK; + /* NOTREACHED */ +} + +/* + * Check quota for blocks. Returns QUOTA_OK if can allocate and + * NO_QUOTA if it can't. When we can't allocate wanted_blocks you get + * the number we can allocate in avail_blocks. + */ +static int check_bdq(struct dquot *dquot, int id, short type, u_long wanted_blocks, u_long *avail_blocks) +{ + *avail_blocks = wanted_blocks; + if (wanted_blocks == 0 || dquot->dq_flags & DQ_FAKE) + return QUOTA_OK; + if (dquot->dq_bhardlimit && + (dquot->dq_curblocks + wanted_blocks) >= dquot->dq_bhardlimit) { + if ((dquot->dq_flags & DQ_BLKS) == 0) { + sprintf(quotamessage, + "Block LIMIT reached on %s for %s %d. !! NO MORE !!\n\r", + dquot->dq_mnt->mnt_devname, quotatypes[type], id); + tty_write_message(current->tty, quotamessage); + dquot->dq_flags |= DQ_BLKS; + } + if (dquot->dq_curblocks < dquot->dq_bhardlimit) { + *avail_blocks = dquot->dq_bhardlimit - dquot->dq_curblocks; + return QUOTA_OK; + } else + return NO_QUOTA; + } + if (dquot->dq_bsoftlimit && + (dquot->dq_curblocks + wanted_blocks) >= dquot->dq_bsoftlimit && + dquot->dq_btime && CURRENT_TIME >= dquot->dq_btime) { + sprintf(quotamessage, + "Block QUOTA exceeded TOO long on %s for %s %d. !! NO MORE !!\n\r", + dquot->dq_mnt->mnt_devname, quotatypes[type], id); + tty_write_message(current->tty, quotamessage); + return NO_QUOTA; + } + if (dquot->dq_bsoftlimit && + (dquot->dq_curblocks + wanted_blocks) >= dquot->dq_bsoftlimit && + dquot->dq_btime == 0) { + sprintf(quotamessage, + "Block QUOTA exceeded on %s for %s %d\n\r", + dquot->dq_mnt->mnt_devname, quotatypes[type], id); + tty_write_message(current->tty, quotamessage); + dquot->dq_btime = CURRENT_TIME + dquot->dq_mnt->mnt_bexp[type]; + } + return QUOTA_OK; + /* NOTREACHED */ +} + +/* + * Add a number of inodes and blocks to a diskquota. + */ +static inline void incr_quota(struct dquot *dquot, u_long inodes, u_long blocks) +{ + lock_dquot(dquot); + dquot->dq_curinodes += inodes; + dquot->dq_curblocks += blocks; + dquot->dq_flags |= DQ_MOD; + unlock_dquot(dquot); +} + +/* + * Remove a number of inodes and blocks from a quota. + * Reset gracetimes if under softlimit. + */ +static inline void decr_quota(struct dquot *dquot, u_long inodes, u_long blocks) +{ + lock_dquot(dquot); + if (dquot->dq_curinodes >= inodes) + dquot->dq_curinodes -= inodes; + else + dquot->dq_curinodes = 0; + if (dquot->dq_curinodes < dquot->dq_isoftlimit) + dquot->dq_itime = (time_t) 0; + dquot->dq_flags &= ~DQ_INODES; + if (dquot->dq_curblocks >= blocks) + dquot->dq_curblocks -= blocks; + else + dquot->dq_curblocks = 0; + if (dquot->dq_curblocks < dquot->dq_bsoftlimit) + dquot->dq_btime = (time_t) 0; + dquot->dq_flags &= ~DQ_BLKS; + dquot->dq_flags |= DQ_MOD; + unlock_dquot(dquot); +} + +/* + * Initialize a dquot-struct with new quota info. This is used by the + * systemcall interface functions. + */ +static int set_dqblk(dev_t dev, int id, short type, int flags, struct dqblk *dqblk) +{ + struct dquot *dquot; + struct dqblk dq_dqblk; + int error; + + if (dqblk == (struct dqblk *)0) + return -EFAULT; + + if (flags & QUOTA_SYSCALL) { + if ((error = verify_area(VERIFY_READ, dqblk, sizeof(struct dqblk))) != 0) + return error; + memcpy_fromfs(&dq_dqblk, dqblk, sizeof(struct dqblk)); + } else { + memcpy(&dq_dqblk, dqblk, sizeof(struct dqblk)); + } + if ((dquot = dqget(dev, id, type)) != NODQUOT) { + lock_dquot(dquot); + if (id > 0 && ((flags & SET_QUOTA) || (flags & SET_QLIMIT))) { + dquot->dq_bhardlimit = dq_dqblk.dqb_bhardlimit; + dquot->dq_bsoftlimit = dq_dqblk.dqb_bsoftlimit; + dquot->dq_ihardlimit = dq_dqblk.dqb_ihardlimit; + dquot->dq_isoftlimit = dq_dqblk.dqb_isoftlimit; + } + if ((flags & SET_QUOTA) || (flags & SET_USE)) { + if (dquot->dq_isoftlimit && + dquot->dq_curinodes < dquot->dq_isoftlimit && + dq_dqblk.dqb_curinodes >= dquot->dq_isoftlimit) + dquot->dq_itime = CURRENT_TIME + dquot->dq_mnt->mnt_iexp[type]; + dquot->dq_curinodes = dq_dqblk.dqb_curinodes; + if (dquot->dq_curinodes < dquot->dq_isoftlimit) + dquot->dq_flags &= ~DQ_INODES; + if (dquot->dq_bsoftlimit && + dquot->dq_curblocks < dquot->dq_bsoftlimit && + dq_dqblk.dqb_curblocks >= dquot->dq_bsoftlimit) + dquot->dq_btime = CURRENT_TIME + dquot->dq_mnt->mnt_bexp[type]; + dquot->dq_curblocks = dq_dqblk.dqb_curblocks; + if (dquot->dq_curblocks < dquot->dq_bsoftlimit) + dquot->dq_flags &= ~DQ_BLKS; + } + if (id == 0) { + /* + * Change in expiretimes, change them in dq_mnt. + */ + dquot->dq_mnt->mnt_bexp[type] = dquot->dq_btime = dq_dqblk.dqb_btime; + dquot->dq_mnt->mnt_iexp[type] = dquot->dq_itime = dq_dqblk.dqb_itime; + } + if (dq_dqblk.dqb_bhardlimit == 0 && dq_dqblk.dqb_bsoftlimit == 0 && + dq_dqblk.dqb_ihardlimit == 0 && dq_dqblk.dqb_isoftlimit == 0) + dquot->dq_flags |= DQ_FAKE; /* No limits, only usage */ + dquot->dq_flags |= DQ_MOD; + unlock_dquot(dquot); + dqput(dquot); + } + return 0; +} + +static int get_quota(dev_t dev, int id, short type, struct dqblk * dqblk) +{ + struct vfsmount *vfsmnt; + struct dquot *dquot; + int error; + + if ((vfsmnt = lookup_vfsmnt(dev)) != (struct vfsmount *)0 && + vfsmnt->mnt_quotas[type] != (struct file *)0) { + if (dqblk == (struct dqblk *) 0) + return -EFAULT; + + if ((error = verify_area(VERIFY_WRITE, dqblk, sizeof(struct dqblk))) != 0) + return (error); + + if ((dquot = dqget(dev, id, type)) != NODQUOT) { + memcpy_tofs(dqblk, (char *)&dquot->dq_dqb, sizeof(struct dqblk)); + dqput(dquot); + return 0; + } + } + return -ESRCH; +} + +/* + * Turn quota off on a device. type == -1 ==> quotaoff for all types (umount) + */ +int quota_off(dev_t dev, short type) +{ + struct vfsmount *vfsmnt; + short cnt; + + for (cnt = 0; cnt < MAXQUOTAS; cnt++) { + if (type != -1 && cnt != type) + continue; + if ((vfsmnt = lookup_vfsmnt(dev)) == (struct vfsmount *)0 || + vfsmnt->mnt_quotas[cnt] == (struct file *)0) + continue; + vfsmnt->mnt_flags |= QF_CLOSING; + reset_dquot_ptrs(dev, cnt); + invalidate_dquots(dev, cnt); + close_fp(vfsmnt->mnt_quotas[cnt], 0); + vfsmnt->mnt_quotas[cnt] = (struct file *)0; + vfsmnt->mnt_iexp[cnt] = vfsmnt->mnt_bexp[cnt] = (time_t)0; + vfsmnt->mnt_flags &= ~QF_CLOSING; + } + return 0; +} + +static int quota_on(dev_t dev, short type, char *path) +{ + struct file *filp = (struct file *)0; + struct vfsmount *vfsmnt; + struct inode *inode; + struct dquot *dquot; + char *tmp; + int error; + + if ((vfsmnt = lookup_vfsmnt(dev)) == (struct vfsmount *)0) + return -ENODEV; + if (vfsmnt->mnt_quotas[type] != (struct file *)0) + return -EBUSY; + if ((error = getname(path, &tmp)) != 0) + return (error); + vfsmnt->mnt_flags |= QF_OPENING; + error = open_namei(tmp, O_RDWR, 0600, &inode, 0); + putname(tmp); + if (error) { + vfsmnt->mnt_flags &= ~QF_OPENING; + return (error); + } + if (!S_ISREG(inode->i_mode)) { + vfsmnt->mnt_flags &= ~QF_OPENING; + iput(inode); + return -EACCES; + } + if ((filp = get_empty_filp()) != (struct file *)0) { + filp->f_mode = (O_RDWR + 1) & O_ACCMODE; + filp->f_flags = O_RDWR; + filp->f_inode = inode; + filp->f_pos = 0; + filp->f_reada = 0; + filp->f_op = inode->i_op->default_file_ops; + if (filp->f_op->read || filp->f_op->write) { + if ((error = vfs_getwriteaccess(filp)) == 0) { + if (filp->f_op && filp->f_op->open) + error = filp->f_op->open(inode, filp); + if (error == 0) { + vfsmnt->mnt_quotas[type] = filp; + vfsmnt->mnt_flags &= ~QF_OPENING; + dquot = dqget(dev, 0, type); + vfsmnt->mnt_iexp[type] = (dquot) ? dquot->dq_itime : MAX_IQ_TIME; + vfsmnt->mnt_bexp[type] = (dquot) ? dquot->dq_btime : MAX_DQ_TIME; + dqput(dquot); + add_dquot_ref(dev, type); + return 0; + } + vfs_putwriteaccess(filp); + } + } else + error = -EIO; + filp->f_count--; + } else + error = -EMFILE; + vfsmnt->mnt_flags &= ~QF_OPENING; + iput(inode); + return error; +} + +/* + * Just like iput, decrement referencecount of dquot. + */ +void dqput(struct dquot *dquot) +{ + if (!dquot) + return; + /* + * If the dq_mnt pointer isn't initialized this entry needs no + * checking and doesn't need to be written. It just an empty + * dquot that is put back into the freelist. + */ + if (dquot->dq_mnt != (struct vfsmount *)0) { + wait_on_dquot(dquot); + if (!dquot->dq_count) { + printk("VFS: iput: trying to free free dquot\n"); + printk("VFS: device %d/%d, dquot of %s %d\n", + MAJOR(dquot->dq_dev), MINOR(dquot->dq_dev), + quotatypes[dquot->dq_type], dquot->dq_id); + return; + } +repeat: + if (dquot->dq_count > 1) { + dquot->dq_count--; + return; + } + wake_up(&dquot_wait); + if (dquot->dq_flags & DQ_MOD) { + write_dquot(dquot); /* we can sleep - so do again */ + wait_on_dquot(dquot); + goto repeat; + } + } + if (dquot->dq_count) { + dquot->dq_count--; + nr_free_dquots++; + } + return; +} + +static struct dquot *get_empty_dquot(void) +{ + struct dquot *dquot, *best; + int i; + + if (nr_dquots < NR_DQUOTS && nr_free_dquots < (nr_dquots >> 2)) + grow_dquots(); + +repeat: + dquot = first_dquot; + best = NODQUOT; + for (i = 0; i < nr_dquots; dquot = dquot->dq_next, i++) { + if (!dquot->dq_count) { + if (!best) + best = dquot; + if (!(dquot->dq_flags & DQ_MOD) && !(dquot->dq_flags & DQ_LOCKED)) { + best = dquot; + break; + } + } + } + if (!best || best->dq_flags & DQ_MOD || best->dq_flags & DQ_LOCKED) + if (nr_dquots < NR_DQUOTS) { + grow_dquots(); + goto repeat; + } + dquot = best; + if (!dquot) { + printk("VFS: No free dquots - contact mvw@mcs.ow.org\n"); + sleep_on(&dquot_wait); + goto repeat; + } + if (dquot->dq_flags & DQ_LOCKED) { + wait_on_dquot(dquot); + goto repeat; + } + if (dquot->dq_flags & DQ_MOD) { + write_dquot(dquot); + goto repeat; + } + if (dquot->dq_count) + goto repeat; + clear_dquot(dquot); + dquot->dq_count = 1; + nr_free_dquots--; + if (nr_free_dquots < 0) { + printk ("VFS: get_empty_dquot: bad free dquot count.\n"); + nr_free_dquots = 0; + } + return dquot; +} + +/* + * Just like iget, increment referencecount of a dquot and return + * pointer to it in the hashqueue. + */ +struct dquot *dqget(dev_t dev, unsigned int id, short type) +{ + struct dquot *dquot, *empty; + struct vfsmount *vfsmnt; + + if ((vfsmnt = lookup_vfsmnt(dev)) == (struct vfsmount *)0 || + (vfsmnt->mnt_flags & (QF_OPENING | QF_CLOSING)) || + (vfsmnt->mnt_quotas[type] == (struct file *)0)) + return (NODQUOT); + empty = get_empty_dquot(); +repeat: + dquot = *(hash(dev, id, type)); + while (dquot) { + if (dquot->dq_dev != dev || dquot->dq_id != id) { + dquot = dquot->dq_hash_next; + continue; + } + wait_on_dquot(dquot); + if (dquot->dq_dev != dev || dquot->dq_id != id) + goto repeat; + if (!dquot->dq_count) + nr_free_dquots--; + dquot->dq_count++; + if (empty) + dqput(empty); + return dquot; + } + if (!empty) + return (NODQUOT); + dquot = empty; + dquot->dq_id = id; + dquot->dq_type = type; + dquot->dq_dev = dev; + dquot->dq_mnt = vfsmnt; + put_last_free(dquot); + insert_dquot_hash(dquot); + read_dquot(dquot); + return dquot; +} + +/* + * Initialize pointer in a inode to the right dquots. + * Be smart and increment count only if already valid pointervalue. + */ +void getinoquota(struct inode *inode, short type) +{ + unsigned int id = 0; + short cnt; + + for (cnt = 0; cnt < MAXQUOTAS; cnt++) { + if (type != -1 && cnt != type) + continue; + if (inode->i_dquot[cnt] != NODQUOT) { + inode->i_dquot[cnt]->dq_count++; + continue; + } + switch (cnt) { + case USRQUOTA: + id = inode->i_uid; + break; + case GRPQUOTA: + id = inode->i_gid; + break; + } + inode->i_dquot[cnt] = dqget(inode->i_dev, id, cnt); + } +} + +void putinoquota(struct inode *inode) +{ + short cnt; + + for (cnt = 0; cnt < MAXQUOTAS; cnt++) { + if (inode->i_dquot[cnt] == NODQUOT) + continue; + dqput(inode->i_dquot[cnt]); + if (!inode->i_writecount) + inode->i_dquot[cnt] = NODQUOT; + } +} + +/* + * This are two simple algorithms that calculates the size of a file in blocks + * and from a number of blocks to a isize. + * It is not perfect but works most of the time. + */ +u_long isize_to_blocks(size_t isize, size_t blksize) +{ + u_long blocks; + u_long indirect; + + if (!blksize) + blksize = BLOCK_SIZE; + blocks = (isize / blksize) + ((isize % blksize) ? 1 : 0); + if (blocks > 10) { + indirect = ((blocks - 11) >> 8) + 1; /* single indirect blocks */ + if (blocks > (10 + 256)) { + indirect += ((blocks - 267) >> 16) + 1; /* double indirect blocks */ + if (blocks > (10 + 256 + (256 << 8))) + indirect++; /* triple indirect blocks */ + } + blocks += indirect; + } + return blocks; +} + +size_t blocks_to_isize(u_long blocks, size_t blksize) +{ + size_t isize; + u_long indirect; + + if (!blksize) + blksize = BLOCK_SIZE; + isize = blocks * blksize; + if (blocks > 10) { + indirect = ((blocks - 11) >> 8) + 1; /* single indirect blocks */ + if (blocks > (10 + 256)) { + indirect += ((blocks - 267) >> 16) + 1; /* double indirect blocks */ + if (blocks > (10 + 256 + (256 << 8))) + indirect++; /* triple indirect blocks */ + } + isize -= indirect * blksize; + } + return isize; +} + +/* + * Allocate the number of inodes and blocks from a diskquota. + */ +int quota_alloc(struct inode *inode, u_long wanted_inodes, u_long wanted_blocks, u_long *avail_blocks) +{ + u_long availblocks, local_avail; + unsigned short cnt; + + availblocks = wanted_blocks; + if (wanted_inodes > 0 || wanted_blocks > 0) { + for (cnt = 0; cnt < MAXQUOTAS; cnt++) { + if (inode->i_dquot[cnt] == NODQUOT) + continue; + if (check_idq(inode->i_dquot[cnt], inode->i_dquot[cnt]->dq_id, + cnt, wanted_inodes) == NO_QUOTA || + check_bdq(inode->i_dquot[cnt], inode->i_dquot[cnt]->dq_id, + cnt, wanted_blocks, &local_avail) == NO_QUOTA) + return NO_QUOTA; + availblocks = min(availblocks, local_avail); + } + for (cnt = 0; cnt < MAXQUOTAS; cnt++) { + if (inode->i_dquot[cnt] == NODQUOT) + continue; + incr_quota(inode->i_dquot[cnt], wanted_inodes, availblocks); + } + } + if (avail_blocks != (u_long *)0) + *avail_blocks = availblocks; + return QUOTA_OK; + /* NOTREACHED */ +} + +/* + * Remove the number of inodes and blocks from a diskquota. + */ +void quota_remove(struct inode *inode, u_long inodes, u_long blocks) +{ + short cnt; + + if (inodes > 0 || blocks > 0) { + for (cnt = 0; cnt < MAXQUOTAS; cnt++) { + if (inode->i_dquot[cnt] == NODQUOT) + continue; + decr_quota(inode->i_dquot[cnt], inodes, blocks); + } + } +} + +/* + * Transfer the number of inode and blocks from one diskquota to an other. + */ +int quota_transfer(struct inode *inode, struct iattr *iattr, u_long inodes, u_long blocks, char direction) +{ + struct dquot *transfer[MAXQUOTAS]; + u_long availblocks; + unsigned int id = 0; + short cnt, disc; + + if (inodes > 0 || blocks > 0) { + for (cnt = 0; cnt < MAXQUOTAS; cnt++) { + transfer[cnt] = NODQUOT; + switch(cnt) { + case USRQUOTA: + if (inode->i_uid == iattr->ia_uid) + continue; + id = (direction) ? inode->i_uid : iattr->ia_uid; + break; + case GRPQUOTA: + if (inode->i_gid == iattr->ia_gid) + continue; + id = (direction) ? inode->i_gid : iattr->ia_gid; + break; + } + if ((transfer[cnt] = dqget(inode->i_dev, id, cnt)) == NODQUOT) + continue; + + if (check_idq(transfer[cnt], id, cnt, inodes) == NO_QUOTA || + check_bdq(transfer[cnt], id, cnt, blocks, &availblocks) == NO_QUOTA || + availblocks != blocks) { + for (disc = 0; disc <= cnt; disc++) + dqput(transfer[disc]); + return NO_QUOTA; + } + } + for (cnt = 0; cnt < MAXQUOTAS; cnt++) { + if (transfer[cnt] == NODQUOT) + continue; + decr_quota(inode->i_dquot[cnt], inodes, blocks); + incr_quota(transfer[cnt], inodes, blocks); + transfer[cnt]->dq_count += inode->i_writecount; + inode->i_dquot[cnt]->dq_count -= inode->i_writecount; + dqput(inode->i_dquot[cnt]); + inode->i_dquot[cnt] = transfer[cnt]; + } + } + return QUOTA_OK; + /* NOTREACHED */ +} + +void quota_init(void) +{ + memset(hash_table, 0, sizeof(hash_table)); + first_dquot = NODQUOT; +} + +/* + * Ok this is the systemcall interface, this communicates with + * the userlevel programs. + */ +asmlinkage int sys_quotactl(int cmd, const char *special, int id, caddr_t addr) +{ + int cmds = 0, type = 0, flags = 0; + struct vfsmount *vfsmnt; + struct inode *ino; + dev_t dev; + + cmds = cmd >> SUBCMDSHIFT; + type = cmd & SUBCMDMASK; + + if ((u_int) type >= MAXQUOTAS) + return -EINVAL; + switch (cmds) { + case Q_SYNC: + break; + case Q_GETQUOTA: + if (((type == USRQUOTA && current->uid != id) || + (type == GRPQUOTA && current->gid != id)) && !suser()) + return -EPERM; + break; + default: + if (!suser()) + return -EPERM; + } + + if (special == (char *)0 && cmds == Q_SYNC) + dev = 0; + else { + if (namei(special, &ino)) + return -EINVAL; + dev = ino->i_rdev; + if (!S_ISBLK(ino->i_mode)) { + iput(ino); + return -ENOTBLK; + } + iput(ino); + } + + switch (cmds) { + case Q_QUOTAON: + return quota_on(dev, type, (char *) addr); + case Q_QUOTAOFF: + return quota_off(dev, type); + case Q_GETQUOTA: + return get_quota(dev, id, type, (struct dqblk *) addr); + case Q_SETQUOTA: + flags |= SET_QUOTA; + break; + case Q_SETUSE: + flags |= SET_USE; + break; + case Q_SETQLIM: + flags |= SET_QLIMIT; + break; + case Q_SYNC: + return sync_dquots(dev, type); + default: + return -EINVAL; + } + + flags |= QUOTA_SYSCALL; + if ((vfsmnt = lookup_vfsmnt(dev)) != (struct vfsmount *)0 && + vfsmnt->mnt_quotas[type] != (struct file *)0) + return set_dqblk(dev, id, type, flags, (struct dqblk *) addr); + return -ESRCH; + /* NOTREACHED */ +} + +#else + +asmlinkage int sys_quotactl(int cmd, const char *special, int id, caddr_t addr) +{ + return -ENOSYS; +} + +#endif /* CONFIG_QUOTA */ + diff -ru --new-file linux-1.2.3/fs/exec.c linux/fs/exec.c --- linux-1.2.3/fs/exec.c Mon Jan 30 12:08:04 1995 +++ linux/fs/exec.c Sun Apr 2 11:39:55 1995 @@ -37,8 +37,10 @@ #include #include #include + #include #include +#include #include #include @@ -102,44 +104,45 @@ return -EINVAL; } -int open_inode(struct inode * inode, int mode) +int open_inode(struct inode *inode, int mode) { - int error, fd; - struct file *f, **fpp; + int error = 0, fd; + struct file *filp, **fpp; if (!inode->i_op || !inode->i_op->default_file_ops) return -EINVAL; - f = get_empty_filp(); - if (!f) + if ((filp = get_empty_filp()) == (struct file *)NULL) return -ENFILE; fd = 0; fpp = current->files->fd; for (;;) { if (!*fpp) break; - if (++fd >= NR_OPEN) { - f->f_count--; + if (++fd > NR_OPEN) { + filp->f_count--; return -EMFILE; } fpp++; } - *fpp = f; - f->f_flags = mode; - f->f_mode = (mode+1) & O_ACCMODE; - f->f_inode = inode; - f->f_pos = 0; - f->f_reada = 0; - f->f_op = inode->i_op->default_file_ops; - if (f->f_op->open) { - error = f->f_op->open(inode,f); - if (error) { - *fpp = NULL; - f->f_count--; - return error; - } - } - inode->i_count++; - return fd; + *fpp = filp; + filp->f_flags = mode; + filp->f_mode = (mode + 1) & O_ACCMODE; + filp->f_inode = inode; + filp->f_pos = 0; + filp->f_reada = 0; + filp->f_op = inode->i_op->default_file_ops; + if ((error = vfs_getwriteaccess(filp)) == 0) { + if (filp->f_op && filp->f_op->open) + error = filp->f_op->open(inode, filp); + if (error == 0) { + inode->i_count++; + return fd; + } + vfs_putwriteaccess(filp); + } + *fpp = NULL; + filp->f_count--; + return error; } /* @@ -147,7 +150,7 @@ * macros to write out all the necessary info. */ #define DUMP_WRITE(addr,nr) \ -while (file.f_op->write(inode,&file,(char *)(addr),(nr)) != (nr)) goto close_coredump +while (vfs_write(inode,&file,(char *)(addr),(nr)) != (nr)) goto close_coredump #define DUMP_SEEK(offset) \ if (file.f_op->lseek) { \ @@ -155,6 +158,8 @@ goto close_coredump; \ } else file.f_pos = (offset) +extern int close_fp(struct file *filp, unsigned int fd); + /* * Routine writes a core dump image in the current directory. * Currently only a stub-function. @@ -197,8 +202,6 @@ goto end_coredump; if (!inode->i_op || !inode->i_op->default_file_ops) goto end_coredump; - if (get_write_access(inode)) - goto end_coredump; file.f_mode = 3; file.f_flags = 0; file.f_count = 1; @@ -208,10 +211,13 @@ file.f_op = inode->i_op->default_file_ops; if (file.f_op->open) if (file.f_op->open(inode,&file)) - goto done_coredump; + goto end_coredump; + if (vfs_getwriteaccess(&file)) + goto end_coredump; if (!file.f_op->write) goto close_coredump; has_dumped = 1; + current->flags |= PF_DUMPCORE; strncpy(dump.u_comm, current->comm, sizeof(current->comm)); dump.u_ar0 = (struct pt_regs *)(((unsigned long)(&dump.regs)) - ((unsigned long)(&dump))); dump.signal = signr; @@ -235,6 +241,7 @@ DUMP_SEEK(PAGE_SIZE); /* now we start writing out the user space info */ set_fs(USER_DS); + /* Dump the data area */ if (dump.u_dsize != 0) { dump_start = dump.u_tsize << 12; @@ -251,10 +258,9 @@ set_fs(KERNEL_DS); DUMP_WRITE(current,sizeof(*current)); close_coredump: - if (file.f_op->release) - file.f_op->release(inode,&file); -done_coredump: - put_write_access(inode); + close_fp(&file, 0); + set_fs(fs); + return has_dumped; end_coredump: set_fs(fs); iput(inode); @@ -603,7 +609,7 @@ goto exec_error2; } /* better not execute files which are being written to */ - if (bprm.inode->i_wcount > 0) { + if (bprm.inode->i_writecount > 0) { retval = -ETXTBSY; goto exec_error2; } @@ -775,6 +781,8 @@ current->mm->mmap = NULL; current->suid = current->euid = current->fsuid = bprm->e_uid; current->sgid = current->egid = current->fsgid = bprm->e_gid; + current->flags &= ~PF_FORKNOEXEC; /* accounting flags */ + current->io_usage = 0; if (N_MAGIC(ex) == OMAGIC) { do_mmap(NULL, 0, ex.a_text+ex.a_data, PROT_READ|PROT_WRITE|PROT_EXEC, diff -ru --new-file linux-1.2.3/fs/ext2/super.c linux/fs/ext2/super.c --- linux-1.2.3/fs/ext2/super.c Wed Mar 22 09:33:59 1995 +++ linux/fs/ext2/super.c Sun Apr 2 11:39:55 1995 @@ -287,11 +287,8 @@ return 0; } } - else { - printk ("EXT2-fs: Unrecognized mount option %s\n", this_char); - return 0; + else return 1; } - } return 1; } diff -ru --new-file linux-1.2.3/fs/fcntl.c linux/fs/fcntl.c --- linux-1.2.3/fs/fcntl.c Mon Jan 2 08:02:59 1995 +++ linux/fs/fcntl.c Sun Apr 2 11:39:55 1995 @@ -12,6 +12,7 @@ #include #include #include +#include extern int fcntl_getlk(unsigned int, struct flock *); extern int fcntl_setlk(unsigned int, unsigned int, struct flock *); @@ -19,6 +20,8 @@ static int dupfd(unsigned int fd, unsigned int arg) { + int error; + if (fd >= NR_OPEN || !current->files->fd[fd]) return -EBADF; if (arg >= NR_OPEN) @@ -30,6 +33,8 @@ break; if (arg >= NR_OPEN) return -EMFILE; + if ((error = vfs_getwriteaccess(current->files->fd[fd]))) + return error; FD_CLR(arg, ¤t->files->close_on_exec); (current->files->fd[arg] = current->files->fd[fd])->f_count++; return arg; diff -ru --new-file linux-1.2.3/fs/file_table.c linux/fs/file_table.c --- linux-1.2.3/fs/file_table.c Fri Oct 21 08:39:35 1994 +++ linux/fs/file_table.c Sun Apr 2 11:39:55 1995 @@ -7,6 +7,7 @@ #include #include #include +#include struct file * first_file; int nr_files = 0; @@ -88,3 +89,35 @@ } return NULL; } + +#ifdef CONFIG_QUOTA +void add_dquot_ref(dev_t dev, short type) +{ + struct file *filp; + int i; + + /* Check files that are currently opened for writing. */ + for (filp = first_file, i = 0; i < nr_files; i++, filp = filp->f_next) { + if (!filp->f_count || !filp->f_inode || filp->f_inode->i_dev != dev) + continue; + if (filp->f_inode->i_writecount > 0) { + getinoquota(filp->f_inode, type); + if (filp->f_inode->i_dquot[type] != NODQUOT) + filp->f_inode->i_dquot[type]->dq_count += + (filp->f_inode->i_writecount - 1); + } + } +} + +void reset_dquot_ptrs(dev_t dev, short type) +{ + struct file *filp; + int i; + + for (filp = first_file, i = 0; i < nr_files; i++, filp = filp->f_next) + if (filp->f_count && filp->f_inode && + filp->f_inode->i_writecount && filp->f_inode->i_dev == dev) + filp->f_inode->i_dquot[type] = NODQUOT; +} +#endif + diff -ru --new-file linux-1.2.3/fs/fileio.c linux/fs/fileio.c --- linux-1.2.3/fs/fileio.c Thu Jan 1 01:00:00 1970 +++ linux/fs/fileio.c Sun Apr 2 11:39:55 1995 @@ -0,0 +1,427 @@ +/* + * + * Simple VFS definitions for fileio. + * + * Authors: Marco van Wieringen + * Edvard Tuinder + * + * Version: $Id: fileio.c,v 1.14 1994/11/06 20:46:41 mvw Exp mvw $ + * + */ + +#include +#include +#include +#include +#include +#include +#include + +#ifdef CONFIG_QUOTA +extern int lookup(struct inode *, const char *, int, struct inode **); + +int vfs_getwriteaccess(struct file *filp) +{ + struct task_struct **p; + struct vm_area_struct *mpnt; + + if (filp->f_inode && S_ISREG(filp->f_inode->i_mode) && (filp->f_mode & 2)) { + for (p = &LAST_TASK; p > &FIRST_TASK; --p) { + if (!*p) + continue; + for (mpnt = (*p)->mm->mmap; mpnt; mpnt = mpnt->vm_next) { + if (filp->f_inode != mpnt->vm_inode) + continue; + if (mpnt->vm_flags & VM_DENYWRITE) + return -ETXTBSY; + } + } + filp->f_inode->i_writecount++; + getinoquota(filp->f_inode, -1); + } + return 0; +} + +void vfs_putwriteaccess(struct file *filp) +{ + if (filp->f_inode && filp->f_inode->i_writecount && + S_ISREG(filp->f_inode->i_mode) && (filp->f_mode & 2)) { + filp->f_inode->i_writecount--; + putinoquota(filp->f_inode); + } +} + +int vfs_write(struct inode *inode, struct file *filp, char *addr, size_t bytes) +{ + size_t written; + u_long cur_blocks, wanted_blocks = 0, avail_blocks = 0; + + if (S_ISREG(inode->i_mode)) { + cur_blocks = isize_to_blocks(inode->i_size, inode->i_blksize); + if ((filp->f_pos + bytes) > inode->i_size) { + wanted_blocks = isize_to_blocks(filp->f_pos + bytes, inode->i_blksize) - cur_blocks; + if (wanted_blocks && quota_alloc(inode, 0, wanted_blocks, &avail_blocks) == NO_QUOTA) + return -EDQUOT; + if (wanted_blocks && (avail_blocks < wanted_blocks)) + bytes = blocks_to_isize((cur_blocks + avail_blocks), + inode->i_blksize) - filp->f_pos; + } + if ((written = filp->f_op->write(inode, filp, addr, bytes)) != bytes) { + quota_remove(inode, 0, avail_blocks - + (isize_to_blocks(inode->i_size, inode->i_blksize) - + isize_to_blocks((inode->i_size - written), inode->i_blksize))); + } + current->io_usage += written; + if (wanted_blocks && (avail_blocks < wanted_blocks)) + return -EDQUOT; + return written; + } else { + current->io_usage += bytes; + return filp->f_op->write(inode, filp, (char *)addr, bytes); + } +} + +int vfs_create(struct inode *dir, const char *basename, int namelen, int mode, struct inode **res_ino) +{ + int error; + struct inode new_inode; + + memset(&new_inode, 0, sizeof(struct inode)); + new_inode.i_dev = dir->i_dev; + new_inode.i_uid = current->fsuid; + new_inode.i_gid = current->fsgid; + getinoquota(&new_inode, -1); + + if (quota_alloc(&new_inode, 1, 0, (u_long *)0) == NO_QUOTA) { + putinoquota(&new_inode); + return -EDQUOT; + } + error = dir->i_op->create(dir, basename, namelen, mode, res_ino); + if (error) + quota_remove(&new_inode, 1, 0); + putinoquota(&new_inode); + + return error; +} + +int vfs_truncate(struct inode *inode, size_t length) +{ + int error; + size_t old_isize; + struct iattr newattrs; + struct file filp; + + memset(&filp, 0, sizeof(struct file)); + filp.f_mode &= 2; + filp.f_inode = inode; + if ((error = vfs_getwriteaccess(&filp))) + return error; + old_isize = inode->i_size; + inode->i_size = newattrs.ia_size = length; + if (inode->i_op && inode->i_op->truncate) + inode->i_op->truncate(inode); + newattrs.ia_ctime = newattrs.ia_mtime = CURRENT_TIME; + newattrs.ia_valid = ATTR_SIZE | ATTR_CTIME | ATTR_MTIME; + if ((error = notify_change(inode, &newattrs)) == 0) { + quota_remove(inode, 0, isize_to_blocks(old_isize, inode->i_blksize)); + inode->i_dirt = 1; + } + vfs_putwriteaccess(&filp); + return error; +} + +int vfs_mknod(struct inode *dir, const char *basename, int namelen, int mode, dev_t dev) +{ + int error; + struct inode new_inode; + + memset(&new_inode, 0, sizeof(struct inode)); + new_inode.i_dev = dir->i_dev; + new_inode.i_uid = current->fsuid; + new_inode.i_gid = current->fsgid; + getinoquota(&new_inode, -1); + + if (quota_alloc(&new_inode, 1, 0, (u_long *)0) == NO_QUOTA) { + putinoquota(&new_inode); + iput(dir); + return -EDQUOT; + } + dir->i_count++; + error = dir->i_op->mknod(dir, basename, namelen, mode, dev); + if (error) + quota_remove(&new_inode, 1, 0); + putinoquota(&new_inode); + iput(dir); + + return error; +} + +int vfs_mkdir(struct inode *dir, const char *basename, int namelen, int mode) +{ + int error; + struct inode new_inode; + + memset(&new_inode, 0, sizeof(struct inode)); + new_inode.i_dev = dir->i_dev; + new_inode.i_uid = current->fsuid; + new_inode.i_gid = current->fsgid; + getinoquota(&new_inode, -1); + + if (quota_alloc(&new_inode, 1, 1, (u_long *)0) == NO_QUOTA) { + putinoquota(&new_inode); + iput(dir); + return -EDQUOT; + } + dir->i_count++; + error = dir->i_op->mkdir(dir, basename, namelen, mode); + if (error) + quota_remove(&new_inode, 1, 1); + putinoquota(&new_inode); + iput(dir); + + return error; +} + +int vfs_rmdir(struct inode *dir, const char *basename, int namelen) +{ + int error; + struct inode *old_inode; + + /* + * Need inode entry of directory for quota operations + */ + dir->i_count++; + if ((error = lookup(dir, basename, namelen, &old_inode))) { + iput(dir); + return error; + } + getinoquota(old_inode, -1); + if (!(error = dir->i_op->rmdir(dir, basename, namelen))) + quota_remove(old_inode, 1, 1); + putinoquota(old_inode); + iput(old_inode); + + return error; +} + +int vfs_unlink(struct inode *dir, const char *basename, int namelen) +{ + int error; + struct inode *old_inode; + + /* + * Need inode info of to remove file for quota operations. + */ + dir->i_count++; + if ((error = lookup(dir, basename, namelen, &old_inode))) { + iput(dir); + return error; + } + getinoquota(old_inode, -1); + error = dir->i_op->unlink(dir, basename, namelen); + /* + * Remove blocks and inode. Only if link-count is 0 ! + */ + if (!error && old_inode->i_nlink == 0) + quota_remove(old_inode, 1, isize_to_blocks(old_inode->i_size, old_inode->i_blksize)); + putinoquota(old_inode); + iput(old_inode); + + return error; +} + +int vfs_symlink(struct inode *dir, const char *basename, int namelen, const char *oldname) +{ + int error; + struct inode new_inode; + + memset(&new_inode, 0, sizeof(struct inode)); + new_inode.i_dev = dir->i_dev; + new_inode.i_uid = current->fsuid; + new_inode.i_gid = current->fsgid; + getinoquota(&new_inode, -1); + + if (quota_alloc(&new_inode, 1, 1, (u_long *)0) == NO_QUOTA) { + putinoquota(&new_inode); + iput(dir); + return -EDQUOT; + } + dir->i_count++; + if (!(error = dir->i_op->symlink(dir, basename, namelen, oldname))) + quota_remove(&new_inode, 1, 1); + putinoquota(&new_inode); + iput(dir); + + return error; +} + +int vfs_chown(struct inode *inode, uid_t uid, gid_t gid) +{ + int error; + struct iattr newattrs; + + if (IS_RDONLY(inode)) + return -EROFS; + if (uid == (uid_t) -1) + uid = inode->i_uid; + if (gid == (gid_t) -1) + gid = inode->i_gid; + newattrs.ia_mode = inode->i_mode; + newattrs.ia_uid = uid; + newattrs.ia_gid = gid; + newattrs.ia_ctime = CURRENT_TIME; + newattrs.ia_valid = ATTR_UID | ATTR_GID | ATTR_CTIME; + /* + * If the owner has been changed, remove the setuid bit + */ + if (uid != inode->i_uid && (inode->i_mode & S_ISUID)) { + newattrs.ia_mode &= ~S_ISUID; + newattrs.ia_valid |= ATTR_MODE; + } + /* + * If the group has been changed, remove the setgid bit + */ + if (gid != inode->i_gid && (inode->i_mode & S_ISGID)) { + newattrs.ia_mode &= ~S_ISGID; + newattrs.ia_valid |= ATTR_MODE; + } + getinoquota(inode, -1); + if (quota_transfer(inode, &newattrs, 1, + isize_to_blocks(inode->i_size, inode->i_blksize), 0) == NO_QUOTA) { + putinoquota(inode); + return -EDQUOT; + } + if ((error = notify_change(inode, &newattrs))) + quota_transfer(inode, &newattrs, 1, + isize_to_blocks(inode->i_size, inode->i_blksize), 1); + putinoquota(inode); + inode->i_dirt = 1; + return error; +} + +int vfs_rename(struct inode *old_dir, const char *old_base, int old_len, + struct inode *new_dir, const char *new_base, int new_len) +{ + int error; + struct inode *old_inode, *new_inode; + + /* + * Check if target file already exists, drop quota of file if + * it already exists and is overwritten. Extra check needed for + * renames of file to the same file. + */ + old_dir->i_count++; + if ((error = lookup(old_dir, old_base, old_len, &old_inode))) { + iput(old_dir); + iput(new_dir); + return error; + } + new_dir->i_count++; + if (!lookup(new_dir, new_base, new_len, &new_inode)) { + if (old_dir != new_dir && old_inode != new_inode) { + iput(old_inode); + error = old_dir->i_op->rename(old_dir, old_base, old_len, new_dir, new_base, new_len); + if (!error) { + getinoquota(new_inode, -1); + quota_remove(new_inode, 1, + isize_to_blocks(new_inode->i_size, new_inode->i_blksize)); + putinoquota(new_inode); + } + iput(new_inode); + return error; + } + iput(new_inode); + } + iput(old_inode); + return old_dir->i_op->rename(old_dir, old_base, old_len, new_dir, new_base, new_len); +} + +#else /* CONFIG_QUOTA */ + +int vfs_getwriteaccess(struct file *filp) +{ + struct task_struct **p; + struct vm_area_struct *mpnt; + + if (filp->f_inode && S_ISREG(filp->f_inode->i_mode) && (filp->f_mode & 2)) { + for (p = &LAST_TASK; p > &FIRST_TASK; --p) { + if (!*p) + continue; + for (mpnt = (*p)->mm->mmap; mpnt; mpnt = mpnt->vm_next) { + if (filp->f_inode != mpnt->vm_inode) + continue; + if (mpnt->vm_flags & VM_DENYWRITE) + return -ETXTBSY; + } + } + filp->f_inode->i_writecount++; + } + return 0; +} + +void vfs_putwriteaccess(struct file *filp) +{ + if (filp->f_inode && filp->f_inode->i_writecount && + S_ISREG(filp->f_inode->i_mode) && (filp->f_mode & 2)) + filp->f_inode->i_writecount--; +} + +int vfs_truncate(struct inode *inode, size_t length) +{ + int error; + struct iattr newattrs; + struct file filp; + + memset(&filp, 0, sizeof(struct file)); + filp.f_mode &= 2; + filp.f_inode = inode; + if ((error = vfs_getwriteaccess(&filp))) + return error; + inode->i_size = newattrs.ia_size = length; + if (inode->i_op && inode->i_op->truncate) + inode->i_op->truncate(inode); + newattrs.ia_ctime = newattrs.ia_mtime = CURRENT_TIME; + newattrs.ia_valid = ATTR_SIZE | ATTR_CTIME | ATTR_MTIME; + if ((error = notify_change(inode, &newattrs)) == 0) + inode->i_dirt = 1; + vfs_putwriteaccess(&filp); + return 0; +} + +int vfs_chown(struct inode *inode, uid_t uid, gid_t gid) +{ + int error; + struct iattr newattrs; + + if (IS_RDONLY(inode)) + return -EROFS; + if (uid == (uid_t) -1) + uid = inode->i_uid; + if (gid == (gid_t) -1) + gid = inode->i_gid; + newattrs.ia_mode = inode->i_mode; + newattrs.ia_uid = uid; + newattrs.ia_gid = gid; + newattrs.ia_ctime = CURRENT_TIME; + newattrs.ia_valid = ATTR_UID | ATTR_GID | ATTR_CTIME; + /* + * If the owner has been changed, remove the setuid bit + */ + if (uid != inode->i_uid && (inode->i_mode & S_ISUID)) { + newattrs.ia_mode = inode->i_mode & ~S_ISUID; + newattrs.ia_valid |= ATTR_MODE; + } + /* + * If the group has been changed, remove the setgid bit + */ + if (gid != inode->i_gid && (inode->i_mode & S_ISGID)) { + newattrs.ia_mode = inode->i_mode & ~S_ISGID; + newattrs.ia_valid |= ATTR_MODE; + } + if ((error = notify_change(inode, &newattrs))) + return error; + inode->i_dirt = 1; + return 0; +} +#endif /* CONFIG_QUOTA */ + diff -ru --new-file linux-1.2.3/fs/inode.c linux/fs/inode.c --- linux-1.2.3/fs/inode.c Wed Nov 30 16:17:39 1994 +++ linux/fs/inode.c Sun Apr 2 11:39:55 1995 @@ -502,6 +502,7 @@ struct inode_hash_entry * h; struct inode * inode; struct inode * empty = NULL; + short cnt; if (!sb) panic("VFS: iget with sb==NULL"); @@ -530,8 +531,11 @@ goto return_it; found_it: - if (!inode->i_count) + if (!inode->i_count) { nr_free_inodes--; + for (cnt = 0; cnt < MAXQUOTAS; cnt++) + inode->i_dquot[cnt] = NODQUOT; + } inode->i_count++; wait_on_inode(inode); if (inode->i_dev != sb->s_dev || inode->i_ino != nr) { diff -ru --new-file linux-1.2.3/fs/isofs/inode.c linux/fs/isofs/inode.c --- linux-1.2.3/fs/isofs/inode.c Wed Feb 22 07:15:14 1995 +++ linux/fs/isofs/inode.c Sun Apr 2 11:39:55 1995 @@ -146,7 +146,7 @@ break; } } - else return 0; + else return 1; } return 1; } diff -ru --new-file linux-1.2.3/fs/msdos/inode.c linux/fs/msdos/inode.c --- linux-1.2.3/fs/msdos/inode.c Sun Feb 26 17:52:02 1995 +++ linux/fs/msdos/inode.c Sun Apr 2 11:39:55 1995 @@ -157,7 +157,7 @@ printk ("MSDOS FS: Invalid blocksize (512 or 1024)\n"); } } - else return 0; + else return 1; } return 1; } diff -ru --new-file linux-1.2.3/fs/namei.c linux/fs/namei.c --- linux-1.2.3/fs/namei.c Sun Jan 22 13:38:25 1995 +++ linux/fs/namei.c Sun Apr 2 11:39:55 1995 @@ -16,6 +16,7 @@ #include #include #include +#include #include #define ACC_MODE(x) ("\000\004\002\006"[(x)&O_ACCMODE]) @@ -114,38 +115,6 @@ } /* - * get_write_access() gets write permission for a file. - * put_write_access() releases this write permission. - * This is used for regular files. - * We cannot support write (and maybe mmap read-write shared) accesses and - * MAP_DENYWRITE mmappings simultaneously. - */ -int get_write_access(struct inode * inode) -{ - struct task_struct ** p; - - if ((inode->i_count > 1) && S_ISREG(inode->i_mode)) /* shortcut */ - for (p = &LAST_TASK ; p > &FIRST_TASK ; --p) { - struct vm_area_struct * mpnt; - if (!*p) - continue; - for(mpnt = (*p)->mm->mmap; mpnt; mpnt = mpnt->vm_next) { - if (inode != mpnt->vm_inode) - continue; - if (mpnt->vm_flags & VM_DENYWRITE) - return -ETXTBSY; - } - } - inode->i_wcount++; - return 0; -} - -void put_write_access(struct inode * inode) -{ - inode->i_wcount--; -} - -/* * lookup() looks up one part of a pathname, using the fs-dependent * routines (currently minix_lookup) for it. It also checks for * fathers (pseudo-roots, mount-points) @@ -372,7 +341,7 @@ error = -EROFS; else { dir->i_count++; /* create eats the dir */ - error = dir->i_op->create(dir,basename,namelen,mode,res_inode); + error = vfs_create(dir,basename,namelen,mode,res_inode); up(&dir->i_sem); iput(dir); return error; @@ -407,6 +376,7 @@ return -EROFS; } } + /* * An append-only file must be opened in append mode for writing */ @@ -414,26 +384,9 @@ iput(inode); return -EPERM; } - if (flag & O_TRUNC) { - struct iattr newattrs; - - if ((error = get_write_access(inode))) { - iput(inode); + if (flag & O_TRUNC) + if ((error = vfs_truncate(inode, 0))) return error; - } - newattrs.ia_size = 0; - newattrs.ia_valid = ATTR_SIZE; - if ((error = notify_change(inode, &newattrs))) { - put_write_access(inode); - iput(inode); - return error; - } - inode->i_size = 0; - if (inode->i_op && inode->i_op->truncate) - inode->i_op->truncate(inode); - inode->i_dirt = 1; - put_write_access(inode); - } *res_inode = inode; return 0; } @@ -466,7 +419,7 @@ } dir->i_count++; down(&dir->i_sem); - error = dir->i_op->mknod(dir,basename,namelen,mode,dev); + error = vfs_mknod(dir,basename,namelen,mode,dev); up(&dir->i_sem); iput(dir); return error; @@ -523,7 +476,7 @@ } dir->i_count++; down(&dir->i_sem); - error = dir->i_op->mkdir(dir, basename, namelen, mode & 0777 & ~current->fs->umask); + error = vfs_mkdir(dir, basename, namelen, mode & 0777 & ~current->fs->umask); up(&dir->i_sem); iput(dir); return error; @@ -574,7 +527,7 @@ iput(dir); return -EPERM; } - return dir->i_op->rmdir(dir,basename,namelen); + return vfs_rmdir(dir,basename,namelen); } asmlinkage int sys_rmdir(const char * pathname) @@ -622,7 +575,7 @@ iput(dir); return -EPERM; } - return dir->i_op->unlink(dir,basename,namelen); + return vfs_unlink(dir,basename,namelen); } asmlinkage int sys_unlink(const char * pathname) @@ -665,7 +618,7 @@ } dir->i_count++; down(&dir->i_sem); - error = dir->i_op->symlink(dir,basename,namelen,oldname); + error = vfs_symlink(dir,basename,namelen,oldname); up(&dir->i_sem); iput(dir); return error; @@ -820,7 +773,7 @@ } new_dir->i_count++; down(&new_dir->i_sem); - error = old_dir->i_op->rename(old_dir, old_base, old_len, + error = vfs_rename(old_dir, old_base, old_len, new_dir, new_base, new_len); up(&new_dir->i_sem); iput(new_dir); diff -ru --new-file linux-1.2.3/fs/open.c linux/fs/open.c --- linux-1.2.3/fs/open.c Wed Feb 15 08:31:56 1995 +++ linux/fs/open.c Sun Apr 2 11:39:55 1995 @@ -17,6 +17,7 @@ #include #include #include +#include #include @@ -70,7 +71,6 @@ { struct inode * inode; int error; - struct iattr newattrs; error = namei(path,&inode); if (error) @@ -91,19 +91,7 @@ iput(inode); return -EPERM; } - error = get_write_access(inode); - if (error) { - iput(inode); - return error; - } - inode->i_size = newattrs.ia_size = length; - if (inode->i_op && inode->i_op->truncate) - inode->i_op->truncate(inode); - newattrs.ia_ctime = newattrs.ia_mtime = CURRENT_TIME; - newattrs.ia_valid = ATTR_SIZE | ATTR_CTIME | ATTR_MTIME; - inode->i_dirt = 1; - error = notify_change(inode, &newattrs); - put_write_access(inode); + error = vfs_truncate(inode, length); iput(inode); return error; } @@ -112,7 +100,6 @@ { struct inode * inode; struct file * file; - struct iattr newattrs; if (fd >= NR_OPEN || !(file = current->files->fd[fd])) return -EBADF; @@ -122,13 +109,7 @@ return -EACCES; if (IS_IMMUTABLE(inode) || IS_APPEND(inode)) return -EPERM; - inode->i_size = newattrs.ia_size = length; - if (inode->i_op && inode->i_op->truncate) - inode->i_op->truncate(inode); - newattrs.ia_ctime = newattrs.ia_mtime = CURRENT_TIME; - newattrs.ia_valid = ATTR_SIZE | ATTR_CTIME | ATTR_MTIME; - inode->i_dirt = 1; - return notify_change(inode, &newattrs); + return vfs_truncate(inode, length); } /* If times==NULL, set access and modification to current time, @@ -314,81 +295,25 @@ { struct inode * inode; struct file * file; - struct iattr newattrs; if (fd >= NR_OPEN || !(file = current->files->fd[fd])) return -EBADF; if (!(inode = file->f_inode)) return -ENOENT; - if (IS_RDONLY(inode)) - return -EROFS; - if (user == (uid_t) -1) - user = inode->i_uid; - if (group == (gid_t) -1) - group = inode->i_gid; - newattrs.ia_mode = inode->i_mode; - newattrs.ia_uid = user; - newattrs.ia_gid = group; - newattrs.ia_ctime = CURRENT_TIME; - newattrs.ia_valid = ATTR_UID | ATTR_GID | ATTR_CTIME; - /* - * If the owner has been changed, remove the setuid bit - */ - if (user != inode->i_uid && (inode->i_mode & S_ISUID)) { - newattrs.ia_mode &= ~S_ISUID; - newattrs.ia_valid |= ATTR_MODE; - } - /* - * If the group has been changed, remove the setgid bit - */ - if (group != inode->i_gid && (inode->i_mode & S_ISGID)) { - newattrs.ia_mode &= ~S_ISGID; - newattrs.ia_valid |= ATTR_MODE; - } - inode->i_dirt = 1; - return notify_change(inode, &newattrs); + return vfs_chown(inode, user, group); } asmlinkage int sys_chown(const char * filename, uid_t user, gid_t group) { struct inode * inode; int error; - struct iattr newattrs; error = lnamei(filename,&inode); if (error) return error; - if (IS_RDONLY(inode)) { - iput(inode); - return -EROFS; - } - if (user == (uid_t) -1) - user = inode->i_uid; - if (group == (gid_t) -1) - group = inode->i_gid; - newattrs.ia_mode = inode->i_mode; - newattrs.ia_uid = user; - newattrs.ia_gid = group; - newattrs.ia_ctime = CURRENT_TIME; - newattrs.ia_valid = ATTR_UID | ATTR_GID | ATTR_CTIME; - /* - * If the owner has been changed, remove the setuid bit - */ - if (user != inode->i_uid && (inode->i_mode & S_ISUID)) { - newattrs.ia_mode &= ~S_ISUID; - newattrs.ia_valid |= ATTR_MODE; - } - /* - * If the group has been changed, remove the setgid bit - */ - if (group != inode->i_gid && (inode->i_mode & S_ISGID)) { - newattrs.ia_mode &= ~S_ISGID; - newattrs.ia_valid |= ATTR_MODE; - } - inode->i_dirt = 1; - error = notify_change(inode, &newattrs); + error = vfs_chown(inode, user, group); iput(inode); - return(error); + return error; } /* @@ -407,56 +332,44 @@ */ int do_open(const char * filename,int flags,int mode) { - struct inode * inode; - struct file * f; - int flag,error,fd; + struct inode *inode; + struct file *filp; + int flag,error, fd; - for(fd=0; fdrlim[RLIMIT_NOFILE].rlim_cur; fd++) + for(fd = 0; fd < NR_OPEN && fd < current->rlim[RLIMIT_NOFILE].rlim_cur; fd++) if (!current->files->fd[fd]) break; - if (fd>=NR_OPEN || fd>=current->rlim[RLIMIT_NOFILE].rlim_cur) + if (fd >= NR_OPEN || fd >= current->rlim[RLIMIT_NOFILE].rlim_cur) return -EMFILE; FD_CLR(fd,¤t->files->close_on_exec); - f = get_empty_filp(); - if (!f) + if ((filp = get_empty_filp()) == (struct file *)NULL) return -ENFILE; - current->files->fd[fd] = f; - f->f_flags = flag = flags; - f->f_mode = (flag+1) & O_ACCMODE; - if (f->f_mode) + current->files->fd[fd] = filp; + filp->f_flags = flag = flags; + filp->f_mode = (flag + 1) & O_ACCMODE; + if (filp->f_mode) flag++; if (flag & (O_TRUNC | O_CREAT)) flag |= 2; - error = open_namei(filename,flag,mode,&inode,NULL); - if (!error && (f->f_mode & 2)) { - error = get_write_access(inode); - if (error) - iput(inode); - } - if (error) { - current->files->fd[fd]=NULL; - f->f_count--; - return error; - } - - f->f_inode = inode; - f->f_pos = 0; - f->f_reada = 0; - f->f_op = NULL; - if (inode->i_op) - f->f_op = inode->i_op->default_file_ops; - if (f->f_op && f->f_op->open) { - error = f->f_op->open(inode,f); - if (error) { - if (f->f_mode & 2) put_write_access(inode); - iput(inode); - f->f_count--; - current->files->fd[fd]=NULL; - return error; + if ((error = open_namei(filename, flag, mode, &inode, NULL)) == 0) { + filp->f_inode = inode; + filp->f_pos = 0; + filp->f_reada = 0; + filp->f_op = inode->i_op->default_file_ops; + if ((error = vfs_getwriteaccess(filp)) == 0) { + if (filp->f_op && filp->f_op->open) + error = filp->f_op->open(inode, filp); + if (error == 0) { + filp->f_flags &= ~(O_CREAT | O_EXCL | O_NOCTTY | O_TRUNC); + return (fd); + } + vfs_putwriteaccess(filp); } + iput(inode); } - f->f_flags &= ~(O_CREAT | O_EXCL | O_NOCTTY | O_TRUNC); - return (fd); + current->files->fd[fd] = NULL; + filp->f_count--; + return error; } asmlinkage int sys_open(const char * filename,int flags,int mode) @@ -488,6 +401,7 @@ inode = filp->f_inode; if (inode) fcntl_remove_locks(current, filp); + vfs_putwriteaccess(filp); if (filp->f_count > 1) { filp->f_count--; return 0; @@ -496,7 +410,6 @@ filp->f_op->release(inode,filp); filp->f_count--; filp->f_inode = NULL; - if (filp->f_mode & 2) put_write_access(inode); iput(inode); return 0; } diff -ru --new-file linux-1.2.3/fs/read_write.c linux/fs/read_write.c --- linux-1.2.3/fs/read_write.c Mon Jan 23 22:04:10 1995 +++ linux/fs/read_write.c Sun Apr 2 11:39:55 1995 @@ -10,6 +10,7 @@ #include #include #include +#include #include @@ -136,6 +137,7 @@ error = verify_area(VERIFY_WRITE,buf,count); if (error) return error; + current->io_usage += count; return file->f_op->read(inode,file,buf,count); } @@ -144,6 +146,7 @@ int error; struct file * file; struct inode * inode; + struct iattr newattrs; int written; if (fd>=NR_OPEN || !(file=current->files->fd[fd]) || !(inode=file->f_inode)) @@ -157,13 +160,12 @@ error = verify_area(VERIFY_READ,buf,count); if (error) return error; - written = file->f_op->write(inode,file,buf,count); + written = vfs_write(inode,file,buf,count); /* * If data has been written to the file, remove the setuid and * the setgid bits */ if (written > 0 && !suser() && (inode->i_mode & (S_ISUID | S_ISGID))) { - struct iattr newattrs; newattrs.ia_mode = inode->i_mode & ~(S_ISUID | S_ISGID); newattrs.ia_valid = ATTR_MODE; notify_change(inode, &newattrs); diff -ru --new-file linux-1.2.3/fs/super.c linux/fs/super.c --- linux-1.2.3/fs/super.c Wed Jan 18 08:31:40 1995 +++ linux/fs/super.c Sun Apr 2 11:39:55 1995 @@ -2,16 +2,20 @@ * linux/fs/super.c * * Copyright (C) 1991, 1992 Linus Torvalds + * + * super.c contains code to handle: - mount structures + * - super-block tables. + * - mount systemcall + * - umount systemcall */ -/* - * super.c contains code to handle the super-block tables. - */ #include #include #include #include +#include +#include #include #include #include @@ -22,22 +26,111 @@ #include #include #include - + extern struct file_operations * get_blkfops(unsigned int); -extern struct file_operations * get_chrfops(unsigned int); extern void wait_for_keypress(void); extern int root_mountflags; -struct super_block super_blocks[NR_SUPER]; - static int do_remount_sb(struct super_block *sb, int flags, char * data); -/* this is initialized in init/main.c */ +/* + * This is initialized in init/main.c + */ dev_t ROOT_DEV = 0; -static struct file_system_type * file_systems = NULL; +struct super_block super_blocks[NR_SUPER]; +static struct file_system_type *file_systems = (struct file_system_type *) NULL; +static struct vfsmount *vfsmntlist = (struct vfsmount *) NULL, + *vfsmnttail = (struct vfsmount *) NULL, + *mru_vfsmnt = (struct vfsmount *) NULL; + +/* + * This part handles the management of the list of mounted filesystems. + * Superblock retrieval is also done with this list. + */ +struct vfsmount *lookup_vfsmnt(dev_t dev) +{ + register struct vfsmount *lptr; + + if (vfsmntlist == (struct vfsmount *) 0) + return ((struct vfsmount *) 0); + + if (mru_vfsmnt != (struct vfsmount *) 0 && mru_vfsmnt->mnt_dev == dev) + return (mru_vfsmnt); + + for (lptr = vfsmntlist; lptr != (struct vfsmount *)0; lptr = lptr->mnt_next) + if (lptr->mnt_dev == dev) + return (lptr); + + return ((struct vfsmount *) 0); + /* NOTREACHED */ +} + +static struct vfsmount *add_vfsmnt(dev_t dev, const char *dev_name, + const char *dir_name) +{ + register struct vfsmount *lptr; + char *tmp; + + if ((lptr = (struct vfsmount *) + kmalloc(sizeof(struct vfsmount), GFP_KERNEL)) == (struct vfsmount *) 0) + panic("VFS: Unable to allocate memory for vfsmount devicelist"); + + memset(lptr, 0, sizeof(struct vfsmount)); + lptr->mnt_dev = dev; + if (dev_name) { + if (!getname(dev_name, &tmp)) { + if ((lptr->mnt_devname = + (char *) kmalloc(strlen(tmp), GFP_KERNEL)) != (char *)0) + strcpy(lptr->mnt_devname, tmp); + putname(tmp); + } + } + if (dir_name) { + if (!getname(dir_name, &tmp)) { + if ((lptr->mnt_dirname = + (char *) kmalloc(strlen(tmp), GFP_KERNEL)) != (char *)0) + strcpy(lptr->mnt_dirname, tmp); + putname(tmp); + } + } + + if (vfsmntlist == (struct vfsmount *)0) + vfsmntlist = vfsmnttail = lptr; + else { + vfsmnttail->mnt_next = lptr; + vfsmnttail = lptr; + } + return (lptr); +} + +static void remove_vfsmnt(dev_t dev) +{ + register struct vfsmount *lptr, *tofree; + + if (vfsmntlist == (struct vfsmount *) 0) + return; + lptr = vfsmntlist; + if (lptr->mnt_dev == dev) { + tofree = lptr; + vfsmntlist = lptr->mnt_next; + } else { + while (lptr->mnt_next != (struct vfsmount *) 0) { + if (lptr->mnt_next->mnt_dev == dev) + break; + lptr = lptr->mnt_next; + } + tofree = lptr->mnt_next; + if (vfsmnttail->mnt_dev == dev) + vfsmnttail = lptr; + lptr->mnt_next = lptr->mnt_next->mnt_next; + } + kfree(tofree->mnt_devname); + kfree(tofree->mnt_dirname); + kfree_s(tofree, sizeof(struct vfsmount)); +} int register_filesystem(struct file_system_type * fs) { @@ -320,17 +413,30 @@ MAJOR(dev), MINOR(dev)); } +extern void acct_auto_close(dev_t dev); + static int do_umount(dev_t dev) { struct super_block * sb; int retval; if (dev==ROOT_DEV) { - /* Special case for "unmounting" root. We just try to remount - it readonly, and sync() the device. */ + /* + * Special case for "unmounting" root. We just try to remount + * it readonly, and sync() the device. + */ if (!(sb=get_super(dev))) return -ENOENT; if (!(sb->s_flags & MS_RDONLY)) { +#ifdef CONFIG_QUOTA + /* + * Make sure all quotas are turned off on this device we need to mount + * it readonly so no more writes by the quotasystem. + * If later on the remount fails to bad there are no quotas running + * anymore. Turn them on again by hand. + */ + (void) quota_off(dev, -1); +#endif fsync_dev(dev); retval = do_remount_sb(sb, MS_RDONLY, 0); if (retval) @@ -343,6 +449,18 @@ if (!sb->s_covered->i_mount) printk("VFS: umount(%d/%d): mounted inode has i_mount=NULL\n", MAJOR(dev), MINOR(dev)); +#ifdef CONFIG_QUOTA + /* + * Before checking if the filesystem is still busy make sure the kernel + * doesn't hold any quotafiles open on that device. If the umount fails + * to bad there are no quotas running anymore. Turn them on again by hand. + */ + (void) quota_off(dev, -1); +#endif + /* + * The same as for quota is also true for the accounting file. + */ + acct_auto_close(dev); if (!fs_may_umount(dev, sb->s_mounted)) return -EBUSY; sb->s_covered->i_mount = NULL; @@ -353,6 +471,7 @@ if (sb->s_op && sb->s_op->write_super && sb->s_dirt) sb->s_op->write_super(sb); put_super(dev); + remove_vfsmnt(dev); return 0; } @@ -428,13 +547,15 @@ * We also have to flush all inode-data for this device, as the new mount * might need new info. */ -static int do_mount(dev_t dev, const char * dir, char * type, int flags, void * data) +static int do_mount(dev_t dev, const char * dev_name, const char * dir_name, + char * type, int flags, void * data) { struct inode * dir_i; struct super_block * sb; + struct vfsmount *vfsmnt; int error; - error = namei(dir,&dir_i); + error = namei(dir_name,&dir_i); if (error) return error; if (dir_i->i_count != 1 || dir_i->i_mount) { @@ -458,6 +579,9 @@ iput(dir_i); return -EBUSY; } + vfsmnt = add_vfsmnt(dev, dev_name, dir_name); + vfsmnt->mnt_sb = sb; + vfsmnt->mnt_sem.count = 1; sb->s_covered = dir_i; dir_i->i_mount = sb->s_mounted; return 0; /* we don't iput(dir_i) - see umount */ @@ -628,7 +752,7 @@ return retval; } } - retval = do_mount(dev,dir_name,t,flags,(void *) page); + retval = do_mount(dev,dev_name,dir_name,t,flags,(void *) page); free_page(page); if (retval && fops && fops->release) fops->release(inode, NULL); @@ -640,10 +764,11 @@ { struct file_system_type * fs_type; struct super_block * sb; + struct vfsmount *vfsmnt; struct inode * inode, d_inode; struct file filp; int retval; - + memset(super_blocks, 0, sizeof(super_blocks)); #ifdef CONFIG_BLK_DEV_FD if (MAJOR(ROOT_DEV) == FLOPPY_MAJOR) { @@ -670,9 +795,9 @@ for (fs_type = file_systems ; fs_type ; fs_type = fs_type->next) { if(retval) break; - if (!fs_type->requires_dev) - continue; - sb = read_super(ROOT_DEV,fs_type->name,root_mountflags,NULL,1); + if (!fs_type->requires_dev) + continue; + sb = read_super(ROOT_DEV,fs_type->name,root_mountflags,NULL,1); if (sb) { inode = sb->s_mounted; inode->i_count += 3 ; /* NOTE! it is logically used 4 times, not 1 */ @@ -683,6 +808,9 @@ printk ("VFS: Mounted root (%s filesystem)%s.\n", fs_type->name, (sb->s_flags & MS_RDONLY) ? " readonly" : ""); + vfsmnt = add_vfsmnt(ROOT_DEV, "rootfs", "/"); + vfsmnt->mnt_sb = sb; + vfsmnt->mnt_sem.count = 1; return; } } diff -ru --new-file linux-1.2.3/include/linux/acct.h linux/include/linux/acct.h --- linux-1.2.3/include/linux/acct.h Thu Jan 1 01:00:00 1970 +++ linux/include/linux/acct.h Sun Apr 2 11:39:55 1995 @@ -0,0 +1,28 @@ +#ifndef __LINUX_ACCT_H +#define __LINUX_ACCT_H + +#define ACCT_COMM 16 + +struct acct +{ + char ac_comm[ACCT_COMM]; /* Accounting command name */ + time_t ac_utime; /* Accounting user time */ + time_t ac_stime; /* Accounting system time */ + time_t ac_etime; /* Accounting elapsed time */ + time_t ac_btime; /* Beginning time */ + uid_t ac_uid; /* Accounting user ID */ + gid_t ac_gid; /* Accounting group ID */ + dev_t ac_tty; /* controlling tty */ + char ac_flag; /* Accounting flag */ + unsigned long ac_mem; /* Pages of memory used */ + unsigned long ac_io; /* Number of bytes read/written */ +}; + +#define AFORK 0001 /* has executed fork, but no exec */ +#define ASU 0002 /* used super-user privileges */ +#define ACORE 0004 /* dumped core */ +#define AXSIG 0010 /* killed by a signal */ + +#define AHZ 100 + +#endif diff -ru --new-file linux-1.2.3/include/linux/fileio.h linux/include/linux/fileio.h --- linux-1.2.3/include/linux/fileio.h Thu Jan 1 01:00:00 1970 +++ linux/include/linux/fileio.h Sun Apr 2 11:39:55 1995 @@ -0,0 +1,56 @@ +/* + * + * Simple VFS definitions for fileio. + * + * Authors: Marco van Wieringen + * Edvard Tuinder + * + * Version: $Id: fileio.h,v 1.8 1994/11/06 20:48:05 mvw Exp mvw $ + * + */ +#ifndef _LINUX_FILEIO_H +#define _LINUX_FILEIO_H + +#include +#include + +#ifdef CONFIG_QUOTA +int vfs_getwriteaccess(struct file *filp); +void vfs_putwriteaccess(struct file *filp); +int vfs_write(struct inode *inode, struct file *file, char *addr, size_t bytes); +int vfs_create(struct inode *dir, const char *basename, + int namelen, int mode, struct inode **res_ino); +int vfs_truncate(struct inode *ino, size_t length); +int vfs_mknod(struct inode *dir, const char *basename, + int namelen, int mode, dev_t dev); +int vfs_mkdir(struct inode *dir, const char *basename, int namelen, int mode); +int vfs_rmdir(struct inode *dir, const char *basename, int namelen); +int vfs_unlink(struct inode *dir, const char *basename, int namelen); +int vfs_symlink(struct inode *dir, const char *basename, + int namelen, const char *oldname); +int vfs_chown(struct inode *inode, uid_t uid, gid_t gid); +int vfs_rename(struct inode *old_dir, const char *old_base, int old_len, + struct inode *new_dir, const char *mew_base, int new_len); +#else /* CONFIG_QUOTA */ +int vfs_getwriteaccess(struct file *filp); +void vfs_putwriteaccess(struct file *filp); +#define vfs_write(inode, file, addr, bytes) \ +(file)->f_op->write((inode),(file),(addr),(bytes)) +#define vfs_create(dir, basename, namelen, mode, res_ino) \ +(dir)->i_op->create((dir),(basename),(namelen),(mode),(res_ino)) +int vfs_truncate(struct inode *inode, size_t length); +#define vfs_mknod(dir, basename, namelen, mode, dev) \ +(dir)->i_op->mknod((dir),(basename),(namelen),(mode),(dev)) +#define vfs_mkdir(dir, basename, namelen, mode) \ +(dir)->i_op->mkdir((dir),(basename),(namelen),(mode)) +#define vfs_rmdir(dir, basename, namelen) \ +(dir)->i_op->rmdir((dir),(basename),(namelen)) +#define vfs_unlink(dir, basename, namelen) \ +(dir)->i_op->unlink((dir),(basename),(namelen)) +#define vfs_symlink(dir, basename, namelen, oldname) \ +(dir)->i_op->symlink((dir),(basename),(namelen),(oldname)) +int vfs_chown(struct inode *inode, uid_t uid, gid_t gid); +#define vfs_rename(old_dir, old_base, old_len, new_dir, new_base, new_len) \ +(old_dir)->i_op->rename((old_dir),(old_base),(old_len),(new_dir),(new_base),(new_len)) +#endif /* CONFIG_QUOTA */ +#endif /* _LINUX_FILEIO_H */ diff -ru --new-file linux-1.2.3/include/linux/fs.h linux/include/linux/fs.h --- linux-1.2.3/include/linux/fs.h Thu Feb 23 12:32:05 1995 +++ linux/include/linux/fs.h Sun Apr 2 11:39:55 1995 @@ -200,6 +200,8 @@ time_t ia_ctime; }; +#include + struct inode { dev_t i_dev; unsigned long i_ino; @@ -226,7 +228,6 @@ struct inode * i_bound_to, * i_bound_by; struct inode * i_mount; unsigned short i_count; - unsigned short i_wcount; unsigned short i_flags; unsigned char i_lock; unsigned char i_dirt; @@ -234,6 +235,8 @@ unsigned char i_sock; unsigned char i_seek; unsigned char i_update; + struct dquot *i_dquot[MAXQUOTAS]; + unsigned short i_writecount; union { struct pipe_inode_info pipe_i; struct minix_inode_info minix_i; diff -ru --new-file linux-1.2.3/include/linux/kernel.h linux/include/linux/kernel.h --- linux-1.2.3/include/linux/kernel.h Wed Jan 4 20:16:05 1995 +++ linux/include/linux/kernel.h Sun Apr 2 11:39:55 1995 @@ -54,19 +54,6 @@ asmlinkage int printk(const char * fmt, ...) __attribute__ ((format (printf, 1, 2))); -/* - * This is defined as a macro, but at some point this might become a - * real subroutine that sets a flag if it returns true (to do - * BSD-style accounting where the process is flagged if it uses root - * privs). The implication of this is that you should do normal - * permissions checks first, and check suser() last. - * - * "suser()" checks against the effective user id, while "fsuser()" - * is used for file permission checking and checks against the fsuid.. - */ -#define suser() (current->euid == 0) -#define fsuser() (current->fsuid == 0) - #endif /* __KERNEL__ */ #define SI_LOAD_SHIFT 16 diff -ru --new-file linux-1.2.3/include/linux/mount.h linux/include/linux/mount.h --- linux-1.2.3/include/linux/mount.h Thu Jan 1 01:00:00 1970 +++ linux/include/linux/mount.h Sun Apr 2 11:39:55 1995 @@ -0,0 +1,34 @@ +/* + * + * Definitions for mount interface. This describes the in the kernel build + * linkedlist with mounted filesystems. + * + * Authors: Marco van Wieringen + * Edvard Tuinder + * + * Version: $Id: mount.h,v 1.3 1994/07/20 22:01:00 mvw Exp mvw $ + * + */ +#ifndef _LINUX_MOUNT_H +#define _LINUX_MOUNT_H + +#define QF_OPENING 0x01 /* Quotafile is in progress of being opened */ +#define QF_CLOSING 0x02 /* Quotafile is in progress of being closed */ + +struct vfsmount +{ + dev_t mnt_dev; /* Device this applies to */ + char *mnt_devname; /* Name of device e.g. /dev/dsk/hda1 */ + char *mnt_dirname; /* Name of directory mounted on */ + unsigned int mnt_flags; /* Flags of this device see above */ + struct semaphore mnt_sem; /* lock device while I/O in progress */ + struct super_block *mnt_sb; /* pointer to superblock */ + struct file *mnt_quotas[MAXQUOTAS]; /* fp's to quotafiles */ + time_t mnt_iexp[MAXQUOTAS]; /* expiretime for inodes */ + time_t mnt_bexp[MAXQUOTAS]; /* expiretime for blocks */ + struct vfsmount *mnt_next; /* pointer to next in linkedlist */ +}; + +struct vfsmount *lookup_vfsmnt(dev_t dev); + +#endif /* _LINUX_MOUNT_H */ diff -ru --new-file linux-1.2.3/include/linux/quota.h linux/include/linux/quota.h --- linux-1.2.3/include/linux/quota.h Thu Jan 1 01:00:00 1970 +++ linux/include/linux/quota.h Sun Apr 2 11:39:55 1995 @@ -0,0 +1,208 @@ +/* + * Copyright (c) 1982, 1986 Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Robert Elz at The University of Melbourne. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * Version: $Id: quota.h,v 1.7 1994/10/30 09:39:03 mvw Exp mvw $ + */ + +#ifndef _LINUX_QUOTA_ +#define _LINUX_QUOTA_ + +#include + +/* + * Convert diskblocks to blocks and the other way around. + * currently only to fool the BSD source. :-) + */ +#define dbtob(num) (num << 10) +#define btodb(num) (num >> 10) + +/* + * Definitions for disk quotas imposed on the average user + * (big brother finally hits Linux). + * + * The following constants define the amount of time given a user + * before the soft limits are treated as hard limits (usually resulting + * in an allocation failure). The timer is started when the user crosses + * their soft limit, it is reset when they go below their soft limit. + */ +#define MAX_IQ_TIME 604800 /* (7*24*60*60) 1 week */ +#define MAX_DQ_TIME 604800 /* (7*24*60*60) 1 week */ + +#define MAXQUOTAS 2 +#define USRQUOTA 0 /* element used for user quotas */ +#define GRPQUOTA 1 /* element used for group quotas */ + +/* + * Definitions for the default names of the quotas files. + */ +#define INITQFNAMES { \ + "user", /* USRQUOTA */ \ + "group", /* GRPQUOTA */ \ + "undefined", \ +}; + +#define QUOTAFILENAME "quota" +#define QUOTAGROUP "staff" + +#define NR_DQHASH 43 /* Just an arbitrary number any suggestions ? */ +#define NR_DQUOTS 256 /* Number of quotas active at one time */ + +/* + * Command definitions for the 'quotactl' system call. + * The commands are broken into a main command defined below + * and a subcommand that is used to convey the type of + * quota that is being manipulated (see above). + */ +#define SUBCMDMASK 0x00ff +#define SUBCMDSHIFT 8 +#define QCMD(cmd, type) (((cmd) << SUBCMDSHIFT) | ((type) & SUBCMDMASK)) + +#define Q_QUOTAON 0x0100 /* enable quotas */ +#define Q_QUOTAOFF 0x0200 /* disable quotas */ +#define Q_GETQUOTA 0x0300 /* get limits and usage */ +#define Q_SETQUOTA 0x0400 /* set limits and usage */ +#define Q_SETUSE 0x0500 /* set usage */ +#define Q_SYNC 0x0600 /* sync disk copy of a filesystems quotas */ +#define Q_SETQLIM 0x0700 /* set limits */ + +/* + * The following structure defines the format of the disk quota file + * (as it appears on disk) - the file is an array of these structures + * indexed by user or group number. + */ +struct dqblk + { + u_long dqb_bhardlimit; /* absolute limit on disk blks alloc */ + u_long dqb_bsoftlimit; /* preferred limit on disk blks */ + u_long dqb_curblocks; /* current block count */ + u_long dqb_ihardlimit; /* maximum # allocated inodes */ + u_long dqb_isoftlimit; /* preferred inode limit */ + u_long dqb_curinodes; /* current # allocated inodes */ + time_t dqb_btime; /* time limit for excessive disk use */ + time_t dqb_itime; /* time limit for excessive files */ + }; + +/* + * Shorthand notation. + */ +#define dq_bhardlimit dq_dqb.dqb_bhardlimit +#define dq_bsoftlimit dq_dqb.dqb_bsoftlimit +#define dq_curblocks dq_dqb.dqb_curblocks +#define dq_ihardlimit dq_dqb.dqb_ihardlimit +#define dq_isoftlimit dq_dqb.dqb_isoftlimit +#define dq_curinodes dq_dqb.dqb_curinodes +#define dq_btime dq_dqb.dqb_btime +#define dq_itime dq_dqb.dqb_itime + +#define dqoff(UID) ((off_t)((UID) * sizeof (struct dqblk))) + +#ifdef __KERNEL__ + +/* + * Maximum lenght of a message generated in the quota system, + * that needs to be kicked onto the tty. + */ +#define MAX_QUOTA_MESSAGE 75 + +#define DQ_LOCKED 0x01 /* locked for update */ +#define DQ_WANT 0x02 /* wanted for update */ +#define DQ_MOD 0x04 /* dquot modified since read */ +#define DQ_BLKS 0x10 /* uid/gid has been warned about blk limit */ +#define DQ_INODES 0x20 /* uid/gid has been warned about inode limit */ +#define DQ_FAKE 0x40 /* no limits only usage */ + +struct dquot +{ + unsigned int dq_id; /* id this applies to (uid, gid) */ + short dq_type; /* type of quota */ + dev_t dq_dev; /* Device this applies to */ + short dq_flags; /* see DQ_* */ + short dq_count; /* reference count */ + struct vfsmount *dq_mnt; /* vfsmountpoint this applies to */ + struct dqblk dq_dqb; /* diskquota usage */ + struct wait_queue *dq_wait; /* pointer to waitqueue */ + struct dquot *dq_prev; /* pointer to prev dquot */ + struct dquot *dq_next; /* pointer to next dquot */ + struct dquot *dq_hash_prev; /* pointer to prev dquot */ + struct dquot *dq_hash_next; /* pointer to next dquot */ +}; + +#define NODQUOT (struct dquot *)NULL + +/* + * Flags used for set_dqblk. + */ +#define QUOTA_SYSCALL 0x01 +#define SET_QUOTA 0x02 +#define SET_USE 0x04 +#define SET_QLIMIT 0x08 + +/* + * Return values when requesting quota. + */ +#define NO_QUOTA 0 /* no more quota available */ +#define QUOTA_OK 1 /* can allocate the space */ + +/* + * declaration of quota_function calls in kernel. + */ +struct dquot *dqget (dev_t dev, unsigned int id, short type); +void dqput (struct dquot *dquot); + +int quota_off (dev_t dev, short type); +int sync_dquots (dev_t dev, short type); + +u_long isize_to_blocks (size_t isize, size_t blksize); +size_t blocks_to_isize (u_long blocks, size_t blksize); + +void quota_remove (struct inode *inode, u_long inodes, u_long blocks); +int quota_alloc (struct inode *inode, u_long wantedinodes, + u_long wantedblocks, u_long * availblocks); +int quota_transfer (struct inode *inode, struct iattr *iattr, u_long inodes, + u_long blocks, char direction); + +void getinoquota (struct inode *inode, short type); +void putinoquota (struct inode *inode); + +#else + +#include + +__BEGIN_DECLS +int quotactl __P ((int, const char *, int, caddr_t)); +__END_DECLS + +#endif /* __KERNEL__ */ +#endif /* _QUOTA_ */ diff -ru --new-file linux-1.2.3/include/linux/sched.h linux/include/linux/sched.h --- linux-1.2.3/include/linux/sched.h Tue Mar 7 13:38:48 1995 +++ linux/include/linux/sched.h Sun Apr 2 11:39:55 1995 @@ -172,6 +172,7 @@ long utime, stime, cutime, cstime, start_time; struct rlimit rlim[RLIM_NLIMITS]; unsigned short used_math; + unsigned long io_usage; /* number of bytes read/written */ char comm[16]; /* file system info */ int link_count; @@ -198,6 +199,10 @@ /* Not implemented yet, only for 486*/ #define PF_PTRACED 0x00000010 /* set if ptrace (0) has been called. */ #define PF_TRACESYS 0x00000020 /* tracing system calls */ +#define PF_FORKNOEXEC 0x00000040 /* forked but didn't exec */ +#define PF_SUPERPREV 0x00000100 /* used super-user privileges */ +#define PF_DUMPCORE 0x00000200 /* dumped core */ +#define PF_SIGNALED 0x00000400 /* killed by a signal */ #define PF_STARTING 0x00000100 /* being created */ #define PF_EXITING 0x00000200 /* getting shut down */ @@ -232,6 +237,7 @@ { 0, LONG_MAX}, {LONG_MAX, LONG_MAX}, \ {MAX_TASKS_PER_USER, MAX_TASKS_PER_USER}, {NR_OPEN, NR_OPEN}}, \ /* math */ 0, \ +/* io_usage */ 0, \ /* comm */ "swapper", \ /* fs info */ 0,NULL, \ /* ipc */ NULL, NULL, \ @@ -276,6 +282,29 @@ extern int do_execve(char *, char **, char **, struct pt_regs *); extern int do_fork(unsigned long, unsigned long, struct pt_regs *); asmlinkage int do_signal(unsigned long, struct pt_regs *); + +/* + * This has now become a routine instead of a macro, it sets a flag if + * it returns true (to do BSD-style accounting where the process is flagged + * if it uses root privs). The implication of this is that you should do + * normal permissions checks first, and check suser() last. + * + * "suser()" checks against the effective user id, while "fsuser()" + * is used for file permission checking and checks against the fsuid.. + */ +extern inline int suser(void) +{ + if (current->euid == 0) + current->flags |= PF_SUPERPREV; + return (current->euid == 0); +} + +extern inline int fsuser(void) +{ + if (current->fsuid == 0) + current->flags |= PF_SUPERPREV; + return (current->fsuid == 0); +} /* * The wait-queues are circular lists, and you have to be *very* sure diff -ru --new-file linux-1.2.3/include/linux/sys.h linux/include/linux/sys.h --- linux-1.2.3/include/linux/sys.h Wed Feb 22 11:27:52 1995 +++ linux/include/linux/sys.h Sun Apr 2 11:39:55 1995 @@ -27,6 +27,5 @@ * These are system calls that haven't been implemented yet * but have an entry in the table for future expansion.. */ -#define _sys_quotactl _sys_ni_syscall #endif diff -ru --new-file linux-1.2.3/include/linux/tty.h linux/include/linux/tty.h --- linux-1.2.3/include/linux/tty.h Sun Feb 26 15:45:26 1995 +++ linux/include/linux/tty.h Sun Apr 2 11:39:55 1995 @@ -297,6 +297,7 @@ extern int tty_unregister_driver(struct tty_driver *driver); extern int tty_read_raw_data(struct tty_struct *tty, unsigned char *bufp, int buflen); +extern void tty_write_message(struct tty_struct *tty, char *msg); extern int is_orphaned_pgrp(int pgrp); extern int is_ignored(int sig); diff -ru --new-file linux-1.2.3/init/main.c linux/init/main.c --- linux-1.2.3/init/main.c Fri Feb 24 15:41:01 1995 +++ linux/init/main.c Sun Apr 2 11:39:55 1995 @@ -82,6 +82,9 @@ #ifdef CONFIG_SYSVIPC extern void ipc_init(void); #endif +#ifdef CONFIG_QUOTA +extern void quota_init(void); +#endif #ifdef CONFIG_SCSI extern unsigned long scsi_dev_init(unsigned long, unsigned long); #endif @@ -383,6 +386,9 @@ sock_init(); #ifdef CONFIG_SYSVIPC ipc_init(); +#endif +#ifdef CONFIG_QUOTA + quota_init(); #endif sti(); check_bugs(); diff -ru --new-file linux-1.2.3/kernel/exit.c linux/kernel/exit.c --- linux-1.2.3/kernel/exit.c Sun Apr 2 11:35:34 1995 +++ linux/kernel/exit.c Sun Apr 2 11:42:34 1995 @@ -18,6 +18,7 @@ #include extern void sem_exit (void); +extern void acct_process (void); int getrusage(struct task_struct *, int, struct rusage *); @@ -381,6 +382,7 @@ } fake_volatile: current->flags |= PF_EXITING; + acct_process(); sem_exit(); exit_mmap(current); free_page_tables(current); diff -ru --new-file linux-1.2.3/kernel/fork.c linux/kernel/fork.c --- linux-1.2.3/kernel/fork.c Wed Mar 1 12:31:54 1995 +++ linux/kernel/fork.c Sun Apr 2 11:39:56 1995 @@ -2,9 +2,7 @@ * linux/kernel/fork.c * * Copyright (C) 1991, 1992 Linus Torvalds - */ - -/* + * * 'fork.c' contains the help-routines for the 'fork' system call * (see also system_call.s). * Fork is rather simple, once you get the hang of it, but the memory @@ -20,6 +18,7 @@ #include #include #include +#include #include #include @@ -58,24 +57,26 @@ return free_task; } -static struct file * copy_fd(struct file * old_file) +static struct file *copy_fd(struct file * old_file) { - struct file * new_file = get_empty_filp(); - int error; + struct file *new_file = get_empty_filp(); + int error = 0; if (new_file) { - memcpy(new_file,old_file,sizeof(struct file)); + memcpy(new_file, old_file, sizeof(struct file)); new_file->f_count = 1; if (new_file->f_inode) new_file->f_inode->i_count++; - if (new_file->f_op && new_file->f_op->open) { - error = new_file->f_op->open(new_file->f_inode,new_file); - if (error) { - iput(new_file->f_inode); - new_file->f_count = 0; - new_file = NULL; - } - } + if ((error = vfs_getwriteaccess(new_file)) == 0) { + if (new_file->f_op && new_file->f_op->open) + error = new_file->f_op->open(new_file->f_inode, new_file); + if (error == 0) + return new_file; + vfs_putwriteaccess(new_file); + } + iput(new_file->f_inode); + new_file->f_count = 0; + new_file = NULL; } return new_file; } @@ -125,8 +126,10 @@ p->files->fd[i] = copy_fd(f); } else { for (i=0; ifiles->fd[i]) != NULL) + if ((f = p->files->fd[i]) != NULL) { f->f_count++; + vfs_getwriteaccess(f); + } } } @@ -188,7 +191,9 @@ p->kernel_stack_page = new_stack; *(unsigned long *) p->kernel_stack_page = STACK_MAGIC; p->state = TASK_UNINTERRUPTIBLE; - p->flags &= ~(PF_PTRACED|PF_TRACESYS); + p->flags &= ~(PF_PTRACED|PF_TRACESYS|PF_SUPERPREV); + p->flags |= PF_FORKNOEXEC; + p->io_usage = 0; /* Child doesn't inherit parent's I/O usage */ p->pid = last_pid; p->p_pptr = p->p_opptr = current; p->p_cptr = NULL; diff -ru --new-file linux-1.2.3/kernel/printk.c linux/kernel/printk.c --- linux-1.2.3/kernel/printk.c Mon Jan 23 22:04:10 1995 +++ linux/kernel/printk.c Sun Apr 2 11:39:56 1995 @@ -20,6 +20,8 @@ #include #include #include +#include +#include #define LOG_BUF_LEN 4096 @@ -229,4 +231,17 @@ msg_level = -1; j = 0; } +} + +/* + * Write a message to a certain tty, not just the console. This is used for + * messages that need to be redirected to a specific tty. + * We don't put it into the syslog queue right now maybe in the future if + * really needed. + */ +void tty_write_message(struct tty_struct *tty, char *msg) +{ + if (tty && tty->driver.write) + tty->driver.write(tty, 0, msg, strlen(msg)); + return; } diff -ru --new-file linux-1.2.3/kernel/sys.c linux/kernel/sys.c --- linux-1.2.3/kernel/sys.c Sat Mar 4 23:16:36 1995 +++ linux/kernel/sys.c Sun Apr 2 11:39:56 1995 @@ -16,6 +16,10 @@ #include #include #include +#include +#include +#include +#include #include #include @@ -236,9 +240,132 @@ return 0; } -asmlinkage int sys_acct(void) +static char acct_active = 0; +static struct file *acct_file; +#define KSTK_ESP(stack) (((unsigned long *) stack)[1022]) + +int acct_process(void) +{ + struct acct ac; + unsigned short fs; + unsigned long vsize, esp; + + if (acct_active) { + memset(&ac, 0, sizeof(struct acct)); + strncpy(ac.ac_comm, current->comm, ACCT_COMM); + ac.ac_comm[ACCT_COMM] = '\0'; + ac.ac_utime = current->utime; + ac.ac_stime = current->stime; + ac.ac_btime = CT_TO_SECS(current->start_time) + (xtime.tv_sec - (jiffies / HZ)); + ac.ac_etime = CURRENT_TIME - ac.ac_btime; + ac.ac_uid = current->uid; + ac.ac_gid = current->gid; + ac.ac_tty = (current->tty) ? MKDEV(4, current->tty->device) : MKDEV(4, -1); + ac.ac_flag = 0; + if (current->flags & PF_FORKNOEXEC) + ac.ac_flag |= AFORK; + if (current->flags & PF_SUPERPREV) + ac.ac_flag |= ASU; + if (current->flags & PF_DUMPCORE) + ac.ac_flag |= ACORE; + if (current->flags & PF_SIGNALED) + ac.ac_flag |= AXSIG; + ac.ac_io = current->io_usage; + + /* Figure out the vsize of the current process and divide by the + * page size to calculate AC_MEM. This is the approved method + * from the proc filesystem. + */ + vsize = current->kernel_stack_page; + if (vsize) { + esp = KSTK_ESP(vsize); + vsize = current->mm->brk - current->mm->start_code + (PAGE_SIZE - 1); + if (esp) + vsize += TASK_SIZE - esp; + } + /* now vsize contains the number of bytes used -- we want to + * find out the number of pages, so divide it by the page size + * and round up. + */ + ac.ac_mem = (vsize / PAGE_SIZE) + ((vsize % PAGE_SIZE) != 0); + + /* Kernel segment override */ + fs = get_fs(); + set_fs(KERNEL_DS); + + acct_file->f_op->write(acct_file->f_inode, acct_file, + (char *)&ac, sizeof(struct acct)); + + set_fs(fs); + } + return 0; +} + +extern void close_fp(struct file *, int); + +asmlinkage int sys_acct(const char *name) { - return -ENOSYS; + struct inode *inode = (struct inode *)0; + char *tmp; + int error; + + if (!suser()) + return -EPERM; + + if (name == (char *)0) { + if (acct_active) { + acct_process(); + acct_active = 0; + close_fp(acct_file, 0); + } + return 0; + } else { + if (!acct_active) { + if ((error = getname(name, &tmp)) != 0) + return (error); + error = open_namei(tmp, O_RDWR, 0600, &inode, 0); + putname(tmp); + if (error) + return (error); + if (!S_ISREG(inode->i_mode)) { + iput(inode); + return -EACCES; + } + if (!inode->i_op || !inode->i_op->default_file_ops || + !inode->i_op->default_file_ops->write) { + iput(inode); + return -EIO; + } + if ((acct_file = get_empty_filp()) != (struct file *)0) { + acct_file->f_mode = (O_WRONLY + 1) & O_ACCMODE; + acct_file->f_flags = O_WRONLY; + acct_file->f_inode = inode; + acct_file->f_pos = inode->i_size; + acct_file->f_reada = 0; + acct_file->f_op = inode->i_op->default_file_ops; + if ((error = vfs_getwriteaccess(acct_file)) == 0) { + if (acct_file->f_op && acct_file->f_op->open) + error = acct_file->f_op->open(inode, acct_file); + if (error == 0) { + acct_active = 1; + return 0; + } + vfs_putwriteaccess(acct_file); + } + acct_file->f_count--; + } else + error = -EUSERS; + iput(inode); + return error; + } else + return -EBUSY; + } +} + +void acct_auto_close(dev_t dev) +{ + if (acct_active && acct_file && acct_file->f_inode->i_dev == dev) + sys_acct((char *)0); } asmlinkage int sys_phys(void) diff -ru --new-file linux-1.2.3/mm/mmap.c linux/mm/mmap.c --- linux-1.2.3/mm/mmap.c Thu Mar 2 08:04:40 1995 +++ linux/mm/mmap.c Sun Apr 2 11:39:56 1995 @@ -77,7 +77,7 @@ default: return -EINVAL; } - if ((flags & MAP_DENYWRITE) && (file->f_inode->i_wcount > 0)) + if ((flags & MAP_DENYWRITE) && (file->f_inode->i_writecount > 0)) return -ETXTBSY; } else if ((flags & MAP_TYPE) != MAP_PRIVATE) return -EINVAL;