@TEST_IO_CMT@TEST_IO_LIB_OBJS = test_io.o
@IMAGER_CMT@E2IMAGE_LIB_OBJS = imager.o
+NLS_OBJS=nls_ascii.o
+NLS_SRCS=nls_ascii.c
+
DEBUG_OBJS= debug_cmds.o extent_cmds.o tst_cmds.o debugfs.o util.o \
ncheck.o icheck.o ls.o lsdel.o dump.o set_fields.o logdump.o \
htree.o unused.o e2freefrag.o filefrag.o extent_inode.o zap.o \
unlink.o \
valid_blk.o \
version.o \
- rbtree.o
+ rbtree.o \
+ $(NLS_OBJS)
SRCS= ext2_err.c \
$(srcdir)/alloc.c \
$(srcdir)/write_bb_file.c \
$(srcdir)/rbtree.c \
$(srcdir)/tst_libext2fs.c \
- $(DEBUG_SRCS)
+ $(DEBUG_SRCS) \
+ $(NLS_SRCS)
HFILES= bitops.h ext2fs.h ext2_io.h ext2_fs.h ext2_ext_attr.h ext3_extents.h \
tdb.h qcow2.h hashmap.h
$(top_srcdir)/lib/support/quotaio_tree.h $(srcdir)/kernel-jbd.h \
$(srcdir)/jfs_compat.h $(srcdir)/kernel-list.h \
$(top_srcdir)/debugfs/journal.h $(srcdir)/../../e2fsck/jfs_user.h
+$(NLS_OBJS): $(srcdir)/nls.h
--- /dev/null
+/*
+ * nls.h - Header for encoding support functions
+ *
+ * Copyright (C) 2017 Collabora Ltd.
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or (at
+ * your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef EXT2FS_NLS_H
+#define EXT2FS_NLS_H
+
+#include <unistd.h>
+#include <string.h>
+#include <stdio.h>
+
+#include "ext2_fs.h"
+
+struct nls_table;
+
+#define ARRAY_SIZE(array) \
+ (sizeof(array) / sizeof(array[0]))
+
+struct nls_ops {
+ int (*normalize)(const struct nls_table *charset,
+ const unsigned char *str, size_t len,
+ unsigned char *dest, size_t dlen);
+
+ int (*casefold)(const struct nls_table *charset,
+ const unsigned char *str, size_t len,
+ unsigned char *dest, size_t dlen);
+};
+
+struct nls_table {
+ int version;
+ const struct nls_ops *ops;
+};
+
+extern const struct nls_table nls_ascii;
+
+static const struct {
+ int encoding_magic;
+ const struct nls_table *tbl;
+} nls_map[] = {
+ { EXT4_ENC_ASCII, &nls_ascii },
+};
+
+static const struct nls_table *nls_load_table(int encoding)
+{
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(nls_map); i++) {
+ if (encoding == nls_map[i].encoding_magic)
+ return nls_map[i].tbl;
+ }
+ return NULL;
+}
+
+#endif
--- /dev/null
+#include "nls.h"
+
+#include <errno.h>
+#include <string.h>
+
+
+static unsigned char charset_tolower(const struct nls_table *table,
+ unsigned int c)
+{
+ if (c >= 'A' && c <= 'Z')
+ return (c | 0x20);
+ return c;
+}
+
+static unsigned char charset_toupper(const struct nls_table *table,
+ unsigned int c)
+{
+ if (c >= 'a' && c <= 'z')
+ return (c & ~0x20);
+ return c;
+}
+
+static int ascii_casefold(const struct nls_table *table,
+ const unsigned char *str, size_t len,
+ unsigned char *dest, size_t dlen)
+{
+ int i;
+
+ if (dlen < len)
+ return -ENAMETOOLONG;
+
+ for (i = 0; i < len; i++) {
+ if (str[i] & 0x80)
+ return -EINVAL;
+
+ dest[i] = charset_toupper(table, str[i]);
+ }
+
+ return len;
+}
+
+static int ascii_normalize(const struct nls_table *table,
+ const unsigned char *str, size_t len,
+ unsigned char *dest, size_t dlen)
+{
+ int i;
+
+ if (dlen < len)
+ return -ENAMETOOLONG;
+
+ for (i = 0; i < len; i++) {
+ if (str[i] & 0x80)
+ return -EINVAL;
+
+ dest[i] = str[i];
+ }
+
+ return len;
+}
+
+const static struct nls_ops ascii_ops = {
+ .casefold = ascii_casefold,
+ .normalize = ascii_normalize,
+};
+
+const struct nls_table nls_ascii = {
+ .ops = &ascii_ops,
+};