/* nls_utf8.c */
extern const struct ext2fs_nls_table *ext2fs_load_nls_table(int encoding);
+extern int ext2fs_check_encoded_name(const struct ext2fs_nls_table *table,
+ char *s, size_t len, char **pos);
/* mkdir.c */
extern errcode_t ext2fs_mkdir(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t inum,
int (*casefold)(const struct ext2fs_nls_table *charset,
const unsigned char *str, size_t len,
unsigned char *dest, size_t dlen);
+ int (*validate)(const struct ext2fs_nls_table *table,
+ char *s, size_t len, char **pos);
};
/* Function prototypes */
return -EINVAL;
}
+static int utf8_validate(const struct ext2fs_nls_table *table,
+ char *s, size_t len, char **pos)
+{
+ const struct utf8data *data = utf8nfdicf(table->version);
+ utf8leaf_t *leaf;
+ unsigned char hangul[UTF8HANGULLEAF];
+
+ if (!data)
+ return -1;
+ while (len && *s) {
+ leaf = utf8nlookup(data, hangul, s, len);
+ if (!leaf) {
+ *pos = s;
+ return 1;
+ }
+ len -= utf8clen(s);
+ s += utf8clen(s);
+ }
+ return 0;
+}
+
static const struct ext2fs_nls_ops utf8_ops = {
.casefold = utf8_casefold,
+ .validate = utf8_validate,
};
static const struct ext2fs_nls_table nls_utf8 = {
return NULL;
}
+
+int ext2fs_check_encoded_name(const struct ext2fs_nls_table *table,
+ char *name, size_t len, char **pos)
+{
+ return table->ops->validate(table, name, len, pos);
+}