]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfsprogs: libxcmd: allow 0 as a wildcard fs_table entry type selector
authorAlex Elder <aelder@sgi.com>
Wed, 28 Sep 2011 11:44:33 +0000 (11:44 +0000)
committerAlex Elder <aelder@sgi.com>
Thu, 29 Sep 2011 14:33:27 +0000 (09:33 -0500)
In libxcmd a table is used to represent filesystems and directories
that could be subject to quota operations.  A cursor mechanism is
used to search that table, and it includes a flag that indicates
whether the type of entry desired represents a directory (for project
quotas) or a mount point (otherwise).  It also allows a search for
either type.

There is only call to fs_cursor_initialise() where both mount points
and project paths are requested--all others just requested one or
the other.

Change it so when searching fs_table (in fs_table_lookup() and
fs_cursor_next_entry()), a zero "flags" value is interpreted as a
wildcard, matching either type of entry.

Also add some commentary explaining the use of 0 as a wildcard, and
simplify fs_cursor_next_entry() a bit in the process.

Signed-off-by: Alex Elder <aelder@sgi.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
libxcmd/paths.c

index f4110d47842ec54adfb3ce6bc8597a5359e8c2d6..1e78099a7704f7d556f261f576715a9f58e985d0 100644 (file)
@@ -76,7 +76,7 @@ fs_table_lookup(
                return NULL;
 
        for (i = 0; i < fs_count; i++) {
-               if ((flags & fs_table[i].fs_flags) == 0)
+               if (flags && !(flags & fs_table[i].fs_flags))
                        continue;
                if (fs_table[i].fs_datadev == dev)
                        return &fs_table[i];
@@ -432,6 +432,16 @@ fs_table_insert_project_path(
  * Table iteration (cursor-based) interfaces
  */
 
+/*
+ * Initialize an fs_table cursor.  If a directory path is supplied,
+ * the cursor is set up to appear as though the table contains only
+ * a single entry which represents the directory specified.
+ * Otherwise it is set up to prepare for visiting all entries in the
+ * global table, starting with the first.  "flags" can be either
+ * FS_MOUNT_POINT or FS_PROJECT_PATH to limit what type of entries
+ * will be selected by fs_cursor_next_entry().  0 can be used as a
+ * wild card (selecting either type).
+ */
 void
 fs_cursor_initialise(
        char            *dir,
@@ -454,17 +464,19 @@ fs_cursor_initialise(
        cur->flags = flags;
 }
 
+/*
+ * Use the cursor to find the next entry in the table having the
+ * type specified by the cursor's "flags" field.
+ */
 struct fs_path *
 fs_cursor_next_entry(
        fs_cursor_t     *cur)
 {
-       fs_path_t       *next = NULL;
-
        while (cur->index < cur->count) {
-               next = &cur->table[cur->index++];
-               if (cur->flags & next->fs_flags)
-                       break;
-               next = NULL;
+               fs_path_t       *next = &cur->table[cur->index++];
+
+               if (!cur->flags || (cur->flags & next->fs_flags))
+                       return next;
        }
-       return next;
+       return NULL;
 }