summaryrefslogtreecommitdiffstats
path: root/libmount/src/tab_parse.c
diff options
context:
space:
mode:
authorMasatake YAMATO2012-01-19 05:28:41 +0100
committerKarel Zak2012-01-23 13:53:40 +0100
commit9deeef8e47bf204298f346a54011c491b2480b0a (patch)
tree7d687d3c96d97b1e14e5fc8d7980192d92de52f5 /libmount/src/tab_parse.c
parentlibmount: scandirat based mnt_table_parse_dir implementation (diff)
downloadkernel-qcow2-util-linux-9deeef8e47bf204298f346a54011c491b2480b0a.tar.gz
kernel-qcow2-util-linux-9deeef8e47bf204298f346a54011c491b2480b0a.tar.xz
kernel-qcow2-util-linux-9deeef8e47bf204298f346a54011c491b2480b0a.zip
libmount: Use filter arg of scandir* to pickup /etc/fstab.d/*.fstab files
This patch is based on my last patch: [PATCH 1/2] scandirat based mnt_table_parse_dir implementation scandir* used in `mnt_table_parse_dir in libmount/src/tab_parse.c can take filter function as an argument. `mnt_table_parse_dir' picks up fstab files from namelist returned from scandir* for itself. However, some parts of picking-up job can be done in the filter function. This patch introduces a new function `mnt_table_parse_dir_filter' to share the code for picking-up job between two implementations of `mnt_table_parse_dir_filter', scandir based and scandirat based. Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Diffstat (limited to 'libmount/src/tab_parse.c')
-rw-r--r--libmount/src/tab_parse.c63
1 files changed, 27 insertions, 36 deletions
diff --git a/libmount/src/tab_parse.c b/libmount/src/tab_parse.c
index 1b0324ef4..bbdea553c 100644
--- a/libmount/src/tab_parse.c
+++ b/libmount/src/tab_parse.c
@@ -435,6 +435,30 @@ int mnt_table_parse_file(struct libmnt_table *tb, const char *filename)
return rc;
}
+static int mnt_table_parse_dir_filter(const struct dirent *d)
+{
+ size_t namesz;
+
+#ifdef _DIRENT_HAVE_D_TYPE
+ if (d->d_type != DT_UNKNOWN && d->d_type != DT_REG &&
+ d->d_type != DT_LNK)
+ return 0;
+#endif
+ if (*d->d_name == '.')
+ return 0;
+
+#define MNT_MNTTABDIR_EXTSIZ (sizeof(MNT_MNTTABDIR_EXT) - 1)
+
+ namesz = strlen(d->d_name);
+ if (!namesz || namesz < MNT_MNTTABDIR_EXTSIZ + 1 ||
+ strcmp(d->d_name + (namesz - MNT_MNTTABDIR_EXTSIZ),
+ MNT_MNTTABDIR_EXT))
+ return 0;
+
+ /* Accept this */
+ return 1;
+}
+
#ifdef HAVE_SCANDIRAT
static int mnt_table_parse_dir(struct libmnt_table *tb, const char *dirname)
{
@@ -445,7 +469,8 @@ static int mnt_table_parse_dir(struct libmnt_table *tb, const char *dirname)
dd = open(dirname, O_RDONLY|O_CLOEXEC|O_DIRECTORY);
if (dd < 0)
return -errno;
- n = scandirat(dd, ".", &namelist, NULL, versionsort);
+
+ n = scandirat(dd, ".", &namelist, mnt_table_parse_dir_filter, versionsort);
if (n <= 0) {
close(dd);
return 0;
@@ -454,25 +479,8 @@ static int mnt_table_parse_dir(struct libmnt_table *tb, const char *dirname)
for (i = 0; i < n; i++) {
struct dirent *d = namelist[i];
struct stat st;
- size_t namesz;
FILE *f;
-#ifdef _DIRENT_HAVE_D_TYPE
- if (d->d_type != DT_UNKNOWN && d->d_type != DT_REG &&
- d->d_type != DT_LNK)
- continue;
-#endif
- if (*d->d_name == '.')
- continue;
-
-#define MNT_MNTTABDIR_EXTSIZ (sizeof(MNT_MNTTABDIR_EXT) - 1)
-
- namesz = strlen(d->d_name);
- if (!namesz || namesz < MNT_MNTTABDIR_EXTSIZ + 1 ||
- strcmp(d->d_name + (namesz - MNT_MNTTABDIR_EXTSIZ),
- MNT_MNTTABDIR_EXT))
- continue;
-
if (fstat_at(dd, ".", d->d_name, &st, 0) ||
!S_ISREG(st.st_mode))
continue;
@@ -497,7 +505,7 @@ static int mnt_table_parse_dir(struct libmnt_table *tb, const char *dirname)
DIR *dir = NULL;
struct dirent **namelist = NULL;
- n = scandir(dirname, &namelist, NULL, versionsort);
+ n = scandir(dirname, &namelist, mnt_table_parse_dir_filter, versionsort);
if (n <= 0)
return 0;
@@ -509,25 +517,8 @@ static int mnt_table_parse_dir(struct libmnt_table *tb, const char *dirname)
for (i = 0; i < n; i++) {
struct dirent *d = namelist[i];
struct stat st;
- size_t namesz;
FILE *f;
-#ifdef _DIRENT_HAVE_D_TYPE
- if (d->d_type != DT_UNKNOWN && d->d_type != DT_REG &&
- d->d_type != DT_LNK)
- continue;
-#endif
- if (*d->d_name == '.')
- continue;
-
-#define MNT_MNTTABDIR_EXTSIZ (sizeof(MNT_MNTTABDIR_EXT) - 1)
-
- namesz = strlen(d->d_name);
- if (!namesz || namesz < MNT_MNTTABDIR_EXTSIZ + 1 ||
- strcmp(d->d_name + (namesz - MNT_MNTTABDIR_EXTSIZ),
- MNT_MNTTABDIR_EXT))
- continue;
-
if (fstat_at(dirfd(dir), _PATH_MNTTAB_DIR, d->d_name, &st, 0) ||
!S_ISREG(st.st_mode))
continue;