Skip to content

Commit

Permalink
add codepage mount option
Browse files Browse the repository at this point in the history
  • Loading branch information
rd235 committed Jul 13, 2023
1 parent 31a7312 commit 33af3e8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion ffconf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 14 additions & 2 deletions fusefatfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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");
Expand All @@ -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 }
Expand All @@ -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'),
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 33af3e8

Please sign in to comment.