免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2064 | 回复: 1
打印 上一主题 下一主题

[FTP] 用用户态文件系统(FUSE)解决假设ftp服务器时的编码问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-04-27 17:40 |只看该作者 |倒序浏览
在假设ftp服务器时最讨厌的就是编码问题,在windows环境下,中文都是GB*的,而在Linux下UTF-8则使用的越来越广泛,为了解决这个矛盾,我写了个fuse-convmv用户态文件系统,现已经支持只读类的操作。
下面是软件的README文件:

Abstract
========


This is a filesystem client use the FUSE(Filesystem in
USErspace) interface to convert file name from one charset
to another.


Motivation
==========


Convmv(http://osx.freshmeat.net/projects/convmv/)is a
utility to converts filenames (not file content),
directories, and even whole filesystems to a different
encoding. Inspired by this tool, born was the convmvfs which
mirror a whole filesystem tree from one charset to another.

For example, in China there's a National Standard called
GB2312 which defined a charset to present most of the
Chinese character. And many ftp client used in China only
accept and show filename in GB2312. But in *nix world i18n
is more acceptable than l10n so many *nix server use UTF-8.
For example, there's a linux hosted box run a ftp server app
on it. The ftp server export /ftp/pub to anonymous access in
which all filenames are in UTF-8 charset. Now we can make a
directory called /ftp/pub_gb2312 and use our convmvfs tool to
mount a special fuse filesystem on /ftp/pub_gb2312, which
hotly convert the filename in /ftp/pub from UTF-8 to GB2312
but leave the contant unchanged.


Install
=======


First you need to download FUSE 2.5 or later from:

http://fuse.sourceforge.net

After installing FUSE, compile convmvfs the usual way:

./configure
make
make install (as root)

And you are ready to go.

If checking out from CVS for the first time also do
'autoreconf -iv' before doing './configure'.


How to use
==========


Once convmvfs is installed running it is very simple:

usage: convmvfs mountpoint [options]

general options:
-o opt,[opt...] mount options
-h --help print help
-V --version print version

FUSE options:
-d -o debug enable debug output (implies -f)
-f foreground operation
-s disable multi-threaded operation

-o allow_other allow access to other users
-o allow_root allow access to root
-o nonempty allow mounts over non-empty file/dir
-o default_permissions enable permission checking by kernel
-o fsname=NAME set filesystem name
-o large_read issue large read requests (2.4 only)
-o max_read=N set maximum size of read requests

-o hard_remove immediate removal (don't hide files)
-o use_ino let filesystem set inode numbers
-o readdir_ino try to fill in d_ino in readdir
-o direct_io use direct I/O
-o kernel_cache cache files in kernel
-o umask=M set file permissions (octal)
-o uid=N set file owner
-o gid=N set file group
-o entry_timeout=T cache timeout for names (1.0s)
-o negative_timeout=T cache timeout for deleted names (0.0s)
-o attr_timeout=T cache timeout for attributes (1.0s)

CONVMVFS options:
-o srcdir=PATH which directory to convert
-o icharset=CHARSET charset used in srcdir
-o ocharset=CHARSET charset used in mounted filesystem

Note:
* If you use normal user to mount file system be sure to have
r/w permision to /dev/fuse.

* use iconv --list to see which charsets are supported.

* to allow other user to access the mount point use allow_other option

Sample use:

* to mount
$convmvfs /ftp/pub_gbk -o srcdir=/ftp/pub, \
icharset=utf8,ocharset=gbk

* to umount
$fusermount -u /ftp/pub_gbk

___________________________________

举个应用例子,我在我的一个服务器上(debian sarge)配置有vsftp服务器。
1、首先安装Fuse>=2.5——不能使用debian sarge自带的,因为版本太老了。
2、编译安装后记住要设置每次开机都加载fuse内核模块,在debian下是修改/etc/modules文件。然后配置udev,让/dev/fuse文件的用户组为fuse(如果没有先添加这个用户组):

  1. #addgroup --system fuse
  2. #cat /etc/udev/rules.d/40-fuse.rules
  3. KERNEL="fuse", NAME="%k", MODE="0660",OWNER="root" GROUP="fuse"
复制代码

3、添加用户fuser属于组fuse
#adduser --ingroup fuse --disabled-password --no-create-home --system --shell /bin/sh fuser
4、修改/etc/fuse.conf添加:

  1. # cat /etc/fuse.conf
  2. user_allow_other
复制代码

5、然后就编译安装fuse-convmv(附件有)。
6、假设/home/ftp/pub中的所有文件名都是UTF-8编码的,现在新建一个/home/ftp/pub_gbk文件夹,并且将这个文件夹的属组设置为fuser。现在执行下列命令:

  1. # su fuser -c '/usr/local/bin/convmvfs -o srcdir=/home/ftp/pub,icharset=utf8,ocharset=gbk,allow_other /home/ftp/pub_gbk'
  2. srcdir=/home/ftp/pub/
  3. icharset=utf8
  4. ocharset=gbk
复制代码


成功后,访问ftp服务器,就会有pub和pub_gbk两个文件夹,其中pub是UTF-8编码的文件,pub_gbk是转换后的gbk编码文件名。

目前只支持读文件/读目录等操作,还不支持写入。欢迎大家与我一同交流。


P.S:0.1版本见附件

fuse-convmvfs-0.1.tar.gz

78.29 KB, 下载次数: 141

论坛徽章:
0
2 [报告]
发表于 2014-10-16 16:09 |只看该作者
convmvfs 镜像以后,编码格式的确转换了,但是目录的context也变成了fusefs_t,而且不能修改,ftp客户端根本无法访问这个目录呀???
chcon  -t public_content_t /var/ftp/wenyk/
convmvfs /var/ftp/wenyk/ -o srcdir=/home/wenyk,icharset=UTF8,ocharset=gbk,nonempty

ls -Z /var/ftp/  
drwxr-xr-x. root  root  system_ubject_r:public_content_t:s0 pub
drwx------. wenyk wenyk system_ubject_r:fusefs_t:s0    wenyk
ftp://wenyk:wenyk@172.17.15.102

cannot change directory:/var/ftp/wenyk
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP