歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux綜合 >> Linux資訊 >> Linux文化

用用戶態文件系統(FUSE)解決假設ftp服務器時的編碼問題


在假設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(如果沒有先添加這個用戶組):

CODE:[Copy to clipboard]#addgroup --system fuse #cat /etc/udev/rules.d/40-fuse.rules 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添加:

CODE:[Copy to clipboard]# cat /etc/fuse.conf user_allow_other 5、然後就編譯安裝fuse-convmv(附件有)。 6、假設/home/ftp/pub中的所有文件名都是UTF-8編碼的,現在新建一個/home/ftp/pub_gbk文件夾,並且將這個文件夾的屬組設置為fuser。現在執行下列命令:

CODE:[Copy to clipboard]# su fuser -c '/usr/local/bin/convmvfs -o srcdir=/home/ftp/pub,icharset=utf8,ocharset=gbk,allow_other /home/ftp/pub_gbk' srcdir=/home/ftp/pub/ icharset=utf8 ocharset=gbk 成功後,訪問ftp服務器,就會有pub和pub_gbk兩個文件夾,其中pub是UTF-8編碼的文件,pub_gbk是轉換後的gbk編碼文件名。

目前只支持讀文件/讀目錄等操作,還不支持寫入。歡迎大家與我一同交流。

Copyright © Linux教程網 All Rights Reserved