home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / KERNEL-S / V1.2 / LINUX-1.2 / LINUX-1 / linux / fs / ext2 / ioctl.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-23  |  2.0 KB  |  77 lines

  1. /*
  2.  * linux/fs/ext2/ioctl.c
  3.  *
  4.  * Copyright (C) 1993, 1994  Remy Card (card@masi.ibp.fr)
  5.  *                           Laboratoire MASI - Institut Blaise Pascal
  6.  *                           Universite Pierre et Marie Curie (Paris VI)
  7.  */
  8.  
  9. #include <asm/segment.h>
  10.  
  11. #include <linux/errno.h>
  12. #include <linux/fs.h>
  13. #include <linux/ext2_fs.h>
  14. #include <linux/ioctl.h>
  15. #include <linux/sched.h>
  16. #include <linux/mm.h>
  17.  
  18. int ext2_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
  19.         unsigned long arg)
  20. {
  21.     int err;
  22.     unsigned long flags;
  23.  
  24.     ext2_debug ("cmd = %u, arg = %lu\n", cmd, arg);
  25.  
  26.     switch (cmd) {
  27.     case EXT2_IOC_GETFLAGS:
  28.         if ((err = verify_area (VERIFY_WRITE, (long *) arg, sizeof(long))))
  29.             return err;
  30.         put_fs_long (inode->u.ext2_i.i_flags, (long *) arg);
  31.         return 0;
  32.     case EXT2_IOC_SETFLAGS:
  33.         flags = get_fs_long ((long *) arg);
  34.         /*
  35.          * Only the super-user can change the IMMUTABLE flag
  36.          */
  37.         if ((flags & EXT2_IMMUTABLE_FL) ^
  38.             (inode->u.ext2_i.i_flags & EXT2_IMMUTABLE_FL)) {
  39.             /* This test looks nicer. Thanks to Pauline Middelink */
  40.             if (!fsuser())
  41.                 return -EPERM;
  42.         } else
  43.             if ((current->fsuid != inode->i_uid) && !fsuser())
  44.                 return -EPERM;
  45.         if (IS_RDONLY(inode))
  46.             return -EROFS;
  47.         inode->u.ext2_i.i_flags = flags;
  48.         if (flags & EXT2_APPEND_FL)
  49.             inode->i_flags |= S_APPEND;
  50.         else
  51.             inode->i_flags &= ~S_APPEND;
  52.         if (flags & EXT2_IMMUTABLE_FL)
  53.             inode->i_flags |= S_IMMUTABLE;
  54.         else
  55.             inode->i_flags &= ~S_IMMUTABLE;
  56.         inode->i_ctime = CURRENT_TIME;
  57.         inode->i_dirt = 1;
  58.         return 0;
  59.     case EXT2_IOC_GETVERSION:
  60.         if ((err = verify_area (VERIFY_WRITE, (long *) arg, sizeof(long))))
  61.             return err;
  62.         put_fs_long (inode->u.ext2_i.i_version, (long *) arg);
  63.         return 0;
  64.     case EXT2_IOC_SETVERSION:
  65.         if ((current->fsuid != inode->i_uid) && !fsuser())
  66.             return -EPERM;
  67.         if (IS_RDONLY(inode))
  68.             return -EROFS;
  69.         inode->u.ext2_i.i_version = get_fs_long ((long *) arg);
  70.         inode->i_ctime = CURRENT_TIME;
  71.         inode->i_dirt = 1;
  72.         return 0;
  73.     default:
  74.         return -EINVAL;
  75.     }
  76. }
  77.