24 #include <linux/stat.h>
25 #include <linux/slab.h>
37 renew_parental_timestamps(
struct dentry *direntry)
60 dirsep = CIFS_DIR_SEP(cifs_sb);
69 for (temp = direntry; !
IS_ROOT(temp);) {
70 namelen += (1 + temp->
d_name.len);
73 cERROR(1,
"corrupt dentry");
81 if (full_path ==
NULL)
85 for (temp = direntry; !
IS_ROOT(temp);) {
87 namelen -= 1 + temp->
d_name.len;
89 spin_unlock(&temp->
d_lock);
95 cFYI(0,
"name: %s", full_path + namelen);
97 spin_unlock(&temp->
d_lock);
100 cERROR(1,
"corrupt dentry");
107 if (namelen != dfsplen || read_seqretry(&
rename_lock, seq)) {
108 cFYI(1,
"did not end path lookup where expected. namelen=%d "
109 "dfsplen=%d", namelen, dfsplen);
114 goto cifs_bp_rename_retry;
127 for (i = 0; i < dfsplen; i++) {
128 if (full_path[i] ==
'\\')
141 check_name(
struct dentry *direntry)
147 for (i = 0; i < direntry->
d_name.len; i++) {
148 if (direntry->
d_name.name[i] ==
'\\') {
149 cFYI(1,
"Invalid file name");
169 struct cifs_tcon *tcon = tlink_tcon(tlink);
170 char *full_path =
NULL;
172 struct inode *newinode =
NULL;
177 if (tcon->
ses->server->oplocks)
181 if (full_path ==
NULL) {
190 oflags, oplock, &fid->
netfid, xid);
193 if (newinode ==
NULL) {
195 goto cifs_create_get_file_info;
207 goto cifs_create_get_file_info;
210 goto cifs_create_set_dentry;
213 goto cifs_create_get_file_info;
259 else if ((oflags &
O_CREAT) == O_CREAT)
262 cFYI(1,
"Create flag not set in create function");
269 if (!server->
ops->open) {
290 rc = server->
ops->open(xid, tcon, full_path, disposition,
291 desired_access, create_options, fid, oplock,
294 cFYI(1,
"cifs_create returned 0x%x", rc);
334 cifs_create_get_file_info:
343 if (server->
ops->set_lease_key)
344 server->
ops->set_lease_key(newinode, fid);
347 if ((*oplock & CIFS_CREATE_ACTION) &&
358 cifs_create_set_dentry:
360 cFYI(1,
"Create worked, get_inode_info failed rc = %d", rc);
361 if (server->
ops->close)
362 server->
ops->close(xid, tcon, fid);
366 d_add(direntry, newinode);
400 if (!(oflags & O_CREAT)) {
407 if (!d_unhashed(direntry))
417 rc = check_name(direntry);
423 cFYI(1,
"parent inode = 0x%p name is: %s and dentry = 0x%p",
424 inode, direntry->
d_name.name, direntry);
430 tcon = tlink_tcon(tlink);
431 server = tcon->
ses->server;
433 if (server->
ops->new_lease_key)
434 server->
ops->new_lease_key(&fid);
438 rc = cifs_do_create(inode, direntry, xid, tlink, oflags, mode,
439 &oplock, &fid, opened);
448 if (server->
ops->close)
449 server->
ops->close(xid, tcon, &fid);
455 if (file_info ==
NULL) {
456 if (server->
ops->close)
457 server->
ops->close(xid, tcon, &fid);
489 cFYI(1,
"cifs_create parent inode = 0x%p name is: %s and dentry = 0x%p",
490 inode, direntry->
d_name.name, direntry);
497 tcon = tlink_tcon(tlink);
498 server = tcon->
ses->server;
500 if (server->
ops->new_lease_key)
501 server->
ops->new_lease_key(&fid);
503 rc = cifs_do_create(inode, direntry, xid, tlink, oflags, mode,
504 &oplock, &fid, &created);
505 if (!rc && server->
ops->close)
506 server->
ops->close(xid, tcon, &fid);
524 char *full_path =
NULL;
525 struct inode *newinode =
NULL;
528 FILE_ALL_INFO *buf =
NULL;
529 unsigned int bytes_written;
532 if (!old_valid_dev(device_number))
535 cifs_sb = CIFS_SB(inode->
i_sb);
538 return PTR_ERR(tlink);
540 pTcon = tlink_tcon(tlink);
545 if (full_path ==
NULL) {
556 .device = device_number,
584 cFYI(1,
"sfu compat create special file");
599 &fileHandle, &oplock, buf, cifs_sb->
local_nls,
608 io_parms.
netfid = fileHandle;
610 io_parms.
tcon = pTcon;
620 &bytes_written, (
char *)pdev,
629 &bytes_written, (
char *)pdev,
654 struct inode *newInode =
NULL;
655 char *full_path =
NULL;
659 cFYI(1,
"parent inode = 0x%p name is: %s and dentry = 0x%p",
660 parent_dir_inode, direntry->
d_name.name, direntry);
664 cifs_sb = CIFS_SB(parent_dir_inode->
i_sb);
668 return (
struct dentry *)tlink;
670 pTcon = tlink_tcon(tlink);
672 rc = check_name(direntry);
680 if (full_path ==
NULL) {
686 cFYI(1,
"non-NULL inode in lookup");
688 cFYI(1,
"NULL inode in lookup");
690 cFYI(1,
"Full path: %s inode = 0x%p", full_path, direntry->
d_inode);
694 parent_dir_inode->
i_sb, xid);
700 if ((rc == 0) && (newInode !=
NULL)) {
701 d_add(direntry, newInode);
704 renew_parental_timestamps(direntry);
706 }
else if (rc == -
ENOENT) {
709 d_add(direntry,
NULL);
712 }
else if (rc != -
EACCES) {
713 cERROR(1,
"Unexpected lookup error %d", rc);
726 cifs_d_revalidate(
struct dentry *direntry,
unsigned int flags)
744 spin_lock(&direntry->
d_lock);
746 spin_unlock(&direntry->
d_lock);
784 .d_revalidate = cifs_d_revalidate,
789 static int cifs_ci_hash(
const struct dentry *
dentry,
const struct inode *inode,
792 struct nls_table *codepage = CIFS_SB(dentry->
d_sb)->local_nls;
797 for (i = 0; i < q->len; i++)
798 hash = partial_name_hash(nls_tolower(codepage, q->
name[i]),
800 q->hash = end_name_hash(hash);
805 static int cifs_ci_compare(
const struct dentry *parent,
806 const struct inode *pinode,
807 const struct dentry *dentry,
const struct inode *inode,
808 unsigned int len,
const char *
str,
const struct qstr *
name)
810 struct nls_table *codepage = CIFS_SB(pinode->
i_sb)->local_nls;
812 if ((name->len == len) &&
813 (nls_strnicmp(codepage, name->
name, str, len) == 0))
819 .d_revalidate = cifs_d_revalidate,
820 .d_hash = cifs_ci_hash,
821 .d_compare = cifs_ci_compare,