/* Fill a cifs_fattr struct with info from SMB_FIND_FILE_POSIX_INFO. */ staticvoid
cifs_posix_to_fattr(struct cifs_fattr *fattr, struct smb2_posix_info *info, struct cifs_sb_info *cifs_sb)
{ struct smb2_posix_info_parsed parsed;
if (fattr->cf_cifsattrs & ATTR_REPARSE)
fattr->cf_cifstag = le32_to_cpu(info->ReparseTag);
/* The Mode field in the response can now include the file type as well */
fattr->cf_mode = wire_mode_to_posix(le32_to_cpu(info->Mode),
fattr->cf_cifsattrs & ATTR_DIRECTORY);
fattr->cf_dtype = S_DT(fattr->cf_mode);
switch (fattr->cf_mode & S_IFMT) { case S_IFLNK: case S_IFBLK: case S_IFCHR:
fattr->cf_flags |= CIFS_FATTR_NEED_REVAL; break; default: break;
}
ffirst_retry: /* test for Unix extensions */ /* but now check for them on the share/mount not on the SMB session */ /* if (cap_unix(tcon->ses) { */ if (tcon->unix_ext)
cifsFile->srch_inf.info_level = SMB_FIND_FILE_UNIX; elseif (tcon->posix_extensions)
cifsFile->srch_inf.info_level = SMB_FIND_FILE_POSIX_INFO; elseif ((tcon->ses->capabilities &
tcon->ses->server->vals->cap_nt_find) == 0) {
cifsFile->srch_inf.info_level = SMB_FIND_FILE_INFO_STANDARD;
} elseif (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) {
cifsFile->srch_inf.info_level = SMB_FIND_FILE_ID_FULL_DIR_INFO;
} else/* not srvinos - BB fixme add check for backlevel? */ {
cifsFile->srch_inf.info_level = SMB_FIND_FILE_FULL_DIRECTORY_INFO;
}
search_flags = CIFS_SEARCH_CLOSE_AT_END | CIFS_SEARCH_RETURN_RESUME; if (backup_cred(cifs_sb))
search_flags |= CIFS_SEARCH_BACKUP_SEARCH;
do {
rc = _initiate_cifs_search(xid, file, full_path); /* *Ifwedon'thaveenoughcreditstostartreadingthe *directoryjusttryagainaftershortwait.
*/ if (rc != -EDEADLK) break;
usleep_range(512, 2048);
} while (retry_count++ < 5);
return rc;
}
/* return length of unicode string in bytes */ staticint cifs_unicode_bytelen(constchar *str)
{ int len; const __le16 *ustr = (const __le16 *)str;
for (len = 0; len <= PATH_MAX; len++) { if (ustr[len] == 0) return len << 1;
}
cifs_dbg(FYI, "Unicode string longer than PATH_MAX found\n"); return len << 1;
}
/* payload should have already been checked at this point */ if (posix_info_parse(info, NULL, &parsed) < 0) {
cifs_dbg(VFS, "Invalid POSIX info payload\n"); return;
}
switch (level) { case SMB_FIND_FILE_POSIX_INFO:
cifs_fill_dirent_posix(de, info); break; case SMB_FIND_FILE_UNIX:
cifs_fill_dirent_unix(de, info, is_unicode); break; case SMB_FIND_FILE_DIRECTORY_INFO:
cifs_fill_dirent_dir(de, info); break; case SMB_FIND_FILE_FULL_DIRECTORY_INFO:
cifs_fill_dirent_full(de, info); break; case SMB_FIND_FILE_ID_FULL_DIR_INFO:
cifs_fill_dirent_search(de, info); break; case SMB_FIND_FILE_BOTH_DIRECTORY_INFO:
cifs_fill_dirent_both(de, info); break; case SMB_FIND_FILE_INFO_STANDARD:
cifs_fill_dirent_std(de, info); break; default:
cifs_dbg(FYI, "Unknown findfirst level %d\n", level); return -EINVAL;
}
return0;
}
#define UNICODE_DOT cpu_to_le16(0x2e)
/* return 0 if no match and 1 for . (current directory) and 2 for .. (parent) */ staticint cifs_entry_is_dot(struct cifs_dirent *de, bool is_unicode)
{ int rc = 0;
if (!de->name) return0;
if (is_unicode) {
__le16 *ufilename = (__le16 *)de->name; if (de->namelen == 2) { /* check for . */ if (ufilename[0] == UNICODE_DOT)
rc = 1;
} elseif (de->namelen == 4) { /* check for .. */ if (ufilename[0] == UNICODE_DOT &&
ufilename[1] == UNICODE_DOT)
rc = 2;
}
} else/* ASCII */ { if (de->namelen == 1) { if (de->name[0] == '.')
rc = 1;
} elseif (de->namelen == 2) { if (de->name[0] == '.' && de->name[1] == '.')
rc = 2;
}
}
return rc;
}
/* Check if directory that we are searching has changed so we can decide
whether we can use the cached search results from the previous search */ staticint is_dir_changed(struct file *file)
{ struct inode *inode = file_inode(file); struct cifsInodeInfo *cifs_inode_info = CIFS_I(inode);
if (cifs_inode_info->time == 0) return1; /* directory was changed, e.g. unlink or new file */ else return0;
dump_cifs_file_struct(file, "In fce "); if (((index_to_find < cfile->srch_inf.index_of_last_entry) &&
is_dir_changed(file)) || (index_to_find < first_entry_in_buffer)) { /* close and restart search */
cifs_dbg(FYI, "search backing up - close and restart search\n");
spin_lock(&cfile->file_info_lock); if (server->ops->dir_needs_close(cfile)) {
cfile->invalidHandle = true;
spin_unlock(&cfile->file_info_lock); if (server->ops->close_dir)
server->ops->close_dir(xid, tcon, &cfile->fid);
} else
spin_unlock(&cfile->file_info_lock); if (cfile->srch_inf.ntwrk_buf_start) {
cifs_dbg(FYI, "freeing SMB ff cache buf on search rewind\n"); if (cfile->srch_inf.smallBuf)
cifs_small_buf_release(cfile->srch_inf.
ntwrk_buf_start); else
cifs_buf_release(cfile->srch_inf.
ntwrk_buf_start); /* Reset all pointers to the network buffer to prevent stale references */
cfile->srch_inf.ntwrk_buf_start = NULL;
cfile->srch_inf.srch_entries_start = NULL;
cfile->srch_inf.last_entry = NULL;
}
rc = initiate_cifs_search(xid, file, full_path); if (rc) {
cifs_dbg(FYI, "error %d reinitiating a search on rewind\n",
rc); return rc;
} /* FindFirst/Next set last_entry to NULL on malformed reply */ if (cfile->srch_inf.last_entry)
cifs_save_resume_key(cfile->srch_inf.last_entry, cfile);
}
search_flags = CIFS_SEARCH_CLOSE_AT_END | CIFS_SEARCH_RETURN_RESUME; if (backup_cred(cifs_sb))
search_flags |= CIFS_SEARCH_BACKUP_SEARCH;
while ((index_to_find >= cfile->srch_inf.index_of_last_entry) &&
(rc == 0) && !cfile->srch_inf.endOfSearch) {
cifs_dbg(FYI, "calling findnext2\n");
rc = server->ops->query_dir_next(xid, tcon, &cfile->fid,
search_flags,
&cfile->srch_inf); if (rc) return -ENOENT; /* FindFirst/Next set last_entry to NULL on malformed reply */ if (cfile->srch_inf.last_entry)
cifs_save_resume_key(cfile->srch_inf.last_entry, cfile);
} if (index_to_find < cfile->srch_inf.index_of_last_entry) { /* we found the buffer that contains the entry */ /* scan and find it */ int i; char *cur_ent; char *end_of_smb;
if (cfile->srch_inf.ntwrk_buf_start == NULL) {
cifs_dbg(VFS, "ntwrk_buf_start is NULL during readdir\n"); return -EIO;
}
for (i = 0; (i < (pos_in_buf)) && (cur_ent != NULL); i++) { /* go entry by entry figuring out which is first */
cur_ent = nxt_dir_entry(cur_ent, end_of_smb,
cfile->srch_inf.info_level);
} if ((cur_ent == NULL) && (i < pos_in_buf)) { /* BB fixme - check if we should flag this error */
cifs_dbg(VFS, "reached end of buf searching for pos in buf %d index to find %lld rc %d\n",
pos_in_buf, index_to_find, rc);
}
rc = 0;
*current_entry = cur_ent;
} else {
cifs_dbg(FYI, "index not in buffer - could not findnext into it\n"); return0;
}
/* Drop the cache while calling initiate_cifs_search and *find_cifs_entryincasetherewillbereconnectsduring *query_directory.
*/
close_cached_dir(cfid);
cfid = NULL;
/* 1) If search is active, isincurrentsearchbuffer? ifitbeforethenrestartsearch
if after then keep searching till find it */
cifsFile = file->private_data; if (cifsFile->srch_inf.endOfSearch) { if (cifsFile->srch_inf.emptyDir) {
cifs_dbg(FYI, "End of search, empty dir\n");
rc = 0; goto rddir2_exit;
}
} /* else { cifsFile->invalidHandle=true; tcon->ses->server->close(xid,tcon,&cifsFile->fid);
} */
for (i = 0; i < num_to_fill; i++) { if (current_entry == NULL) { /* evaluate whether this case is an error */
cifs_dbg(VFS, "past SMB end, num to fill %d i %d\n",
num_to_fill, i); break;
} /* *ifbuggyserverreturns.and..latedowewantto *checkforthathere?
*/
*tmp_buf = 0;
rc = cifs_filldir(current_entry, file, ctx,
tmp_buf, max_len, cfid); if (rc) { if (rc > 0)
rc = 0; break;
}
ctx->pos++; if (cfid) {
mutex_lock(&cfid->dirents.de_mutex);
update_cached_dirents_count(&cfid->dirents, file);
mutex_unlock(&cfid->dirents.de_mutex);
}
if (ctx->pos ==
cifsFile->srch_inf.index_of_last_entry) {
cifs_dbg(FYI, "last entry in buf at pos %lld %s\n",
ctx->pos, tmp_buf);
cifs_save_resume_key(current_entry, cifsFile); break;
}
current_entry =
nxt_dir_entry(current_entry, end_of_smb,
cifsFile->srch_inf.info_level);
}
kfree(tmp_buf);
rddir2_exit: if (cfid)
close_cached_dir(cfid);
free_dentry_path(page);
free_xid(xid); return rc;
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.17 Sekunden
(vorverarbeitet am 2026-09-30)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.