| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
 | 2 |  *   fs/cifs/ioctl.c | 
 | 3 |  * | 
 | 4 |  *   vfs operations that deal with io control | 
 | 5 |  * | 
| Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 6 |  *   Copyright (C) International Business Machines  Corp., 2005,2007 | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 |  *   Author(s): Steve French (sfrench@us.ibm.com) | 
 | 8 |  * | 
 | 9 |  *   This library is free software; you can redistribute it and/or modify | 
 | 10 |  *   it under the terms of the GNU Lesser General Public License as published | 
 | 11 |  *   by the Free Software Foundation; either version 2.1 of the License, or | 
 | 12 |  *   (at your option) any later version. | 
 | 13 |  * | 
 | 14 |  *   This library is distributed in the hope that it will be useful, | 
 | 15 |  *   but WITHOUT ANY WARRANTY; without even the implied warranty of | 
 | 16 |  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See | 
 | 17 |  *   the GNU Lesser General Public License for more details. | 
 | 18 |  * | 
 | 19 |  *   You should have received a copy of the GNU Lesser General Public License | 
 | 20 |  *   along with this library; if not, write to the Free Software | 
 | 21 |  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 
 | 22 |  */ | 
| Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 23 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <linux/fs.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include "cifspdu.h" | 
 | 26 | #include "cifsglob.h" | 
 | 27 | #include "cifsproto.h" | 
 | 28 | #include "cifs_debug.h" | 
| Steve French | c67593a | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 29 | #include "cifsfs.h" | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 |  | 
| Steve French | f28ac91 | 2005-04-28 22:41:07 -0700 | [diff] [blame] | 31 | #define CIFS_IOC_CHECKUMOUNT _IO(0xCF, 2) | 
 | 32 |  | 
