GIO OverviewIntroduction
GIO is striving to provide a modern, easy-to-use VFS API that sits
at the right level in the library stack. The goal is to overcome the
shortcomings of GnomeVFS and provide an API that is so good that
developers prefer it over raw POSIX calls. Among other things
that means using GObject. It also means not cloning the POSIX
API, but providing higher-level, document-centric interfaces.
The abstract file system model of GIO consists of a number of
interfaces and base classes for I/O and files:
GFilereference to a fileGFileInfoinformation about a file or filesystemGFileEnumeratorlist files in directoriesGDriverepresents a driveGVolumerepresents a file system in an abstract wayGMountrepresents a mounted file system
Then there is a number of stream classes, similar to the input and
output stream hierarchies that can be found in frameworks like Java:
GInputStreamread dataGOutputStreamwrite dataGSeekableinterface optionally implemented by streams to support seeking
There are interfaces related to applications and the types
of files they handle:
GAppInfoinformation about an installed applicationGIconabstract type for file and application icons
Beyond these, GIO provides facilities for file monitoring,
asynchronous I/O and filename completion. In addition to the
interfaces, GIO provides implementations for the local case.
Implementations for various network file systems are provided
by the GVFS package as loadable modules.
Other design choices which consciously break with the GnomeVFS
design are to move backends out-of-process, which minimizes the
dependency bloat and makes the whole system more robust. The backends
are not included in GIO, but in the separate GVFS package. The GVFS
package also contains the GVFS daemon, which spawn further mount
daemons for each individual connection.
The GIO model of I/O is stateful: if an application establishes e.g.
a SFTP connection to a server, it becomes available to all applications
in the session; the user does not have to enter his password over
and over again.
One of the big advantages of putting the VFS in the GLib layer
is that GTK+ can directly use it, e.g. in the filechooser.
Compiling GIO applications
GIO comes with a gio-2.0.pc file that you
should use together with pkg-config to obtain
the necessary information about header files and libraries. See
the pkg-config man page or the GLib documentation
for more information on how to use pkg-config
to compile your application.
If you are using GIO on UNIX-like systems, you may want to use
UNIX-specific GIO interfaces such as #GUnixInputStream,
#GUnixOutputStream, #GUnixMount or #GDesktopAppInfo.
To do so, use the gio-unix-2.0.pc file
instead of gio-2.0.pcRunning GIO applications
GIO inspects a few of environment variables in addition to the
ones used by GLib.
XDG_DATA_HOME, XDG_DATA_DIRS
GIO uses these environment variables to locate MIME information.
For more information, see the Shared MIME-info Database
and the Base Directory Specification.
The following environment variables are only useful for debugging
GIO itself or modules that it loads. They should not be set in a
production environment.
GIO_USE_VFS
This environment variable can be set to the name of a #GVfs
implementation to override the default for debugging purposes.
The #GVfs implementation for local files that is included in GIO
has the name "local", the implementation in the gvfs module has
the name "gvfs".
GIO_USE_VOLUME_MONITOR
This variable can be set to the name of a #GVolumeMonitor
implementation to override the default for debugging purposes.
The #GVolumeMonitor implementation for local files that is included
in GIO has the name "unix", the hal-based implementation in the
gvfs module has the name "hal".
GVFS_INOTIFY_DIAG
When this environment variable is set and GIO has been built
with inotify support, a dump of diagnostic inotify information
will be written every 20 seconds to a file named
/tmp/gvfsdid.pid.