View | Details | Raw Unified | Return to bug 10658
Collapse All | Expand All

(-)fuse-2.6.1/include/fuse_common.h.charset (-1 / +1 lines)
Lines 158-164 Link Here
158
 * @return 0 on success, -1 on failure
158
 * @return 0 on success, -1 on failure
159
 */
159
 */
160
int fuse_parse_cmdline(struct fuse_args *args, char **mountpoint,
160
int fuse_parse_cmdline(struct fuse_args *args, char **mountpoint,
161
                       int *multithreaded, int *foreground);
161
                       int *multithreaded, int *foreground, char **charset);
162
162
163
163
164
int fuse_daemonize(int foreground);
164
int fuse_daemonize(int foreground);
(-)fuse-2.6.1/lib/fuse_i.h.charset (+6 lines)
Lines 34-36 Link Here
34
void fuse_kern_unmount_compat22(const char *mountpoint);
34
void fuse_kern_unmount_compat22(const char *mountpoint);
35
void fuse_kern_unmount(const char *mountpoint, int fd);
35
void fuse_kern_unmount(const char *mountpoint, int fd);
36
int fuse_kern_mount(const char *mountpoint, struct fuse_args *args);
36
int fuse_kern_mount(const char *mountpoint, struct fuse_args *args);
37
38
int fuse_iconv_open(const char *charset, int debug);
39
char *fuse_iconv_from(const char *input);
40
char *fuse_iconv_to(const char *input);
41
void fuse_iconv_close(void);
42
(-)fuse-2.6.1/lib/fuse.c.charset (-8 / +15 lines)
Lines 908-917 Link Here
908
    struct fuse_entry_param e;
908
    struct fuse_entry_param e;
909
    char *path;
909
    char *path;
910
    int err;
910
    int err;
911
    char *name2 = fuse_iconv_to(name);
911
912
912
    err = -ENOENT;
913
    err = -ENOENT;
913
    pthread_rwlock_rdlock(&f->tree_lock);
914
    pthread_rwlock_rdlock(&f->tree_lock);
914
    path = get_path_name(f, parent, name);
915
    path = get_path_name(f, parent, name2);
