Home Home > 2009 > 07 > 20 > Introducing Libstorage
Sign up | Login

Deprecation notice: openSUSE Lizards user blog platform is deprecated, and will remain read only for the time being. Learn more...

Introducing Libstorage

July 20th, 2009 by

Libstorage is a C++ library for managing Linux storage devices. So far it was developed as part of YaST but since a few weeks it is an independent project.

Here is a code example creating a 1GB partition on /dev/sdb.

  Environment env(false);
  StorageInterface* s = createStorageInterface(env);

  string name;

  // Create 1GB partition on /dev/sdb and format it with Ext4.
  s->createPartitionAny("/dev/sdb", 1048576, name);
  s->changeFormatVolume(name, true, EXT4);

  // Set mount-point to "/home" and fstab option to "relatime".
  s->changeMountPoint(name, "/home");
  s->changeFstabOptions(name, "relatime");

  // Set filesystem label to "HOME" and mount filesystem by label.
  s->changeLabelVolume(name, "HOME");
  s->changeMountBy(name, MOUNTBY_LABEL);

  // Commit the change to the system. This will create the partition,
  // format and mount it and update /etc/fstab.
  s->commit();

  destroyStorageInterface(s);

Besides of hard-disks libstorage handles RAID, LVM, NFS, various filesystems and encryption. Swig generated Python bindings are also provided. Libstorage has no dependencies on YaST, neither for building nor runtime. We hope libstorage will also be useful for other projects.

More information is available in the openSUSE Wiki, including a list of useful features people would love to see implemented in the near future.

Comments are as always welcome.

Both comments and pings are currently closed.

5 Responses to “Introducing Libstorage”

  1. How could you discover what values you could set as the various parameters?
    Are there methods to quiz the interface about partitions, their size, file-systems, etc.
    In fact, are you not just calling a series of methods like they were procedures? Could I swap the order of some of the method calls and not change the result?

  2. Sorry, you can scrub some of my previous comment.
    I was thinking that you would model the partition with a C++ object, get/set various attributes and then commit. Perhaps like:

    Partition *p = new Partition();
    p->device = “/dev/sdb”;
    p->size = “1GB”; or = 1073741824;
    FileSystem *f = New FileSystemExt4(); or = New FileSystem(“Ext4”);
    p->fileSystem = f;

    p->mountBy = “Label”;
    s->Add(p); or s <commit();