The World Is a libferris Filesystem
Listing 1. A Long Listing of a Directory with Explicit Metadata
$ fls -l \ --show-ea=size-human-readable,width,height,name 4.5k 48 46 emacs.png 1.9k 48 48 gnome-warning.png 3.2k 48 48 gnome-xterm.png 2.5k 48 48 gtkvim.png
Listing 2. Asking libferris itself to determine which EAs are of interest for the current directory and producing an XML document as output.
$ fls -0 --xml <ferrisls> <ferrisls url="file:///tmp/lj" name="lj" > <context size-human-readable="4.5k" protection-ls="-rw-r-----" mtime-display="05 Dec 4 23:39" name="emacs.png" width="48" height="46" /> ... </ferrisls> </ferrisls>
As mentioned previously, if you are sorting a directory on an EA that does not provide a complete ordering, you can chain together sorting predicates. For example, in Listing 3, I have sorted the output based on the numeric EA height and then used a version string sort on the name EA. A version sort is similar to the ls(1) -v option, which in Listing 3 has placed foo20.png after foo3.png. Such sorting is very useful when sorting by file type or MIME major type followed by name.
Listing 3. Sorting Your Output
$ fls --show-ea=width,height,size,name \ --ferris-sort='(:#:height)(:V:name)' 48 48 1968 gnome-warning.png 48 48 3253 gnome-xterm.png 48 48 2550 gtkvim.png 48 46 4589 emacs.png 48 46 4589 foo3.png 48 46 4589 foo20.png
The two concepts of files forming a tree and files having key-value pairs attached to them are similar to the structure of XML. With libferris, you can poke inside XML documents as though they were just another filesystem. For example, see Listing 4.
Listing 4. Initial Exploration of XML as a Filesystem
$ cat example.xml <root> <file1 size="200" /> <file2 interesting="yes" /> <file3>filesystems rock </file3> </root> $ fls -0 ./example.xml/root file1 file2 file3 $ fls -d --show-ea=name,interesting \ ./example.xml/root/file2 file2 yes $ fcat example.xml/root/file3 filesystems rock
By interacting with your filesystem, you can cause updates on the underlying XML document as well. The ferris-redirect client exists to allow shell-like redirection into libferris files. The -T or --trunc option truncates an existing file before writing stdin into it. This is much like the >| shell option. As you can see from the interaction in Listing 5, we have changed the structure of the example.xml document significantly through filesystem interaction.
Listing 5. Changing an XML File through Its Filesystem
$ echo "VIRTUAL filesystems rock more" | \ ferris-redirect -T ./example.xml/root/file3 $ echo "a new way" | \ ferris-redirect ./example.xml/root/file4 $ ferrisrm ./example.xml/root/file2 $ ftouch ./example.xml/root/touched $ cat example.xml <?xml version="1.0" encoding="UTF-8" standalone="no" ?> <root> <file1 size="200"/> <file3>VIRTUAL filesystems rock more </file3> <file4>a new way </file4> <touched/> </root>
As many modern word-processing documents are XML inside a compressed container, libferris allows you to drill down into the office document as though it were a filesystem. In Listing 6, I am listing a simple OpenOffice.org Writer document as a filesystem.
Listing 6. OpenOffice.org Documents Are Filesystems Too
$ fls -lh show-ea=size,name,content \ ~/sample-oo-writer.odt/content.xml/ \ office:document-content/office:body/office:text 0 office:forms 18 text:p Paragraph number 1 0 text:p-1 116 text:p-2 This is the second paragraph ... 0 text:p-3 39 text:p-4 And in summary, this is really... 0 text:p=5 0 text:sequence-decls
A Xerces-C Document Object Model (DOM) can be obtained for any libferris filesystem, just as a Xerces-C DOM can be mounted as a libferris filesystem. Creation of a DOM for a filesystem is evaluated lazily, so you can get a DOM for file:// and only the parts of the DOM that are required are ever created.
The ability to convert any libferris filesystem into a DOM allows you to apply XSLT to your filesystems easily. The example C++ code in Listing 7 applies a stylesheet to a mounted OpenOffice.org document.
|HPC Cluster Grant Accepting Applications!||Jan 28, 2015|
|Sharing Admin Privileges for Many Hosts Securely||Jan 28, 2015|
|Red Hat Enterprise Linux 7.1 beta available on IBM Power Platform||Jan 23, 2015|
|Designing with Linux||Jan 22, 2015|
|Wondershaper—QOS in a Pinch||Jan 21, 2015|
|Ideal Backups with zbackup||Jan 19, 2015|
- Sharing Admin Privileges for Many Hosts Securely
- HPC Cluster Grant Accepting Applications!
- Red Hat Enterprise Linux 7.1 beta available on IBM Power Platform
- Internet of Things Blows Away CES, and it May Be Hunting for YOU Next
- Designing with Linux
- Ideal Backups with zbackup
- Wondershaper—QOS in a Pinch
- Slow System? iotop Is Your Friend
- diff -u: What's New in Kernel Development
- Hats Off to Mozilla
Editorial Advisory Panel
Thank you to our 2014 Editorial Advisors!
- Jeff Parent
- Brad Baillio
- Nick Baronian
- Steve Case
- Chadalavada Kalyana
- Caleb Cullen
- Keir Davis
- Michael Eager
- Nick Faltys
- Dennis Frey
- Philip Jacob
- Jay Kruizenga
- Steve Marquez
- Dave McAllister
- Craig Oda
- Mike Roberts
- Chris Stark
- Patrick Swartz
- David Lynch
- Alicia Gibb
- Thomas Quinlan
- Carson McDonald
- Kristen Shoemaker
- Charnell Luchich
- James Walker
- Victor Gregorio
- Hari Boukis
- Brian Conner
- David Lane