linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Gabriel Krisman Bertazi <krisman@collabora.co.uk>
To: viro@ZenIV.linux.org.uk
Cc: linux-fsdevel@vger.kernel.org,
	Gabriel Krisman Bertazi <krisman@collabora.co.uk>
Subject: [PATCH NOMERGE 12/13] ext4: Implement ext4 dcache hooks for custom charsets
Date: Tue, 22 May 2018 17:38:17 -0300	[thread overview]
Message-ID: <20180522203818.14666-13-krisman@collabora.co.uk> (raw)
In-Reply-To: <20180522203818.14666-1-krisman@collabora.co.uk>

Changes from RFC v1:
  - Handle errors from charset_normalize/casefold (Olaf Weber)
  - Send length of both strings to comparison functions.
  - Cast length type to size_t

Signed-off-by: Gabriel Krisman Bertazi <krisman@collabora.co.uk>
---
 fs/ext4/dir.c   | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 fs/ext4/ext4.h  |  2 ++
 fs/ext4/super.c |  2 ++
 3 files changed, 52 insertions(+)

diff --git a/fs/ext4/dir.c b/fs/ext4/dir.c
index da87cf757f7d..02911f2681ab 100644
--- a/fs/ext4/dir.c
+++ b/fs/ext4/dir.c
@@ -26,6 +26,7 @@
 #include <linux/buffer_head.h>
 #include <linux/slab.h>
 #include <linux/iversion.h>
+#include <linux/nls.h>
 #include "ext4.h"
 #include "xattr.h"
 
@@ -662,3 +663,50 @@ const struct file_operations ext4_dir_operations = {
 	.open		= ext4_dir_open,
 	.release	= ext4_release_dir,
 };
+
+static int ext4_d_compare(const struct dentry *dentry, unsigned int len,
+			  const char *str, const struct qstr *name)
+{
+	struct nls_table *charset = EXT4_SB(dentry->d_sb)->encoding;
+	size_t nlen = strlen(name->name);
+
+	return nls_strncmp(charset, str, len, name->name, nlen);
+}
+
+static int ext4_d_compare_ci(const struct dentry *dentry, unsigned int len,
+			     const char *str, const struct qstr *name)
+{
+	struct nls_table *charset = EXT4_SB(dentry->d_sb)->encoding;
+	size_t nlen = strlen(name->name);
+
+	return nls_strncasecmp(charset, str, len, name->name, nlen);
+}
+
+static int ext4_d_ci_hash(const struct dentry *dentry, struct qstr *q)
+{
+	unsigned long hash;
+	int i, len;
+	unsigned char *folded = NULL;
+	const struct nls_table *charset = EXT4_SB(dentry->d_sb)->encoding;
+
+	len = nls_casefold(charset, q->name, q->len, &folded);
+
+	if (len < 0) {
+		kfree(folded);
+		return -EINVAL;
+	}
+
+	hash = init_name_hash(dentry);
+	for (i = 0; i < len; i++)
+		hash = partial_name_hash(folded[i], hash);
+	q->hash = end_name_hash(hash);
+
+	kfree(folded);
+	return 0;
+}
+
+const struct dentry_operations ext4_dentry_ops = {
+	.d_hash = ext4_d_ci_hash,
+	.d_compare = ext4_d_compare,
+	.d_compare_ci = ext4_d_compare_ci,
+};
diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index ebda06e4cb24..eb193d66565a 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -2939,6 +2939,8 @@ static inline void ext4_unlock_group(struct super_block *sb,
 
 /* dir.c */
 extern const struct file_operations ext4_dir_operations;
+extern const struct dentry_operations ext4_dentry_ops;
+extern const struct dentry_operations ext4_ci_dentry_ops;
 
 /* file.c */
 extern const struct inode_operations ext4_file_inode_operations;
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index bbf0a5c4104b..e73976986dcb 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -4241,6 +4241,8 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
 		iput(root);
 		goto failed_mount4;
 	}
+
+	sb->s_d_op = &ext4_dentry_ops;
 	sb->s_root = d_make_root(root);
 	if (!sb->s_root) {
 		ext4_msg(sb, KERN_ERR, "get root dentry failed");
-- 
2.17.0

  parent reply	other threads:[~2018-05-22 20:38 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-22 20:38 [PATCH NOMERGE 00/13] Case insensitiveness as a mountpoint Gabriel Krisman Bertazi
2018-05-22 20:38 ` [PATCH NOMERGE 01/13] vfs: Add support for mounting with MS_CASEFOLD Gabriel Krisman Bertazi
2018-05-22 20:38 ` [PATCH NOMERGE 02/13] vfs: Propagate LOOKUP_CASEFOLD after doing parent lookups Gabriel Krisman Bertazi
2018-05-22 20:38 ` [PATCH NOMERGE 03/13] vfs: Add support for positive dentries CI lookups in the dentry cache Gabriel Krisman Bertazi
2018-05-22 20:38 ` [PATCH NOMERGE 04/13] vfs: Allow bind,remount with MS_CASEFOLD Gabriel Krisman Bertazi
2018-05-22 20:38 ` [PATCH NOMERGE 05/13] vfs: Handle case-exact lookup in d_add_ci Gabriel Krisman Bertazi
2018-05-22 20:38 ` [PATCH NOMERGE 06/13] vfs: Add Support for hard negative dentries in the dcache Gabriel Krisman Bertazi
2018-05-22 20:38 ` [PATCH NOMERGE 07/13] vfs: Handle MNT_CASEFOLD in /proc/mounts Gabriel Krisman Bertazi
2018-05-22 20:38 ` [PATCH NOMERGE 08/13] fscrypt: Introduce charset-based matching functions Gabriel Krisman Bertazi
2018-05-22 20:38 ` [PATCH NOMERGE 09/13] ext4: Include encoding information on the superblock Gabriel Krisman Bertazi
2018-05-22 20:38 ` [PATCH NOMERGE 10/13] ext4: Plumb LOOK_CASEFOLD up to ext4 comparison functions Gabriel Krisman Bertazi
2018-05-22 20:38 ` [PATCH NOMERGE 11/13] ext4: Support charset name matching Gabriel Krisman Bertazi
2018-05-22 20:38 ` Gabriel Krisman Bertazi [this message]
2018-05-22 20:38 ` [PATCH NOMERGE 13/13] ext4: Notify VFS of support for casefolded mountpoints Gabriel Krisman Bertazi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180522203818.14666-13-krisman@collabora.co.uk \
    --to=krisman@collabora.co.uk \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=viro@ZenIV.linux.org.uk \
    --subject='Re: [PATCH NOMERGE 12/13] ext4: Implement ext4 dcache hooks for custom charsets' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).