| Steve French | f9ddcca | 2008-05-15 05:51:55 +0000 | [diff] [blame] | 33 | long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | { | 
| Steve French | f9ddcca | 2008-05-15 05:51:55 +0000 | [diff] [blame] | 35 | 	struct inode *inode = filep->f_dentry->d_inode; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | 	int rc = -ENOTTY; /* strange error - but the precedent */ | 
| Steve French | c81156d | 2005-04-28 22:41:07 -0700 | [diff] [blame] | 37 | 	int xid; | 
 | 38 | 	struct cifs_sb_info *cifs_sb; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #ifdef CONFIG_CIFS_POSIX | 
| Jeff Layton | ba00ba6 | 2010-09-20 16:01:31 -0700 | [diff] [blame] | 40 | 	struct cifsFileInfo *pSMBFile = filep->private_data; | 
| Jeff Layton | 6187639 | 2010-11-08 07:28:32 -0500 | [diff] [blame] | 41 | 	struct cifsTconInfo *tcon; | 
| Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 42 | 	__u64	ExtAttrBits = 0; | 
 | 43 | 	__u64	ExtAttrMask = 0; | 
| Jeff Layton | 6187639 | 2010-11-08 07:28:32 -0500 | [diff] [blame] | 44 | 	__u64   caps; | 
| Steve French | c81156d | 2005-04-28 22:41:07 -0700 | [diff] [blame] | 45 | #endif /* CONFIG_CIFS_POSIX */ | 
| Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 46 |  | 
 | 47 | 	xid = GetXid(); | 
 | 48 |  | 
| Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 49 | 	cFYI(1, "ioctl file %p  cmd %u  arg %lu", filep, command, arg); | 
| Steve French | f28ac91 | 2005-04-28 22:41:07 -0700 | [diff] [blame] | 50 |  | 
| Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 51 | 	cifs_sb = CIFS_SB(inode->i_sb); | 
| Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 52 |  | 
| Steve French | 5fdae1f | 2007-06-05 18:30:44 +0000 | [diff] [blame] | 53 | 	switch (command) { | 
| Steve French | f28ac91 | 2005-04-28 22:41:07 -0700 | [diff] [blame] | 54 | 		case CIFS_IOC_CHECKUMOUNT: | 
| Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 55 | 			cFYI(1, "User unmount attempted"); | 
| David Howells | a001e5b | 2008-11-14 10:38:47 +1100 | [diff] [blame] | 56 | 			if (cifs_sb->mnt_uid == current_uid()) | 
| Steve French | f28ac91 | 2005-04-28 22:41:07 -0700 | [diff] [blame] | 57 | 				rc = 0; | 
 | 58 | 			else { | 
 | 59 | 				rc = -EACCES; | 
| Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 60 | 				cFYI(1, "uids do not match"); | 
| Steve French | f28ac91 | 2005-04-28 22:41:07 -0700 | [diff] [blame] | 61 | 			} | 
 | 62 | 			break; | 
 | 63 | #ifdef CONFIG_CIFS_POSIX | 
| David Howells | 3669567 | 2006-08-29 19:06:16 +0100 | [diff] [blame] | 64 | 		case FS_IOC_GETFLAGS: | 
| Jeff Layton | 6187639 | 2010-11-08 07:28:32 -0500 | [diff] [blame] | 65 | 			if (pSMBFile == NULL) | 
 | 66 | 				break; | 
 | 67 | 			tcon = tlink_tcon(pSMBFile->tlink); | 
 | 68 | 			caps = le64_to_cpu(tcon->fsUnixInfo.Capability); | 
| Steve French | 5fdae1f | 2007-06-05 18:30:44 +0000 | [diff] [blame] | 69 | 			if (CIFS_UNIX_EXTATTR_CAP & caps) { | 
| Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 70 | 				rc = CIFSGetExtAttr(xid, tcon, pSMBFile->netfid, | 
 | 71 | 					&ExtAttrBits, &ExtAttrMask); | 
| Steve French | 5fdae1f | 2007-06-05 18:30:44 +0000 | [diff] [blame] | 72 | 				if (rc == 0) | 
| Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 73 | 					rc = put_user(ExtAttrBits & | 
| David Howells | 3669567 | 2006-08-29 19:06:16 +0100 | [diff] [blame] | 74 | 						FS_FL_USER_VISIBLE, | 
| Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 75 | 						(int __user *)arg); | 
 | 76 | 			} | 
 | 77 | 			break; | 
 | 78 |  | 
| David Howells | 3669567 | 2006-08-29 19:06:16 +0100 | [diff] [blame] | 79 | 		case FS_IOC_SETFLAGS: | 
| Jeff Layton | 6187639 | 2010-11-08 07:28:32 -0500 | [diff] [blame] | 80 | 			if (pSMBFile == NULL) | 
 | 81 | 				break; | 
 | 82 | 			tcon = tlink_tcon(pSMBFile->tlink); | 
 | 83 | 			caps = le64_to_cpu(tcon->fsUnixInfo.Capability); | 
| Steve French | 5fdae1f | 2007-06-05 18:30:44 +0000 | [diff] [blame] | 84 | 			if (CIFS_UNIX_EXTATTR_CAP & caps) { | 
 | 85 | 				if (get_user(ExtAttrBits, (int __user *)arg)) { | 
| Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 86 | 					rc = -EFAULT; | 
| Steve French | c81156d | 2005-04-28 22:41:07 -0700 | [diff] [blame] | 87 | 					break; | 
| Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 88 | 				} | 
| Steve French | f28ac91 | 2005-04-28 22:41:07 -0700 | [diff] [blame] | 89 | 				/* rc= CIFSGetExtAttr(xid,tcon,pSMBFile->netfid, | 
| Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 90 | 					extAttrBits, &ExtAttrMask);*/ | 
| Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 91 | 			} | 
| Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 92 | 			cFYI(1, "set flags not implemented yet"); | 
| Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 93 | 			break; | 
| Steve French | f28ac91 | 2005-04-28 22:41:07 -0700 | [diff] [blame] | 94 | #endif /* CONFIG_CIFS_POSIX */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | 		default: | 
| Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 96 | 			cFYI(1, "unsupported ioctl"); | 
| Steve French | f28ac91 | 2005-04-28 22:41:07 -0700 | [diff] [blame] | 97 | 			break; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | 	} | 
| Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 99 |  | 
| Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 100 | 	FreeXid(xid); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | 	return rc; | 
| Steve French | 5fdae1f | 2007-06-05 18:30:44 +0000 | [diff] [blame] | 102 | } |