915
    if (path != NULL) {
916
    if (path != NULL) {
916
        if (f->conf.debug) {
917
        if (f->conf.debug) {
917
            printf("LOOKUP %s\n", path);
918
            printf("LOOKUP %s\n", path);
Lines 919-925 Link Here
919
        }
920
        }
920
        err = -ENOSYS;
921
        err = -ENOSYS;
921
        if (f->op.getattr) {
922
        if (f->op.getattr) {
922
            err = lookup_path(f, req, parent, name, path, &e, NULL);
923
            err = lookup_path(f, req, parent, name2, path, &e, NULL);
923
            if (err == -ENOENT && f->conf.negative_timeout != 0.0) {
924
            if (err == -ENOENT && f->conf.negative_timeout != 0.0) {
924
                e.ino = 0;
925
                e.ino = 0;
925
                e.entry_timeout = f->conf.negative_timeout;
926
                e.entry_timeout = f->conf.negative_timeout;
Lines 929-934 Link Here
929
        free(path);
930
        free(path);
930
    }
931
    }
931
    pthread_rwlock_unlock(&f->tree_lock);
932
    pthread_rwlock_unlock(&f->tree_lock);
933
    free(name2);
932
    reply_entry(req, &e, err);
934
    reply_entry(req, &e, err);
933
}
935
}
934
936
Lines 1796-1801 Link Here
1796
{
1798
{
1797
    struct stat stbuf;
1799
    struct stat stbuf;
1798
    size_t newlen;
1800
    size_t newlen;
1801
    char *name2 = fuse_iconv_from(name);
1799
1802
1800
    if (statp)
1803
    if (statp)
1801
        stbuf = *statp;
1804
        stbuf = *statp;
Lines 1818-1841 Link Here
1818
1821
1819
    if (off) {
1822
    if (off) {
1820
        if (extend_contents(dh, dh->needlen) == -1)
1823
        if (extend_contents(dh, dh->needlen) == -1)
1821
            return 1;
1824
            goto out_err;
1822
1825
1823
        dh->filled = 0;
1826
        dh->filled = 0;
1824
        newlen = dh->len + fuse_add_direntry(dh->req, dh->contents + dh->len,
1827
        newlen = dh->len + fuse_add_direntry(dh->req, dh->contents + dh->len,
1825
                                             dh->needlen - dh->len, name,
1828
                                             dh->needlen - dh->len, name2,
1826
                                             &stbuf, off);
1829
                                             &stbuf, off);
1827
        if (newlen > dh->needlen)
1830
        if (newlen > dh->needlen)
1828
            return 1;
1831
            goto out_err;
1829
    } else {
1832
    } else {
1830
        newlen = dh->len + fuse_add_direntry(dh->req, NULL, 0, name, NULL, 0);
1833
        newlen = dh->len + fuse_add_direntry(dh->req, NULL, 0, name2, NULL, 0);
1831
        if (extend_contents(dh, newlen) == -1)
1834
        if (extend_contents(dh, newlen) == -1)
1832
            return 1;
1835
            goto out_err;
1833
1836
1834
        fuse_add_direntry(dh->req, dh->contents + dh->len, dh->size - dh->len,
1837
        fuse_add_direntry(dh->req, dh->contents + dh->len, dh->size - dh->len,
1835
                          name, &stbuf, newlen);
1838
                          name2, &stbuf, newlen);
1836
    }
1839
    }
1837
    dh->len = newlen;
1840
    dh->len = newlen;
1841
    free(name2);
1838
    return 0;
1842
    return 0;
1843
out_err:
1844
    free(name2);
1845
    return 1;
1839
}
1846
}
1840
1847
1841
static int fill_dir(void *buf, const char *name, const struct stat *stbuf,
1848
static int fill_dir(void *buf, const char *name, const struct stat *stbuf,
(-)fuse-2.6.1/lib/Makefile.am.charset (+1 lines)
Lines 14-19 Link Here
14
libfuse_la_SOURCES = 		\
14
libfuse_la_SOURCES = 		\
15
	fuse.c			\
15
	fuse.c			\
16
	fuse_i.h		\
16
	fuse_i.h		\
17
	fuse_iconv.c		\
17
	fuse_kern_chan.c	\
18
	fuse_kern_chan.c	\
18
	fuse_loop.c		\
19
	fuse_loop.c		\
19
	fuse_loop_mt.c		\
20
	fuse_loop_mt.c		\
(-) (+100 lines)
Added Link Here
1
/*
2
 */
3
4
#include "fuse_i.h"
5
6
#include <stdio.h>
7
#include <string.h>
8
#include <locale.h>
9
#include <langinfo.h>
10
#include <iconv.h>
11
12
static iconv_t conv_ft = (iconv_t) -1;
13
static iconv_t conv_tf = (iconv_t) -1;
14
15
/* Local functions */
16
static char *name_conv(iconv_t cd, const char *input);
17
static const char *get_current_charmap(void);
18
19
/* ========================================================== */
20
static char *name_conv(iconv_t cd, const char *input) {
21
    size_t insize = strlen(input);
22
    size_t outsize = insize * 6;	/* enought for UTF-8 */
23
    char *output, *inptr, *outptr;
24
    size_t nconv;
25
26
    if (cd == (iconv_t) -1)
27
        return strdup(input);
28
29
    output = calloc(outsize + 1, sizeof(*output));
30
31
    outptr = output;
32
    inptr = (char *) input;
33
34
    nconv = iconv(cd, &inptr, &insize, &outptr, &outsize);
35
36
    if (nconv == (size_t) -1) {
37
        free(output);
38
        return strdup(input);
39
    }
40
41
    return output;
42
}
43
44
static const char *get_current_charmap(void)
45
{
46
    static int init = -1;
47
    static char *charmap = NULL;
48
49
    if (init == -1) {
50
       char *lc_ctype = setlocale (LC_CTYPE, "");
51
       charmap = nl_langinfo (CODESET);
52
       setlocale (LC_CTYPE, lc_ctype);
53
       init = 0;
54
    }
55
    return charmap;
56
}
57
58
/* ========================================================== */
59
int fuse_iconv_open(const char *charset, int debug)
60
{
61
    const char *lang = get_current_charmap();
62
63
    if (lang && charset && (strcasecmp(lang, charset) != 0)) {
64
	conv_ft = iconv_open(lang, charset);
65
	if (conv_ft != (iconv_t) -1) {
66
	    conv_tf = iconv_open(charset, lang);
67
	    if (conv_tf == (iconv_t) -1) {
68
		iconv_close(conv_ft);
69
		conv_ft = (iconv_t) -1;
70
	    	return -1;
71
	    } else {
72
		if (debug) {
73
		    printf("ICONV %s <-> %s\n", lang, charset);
74
		    fflush(stdout);
75
		}
76
	    }
77
	}
78
    }
79
    return 0;
80
}
81
82
char *fuse_iconv_from(const char *input)
83
{
84
    return name_conv(conv_ft, input);
85
}
86
87
char *fuse_iconv_to(const char *input)
88
{
89
    return name_conv(conv_tf, input);
90
}
91
92
void fuse_iconv_close(void)
93
{
94
    if (conv_ft != (iconv_t) -1)
95
	iconv_close(conv_ft);
96
97
    if (conv_tf != (iconv_t) -1)
98
	iconv_close(conv_tf);
99
}
100
(-)fuse-2.6.1/lib/helper.c.charset (-2 / +26 lines)
Lines 24-29 Link Here
24
    KEY_HELP,
24
    KEY_HELP,
25
    KEY_HELP_NOHEADER,
25
    KEY_HELP_NOHEADER,
26
    KEY_VERSION,
26
    KEY_VERSION,
27
    KEY_CHARSET,
27
};
28
};
28
29
29
struct helper_opts {
30
struct helper_opts {
Lines 31-36 Link Here
31
    int foreground;
32
    int foreground;
32
    int fsname;
33
    int fsname;
33
    char *mountpoint;
34
    char *mountpoint;
35
    char *charset;
34
};
36
};
35
37
36
#define FUSE_HELPER_OPT(t, p) { t, offsetof(struct helper_opts, p), 1 }
38
#define FUSE_HELPER_OPT(t, p) { t, offsetof(struct helper_opts, p), 1 }
Lines 41-46 Link Here
41
    FUSE_HELPER_OPT("-f",          foreground),
43
    FUSE_HELPER_OPT("-f",          foreground),
42
    FUSE_HELPER_OPT("-s",          singlethread),
44
    FUSE_HELPER_OPT("-s",          singlethread),
43
    FUSE_HELPER_OPT("fsname=",     fsname),
45
    FUSE_HELPER_OPT("fsname=",     fsname),
46
    FUSE_HELPER_OPT("charset=",    charset),
44
47
45
    FUSE_OPT_KEY("-h",          KEY_HELP),
48
    FUSE_OPT_KEY("-h",          KEY_HELP),
46
    FUSE_OPT_KEY("--help",      KEY_HELP),
49
    FUSE_OPT_KEY("--help",      KEY_HELP),
Lines 50-55 Link Here
50
    FUSE_OPT_KEY("-d",          FUSE_OPT_KEY_KEEP),
53
    FUSE_OPT_KEY("-d",          FUSE_OPT_KEY_KEEP),
51
    FUSE_OPT_KEY("debug",       FUSE_OPT_KEY_KEEP),
54
    FUSE_OPT_KEY("debug",       FUSE_OPT_KEY_KEEP),
52
    FUSE_OPT_KEY("fsname=",     FUSE_OPT_KEY_KEEP),
55
    FUSE_OPT_KEY("fsname=",     FUSE_OPT_KEY_KEEP),
56
    FUSE_OPT_KEY("charset=",    KEY_CHARSET),
53
    FUSE_OPT_END
57
    FUSE_OPT_END
54
};
58
};
55
59
Lines 72-77 Link Here
72
            "    -d   -o debug          enable debug output (implies -f)\n"
