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.
Fast/Flexible Linux OS Recovery
On Demand Now
In this live one-hour webinar, learn how to enhance your existing backup strategies for complete disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible full-system recovery solution for UNIX and Linux systems.
Join Linux Journal's Shawn Powers and David Huffman, President/CEO, Storix, Inc.
Free to Linux Journal readers.Register Now!
- Google's Abacus Project: It's All about Trust
- Seeing Red and Getting Sleep
- Download "Linux Management with Red Hat Satellite: Measuring Business Impact and ROI"
- Secure Desktops with Qubes: Introduction
- Fancy Tricks for Changing Numeric Base
- Working with Command Arguments
- Secure Desktops with Qubes: Installation
- CentOS 6.8 Released
- The Italian Army Switches to LibreOffice
- Linux Mint 18
Until recently, IBM’s Power Platform was looked upon as being the system that hosted IBM’s flavor of UNIX and proprietary operating system called IBM i. These servers often are found in medium-size businesses running ERP, CRM and financials for on-premise customers. By enabling the Power platform to run the Linux OS, IBM now has positioned Power to be the platform of choice for those already running Linux that are facing scalability issues, especially customers looking at analytics, big data or cloud computing.
￼Running Linux on IBM’s Power hardware offers some obvious benefits, including improved processing speed and memory bandwidth, inherent security, and simpler deployment and management. But if you look beyond the impressive architecture, you’ll also find an open ecosystem that has given rise to a strong, innovative community, as well as an inventory of system and network management applications that really help leverage the benefits offered by running Linux on Power.Get the Guide