/* * If new entry was created in the parent, it could create the 8.3 alias (the * shortname of logname). So, the parent may have the negative-dentry which * matches the created 8.3 alias. * * If it happened, the negative dentry isn't actually negative anymore. So, * drop it.
*/ staticint exfat_d_revalidate(struct inode *dir, conststruct qstr *name, struct dentry *dentry, unsignedint flags)
{ if (flags & LOOKUP_RCU) return -ECHILD;
/* * This is not negative dentry. Always valid. * * Note, rename() to existing directory entry will have ->d_inode, and * will use existing name which isn't specified name by user. * * We may be able to drop this positive dentry here. But dropping * positive dentry isn't good idea. So it's unsupported like * rename("filename", "FILENAME") for now.
*/ if (d_really_is_positive(dentry)) return 1;
/* * Drop the negative dentry, in order to make sure to use the case * sensitive name which is specified by user if this is for creation.
*/ if (flags & (LOOKUP_CREATE | LOOKUP_RENAME_TARGET)) return 0;
/* returns the length of a struct qstr, ignoring trailing dots if necessary */ staticunsignedint exfat_striptail_len(unsignedint len, constchar *name, bool keep_last_dots)
{ if (!keep_last_dots) { while (len && name[len - 1] == '.')
len--;
} return len;
}
/* * Compute the hash for the exfat name corresponding to the dentry. If the name * is invalid, we leave the hash code unchanged so that the existing dentry can * be used. The exfat fs routines will return ENOENT or EINVAL as appropriate.
*/ staticint exfat_d_hash(conststruct dentry *dentry, struct qstr *qstr)
{ struct super_block *sb = dentry->d_sb; struct nls_table *t = EXFAT_SB(sb)->nls_io; constunsignedchar *name = qstr->name; unsignedint len = exfat_striptail_len(qstr->len, qstr->name,
EXFAT_SB(sb)->options.keep_last_dots); unsignedlong hash = init_name_hash(dentry); int i, charlen; wchar_t c;
for (i = 0; i < len; i += charlen) {
charlen = t->char2uni(&name[i], len - i, &c); if (charlen < 0) return charlen;
hash = partial_name_hash(exfat_toupper(sb, c), hash);
}
for (i = 0; i < len; i += charlen) {
charlen = t->char2uni(&name->name[i], alen - i, &c1); if (charlen < 0) return 1; if (charlen != t->char2uni(&str[i], blen - i, &c2)) return 1;
if (exfat_toupper(sb, c1) != exfat_toupper(sb, c2)) return 1;
}
for (i = 0; i < alen; i += charlen) {
charlen = utf8_to_utf32(&name->name[i], alen - i, &u_a); if (charlen < 0) return 1; if (charlen != utf8_to_utf32(&str[i], blen - i, &u_b)) return 1;
if (u_a <= 0xFFFF && u_b <= 0xFFFF) { if (exfat_toupper(sb, u_a) != exfat_toupper(sb, u_b)) return 1;
} else { if (u_a != u_b) return 1;
}
}
/* search EMPTY CONTINUOUS "num_entries" entries */ staticint exfat_search_empty_slot(struct super_block *sb, struct exfat_hint_femp *hint_femp, struct exfat_chain *p_dir, int num_entries, struct exfat_entry_set_cache *es)
{ int i, dentry, ret; int dentries_per_clu; struct exfat_chain clu; struct exfat_sb_info *sbi = EXFAT_SB(sb); int total_entries = EXFAT_CLU_TO_DEN(p_dir->size, sbi);
dentries_per_clu = sbi->dentries_per_clu;
if (hint_femp->eidx != EXFAT_HINT_NONE) {
dentry = hint_femp->eidx;
/* * If hint_femp->count is enough, it is needed to check if * there are actual empty entries. * Otherwise, and if "dentry + hint_famp->count" is also equal * to "p_dir->size * dentries_per_clu", it means ENOSPC.
*/ if (dentry + hint_femp->count == total_entries &&
num_entries > hint_femp->count) return -ENOSPC;
staticint exfat_check_max_dentries(struct inode *inode)
{ if (EXFAT_B_TO_DEN(i_size_read(inode)) >= MAX_EXFAT_DENTRIES) { /* * exFAT spec allows a dir to grow up to 8388608(256MB) * dentries
*/ return -ENOSPC;
} return 0;
}
/* * Find an empty directory entry set. * * If there isn't any empty slot, expand cluster chain. * * in: * inode: inode of the parent directory * num_entries: specifies how many dentries in the empty directory entry set * * out: * p_dir: the cluster where the empty directory entry set is located * es: The found empty directory entry set * * return: * the directory entry index in p_dir is returned on succeeds * -error code is returned on failure
*/ staticint exfat_find_empty_entry(struct inode *inode, struct exfat_chain *p_dir, int num_entries, struct exfat_entry_set_cache *es)
{ int dentry; unsignedint ret, last_clu;
loff_t size = 0; struct exfat_chain clu; struct super_block *sb = inode->i_sb; struct exfat_sb_info *sbi = EXFAT_SB(sb); struct exfat_inode_info *ei = EXFAT_I(inode); struct exfat_hint_femp hint_femp;
while ((dentry = exfat_search_empty_slot(sb, &hint_femp, p_dir,
num_entries, es)) < 0) { if (dentry != -ENOSPC) return dentry;
if (exfat_check_max_dentries(inode)) return -ENOSPC;
/* * Allocate new cluster to this directory
*/ if (ei->start_clu != EXFAT_EOF_CLUSTER) { /* we trust p_dir->size regardless of FAT type */ if (exfat_find_last_cluster(sb, p_dir, &last_clu)) return -EIO;
exfat_chain_set(&clu, last_clu + 1, 0, p_dir->flags);
} else { /* This directory is empty */
exfat_chain_set(&clu, EXFAT_EOF_CLUSTER, 0,
ALLOC_NO_FAT_CHAIN);
}
/* allocate a cluster */
ret = exfat_alloc_cluster(inode, 1, &clu, IS_DIRSYNC(inode)); if (ret) return ret;
if (exfat_zeroed_cluster(inode, clu.dir)) return -EIO;
/* append to the FAT chain */ if (clu.flags != p_dir->flags) { /* no-fat-chain bit is disabled, * so fat-chain should be synced with alloc-bitmap
*/
exfat_chain_cont_cluster(sb, p_dir->dir, p_dir->size);
p_dir->flags = ALLOC_FAT_CHAIN;
hint_femp.cur.flags = ALLOC_FAT_CHAIN;
}
if (clu.flags == ALLOC_FAT_CHAIN) if (exfat_ent_set(sb, last_clu, clu.dir)) return -EIO;
if (hint_femp.cur.dir == EXFAT_EOF_CLUSTER)
exfat_chain_set(&hint_femp.cur, clu.dir, 0, clu.flags);
/* * Name Resolution Functions : * Zero if it was successful; otherwise nonzero.
*/ staticint __exfat_resolve_path(struct inode *inode, constunsignedchar *path, struct exfat_uni_name *p_uniname, int lookup)
{ int namelen; int lossy = NLS_NAME_NO_LOSSY; struct super_block *sb = inode->i_sb; int pathlen = strlen(path);
/* * get the length of the pathname excluding * trailing periods, if any.
*/
namelen = exfat_striptail_len(pathlen, path, false); if (EXFAT_SB(sb)->options.keep_last_dots) { /* * Do not allow the creation of files with names * ending with period(s).
*/ if (!lookup && (namelen < pathlen)) return -EINVAL;
namelen = pathlen;
} if (!namelen) return -ENOENT; if (pathlen > (MAX_NAME_LENGTH * MAX_CHARSET_SIZE)) return -ENAMETOOLONG;
/* * strip all leading spaces : * "MS windows 7" supports leading spaces. * So we should skip this preprocessing for compatibility.
*/
/* file name conversion : * If lookup case, we allow bad-name for compatibility.
*/
namelen = exfat_nls_to_utf16(sb, path, namelen, p_uniname,
&lossy); if (namelen < 0) return namelen; /* return error value */
ret = exfat_resolve_path(inode, path, &uniname); if (ret) goto out;
num_entries = exfat_calc_num_entries(&uniname); if (num_entries < 0) {
ret = num_entries; goto out;
}
/* exfat_find_empty_entry must be called before alloc_cluster() */
dentry = exfat_find_empty_entry(inode, &info->dir, num_entries, &es); if (dentry < 0) {
ret = dentry; /* -EIO or -ENOSPC */ goto out;
}
if (type == TYPE_DIR && !sbi->options.zero_size_dir) {
ret = exfat_alloc_new_dir(inode, &clu); if (ret) {
exfat_put_dentry_set(&es, false); goto out;
}
start_clu = clu.dir;
clu_size = sbi->cluster_size;
}
/* update the directory entry */ /* fill the dos name directory entry information of the created file. * the first cluster is not determined yet. (0)
*/
exfat_init_dir_entry(&es, type, start_clu, clu_size, &ts);
exfat_init_ext_entry(&es, num_entries, &uniname);
ret = exfat_put_dentry_set(&es, IS_DIRSYNC(inode)); if (ret) goto out;
/* lookup a file */ staticint exfat_find(struct inode *dir, struct qstr *qname, struct exfat_dir_entry *info)
{ int ret, dentry, count; struct exfat_chain cdir; struct exfat_uni_name uni_name; struct super_block *sb = dir->i_sb; struct exfat_sb_info *sbi = EXFAT_SB(sb); struct exfat_inode_info *ei = EXFAT_I(dir); struct exfat_dentry *ep, *ep2; struct exfat_entry_set_cache es; /* for optimized dir & entry to prevent long traverse of cluster chain */ struct exfat_hint hint_opt;
if (qname->len == 0) return -ENOENT;
/* check the validity of directory name in the given pathname */
ret = exfat_resolve_path_for_lookup(dir, qname->name, &uni_name); if (ret) return ret;
/* check the validation of hint_stat and initialize it if required */ if (ei->version != (inode_peek_iversion_raw(dir) & 0xffffffff)) {
ei->hint_stat.clu = cdir.dir;
ei->hint_stat.eidx = 0;
ei->version = (inode_peek_iversion_raw(dir) & 0xffffffff);
ei->hint_femp.eidx = EXFAT_HINT_NONE;
}
/* search the file name for directories */
dentry = exfat_find_dir_entry(sb, ei, &cdir, &uni_name, &hint_opt); if (dentry < 0) return dentry; /* -error value */
/* adjust cdir to the optimized value */
cdir.dir = hint_opt.clu; if (cdir.flags & ALLOC_NO_FAT_CHAIN)
cdir.size -= dentry / sbi->dentries_per_clu;
dentry = hint_opt.eidx;
i_mode = inode->i_mode;
alias = d_find_alias(inode);
/* * Checking "alias->d_parent == dentry->d_parent" to make sure * FS is not corrupted (especially double linked dir).
*/ if (alias && alias->d_parent == dentry->d_parent &&
!exfat_d_anon_disconn(alias)) {
/* * Unhashed alias is able to exist because of revalidate() * called by lookup_fast. You can easily make this status * by calling create and lookup concurrently * In such case, we reuse an alias instead of new dentry
*/ if (d_unhashed(alias)) {
WARN_ON(alias->d_name.hash_len !=
dentry->d_name.hash_len);
exfat_info(sb, "rehashed a dentry(%p) in read lookup",
alias);
d_drop(dentry);
d_rehash(alias);
} elseif (!S_ISDIR(i_mode)) { /* * This inode has non anonymous-DCACHE_DISCONNECTED * dentry. This means, the user did ->lookup() by an * another name (longname vs 8.3 alias of it) in past. * * Switch to new one for reason of locality if possible.
*/
d_move(alias, dentry);
}
iput(inode);
mutex_unlock(&EXFAT_SB(sb)->s_lock); return alias;
}
dput(alias);
out:
mutex_unlock(&EXFAT_SB(sb)->s_lock); if (!inode)
exfat_d_version_set(dentry, inode_query_iversion(dir));
inode_inc_iversion(inode);
EXFAT_I(inode)->i_crtime = simple_inode_init_ts(inode);
exfat_truncate_inode_atime(inode); /* timestamp is already written, so mark_inode_dirty() is unneeded. */
while (clu.dir != EXFAT_EOF_CLUSTER) { for (i = 0; i < dentries_per_clu; i++) {
ep = exfat_get_dentry(sb, &clu, i, &bh); if (!ep) return -EIO;
type = exfat_get_entry_type(ep);
brelse(bh); if (type == TYPE_UNUSED) return 0;
if (type != TYPE_FILE && type != TYPE_DIR) continue;
return -ENOTEMPTY;
}
if (clu.flags == ALLOC_NO_FAT_CHAIN) { if (--clu.size > 0)
clu.dir++; else
clu.dir = EXFAT_EOF_CLUSTER;
} else { if (exfat_get_next_cluster(sb, &(clu.dir))) return -EIO;
/* break if the cluster chain includes a loop */ if (unlikely(++clu_count > EXFAT_DATA_CLUSTER_COUNT(sbi))) break;
}
}
ret = exfat_check_dir_empty(sb, &new_clu); if (ret) goto out;
}
}
/* check the validity of directory name in the given new pathname */
ret = exfat_resolve_path(new_parent_inode, new_path, &uni_name); if (ret) goto out;
exfat_set_volume_dirty(sb);
if (new_parent_inode == old_parent_inode)
ret = exfat_rename_file(new_parent_inode, &uni_name, ei); else
ret = exfat_move_file(new_parent_inode, &uni_name, ei);
if (!ret && new_inode) { struct exfat_entry_set_cache es;
/* delete entries of new_dir */
ret = exfat_get_dentry_set_by_ei(&es, sb, new_ei); if (ret) {
ret = -EIO; goto del_out;
}
ret = exfat_put_dentry_set(&es, IS_DIRSYNC(new_inode)); if (ret) goto del_out;
/* Free the clusters if new_inode is a dir(as if exfat_rmdir) */ if (S_ISDIR(new_inode->i_mode) &&
new_ei->start_clu != EXFAT_EOF_CLUSTER) { /* new_ei, new_clu_to_free */ struct exfat_chain new_clu_to_free;
/* * The VFS already checks for existence, so for local filesystems * the RENAME_NOREPLACE implementation is equivalent to plain rename. * Don't support any other flags
*/ if (flags & ~RENAME_NOREPLACE) return -EINVAL;
if (S_ISDIR(old_inode->i_mode) && old_dir != new_dir) {
drop_nlink(old_dir); if (!new_inode)
inc_nlink(new_dir);
}
inode_inc_iversion(old_dir); if (new_dir != old_dir)
mark_inode_dirty(old_dir);
if (new_inode) {
exfat_unhash_inode(new_inode);
/* skip drop_nlink if new_inode already has been dropped */ if (new_inode->i_nlink) {
drop_nlink(new_inode); if (S_ISDIR(new_inode->i_mode))
drop_nlink(new_inode);
} else {
exfat_warn(sb, "abnormal access to an inode dropped");
WARN_ON(new_inode->i_nlink == 0);
}
EXFAT_I(new_inode)->i_crtime = current_time(new_inode);
}
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.