From 33af3e8f993f0bd2e864fae1261d767eade5d8c8 Mon Sep 17 00:00:00 2001 From: Renzo Davoli Date: Thu, 13 Jul 2023 14:33:32 +0200 Subject: [PATCH] add codepage mount option --- ffconf.h | 2 +- fusefatfs.c | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/ffconf.h b/ffconf.h index 459ab9a..ad19fe2 100644 --- a/ffconf.h +++ b/ffconf.h @@ -133,7 +133,7 @@ / ff_memfree() exemplified in ffsystem.c, need to be added to the project. */ -#define FF_LFN_UNICODE 0 +#define FF_LFN_UNICODE 2 /* This option switches the character encoding on the API when LFN is enabled. / / 0: ANSI/OEM in current CP (TCHAR = char) diff --git a/fusefatfs.c b/fusefatfs.c index debdf35..decda9b 100644 --- a/fusefatfs.c +++ b/fusefatfs.c @@ -33,6 +33,8 @@ int fuse_reentrant_tag = 0; +#define FAT_DEFAULT_CODEPAGE 850 + static pthread_mutex_t fff_mutex = PTHREAD_MUTEX_INITIALIZER; #define mutex_in() pthread_mutex_lock(&fff_mutex) #define mutex_out() pthread_mutex_unlock(&fff_mutex) @@ -398,7 +400,7 @@ static int fff_statfs(const char *path, struct statvfs *buf) { mutex_out_return(fr2errno(fres)); } -static struct fftab *fff_init(const char *source, int flags) { +static struct fftab *fff_init(const char *source, int codepage, int flags) { int index = fftab_new(source, flags); if (index >= 0) { struct fftab *ffentry = fftab_get(index); @@ -409,6 +411,13 @@ static struct fftab *fff_init(const char *source, int flags) { fftab_del(index); return NULL; } + if (codepage != 0) { + if (f_setcp(codepage) != FR_OK) { + fprintf(stderr, "codepage %d unavailable\n", codepage); + f_setcp(FAT_DEFAULT_CODEPAGE); + } + } else + f_setcp(FAT_DEFAULT_CODEPAGE); return ffentry; } else return NULL; @@ -455,6 +464,7 @@ static void usage(void) " -o rw+ enable write support\n" " -o rw enable write support only together with -force\n" " -o force enable write support only together with -rw\n" + " -o codepage=XXX set codepage (default 850)\n" "\n" " this software is still experimental\n" "\n"); @@ -467,6 +477,7 @@ struct options { int rw; int rwplus; int force; + int codepage; }; #define FFF_OPT(t, p, v) { t, offsetof(struct options, p), v } @@ -477,6 +488,7 @@ static struct fuse_opt fff_opts[] = FFF_OPT("rw", rw, 1), FFF_OPT("rw+", rwplus, 1), FFF_OPT("force", force, 1), + FFF_OPT("codepage=%u", codepage, 1), FUSE_OPT_KEY("-V", 'V'), FUSE_OPT_KEY("--version", 'V'), @@ -558,7 +570,7 @@ int main(int argc, char *argv[]) } if (options.ro) flags |= FFFF_RDONLY; - if ((ffentry = fff_init(options.source, flags)) == NULL) { + if ((ffentry = fff_init(options.source, options.codepage, flags)) == NULL) { fprintf(stderr, "Fuse init error\n"); goto returnerr; }