76
            "    -d   -o debug          enable debug output (implies -f)\n"
73
            "    -f                     foreground operation\n"
77
            "    -f                     foreground operation\n"
74
            "    -s                     disable multi-threaded operation\n"
78
            "    -s                     disable multi-threaded operation\n"
79
            "    -o charset=CHARSET     assume filename encoding\n"
75
            "\n"
80
            "\n"
76
            );
81
            );
77
}
82
}
Lines 99-104 Link Here
99
        helper_version();
104
        helper_version();
100
        return 1;
105
        return 1;
101
106
107
    case KEY_CHARSET: {
108
	    char *charset = strchr(arg, '=');
109
	    if (charset == NULL)
110
		charset = arg;
111
	    else
112
		charset++;
113
	    hopts->charset = strdup(charset);
114
	    return 0;
115
        }
116
102
    case FUSE_OPT_KEY_NONOPT:
117
    case FUSE_OPT_KEY_NONOPT:
103
        if (!hopts->mountpoint) {
118
        if (!hopts->mountpoint) {
104
            char mountpoint[PATH_MAX];
119
            char mountpoint[PATH_MAX];
Lines 139-145 Link Here
139
}
154
}
140
155
141
int fuse_parse_cmdline(struct fuse_args *args, char **mountpoint,
156
int fuse_parse_cmdline(struct fuse_args *args, char **mountpoint,
142
                       int *multithreaded, int *foreground)
157
                       int *multithreaded, int *foreground, char **charset)
