blob: 029867078affcc47fc37ebdd5cf46f98245e8578 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * fs/cifs/ioctl.c
3 *
4 * vfs operations that deal with io control
5 *
Steve French64a5cfa2013-10-14 15:31:32 -05006 * Copyright (C) International Business Machines Corp., 2005,2013
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * 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 Frenchf654bac2005-04-28 22:41:04 -070023
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <linux/fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include "cifspdu.h"
26#include "cifsglob.h"
27#include "cifsproto.h"
28#include "cifs_debug.h"
Steve Frenchc67593a2005-04-28 22:41:04 -070029#include "cifsfs.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
Steve Frenchf9ddcca2008-05-15 05:51:55 +000031long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -070032{
Al Viro496ad9a2013-01-23 17:07:38 -050033 struct inode *inode = file_inode(filep);
Linus Torvalds1da177e2005-04-16 15:20:36 -070034 int rc = -ENOTTY; /* strange error - but the precedent */
Pavel Shilovsky6d5786a2012-06-20 11:21:16 +040035 unsigned int xid;
Steve Frenchc81156d2005-04-28 22:41:07 -070036 struct cifs_sb_info *cifs_sb;
Jeff Laytonba00ba62010-09-20 16:01:31 -070037 struct cifsFileInfo *pSMBFile = filep->private_data;
Steve French96daf2b2011-05-27 04:34:02 +000038 struct cifs_tcon *tcon;
Steve Frenchf654bac2005-04-28 22:41:04 -070039 __u64 ExtAttrBits = 0;
40 __u64 ExtAttrMask = 0;
Jeff Layton61876392010-11-08 07:28:32 -050041 __u64 caps;
Steve Frenchf654bac2005-04-28 22:41:04 -070042
Pavel Shilovsky6d5786a2012-06-20 11:21:16 +040043 xid = get_xid();
Steve Frenchf654bac2005-04-28 22:41:04 -070044
Joe Perchesf96637b2013-05-04 22:12:25 -050045 cifs_dbg(FYI, "ioctl file %p cmd %u arg %lu\n", filep, command, arg);
Steve Frenchf28ac912005-04-28 22:41:07 -070046
Steve Frenchf654bac2005-04-28 22:41:04 -070047 cifs_sb = CIFS_SB(inode->i_sb);
Steve Frenchf654bac2005-04-28 22:41:04 -070048
Steve French5fdae1f2007-06-05 18:30:44 +000049 switch (command) {
David Howells36695672006-08-29 19:06:16 +010050 case FS_IOC_GETFLAGS:
Jeff Layton61876392010-11-08 07:28:32 -050051 if (pSMBFile == NULL)
52 break;
53 tcon = tlink_tcon(pSMBFile->tlink);
54 caps = le64_to_cpu(tcon->fsUnixInfo.Capability);
Steve French64a5cfa2013-10-14 15:31:32 -050055#ifdef CONFIG_CIFS_POSIX
Steve French5fdae1f2007-06-05 18:30:44 +000056 if (CIFS_UNIX_EXTATTR_CAP & caps) {
Pavel Shilovsky4b4de762012-09-18 16:20:26 -070057 rc = CIFSGetExtAttr(xid, tcon,
58 pSMBFile->fid.netfid,
59 &ExtAttrBits, &ExtAttrMask);
Steve French5fdae1f2007-06-05 18:30:44 +000060 if (rc == 0)
Steve Frenchf654bac2005-04-28 22:41:04 -070061 rc = put_user(ExtAttrBits &
David Howells36695672006-08-29 19:06:16 +010062 FS_FL_USER_VISIBLE,
Steve Frenchf654bac2005-04-28 22:41:04 -070063 (int __user *)arg);
Steve French64a5cfa2013-10-14 15:31:32 -050064 if (rc != EOPNOTSUPP)
65 break;
66 }
67#endif /* CONFIG_CIFS_POSIX */
68 rc = 0;
69 if (CIFS_I(inode)->cifsAttrs & ATTR_COMPRESSED) {
70 /* add in the compressed bit */
71 ExtAttrBits = FS_COMPR_FL;
72 rc = put_user(ExtAttrBits & FS_FL_USER_VISIBLE,
73 (int __user *)arg);
Steve Frenchf654bac2005-04-28 22:41:04 -070074 }
75 break;
David Howells36695672006-08-29 19:06:16 +010076 case FS_IOC_SETFLAGS:
Jeff Layton61876392010-11-08 07:28:32 -050077 if (pSMBFile == NULL)
78 break;
79 tcon = tlink_tcon(pSMBFile->tlink);
80 caps = le64_to_cpu(tcon->fsUnixInfo.Capability);
Steve French64a5cfa2013-10-14 15:31:32 -050081
82 if (get_user(ExtAttrBits, (int __user *)arg)) {
83 rc = -EFAULT;
84 break;
Steve Frenchf654bac2005-04-28 22:41:04 -070085 }
Steve French64a5cfa2013-10-14 15:31:32 -050086
87 /*
88 * if (CIFS_UNIX_EXTATTR_CAP & caps)
89 * rc = CIFSSetExtAttr(xid, tcon,
90 * pSMBFile->fid.netfid,
91 * extAttrBits,
92 * &ExtAttrMask);
93 * if (rc != EOPNOTSUPP)
94 * break;
95 */
96
97 /* Currently only flag we can set is compressed flag */
98 if ((ExtAttrBits & FS_COMPR_FL) == 0)
99 break;
100
101 /* Try to set compress flag */
102 if (tcon->ses->server->ops->set_compression) {
103 rc = tcon->ses->server->ops->set_compression(
104 xid, tcon, pSMBFile);
105 cifs_dbg(FYI, "set compress flag rc %d\n", rc);
106 }
Steve Frenchf654bac2005-04-28 22:41:04 -0700107 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 default:
Joe Perchesf96637b2013-05-04 22:12:25 -0500109 cifs_dbg(FYI, "unsupported ioctl\n");
Steve Frenchf28ac912005-04-28 22:41:07 -0700110 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 }
Steve Frenchf654bac2005-04-28 22:41:04 -0700112
Pavel Shilovsky6d5786a2012-06-20 11:21:16 +0400113 free_xid(xid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 return rc;
Steve French5fdae1f2007-06-05 18:30:44 +0000115}