ia64/linux-2.6.18-xen.hg

annotate fs/jfs/ioctl.c @ 524:7f8b544237bf

netfront: Allow netfront in domain 0.

This is useful if your physical network device is in a utility domain.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Tue Apr 15 15:18:58 2008 +0100 (2008-04-15)
parents 831230e53067
children
rev   line source
ian@0 1 /*
ian@0 2 * linux/fs/jfs/ioctl.c
ian@0 3 *
ian@0 4 * Copyright (C) 2006 Herbert Poetzl
ian@0 5 * adapted from Remy Card's ext2/ioctl.c
ian@0 6 */
ian@0 7
ian@0 8 #include <linux/fs.h>
ian@0 9 #include <linux/ext2_fs.h>
ian@0 10 #include <linux/ctype.h>
ian@0 11 #include <linux/capability.h>
ian@0 12 #include <linux/time.h>
ian@0 13 #include <asm/current.h>
ian@0 14 #include <asm/uaccess.h>
ian@0 15
ian@0 16 #include "jfs_incore.h"
ian@0 17 #include "jfs_dinode.h"
ian@0 18 #include "jfs_inode.h"
ian@0 19
ian@0 20
ian@0 21 static struct {
ian@0 22 long jfs_flag;
ian@0 23 long ext2_flag;
ian@0 24 } jfs_map[] = {
ian@0 25 {JFS_NOATIME_FL, EXT2_NOATIME_FL},
ian@0 26 {JFS_DIRSYNC_FL, EXT2_DIRSYNC_FL},
ian@0 27 {JFS_SYNC_FL, EXT2_SYNC_FL},
ian@0 28 {JFS_SECRM_FL, EXT2_SECRM_FL},
ian@0 29 {JFS_UNRM_FL, EXT2_UNRM_FL},
ian@0 30 {JFS_APPEND_FL, EXT2_APPEND_FL},
ian@0 31 {JFS_IMMUTABLE_FL, EXT2_IMMUTABLE_FL},
ian@0 32 {0, 0},
ian@0 33 };
ian@0 34
ian@0 35 static long jfs_map_ext2(unsigned long flags, int from)
ian@0 36 {
ian@0 37 int index=0;
ian@0 38 long mapped=0;
ian@0 39
ian@0 40 while (jfs_map[index].jfs_flag) {
ian@0 41 if (from) {
ian@0 42 if (jfs_map[index].ext2_flag & flags)
ian@0 43 mapped |= jfs_map[index].jfs_flag;
ian@0 44 } else {
ian@0 45 if (jfs_map[index].jfs_flag & flags)
ian@0 46 mapped |= jfs_map[index].ext2_flag;
ian@0 47 }
ian@0 48 index++;
ian@0 49 }
ian@0 50 return mapped;
ian@0 51 }
ian@0 52
ian@0 53
ian@0 54 int jfs_ioctl(struct inode * inode, struct file * filp, unsigned int cmd,
ian@0 55 unsigned long arg)
ian@0 56 {
ian@0 57 struct jfs_inode_info *jfs_inode = JFS_IP(inode);
ian@0 58 unsigned int flags;
ian@0 59
ian@0 60 switch (cmd) {
ian@0 61 case JFS_IOC_GETFLAGS:
ian@0 62 flags = jfs_inode->mode2 & JFS_FL_USER_VISIBLE;
ian@0 63 flags = jfs_map_ext2(flags, 0);
ian@0 64 return put_user(flags, (int __user *) arg);
ian@0 65 case JFS_IOC_SETFLAGS: {
ian@0 66 unsigned int oldflags;
ian@0 67
ian@0 68 if (IS_RDONLY(inode))
ian@0 69 return -EROFS;
ian@0 70
ian@0 71 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
ian@0 72 return -EACCES;
ian@0 73
ian@0 74 if (get_user(flags, (int __user *) arg))
ian@0 75 return -EFAULT;
ian@0 76
ian@0 77 flags = jfs_map_ext2(flags, 1);
ian@0 78 if (!S_ISDIR(inode->i_mode))
ian@0 79 flags &= ~JFS_DIRSYNC_FL;
ian@0 80
ian@0 81 oldflags = jfs_inode->mode2;
ian@0 82
ian@0 83 /*
ian@0 84 * The IMMUTABLE and APPEND_ONLY flags can only be changed by
ian@0 85 * the relevant capability.
ian@0 86 */
ian@0 87 if ((oldflags & JFS_IMMUTABLE_FL) ||
ian@0 88 ((flags ^ oldflags) &
ian@0 89 (JFS_APPEND_FL | JFS_IMMUTABLE_FL))) {
ian@0 90 if (!capable(CAP_LINUX_IMMUTABLE))
ian@0 91 return -EPERM;
ian@0 92 }
ian@0 93
ian@0 94 flags = flags & JFS_FL_USER_MODIFIABLE;
ian@0 95 flags |= oldflags & ~JFS_FL_USER_MODIFIABLE;
ian@0 96 jfs_inode->mode2 = flags;
ian@0 97
ian@0 98 jfs_set_inode_flags(inode);
ian@0 99 inode->i_ctime = CURRENT_TIME_SEC;
ian@0 100 mark_inode_dirty(inode);
ian@0 101 return 0;
ian@0 102 }
ian@0 103 default:
ian@0 104 return -ENOTTY;
ian@0 105 }
ian@0 106 }
ian@0 107