Server clinic: Make the Virtual File System work

Source: Internet
Author: User
Article Title: Server clinic: Make the virtual file system work. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
A Virtual File System (VFS) is an abstract concept with extremely efficient usage. Several popular languages now support VFS constructor. Cameron Laird shows you what these constructor applies.
  
"If you don't try it yourself, you won't understand how useful it is ". When someone says this to me, I always say that people who say this do not know enough about the features, so they cannot make it clear.
  
However, for a virtual file system, it is right to tell me what to say. Jeffrey Hobbs is a high developer of ActiveState Corp. And we both see how incredibly powerful it is to use virtual file systems (VFS.
  
   Simple ideas and major achievements
The idea behind VFS is simple: it expresses things that are not a file system as a file system. The file system here refers to the "traditional Linux-like file system": a tree or hierarchy consisting of directly accessible directories and (common) files. Of course, this concept will interest all Linux users, because many features of Linux are derived from the representation of devices, tables, and other objects in UNIX file systems. UNIX is built on the following principle: Everything (or at least many) is a file; VFS promotes this principle and regards as many as possible as a file system.
  
Note: Linux kernel engineers also talked about VFS, but it has different meanings. This month's column is not about the Linux Virtual File System switch, which distributes the file system driver to ext2, ext3, and reiserfs.
  
One view of VFS is that it is another example of a technology or concept, in the words of independent developer Jean-clude Wippler, this technology "blur the boundaries between the OS and the advanced language environment ". In addition, the emergence of "system services" in application development languages makes portability easier, because the operating system disappears from the field of view.
  
Which of the following is NOT a file system, but it is very useful in this way? There are many such problems: FTP, HTTP, WebDAV, or other network protocols, such as. ZIP files, CVS (concurrent version control system, concurrent versions system), and other archive file contents; database tables; project of a real file system restricted by security or other constraints; and others.
  
It is easy to see that such resources can be mapped to the file system in a natural way. Suppose example.zip compresses the following files:
  
First
Subdir1/second
Subdir1/third
Subdir2/fourth
This archive file is likely to be created as a direct (partial) image of the existing file system tree, so it can naturally be represented by a root tree:
  
./First
./Subdir1/second
./Subdir1/third
./Subdir2/fourth
Many influential products in the industry depend on VFS. The architecture of DB2 functional components such as the log recording file system relies on the VFS model. The well-known Zope application server provides a challenging VFS example. Zope's "obtain (acquisition)" Concept maps procedural objects to URLs. In Zope, a method call is similar to the following:
  
Context. myproject. object1.method1 (year = "1999 ")
It is equivalent to an HTTP request for the following URL:
  
Http://myzope.com/myproject/object1/method1? Year = 1999
Do you see the advantages? The concept of "Everything is a file" in VFS is similar to that in UNIX because it is easy to understand and imitate, but you need to be aware of the extent to which it can simplify the application design, it may take several years.
  
Let's look at an example. Assume that you have compiled a text editor that provides methods to access, read, modify, and write individual files back to storage. If you use the File System "Virtual Machine", you can immediately use all the same code to browse FTP or ZIP archive files, select, modify, and save individual items. Do you have a browser, backup utility, security scanner, or version control system that works well when operating local files? Virtualize access to its file system. It can immediately operate on. tar files, vintage tape disks, and company resources that can only be accessed through a virtual private network (VPN. Suppliers like to sell such accessories for thousands of US dollars. VFS provides such a function for free.
  
Or this is almost free. Programmers do not need to learn any new knowledge; they only need to perform the same open, close and other file system operations as before. The key is that all the code is the same as before. The biggest difficulty is that few Language Runtime Libraries currently support mature VFS. One of the common difficulties is that drivers are usually read-only, either because the write function requires more complex programming, or because no write operation is defined in a protocol similar to HTTP.
  
   Which language has the VFS function?
The best supported language for VFS is Tcl, And Hobbs of ActiveState is good at this language. In other languages (including Java and Perl), the existing VFS implementations are "not pure" because they provide new methods (such as Perl's vfsopen) in implementations) to supplement the core library entry point. In contrast, in Tcl release 8.4, as described on the VFS community page: "Tcl file systems fully support virtual file systems ". This means that virtual file resources can be used according to syntax rules wherever common files are identified. Typical Tcl permits:
  
Image create-file myimage.gif
Tcl 8.4 naturally expands this usage:
  
Image create-file ftp://myserver.com/myimage.gif
Independent consultant Matt Newman first implemented a robust VFS for Tcl at the end of 1990s to help him develop for a large financial enterprise. By the end of 2000, Eurobios scientist Vince Darley was ambitious to rewrite Tcl's file system application programming interface (API). One of the advantages was the provision of VFS hooks ).
  
Most active Tcl application developers first apply VFS in the preceding example-for example, flexible FTP-supported editor. However, it is worth noting that Tcl's VFS pioneers (including Wippler, as mentioned in the previous "Server clinic" column about application deployment, see references.) The original intention is to develop "thorough" VFS. That is to say, instead of using VFS technology to access existing external resources, we need to manage a special-purpose database (inside the application) as a complete file system. They have used this mechanism to significantly simplify application development and deployment. From this perspective, VFS can be used to unify and integrate different operating environments-development, quality assurance, and customer sites, so that applications can operate in all operating environments. Transparently promote the file system to external files, which is only a benefit. Listing 1 shows two sample code taken from the Tcl community page, which implies the power of this included benefit.
  
Listing 1. Using VFS in Tcl
  
Package require vfs: urltype
Vfs: urltype: Mount ftp
# With VFS activated, normal Tcl file commands
# Can copy files even to and from FTP servers.
File copy ftp://foo.bar.com/pub/Readme.
File copy myfile ftp: // user: password@foo.bar.com/private.txt
  
  
Package require vfs: zip
Vfs: zip: Mount foo.zip
# Foo.zip is now part of the normal filesystem hierarchy.
Cd foo.zip
# Within subdir1 on foo.zip, list all items.
Set listing [glob-dir subdir1 *]
  
Most languages have tools for accessing FTP or ZIP. In this sense, VFS is similar to an object-oriented high-level language or Runtime Library: it does not provide any new content, and you can program it to do anything VFS can do. However, with VFS, resource management becomes easier and more reasonable. It is not a very difficult concept; it is just a good concept.
  
VFS simplifies many interesting questions. Tcl programmers are currently dealing with problems similar to the following:
  
Version-based centralized compressed archive files that can be dynamically loaded into the database
Intelligent Network Agent
Advanced hybrid media backup Manager
I have tested the programmability of "active system files. They can be seen as "Features" supported by some languages ". The feature is that its access will include the attributes of the side effects of write operations:
  
Result = thing. property
It may not just retrieve the value of "property" from the memory, but may involve such calculation: transferring data on the network, checking the system status, and so on. Similarly, when I write:
  
File copy reportaskbackup
This is not just to copy files to directories, but to generate files based on the environment and perform other operations.
  
Feature-oriented programming is considered dangerous because of its many side effects. Basically, operations that cannot be completed using explicit access methods cannot be completed. However, this style is still suitable for some situations, and I find that the active file system is at least sometimes easier to code than the makefile and script they replace.
  
   Conclusion
Tcl takes precedence over other languages in terms of VFS maturity. It has solved the difficulties in character encoding, I/O architecture and performance constraints, these challenges have just begun to emerge in other language communities. However, you do not have to use Tcl to apply the idea of VFS. Can your own programming benefit from a more consistent way of using class file resources? Most modern languages provide some method to extend the built-in structure, so I/O can be encoded in a more consistent and powerful way.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.