22 #include <linux/stat.h>
23 #include <linux/slab.h>
25 #include <asm/div64.h>
66 #ifdef CONFIG_CIFS_DFS_UPCALL
90 cifs_revalidate_cache(
struct inode *inode,
struct cifs_fattr *fattr)
94 cFYI(1,
"%s: revalidating inode %llu", __func__, cifs_i->
uniqueid);
97 cFYI(1,
"%s: inode %llu is new", __func__, cifs_i->
uniqueid);
103 cFYI(1,
"%s: inode %llu is oplocked", __func__,
111 cFYI(1,
"%s: inode %llu is unchanged", __func__,
116 cFYI(1,
"%s: invalidating inode %llu mapping", __func__,
128 cifs_revalidate_cache(inode, fattr);
130 spin_lock(&inode->
i_lock);
159 i_size_write(inode, fattr->
cf_eof);
168 spin_unlock(&inode->
i_lock);
191 memset(fattr, 0,
sizeof(*fattr));
272 cFYI(1,
"creating fake fattr for DFS referral");
274 memset(fattr, 0,
sizeof(*fattr));
286 cifs_get_file_info_unix(
struct file *filp)
292 struct inode *inode = filp->
f_path.dentry->d_inode;
302 cifs_create_dfs_fattr(&fattr, inode->
i_sb);
312 const unsigned char *full_path,
316 FILE_UNIX_BASIC_INFO find_data;
322 cFYI(1,
"Getting info on %s", full_path);
326 return PTR_ERR(tlink);
327 tcon = tlink_tcon(tlink);
338 cifs_create_dfs_fattr(&fattr, sb);
348 cFYI(1,
"CIFSCheckMFSymlink: %d", tmprc);
351 if (*pinode ==
NULL) {
366 cifs_sfu_type(
struct cifs_fattr *fattr,
const unsigned char *
path,
376 unsigned int bytes_read;
387 }
else if (fattr->
cf_eof < 8) {
395 return PTR_ERR(tlink);
396 tcon = tlink_tcon(tlink);
408 io_parms.tcon =
tcon;
410 io_parms.length = 24;
411 rc =
CIFSSMBRead(xid, &io_parms, &bytes_read, &pbuf,
413 if ((rc == 0) && (bytes_read >= 8)) {
414 if (
memcmp(
"IntxBLK", pbuf, 8) == 0) {
415 cFYI(1,
"Block device");
418 if (bytes_read == 24) {
426 }
else if (
memcmp(
"IntxCHR", pbuf, 8) == 0) {
427 cFYI(1,
"Char device");
430 if (bytes_read == 24) {
438 }
else if (
memcmp(
"IntxLNK", pbuf, 7) == 0) {
458 #define SFBITS_MASK (S_ISVTX | S_ISGID | S_ISUID)
465 static int cifs_sfu_mode(
struct cifs_fattr *fattr,
const unsigned char *path,
468 #ifdef CONFIG_CIFS_XATTR
477 return PTR_ERR(tlink);
478 tcon = tlink_tcon(tlink);
490 cFYI(1,
"special bits 0%o org mode 0%o", mode,
493 cFYI(1,
"special mode bits 0%o", mode);
504 cifs_all_info_to_fattr(
struct cifs_fattr *fattr, FILE_ALL_INFO *
info,
509 memset(fattr, 0,
sizeof(*fattr));
511 if (info->DeletePending)
514 if (info->LastAccessTime)
523 fattr->
cf_ctime.tv_sec += tcon->
ses->server->timeAdj;
524 fattr->
cf_mtime.tv_sec += tcon->
ses->server->timeAdj;
555 cifs_get_file_info(
struct file *filp)
559 FILE_ALL_INFO find_data;
561 struct inode *inode = filp->
f_path.dentry->d_inode;
567 if (!server->
ops->query_file_info)
571 rc = server->
ops->query_file_info(xid, tcon, &cfile->
fid, &find_data);
574 cifs_all_info_to_fattr(&fattr, &find_data, cifs_sb,
false);
577 cifs_create_dfs_fattr(&fattr, inode->
i_sb);
588 CIFS_I(inode)->time = 0;
610 bool validinum =
false;
612 int rc = 0, tmprc =
ENOSYS;
618 bool adjust_tz =
false;
624 return PTR_ERR(tlink);
625 tcon = tlink_tcon(tlink);
626 server = tcon->
ses->server;
628 cFYI(1,
"Getting info on %s", full_path);
630 if ((data ==
NULL) && (*inode !=
NULL)) {
631 if (CIFS_I(*inode)->clientCanCacheRead) {
632 cFYI(1,
"No need to revalidate cached inode sizes");
639 if (!server->
ops->query_path_info) {
648 data = (FILE_ALL_INFO *)buf;
649 rc = server->
ops->query_path_info(xid, tcon, cifs_sb, full_path,
654 cifs_all_info_to_fattr(&fattr, (FILE_ALL_INFO *)data, cifs_sb,
657 cifs_create_dfs_fattr(&fattr, sb);
662 if (srchinf ==
NULL) {
675 cifs_sb,
NULL, srchflgs, srchinf,
false);
681 (FILE_DIRECTORY_INFO *)
data, cifs_sb);
683 ((SEARCH_ID_FULL_DIR_INFO *)data)->
UniqueId);
699 if (*inode ==
NULL) {
701 if (validinum ==
false) {
702 if (server->
ops->get_srv_inum)
703 tmprc = server->
ops->get_srv_inum(xid,
704 tcon, cifs_sb, full_path,
707 cFYI(1,
"GetSrvInodeNum rc %d", tmprc);
720 tmprc = cifs_sfu_type(&fattr, full_path, cifs_sb, xid);
722 cFYI(1,
"cifs_sfu_type failed: %d", tmprc);
725 #ifdef CONFIG_CIFS_ACL
730 cFYI(1,
"%s: Getting ACL failed with error: %d",
739 cifs_sfu_mode(&fattr, full_path, cifs_sb, xid);
745 cFYI(1,
"CIFSCheckMFSymlink: %d", tmprc);
767 cifs_find_inode(
struct inode *inode,
void *opaque)
791 cifs_init_inode(
struct inode *inode,
void *opaque)
806 inode_has_hashed_dentries(
struct inode *inode)
811 spin_lock(&inode->
i_lock);
813 if (!d_unhashed(dentry) ||
IS_ROOT(dentry)) {
814 spin_unlock(&inode->
i_lock);
818 spin_unlock(&inode->
i_lock);
835 inode =
iget5_locked(sb, hash, cifs_find_inode, cifs_init_inode, fattr);
841 if (inode_has_hashed_dentries(inode)) {
845 goto retry_iget5_locked;
856 #ifdef CONFIG_CIFS_FSCACHE
858 CIFS_I(inode)->fscache =
NULL;
872 struct inode *inode =
NULL;
887 #ifdef CONFIG_CIFS_FSCACHE
889 tcon->resource_id = CIFS_I(inode)->uniqueid;
892 if (rc && tcon->
ipc) {
893 cFYI(1,
"ipc connection - fake read inode");
894 spin_lock(&inode->
i_lock);
897 inode->
i_op = &cifs_ipc_inode_ops;
901 spin_unlock(&inode->
i_lock);
917 char *full_path,
__u32 dosattr)
919 bool set_time =
false;
922 FILE_BASIC_INFO info_buf;
928 if (!server->
ops->set_file_info)
933 info_buf.LastAccessTime =
936 info_buf.LastAccessTime = 0;
940 info_buf.LastWriteTime =
943 info_buf.LastWriteTime = 0;
952 cFYI(1,
"CIFS - CTIME changed");
953 info_buf.ChangeTime =
956 info_buf.ChangeTime = 0;
958 info_buf.CreationTime = 0;
961 return server->
ops->set_file_info(inode, full_path, &info_buf, xid);
971 const unsigned int xid)
976 struct inode *inode = dentry->
d_inode;
981 __u32 dosattr, origattr;
982 FILE_BASIC_INFO *info_buf =
NULL;
986 return PTR_ERR(tlink);
987 tcon = tlink_tcon(tlink);
1006 if (dosattr != origattr) {
1007 info_buf = kzalloc(
sizeof(*info_buf),
GFP_KERNEL);
1008 if (info_buf ==
NULL) {
1070 if (dosattr != origattr) {
1082 cifs_drop_nlink(
struct inode *inode)
1084 spin_lock(&inode->
i_lock);
1087 spin_unlock(&inode->
i_lock);
1101 char *full_path =
NULL;
1102 struct inode *inode = dentry->
d_inode;
1110 __u32 dosattr = 0, origattr = 0;
1112 cFYI(1,
"cifs_unlink, dir=0x%p, dentry=0x%p", dir, dentry);
1116 return PTR_ERR(tlink);
1117 tcon = tlink_tcon(tlink);
1118 server = tcon->
ses->server;
1125 if (full_path ==
NULL) {
1135 cFYI(1,
"posix del rc %d", rc);
1136 if ((rc == 0) || (rc == -
ENOENT))
1137 goto psx_del_no_retry;
1141 if (!server->
ops->unlink) {
1143 goto psx_del_no_retry;
1146 rc = server->
ops->unlink(xid, tcon, full_path, cifs_sb);
1151 cifs_drop_nlink(inode);
1152 }
else if (rc == -
ENOENT) {
1155 if (server->
ops->rename_pending_delete) {
1156 rc = server->
ops->rename_pending_delete(full_path,
1159 cifs_drop_nlink(inode);
1163 }
else if ((rc == -
EACCES) && (dosattr == 0) && inode) {
1165 if (attrs ==
NULL) {
1171 cifs_inode = CIFS_I(inode);
1184 goto retry_std_delete;
1188 if (rc != 0 && dosattr != 0)
1193 cifs_inode = CIFS_I(inode);
1194 cifs_inode->
time = 0;
1199 cifs_inode = CIFS_I(dir);
1200 CIFS_I(dir)->time = 0;
1210 cifs_mkdir_qinfo(
struct inode *parent,
struct dentry *dentry,
umode_t mode,
1212 struct cifs_tcon *tcon,
const unsigned int xid)
1215 struct inode *inode =
NULL;
1264 (mode &
S_IWUGO) == 0 && server->
ops->mkdir_setinfo)
1265 server->
ops->mkdir_setinfo(inode, full_path, cifs_sb,
1283 cifs_posix_mkdir(
struct inode *inode,
struct dentry *dentry,
umode_t mode,
1285 struct cifs_tcon *tcon,
const unsigned int xid)
1289 FILE_UNIX_BASIC_INFO *info =
NULL;
1290 struct inode *newinode =
NULL;
1293 info = kzalloc(
sizeof(FILE_UNIX_BASIC_INFO),
GFP_KERNEL);
1296 goto posix_mkdir_out;
1301 NULL , info, &oplock, full_path,
1305 goto posix_mkdir_out;
1307 cFYI(1,
"posix mkdir returned 0x%x", rc);
1309 goto posix_mkdir_out;
1314 goto posix_mkdir_get_info;
1324 goto posix_mkdir_get_info;
1328 #ifdef CONFIG_CIFS_DEBUG2
1329 cFYI(1,
"instantiated dentry %p %s to inode %p", dentry,
1330 dentry->
d_name.name, newinode);
1333 cFYI(1,
"unexpected number of links %d", newinode->
i_nlink);
1339 posix_mkdir_get_info:
1340 rc = cifs_mkdir_qinfo(inode, dentry, mode, full_path, cifs_sb, tcon,
1342 goto posix_mkdir_out;
1355 cFYI(1,
"In cifs_mkdir, mode = 0x%hx inode = 0x%p", mode, inode);
1357 cifs_sb = CIFS_SB(inode->
i_sb);
1360 return PTR_ERR(tlink);
1361 tcon = tlink_tcon(tlink);
1366 if (full_path ==
NULL) {
1373 rc = cifs_posix_mkdir(inode, direntry, mode, full_path, cifs_sb,
1379 server = tcon->
ses->server;
1381 if (!server->
ops->mkdir) {
1387 rc = server->
ops->mkdir(xid, tcon, full_path, cifs_sb);
1389 cFYI(1,
"cifs_mkdir returned 0x%x", rc);
1394 rc = cifs_mkdir_qinfo(inode, direntry, mode, full_path, cifs_sb, tcon,
1401 CIFS_I(inode)->time = 0;
1416 char *full_path =
NULL;
1419 cFYI(1,
"cifs_rmdir, inode = 0x%p", inode);
1424 if (full_path ==
NULL) {
1429 cifs_sb = CIFS_SB(inode->
i_sb);
1431 if (IS_ERR(tlink)) {
1432 rc = PTR_ERR(tlink);
1435 tcon = tlink_tcon(tlink);
1436 server = tcon->
ses->server;
1438 if (!server->
ops->rmdir) {
1444 rc = server->
ops->rmdir(xid, tcon, full_path, cifs_sb);
1448 spin_lock(&direntry->
d_inode->i_lock);
1449 i_size_write(direntry->
d_inode, 0);
1451 spin_unlock(&direntry->
d_inode->i_lock);
1454 cifsInode = CIFS_I(direntry->
d_inode);
1456 cifsInode->
time = 0;
1458 cifsInode = CIFS_I(inode);
1463 cifsInode->
time = 0;
1475 cifs_do_rename(
const unsigned int xid,
struct dentry *from_dentry,
1476 const char *from_path,
struct dentry *to_dentry,
1477 const char *to_path)
1488 return PTR_ERR(tlink);
1489 tcon = tlink_tcon(tlink);
1490 server = tcon->
ses->server;
1492 if (!server->
ops->rename)
1496 rc = server->
ops->rename(xid, tcon, from_path, to_path, cifs_sb);
1503 if (rc == 0 || rc != -
ETXTBSY)
1504 goto do_rename_exit;
1508 goto do_rename_exit;
1517 (
const char *) to_dentry->
d_name.name,
1529 struct inode *target_dir,
struct dentry *target_dentry)
1531 char *from_name =
NULL;
1532 char *to_name =
NULL;
1536 FILE_UNIX_BASIC_INFO *info_buf_source =
NULL;
1537 FILE_UNIX_BASIC_INFO *info_buf_target;
1541 cifs_sb = CIFS_SB(source_dir->
i_sb);
1544 return PTR_ERR(tlink);
1545 tcon = tlink_tcon(tlink);
1554 if (from_name ==
NULL) {
1556 goto cifs_rename_exit;
1560 if (to_name ==
NULL) {
1562 goto cifs_rename_exit;
1565 rc = cifs_do_rename(xid, source_dentry, from_name, target_dentry,
1574 kmalloc(2 *
sizeof(FILE_UNIX_BASIC_INFO),
1576 if (info_buf_source ==
NULL) {
1578 goto cifs_rename_exit;
1581 info_buf_target = info_buf_source + 1;
1596 if (tmprc == 0 && (info_buf_source->UniqueId ==
1597 info_buf_target->UniqueId)) {
1600 goto cifs_rename_exit;
1613 goto cifs_rename_exit;
1614 rc = cifs_do_rename(xid, source_dentry, from_name,
1615 target_dentry, to_name);
1619 kfree(info_buf_source);
1628 cifs_inode_needs_reval(
struct inode *inode)
1639 if (cifs_i->
time == 0)
1668 cERROR(1,
"%s: could not invalidate inode %p", __func__,
1681 struct inode *inode = filp->
f_path.dentry->d_inode;
1684 if (!cifs_inode_needs_reval(inode))
1687 if (tlink_tcon(cfile->
tlink)->unix_ext)
1688 rc = cifs_get_file_info_unix(filp);
1690 rc = cifs_get_file_info(filp);
1699 struct inode *inode = dentry->
d_inode;
1701 char *full_path =
NULL;
1706 if (!cifs_inode_needs_reval(inode))
1714 if (full_path ==
NULL) {
1719 cFYI(1,
"Update attributes: %s inode 0x%p count %d dentry: 0x%p d_time "
1738 struct inode *inode = filp->
f_path.dentry->d_inode;
1744 if (CIFS_I(inode)->invalid_mapping)
1753 struct inode *inode = dentry->
d_inode;
1759 if (CIFS_I(inode)->invalid_mapping)
1769 struct inode *inode = dentry->
d_inode;
1776 if (!CIFS_I(inode)->clientCanCacheRead && inode->
i_mapping &&
1780 mapping_set_error(inode->
i_mapping, rc);
1791 stat->
ino = CIFS_I(inode)->uniqueid;
1815 page = grab_cache_page(mapping, index);
1825 static void cifs_setsize(
struct inode *inode, loff_t offset)
1829 spin_lock(&inode->
i_lock);
1831 i_size_write(inode, offset);
1832 spin_unlock(&inode->
i_lock);
1838 cifs_set_file_size(
struct inode *inode,
struct iattr *attrs,
1839 unsigned int xid,
char *full_path)
1861 tcon = tlink_tcon(open_file->tlink);
1862 server = tcon->
ses->server;
1863 if (server->
ops->set_file_size)
1864 rc = server->
ops->set_file_size(xid, tcon, open_file,
1869 cFYI(1,
"SetFSize for attrs rc = %d", rc);
1871 unsigned int bytes_written;
1873 io_parms.netfid = open_file->fid.netfid;
1874 io_parms.pid = open_file->pid;
1875 io_parms.tcon =
tcon;
1876 io_parms.offset = 0;
1877 io_parms.length = attrs->
ia_size;
1880 cFYI(1,
"Wrt seteof rc %d", rc);
1891 return PTR_ERR(tlink);
1892 tcon = tlink_tcon(tlink);
1893 server = tcon->
ses->server;
1901 if (server->
ops->set_path_size)
1902 rc = server->
ops->set_path_size(xid, tcon, full_path,
1903 attrs->
ia_size, cifs_sb,
false);
1906 cFYI(1,
"SetEOF by path (setattrs) rc = %d", rc);
1917 unsigned int bytes_written;
1919 io_parms.netfid =
netfid;
1921 io_parms.tcon =
tcon;
1922 io_parms.offset = 0;
1923 io_parms.length = attrs->
ia_size;
1926 cFYI(1,
"wrt seteof rc %d", rc);
1936 cifs_setsize(inode, attrs->
ia_size);
1944 cifs_setattr_unix(
struct dentry *direntry,
struct iattr *attrs)
1948 char *full_path =
NULL;
1949 struct inode *inode = direntry->
d_inode;
1957 cFYI(1,
"setattr_unix on file %s attrs->ia_valid=0x%x",
1970 if (full_path ==
NULL) {
1987 mapping_set_error(inode->
i_mapping, rc);
1991 rc = cifs_set_file_size(inode, attrs, xid, full_path);
2040 u16 nfid = open_file->
fid.netfid;
2041 u32 npid = open_file->
pid;
2042 pTcon = tlink_tcon(open_file->
tlink);
2047 if (IS_ERR(tlink)) {
2048 rc = PTR_ERR(tlink);
2051 pTcon = tlink_tcon(tlink);
2063 attrs->
ia_size != i_size_read(inode))
2067 mark_inode_dirty(inode);
2076 cifsInode->
time = 0;
2085 cifs_setattr_nounix(
struct dentry *direntry,
struct iattr *attrs)
2090 struct inode *inode = direntry->
d_inode;
2093 char *full_path =
NULL;
2100 cFYI(1,
"setattr on file %s attrs->iavalid 0x%x",
2113 if (full_path ==
NULL) {
2131 mapping_set_error(inode->
i_mapping, rc);
2135 rc = cifs_set_file_size(inode, attrs, xid, full_path);
2137 goto cifs_setattr_exit;
2146 #ifdef CONFIG_CIFS_ACL
2152 cFYI(1,
"%s: Setting id failed with error: %d",
2154 goto cifs_setattr_exit;
2169 #ifdef CONFIG_CIFS_ACL
2174 cFYI(1,
"%s: Setting ACL failed with error: %d",
2176 goto cifs_setattr_exit;
2180 if (((mode & S_IWUGO) == 0) &&
2188 }
else if ((mode & S_IWUGO) &&
2230 goto cifs_setattr_exit;
2233 attrs->
ia_size != i_size_read(inode))
2237 mark_inode_dirty(inode);
2248 struct inode *inode = direntry->
d_inode;
2253 return cifs_setattr_unix(direntry, attrs);
2255 return cifs_setattr_nounix(direntry, attrs);
2261 void cifs_delete_inode(
struct inode *inode)
2263 cFYI(1,
"In cifs_delete_inode, inode = 0x%p", inode);