// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (C) 2012-2013 Samsung Electronics Co., Ltd.
*/
#include <linux/iversion.h>
#include <linux/namei.h>
#include <linux/slab.h>
#include <linux/buffer_head.h>
#include <linux/nls.h>
#include "exfat_raw.h"
#include "exfat_fs.h"
static inline unsigned long exfat_d_version(struct dentry *dentry)
{
return (unsigned long) dentry->d_fsdata;
}
static inline void exfat_d_version_set(struct dentry *dentry,
unsigned long version)
{
dentry->d_fsdata = (void *) version;
}
/*
* 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.
*/
static int exfat_d_revalidate(struct dentry *dentry, unsigned int flags)
{
int ret;
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;
spin_lock(&dentry->d_lock);
ret = inode_eq_iversion(d_inode(dentry->d_parent),
exfat_d_version(dentry));
spin_unlock(&dentry->d_lock);
return ret;
}
/* returns the length of a struct qstr, ignoring trailing dots */
static unsigned int exfat_striptail_len(unsigned int len, const char *name)
{
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 appropri