+static int print_instance(const char *mntdir, char *fsname, size_t fsnamelen,
+ bool opt_instance, bool opt_fsname, bool opt_mntdir)
+{
+ char *buf = fsname;
+
+ /* llapi_search_mounts() fills "fsname", but that is not called if
+ * explicit paths are specified on the command-line
+ */
+ if (opt_instance || (opt_fsname && fsname[0] == '\0')) {
+ int rc = llapi_getname(mntdir, fsname, fsnamelen);
+
+ if (rc < 0) {
+ fprintf(stderr, "cannot get instance for '%s': %s\n",
+ mntdir, strerror(-rc));
+ return rc;
+ }
+ buf = fsname;
+ if (!opt_instance) {
+ /* print only the fsname name */
+ buf = strchr(fsname, '-');
+ if (buf)
+ *buf = '\0';
+ buf = fsname;
+ } else if (!opt_fsname) {
+ /* print only the instance name */
+ buf = strchr(fsname, '-');
+ if (buf)
+ buf++;
+ else
+ buf = fsname;
+ }
+ } else if (opt_fsname) {
+ /* print only the fsname */
+ buf = fsname;
+ }
+
+ printf("%s %s\n", buf, opt_mntdir ? mntdir : "");
+
+ return 0;
+}
+