0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #include <linux/fs.h>
0011 #include <linux/stat.h>
0012 #include <linux/slab.h>
0013 #include <linux/namei.h>
0014 #include <linux/mount.h>
0015 #include <linux/file.h>
0016 #include "cifsfs.h"
0017 #include "cifspdu.h"
0018 #include "cifsglob.h"
0019 #include "cifsproto.h"
0020 #include "cifs_debug.h"
0021 #include "cifs_fs_sb.h"
0022 #include "cifs_unicode.h"
0023 #include "fs_context.h"
0024 #include "cifs_ioctl.h"
0025 #include "fscache.h"
0026
0027 static void
0028 renew_parental_timestamps(struct dentry *direntry)
0029 {
0030
0031
0032 do {
0033 cifs_set_time(direntry, jiffies);
0034 direntry = direntry->d_parent;
0035 } while (!IS_ROOT(direntry));
0036 }
0037
0038 char *
0039 cifs_build_path_to_root(struct smb3_fs_context *ctx, struct cifs_sb_info *cifs_sb,
0040 struct cifs_tcon *tcon, int add_treename)
0041 {
0042 int pplen = ctx->prepath ? strlen(ctx->prepath) + 1 : 0;
0043 int dfsplen;
0044 char *full_path = NULL;
0045
0046
0047 if (pplen == 0) {
0048 full_path = kzalloc(1, GFP_KERNEL);
0049 return full_path;
0050 }
0051
0052 if (add_treename)
0053 dfsplen = strnlen(tcon->treeName, MAX_TREE_SIZE + 1);
0054 else
0055 dfsplen = 0;
0056
0057 full_path = kmalloc(dfsplen + pplen + 1, GFP_KERNEL);
0058 if (full_path == NULL)
0059 return full_path;
0060
0061 if (dfsplen)
0062 memcpy(full_path, tcon->treeName, dfsplen);
0063 full_path[dfsplen] = CIFS_DIR_SEP(cifs_sb);
0064 memcpy(full_path + dfsplen + 1, ctx->prepath, pplen);
0065 convert_delimiter(full_path, CIFS_DIR_SEP(cifs_sb));
0066 return full_path;
0067 }
0068
0069
0070 const char *
0071 build_path_from_dentry(struct dentry *direntry, void *page)
0072 {
0073 struct cifs_sb_info *cifs_sb = CIFS_SB(direntry->d_sb);
0074 struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb);
0075 bool prefix = tcon->Flags & SMB_SHARE_IS_IN_DFS;
0076
0077 return build_path_from_dentry_optional_prefix(direntry, page,
0078 prefix);
0079 }
0080
0081 char *
0082 build_path_from_dentry_optional_prefix(struct dentry *direntry, void *page,
0083 bool prefix)
0084 {
0085 int dfsplen;
0086 int pplen = 0;
0087 struct cifs_sb_info *cifs_sb = CIFS_SB(direntry->d_sb);
0088 struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb);
0089 char dirsep = CIFS_DIR_SEP(cifs_sb);
0090 char *s;
0091
0092 if (unlikely(!page))
0093 return ERR_PTR(-ENOMEM);
0094
0095 if (prefix)
0096 dfsplen = strnlen(tcon->treeName, MAX_TREE_SIZE + 1);
0097 else
0098 dfsplen = 0;
0099
0100 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_USE_PREFIX_PATH)
0101 pplen = cifs_sb->prepath ? strlen(cifs_sb->prepath) + 1 : 0;
0102
0103 s = dentry_path_raw(direntry, page, PATH_MAX);
0104 if (IS_ERR(s))
0105 return s;
0106 if (!s[1])
0107 s++;
0108 if (s < (char *)page + pplen + dfsplen)
0109 return ERR_PTR(-ENAMETOOLONG);
0110 if (pplen) {
0111 cifs_dbg(FYI, "using cifs_sb prepath <%s>\n", cifs_sb->prepath);
0112 s -= pplen;
0113 memcpy(s + 1, cifs_sb->prepath, pplen - 1);
0114 *s = '/';
0115 }
0116 if (dirsep != '/') {
0117
0118 char *p;
0119
0120 for (p = s; *p; p++)
0121 if (*p == '/')
0122 *p = dirsep;
0123 }
0124 if (dfsplen) {
0125 s -= dfsplen;
0126 memcpy(s, tcon->treeName, dfsplen);
0127 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIX_PATHS) {
0128 int i;
0129 for (i = 0; i < dfsplen; i++) {
0130 if (s[i] == '\\')
0131 s[i] = '/';
0132 }
0133 }
0134 }
0135 return s;
0136 }
0137
0138
0139
0140
0141
0142
0143 static int
0144 check_name(struct dentry *direntry, struct cifs_tcon *tcon)
0145 {
0146 struct cifs_sb_info *cifs_sb = CIFS_SB(direntry->d_sb);
0147 int i;
0148
0149 if (unlikely(tcon->fsAttrInfo.MaxPathNameComponentLength &&
0150 direntry->d_name.len >
0151 le32_to_cpu(tcon->fsAttrInfo.MaxPathNameComponentLength)))
0152 return -ENAMETOOLONG;
0153
0154 if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIX_PATHS)) {
0155 for (i = 0; i < direntry->d_name.len; i++) {
0156 if (direntry->d_name.name[i] == '\\') {
0157 cifs_dbg(FYI, "Invalid file name\n");
0158 return -EINVAL;
0159 }
0160 }
0161 }
0162 return 0;
0163 }
0164
0165
0166
0167
0168 static int
0169 cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned int xid,
0170 struct tcon_link *tlink, unsigned oflags, umode_t mode,
0171 __u32 *oplock, struct cifs_fid *fid)
0172 {
0173 int rc = -ENOENT;
0174 int create_options = CREATE_NOT_DIR;
0175 int desired_access;
0176 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
0177 struct cifs_tcon *tcon = tlink_tcon(tlink);
0178 const char *full_path;
0179 void *page = alloc_dentry_path();
0180 FILE_ALL_INFO *buf = NULL;
0181 struct inode *newinode = NULL;
0182 int disposition;
0183 struct TCP_Server_Info *server = tcon->ses->server;
0184 struct cifs_open_parms oparms;
0185
0186 *oplock = 0;
0187 if (tcon->ses->server->oplocks)
0188 *oplock = REQ_OPLOCK;
0189
0190 full_path = build_path_from_dentry(direntry, page);
0191 if (IS_ERR(full_path)) {
0192 free_dentry_path(page);
0193 return PTR_ERR(full_path);
0194 }
0195
0196 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
0197 if (tcon->unix_ext && cap_unix(tcon->ses) && !tcon->broken_posix_open &&
0198 (CIFS_UNIX_POSIX_PATH_OPS_CAP &
0199 le64_to_cpu(tcon->fsUnixInfo.Capability))) {
0200 rc = cifs_posix_open(full_path, &newinode, inode->i_sb, mode,
0201 oflags, oplock, &fid->netfid, xid);
0202 switch (rc) {
0203 case 0:
0204 if (newinode == NULL) {
0205
0206 goto cifs_create_get_file_info;
0207 }
0208
0209 if (S_ISDIR(newinode->i_mode)) {
0210 CIFSSMBClose(xid, tcon, fid->netfid);
0211 iput(newinode);
0212 rc = -EISDIR;
0213 goto out;
0214 }
0215
0216 if (!S_ISREG(newinode->i_mode)) {
0217
0218
0219
0220
0221
0222
0223
0224 CIFSSMBClose(xid, tcon, fid->netfid);
0225 goto cifs_create_get_file_info;
0226 }
0227
0228 goto cifs_create_set_dentry;
0229
0230 case -ENOENT:
0231 goto cifs_create_get_file_info;
0232
0233 case -EIO:
0234 case -EINVAL:
0235
0236
0237
0238
0239
0240
0241
0242
0243 tcon->broken_posix_open = true;
0244 break;
0245
0246 case -EREMOTE:
0247 case -EOPNOTSUPP:
0248
0249
0250
0251
0252
0253 break;
0254
0255 default:
0256 goto out;
0257 }
0258
0259
0260
0261
0262
0263
0264 }
0265 #endif
0266
0267 desired_access = 0;
0268 if (OPEN_FMODE(oflags) & FMODE_READ)
0269 desired_access |= GENERIC_READ;
0270 if (OPEN_FMODE(oflags) & FMODE_WRITE)
0271 desired_access |= GENERIC_WRITE;
0272
0273 disposition = FILE_OVERWRITE_IF;
0274 if ((oflags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL))
0275 disposition = FILE_CREATE;
0276 else if ((oflags & (O_CREAT | O_TRUNC)) == (O_CREAT | O_TRUNC))
0277 disposition = FILE_OVERWRITE_IF;
0278 else if ((oflags & O_CREAT) == O_CREAT)
0279 disposition = FILE_OPEN_IF;
0280 else
0281 cifs_dbg(FYI, "Create flag not set in create function\n");
0282
0283
0284
0285
0286
0287
0288 if (!server->ops->open) {
0289 rc = -ENOSYS;
0290 goto out;
0291 }
0292
0293 buf = kmalloc(sizeof(FILE_ALL_INFO), GFP_KERNEL);
0294 if (buf == NULL) {
0295 rc = -ENOMEM;
0296 goto out;
0297 }
0298
0299
0300
0301
0302
0303 if (!tcon->unix_ext && (mode & S_IWUGO) == 0)
0304 create_options |= CREATE_OPTION_READONLY;
0305
0306 oparms.tcon = tcon;
0307 oparms.cifs_sb = cifs_sb;
0308 oparms.desired_access = desired_access;
0309 oparms.create_options = cifs_create_options(cifs_sb, create_options);
0310 oparms.disposition = disposition;
0311 oparms.path = full_path;
0312 oparms.fid = fid;
0313 oparms.reconnect = false;
0314 oparms.mode = mode;
0315 rc = server->ops->open(xid, &oparms, oplock, buf);
0316 if (rc) {
0317 cifs_dbg(FYI, "cifs_create returned 0x%x\n", rc);
0318 goto out;
0319 }
0320
0321 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
0322
0323
0324
0325
0326 if ((tcon->unix_ext) && (*oplock & CIFS_CREATE_ACTION)) {
0327 struct cifs_unix_set_info_args args = {
0328 .mode = mode,
0329 .ctime = NO_CHANGE_64,
0330 .atime = NO_CHANGE_64,
0331 .mtime = NO_CHANGE_64,
0332 .device = 0,
0333 };
0334
0335 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID) {
0336 args.uid = current_fsuid();
0337 if (inode->i_mode & S_ISGID)
0338 args.gid = inode->i_gid;
0339 else
0340 args.gid = current_fsgid();
0341 } else {
0342 args.uid = INVALID_UID;
0343 args.gid = INVALID_GID;
0344 }
0345 CIFSSMBUnixSetFileInfo(xid, tcon, &args, fid->netfid,
0346 current->tgid);
0347 } else {
0348
0349
0350
0351
0352
0353
0354
0355 }
0356
0357 cifs_create_get_file_info:
0358
0359 if (tcon->unix_ext)
0360 rc = cifs_get_inode_info_unix(&newinode, full_path, inode->i_sb,
0361 xid);
0362 else {
0363 #else
0364 {
0365 #endif
0366
0367 rc = cifs_get_inode_info(&newinode, full_path, buf, inode->i_sb,
0368 xid, fid);
0369 if (newinode) {
0370 if (server->ops->set_lease_key)
0371 server->ops->set_lease_key(newinode, fid);
0372 if ((*oplock & CIFS_CREATE_ACTION) && S_ISREG(newinode->i_mode)) {
0373 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DYNPERM)
0374 newinode->i_mode = mode;
0375 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID) {
0376 newinode->i_uid = current_fsuid();
0377 if (inode->i_mode & S_ISGID)
0378 newinode->i_gid = inode->i_gid;
0379 else
0380 newinode->i_gid = current_fsgid();
0381 }
0382 }
0383 }
0384 }
0385
0386 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
0387 cifs_create_set_dentry:
0388 #endif
0389 if (rc != 0) {
0390 cifs_dbg(FYI, "Create worked, get_inode_info failed rc = %d\n",
0391 rc);
0392 goto out_err;
0393 }
0394
0395 if (newinode)
0396 if (S_ISDIR(newinode->i_mode)) {
0397 rc = -EISDIR;
0398 goto out_err;
0399 }
0400
0401 d_drop(direntry);
0402 d_add(direntry, newinode);
0403
0404 out:
0405 kfree(buf);
0406 free_dentry_path(page);
0407 return rc;
0408
0409 out_err:
0410 if (server->ops->close)
0411 server->ops->close(xid, tcon, fid);
0412 if (newinode)
0413 iput(newinode);
0414 goto out;
0415 }
0416
0417 int
0418 cifs_atomic_open(struct inode *inode, struct dentry *direntry,
0419 struct file *file, unsigned oflags, umode_t mode)
0420 {
0421 int rc;
0422 unsigned int xid;
0423 struct tcon_link *tlink;
0424 struct cifs_tcon *tcon;
0425 struct TCP_Server_Info *server;
0426 struct cifs_fid fid;
0427 struct cifs_pending_open open;
0428 __u32 oplock;
0429 struct cifsFileInfo *file_info;
0430
0431 if (unlikely(cifs_forced_shutdown(CIFS_SB(inode->i_sb))))
0432 return -EIO;
0433
0434
0435
0436
0437
0438
0439
0440
0441
0442
0443
0444
0445 if (!(oflags & O_CREAT)) {
0446 struct dentry *res;
0447
0448
0449
0450
0451
0452 if (!d_in_lookup(direntry))
0453 return -ENOENT;
0454
0455 res = cifs_lookup(inode, direntry, 0);
0456 if (IS_ERR(res))
0457 return PTR_ERR(res);
0458
0459 return finish_no_open(file, res);
0460 }
0461
0462 xid = get_xid();
0463
0464 cifs_dbg(FYI, "parent inode = 0x%p name is: %pd and dentry = 0x%p\n",
0465 inode, direntry, direntry);
0466
0467 tlink = cifs_sb_tlink(CIFS_SB(inode->i_sb));
0468 if (IS_ERR(tlink)) {
0469 rc = PTR_ERR(tlink);
0470 goto out_free_xid;
0471 }
0472
0473 tcon = tlink_tcon(tlink);
0474
0475 rc = check_name(direntry, tcon);
0476 if (rc)
0477 goto out;
0478
0479 server = tcon->ses->server;
0480
0481 if (server->ops->new_lease_key)
0482 server->ops->new_lease_key(&fid);
0483
0484 cifs_add_pending_open(&fid, tlink, &open);
0485
0486 rc = cifs_do_create(inode, direntry, xid, tlink, oflags, mode,
0487 &oplock, &fid);
0488
0489 if (rc) {
0490 cifs_del_pending_open(&open);
0491 goto out;
0492 }
0493
0494 if ((oflags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL))
0495 file->f_mode |= FMODE_CREATED;
0496
0497 rc = finish_open(file, direntry, generic_file_open);
0498 if (rc) {
0499 if (server->ops->close)
0500 server->ops->close(xid, tcon, &fid);
0501 cifs_del_pending_open(&open);
0502 goto out;
0503 }
0504
0505 if (file->f_flags & O_DIRECT &&
0506 CIFS_SB(inode->i_sb)->mnt_cifs_flags & CIFS_MOUNT_STRICT_IO) {
0507 if (CIFS_SB(inode->i_sb)->mnt_cifs_flags & CIFS_MOUNT_NO_BRL)
0508 file->f_op = &cifs_file_direct_nobrl_ops;
0509 else
0510 file->f_op = &cifs_file_direct_ops;
0511 }
0512
0513 file_info = cifs_new_fileinfo(&fid, file, tlink, oplock);
0514 if (file_info == NULL) {
0515 if (server->ops->close)
0516 server->ops->close(xid, tcon, &fid);
0517 cifs_del_pending_open(&open);
0518 rc = -ENOMEM;
0519 goto out;
0520 }
0521
0522 fscache_use_cookie(cifs_inode_cookie(file_inode(file)),
0523 file->f_mode & FMODE_WRITE);
0524
0525 out:
0526 cifs_put_tlink(tlink);
0527 out_free_xid:
0528 free_xid(xid);
0529 return rc;
0530 }
0531
0532 int cifs_create(struct user_namespace *mnt_userns, struct inode *inode,
0533 struct dentry *direntry, umode_t mode, bool excl)
0534 {
0535 int rc;
0536 unsigned int xid = get_xid();
0537
0538
0539
0540
0541
0542
0543
0544 unsigned oflags = O_EXCL | O_CREAT | O_RDWR;
0545 struct tcon_link *tlink;
0546 struct cifs_tcon *tcon;
0547 struct TCP_Server_Info *server;
0548 struct cifs_fid fid;
0549 __u32 oplock;
0550
0551 cifs_dbg(FYI, "cifs_create parent inode = 0x%p name is: %pd and dentry = 0x%p\n",
0552 inode, direntry, direntry);
0553
0554 if (unlikely(cifs_forced_shutdown(CIFS_SB(inode->i_sb))))
0555 return -EIO;
0556
0557 tlink = cifs_sb_tlink(CIFS_SB(inode->i_sb));
0558 rc = PTR_ERR(tlink);
0559 if (IS_ERR(tlink))
0560 goto out_free_xid;
0561
0562 tcon = tlink_tcon(tlink);
0563 server = tcon->ses->server;
0564
0565 if (server->ops->new_lease_key)
0566 server->ops->new_lease_key(&fid);
0567
0568 rc = cifs_do_create(inode, direntry, xid, tlink, oflags, mode,
0569 &oplock, &fid);
0570 if (!rc && server->ops->close)
0571 server->ops->close(xid, tcon, &fid);
0572
0573 cifs_put_tlink(tlink);
0574 out_free_xid:
0575 free_xid(xid);
0576 return rc;
0577 }
0578
0579 int cifs_mknod(struct user_namespace *mnt_userns, struct inode *inode,
0580 struct dentry *direntry, umode_t mode, dev_t device_number)
0581 {
0582 int rc = -EPERM;
0583 unsigned int xid;
0584 struct cifs_sb_info *cifs_sb;
0585 struct tcon_link *tlink;
0586 struct cifs_tcon *tcon;
0587 const char *full_path;
0588 void *page;
0589
0590 if (!old_valid_dev(device_number))
0591 return -EINVAL;
0592
0593 cifs_sb = CIFS_SB(inode->i_sb);
0594 if (unlikely(cifs_forced_shutdown(cifs_sb)))
0595 return -EIO;
0596
0597 tlink = cifs_sb_tlink(cifs_sb);
0598 if (IS_ERR(tlink))
0599 return PTR_ERR(tlink);
0600
0601 page = alloc_dentry_path();
0602 tcon = tlink_tcon(tlink);
0603 xid = get_xid();
0604
0605 full_path = build_path_from_dentry(direntry, page);
0606 if (IS_ERR(full_path)) {
0607 rc = PTR_ERR(full_path);
0608 goto mknod_out;
0609 }
0610
0611 rc = tcon->ses->server->ops->make_node(xid, inode, direntry, tcon,
0612 full_path, mode,
0613 device_number);
0614
0615 mknod_out:
0616 free_dentry_path(page);
0617 free_xid(xid);
0618 cifs_put_tlink(tlink);
0619 return rc;
0620 }
0621
0622 struct dentry *
0623 cifs_lookup(struct inode *parent_dir_inode, struct dentry *direntry,
0624 unsigned int flags)
0625 {
0626 unsigned int xid;
0627 int rc = 0;
0628 struct cifs_sb_info *cifs_sb;
0629 struct tcon_link *tlink;
0630 struct cifs_tcon *pTcon;
0631 struct inode *newInode = NULL;
0632 const char *full_path;
0633 void *page;
0634 int retry_count = 0;
0635
0636 xid = get_xid();
0637
0638 cifs_dbg(FYI, "parent inode = 0x%p name is: %pd and dentry = 0x%p\n",
0639 parent_dir_inode, direntry, direntry);
0640
0641
0642
0643 cifs_sb = CIFS_SB(parent_dir_inode->i_sb);
0644 tlink = cifs_sb_tlink(cifs_sb);
0645 if (IS_ERR(tlink)) {
0646 free_xid(xid);
0647 return ERR_CAST(tlink);
0648 }
0649 pTcon = tlink_tcon(tlink);
0650
0651 rc = check_name(direntry, pTcon);
0652 if (unlikely(rc)) {
0653 cifs_put_tlink(tlink);
0654 free_xid(xid);
0655 return ERR_PTR(rc);
0656 }
0657
0658
0659
0660
0661 page = alloc_dentry_path();
0662 full_path = build_path_from_dentry(direntry, page);
0663 if (IS_ERR(full_path)) {
0664 cifs_put_tlink(tlink);
0665 free_xid(xid);
0666 free_dentry_path(page);
0667 return ERR_CAST(full_path);
0668 }
0669
0670 if (d_really_is_positive(direntry)) {
0671 cifs_dbg(FYI, "non-NULL inode in lookup\n");
0672 } else {
0673 cifs_dbg(FYI, "NULL inode in lookup\n");
0674 }
0675 cifs_dbg(FYI, "Full path: %s inode = 0x%p\n",
0676 full_path, d_inode(direntry));
0677
0678 again:
0679 if (pTcon->posix_extensions)
0680 rc = smb311_posix_get_inode_info(&newInode, full_path, parent_dir_inode->i_sb, xid);
0681 else if (pTcon->unix_ext) {
0682 rc = cifs_get_inode_info_unix(&newInode, full_path,
0683 parent_dir_inode->i_sb, xid);
0684 } else {
0685 rc = cifs_get_inode_info(&newInode, full_path, NULL,
0686 parent_dir_inode->i_sb, xid, NULL);
0687 }
0688
0689 if (rc == 0) {
0690
0691
0692 renew_parental_timestamps(direntry);
0693 } else if (rc == -EAGAIN && retry_count++ < 10) {
0694 goto again;
0695 } else if (rc == -ENOENT) {
0696 cifs_set_time(direntry, jiffies);
0697 newInode = NULL;
0698 } else {
0699 if (rc != -EACCES) {
0700 cifs_dbg(FYI, "Unexpected lookup error %d\n", rc);
0701
0702
0703 }
0704 newInode = ERR_PTR(rc);
0705 }
0706 free_dentry_path(page);
0707 cifs_put_tlink(tlink);
0708 free_xid(xid);
0709 return d_splice_alias(newInode, direntry);
0710 }
0711
0712 static int
0713 cifs_d_revalidate(struct dentry *direntry, unsigned int flags)
0714 {
0715 struct inode *inode;
0716 int rc;
0717
0718 if (flags & LOOKUP_RCU)
0719 return -ECHILD;
0720
0721 if (d_really_is_positive(direntry)) {
0722 inode = d_inode(direntry);
0723 if ((flags & LOOKUP_REVAL) && !CIFS_CACHE_READ(CIFS_I(inode)))
0724 CIFS_I(inode)->time = 0;
0725
0726 rc = cifs_revalidate_dentry(direntry);
0727 if (rc) {
0728 cifs_dbg(FYI, "cifs_revalidate_dentry failed with rc=%d", rc);
0729 switch (rc) {
0730 case -ENOENT:
0731 case -ESTALE:
0732
0733
0734
0735
0736 return 0;
0737 default:
0738
0739
0740
0741
0742 return rc;
0743 }
0744 }
0745 else {
0746
0747
0748
0749
0750
0751
0752
0753 if (IS_AUTOMOUNT(inode) &&
0754 !(direntry->d_flags & DCACHE_NEED_AUTOMOUNT)) {
0755 spin_lock(&direntry->d_lock);
0756 direntry->d_flags |= DCACHE_NEED_AUTOMOUNT;
0757 spin_unlock(&direntry->d_lock);
0758 }
0759
0760 return 1;
0761 }
0762 }
0763
0764
0765
0766
0767
0768 if (!flags)
0769 return 0;
0770
0771
0772
0773
0774
0775
0776 if (flags & (LOOKUP_CREATE | LOOKUP_RENAME_TARGET))
0777 return 0;
0778
0779 if (time_after(jiffies, cifs_get_time(direntry) + HZ) || !lookupCacheEnabled)
0780 return 0;
0781
0782 return 1;
0783 }
0784
0785
0786
0787
0788
0789
0790
0791
0792
0793
0794 const struct dentry_operations cifs_dentry_ops = {
0795 .d_revalidate = cifs_d_revalidate,
0796 .d_automount = cifs_dfs_d_automount,
0797
0798 };
0799
0800 static int cifs_ci_hash(const struct dentry *dentry, struct qstr *q)
0801 {
0802 struct nls_table *codepage = CIFS_SB(dentry->d_sb)->local_nls;
0803 unsigned long hash;
0804 wchar_t c;
0805 int i, charlen;
0806
0807 hash = init_name_hash(dentry);
0808 for (i = 0; i < q->len; i += charlen) {
0809 charlen = codepage->char2uni(&q->name[i], q->len - i, &c);
0810
0811 if (unlikely(charlen < 0))
0812 return charlen;
0813 hash = partial_name_hash(cifs_toupper(c), hash);
0814 }
0815 q->hash = end_name_hash(hash);
0816
0817 return 0;
0818 }
0819
0820 static int cifs_ci_compare(const struct dentry *dentry,
0821 unsigned int len, const char *str, const struct qstr *name)
0822 {
0823 struct nls_table *codepage = CIFS_SB(dentry->d_sb)->local_nls;
0824 wchar_t c1, c2;
0825 int i, l1, l2;
0826
0827
0828
0829
0830
0831
0832
0833 if (name->len != len)
0834 return 1;
0835
0836 for (i = 0; i < len; i += l1) {
0837
0838 l1 = codepage->char2uni(&str[i], len - i, &c1);
0839 l2 = codepage->char2uni(&name->name[i], name->len - i, &c2);
0840
0841
0842
0843
0844
0845 if (unlikely(l1 < 0 && l2 < 0)) {
0846 if (str[i] != name->name[i])
0847 return 1;
0848 l1 = 1;
0849 continue;
0850 }
0851
0852
0853
0854
0855
0856 if (l1 != l2)
0857 return 1;
0858
0859
0860 if (cifs_toupper(c1) != cifs_toupper(c2))
0861 return 1;
0862 }
0863
0864 return 0;
0865 }
0866
0867 const struct dentry_operations cifs_ci_dentry_ops = {
0868 .d_revalidate = cifs_d_revalidate,
0869 .d_hash = cifs_ci_hash,
0870 .d_compare = cifs_ci_compare,
0871 .d_automount = cifs_dfs_d_automount,
0872 };