ioctl.c 3.2 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5
/*
 *   fs/cifs/ioctl.c
 *
 *   vfs operations that deal with io control
 *
6
 *   Copyright (C) International Business Machines  Corp., 2005,2013
L
Linus Torvalds 已提交
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
 *   Author(s): Steve French (sfrench@us.ibm.com)
 *
 *   This library is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU Lesser General Public License as published
 *   by the Free Software Foundation; either version 2.1 of the License, or
 *   (at your option) any later version.
 *
 *   This library is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
 *   the GNU Lesser General Public License for more details.
 *
 *   You should have received a copy of the GNU Lesser General Public License
 *   along with this library; if not, write to the Free Software
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */
23

L
Linus Torvalds 已提交
24 25 26 27 28
#include <linux/fs.h>
#include "cifspdu.h"
#include "cifsglob.h"
#include "cifsproto.h"
#include "cifs_debug.h"
29
#include "cifsfs.h"
L
Linus Torvalds 已提交
30

31
long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg)
L
Linus Torvalds 已提交
32
{
A
Al Viro 已提交
33
	struct inode *inode = file_inode(filep);
L
Linus Torvalds 已提交
34
	int rc = -ENOTTY; /* strange error - but the precedent */
35
	unsigned int xid;
36
	struct cifs_sb_info *cifs_sb;
37
	struct cifsFileInfo *pSMBFile = filep->private_data;
38
	struct cifs_tcon *tcon;
39
	__u64	ExtAttrBits = 0;
40
	__u64   caps;
41

42
	xid = get_xid();
43

44
	cifs_dbg(FYI, "ioctl file %p  cmd %u  arg %lu\n", filep, command, arg);
45

46 47
	cifs_sb = CIFS_SB(inode->i_sb);

S
Steve French 已提交
48
	switch (command) {
49
		case FS_IOC_GETFLAGS:
50 51 52 53
			if (pSMBFile == NULL)
				break;
			tcon = tlink_tcon(pSMBFile->tlink);
			caps = le64_to_cpu(tcon->fsUnixInfo.Capability);
54
#ifdef CONFIG_CIFS_POSIX
S
Steve French 已提交
55
			if (CIFS_UNIX_EXTATTR_CAP & caps) {
56
				__u64	ExtAttrMask = 0;
57 58 59
				rc = CIFSGetExtAttr(xid, tcon,
						    pSMBFile->fid.netfid,
						    &ExtAttrBits, &ExtAttrMask);
S
Steve French 已提交
60
				if (rc == 0)
61
					rc = put_user(ExtAttrBits &
62
						FS_FL_USER_VISIBLE,
63
						(int __user *)arg);
64 65 66 67 68 69 70 71 72 73
				if (rc != EOPNOTSUPP)
					break;
			}
#endif /* CONFIG_CIFS_POSIX */
			rc = 0;
			if (CIFS_I(inode)->cifsAttrs & ATTR_COMPRESSED) {
				/* add in the compressed bit */
				ExtAttrBits = FS_COMPR_FL;
				rc = put_user(ExtAttrBits & FS_FL_USER_VISIBLE,
					      (int __user *)arg);
74 75
			}
			break;
76
		case FS_IOC_SETFLAGS:
77 78 79 80
			if (pSMBFile == NULL)
				break;
			tcon = tlink_tcon(pSMBFile->tlink);
			caps = le64_to_cpu(tcon->fsUnixInfo.Capability);
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105

			if (get_user(ExtAttrBits, (int __user *)arg)) {
				rc = -EFAULT;
				break;
			}

			/*
			 * if (CIFS_UNIX_EXTATTR_CAP & caps)
			 *	rc = CIFSSetExtAttr(xid, tcon,
			 *		       pSMBFile->fid.netfid,
			 *		       extAttrBits,
			 *		       &ExtAttrMask);
			 * if (rc != EOPNOTSUPP)
			 *	break;
			 */

			/* Currently only flag we can set is compressed flag */
			if ((ExtAttrBits & FS_COMPR_FL) == 0)
				break;

			/* Try to set compress flag */
			if (tcon->ses->server->ops->set_compression) {
				rc = tcon->ses->server->ops->set_compression(
							xid, tcon, pSMBFile);
				cifs_dbg(FYI, "set compress flag rc %d\n", rc);
106 107
			}
			break;
L
Linus Torvalds 已提交
108
		default:
109
			cifs_dbg(FYI, "unsupported ioctl\n");
110
			break;
L
Linus Torvalds 已提交
111
	}
112

113
	free_xid(xid);
L
Linus Torvalds 已提交
114
	return rc;
S
Steve French 已提交
115
}