143
{
158
{
144
    int res;
159
    int res;
145
    struct helper_opts hopts;
160
    struct helper_opts hopts;
Lines 159-164 Link Here
159
    else
174
    else
160
        free(hopts.mountpoint);
175
        free(hopts.mountpoint);
161
176
177
    if (charset)
178
        *charset = hopts.charset;
179
    else
180
        free(hopts.charset);
181
162
    if (multithreaded)
182
    if (multithreaded)
163
        *multithreaded = !hopts.singlethread;
183
        *multithreaded = !hopts.singlethread;
164
    if (foreground)
184
    if (foreground)
Lines 167-172 Link Here
167
187
168
 err:
188
 err:
169
    free(hopts.mountpoint);
189
    free(hopts.mountpoint);
190
    free(hopts.charset);
170
    return -1;
191
    return -1;
171
}
192
}
172
193
Lines 237-244 Link Here
237
    struct fuse *fuse;
258
    struct fuse *fuse;
238
    int foreground;
259
    int foreground;
239
    int res;
260
    int res;
261
    char *charset;
240
262
241
    res = fuse_parse_cmdline(&args, mountpoint, multithreaded, &foreground);
263
    res = fuse_parse_cmdline(&args, mountpoint, multithreaded, &foreground, &charset);
242
    if (res == -1)
264
    if (res == -1)
243
        return NULL;
265
        return NULL;
244
266
Lines 264-269 Link Here
264
    if (fd)
286
    if (fd)
265
        *fd = fuse_chan_fd(ch);
287
        *fd = fuse_chan_fd(ch);
266
288
289
    fuse_iconv_open(charset, foreground);
267
    return fuse;
290
    return fuse;
268
291
269
 err_unmount:
292
 err_unmount:
Lines 289-294 Link Here
289
    struct fuse_chan *ch = fuse_session_next_chan(se, NULL);
312
    struct fuse_chan *ch = fuse_session_next_chan(se, NULL);
290
    fuse_remove_signal_handlers(se);
313
    fuse_remove_signal_handlers(se);
291
    fuse_unmount_common(mountpoint, ch);
314
    fuse_unmount_common(mountpoint, ch);
315
    fuse_iconv_close();
292
    fuse_destroy(fuse);
316
    fuse_destroy(fuse);
293
    free(mountpoint);
317
    free(mountpoint);
294
}
318
}
(-)fuse-2.6.1/example/hello_ll.c.charset (-1 / +1 lines)
Lines 157-163 Link Here
157
    char *mountpoint;
157
    char *mountpoint;
158
    int err = -1;
158
    int err = -1;
159
159
160
    if (fuse_parse_cmdline(&args, &mountpoint, NULL, NULL) != -1 &&
160
    if (fuse_parse_cmdline(&args, &mountpoint, NULL, NULL, NULL) != -1 &&
161
        (ch = fuse_mount(mountpoint, &args)) != NULL) {
161
        (ch = fuse_mount(mountpoint, &args)) != NULL) {
162
        struct fuse_session *se;
162
        struct fuse_session *se;
163
163

Return to bug 10658