/** * mnt_table_parse_fstab: * @tb: table * @filename: overwrites default (/etc/fstab or $LIBMOUNT_FSTAB) or NULL * * This function parses /etc/fstab and appends new lines to the @tab. If the * @filename is a directory then mnt_table_parse_dir() is called. * * See also mnt_table_set_parser_errcb(). * * Returns: 0 on success or negative number in case of error. */ int mnt_table_parse_fstab(struct libmnt_table *tb, const char *filename) { struct stat st; int rc = 0; assert(tb); if (!tb) return -EINVAL; if (!filename) filename = mnt_get_fstab_path(); if (!filename || stat(filename, &st)) return -EINVAL; tb->fmt = MNT_FMT_FSTAB; if (S_ISREG(st.st_mode)) rc = mnt_table_parse_file(tb, filename); else if (S_ISDIR(st.st_mode)) rc = mnt_table_parse_dir(tb, filename); else rc = -EINVAL; return rc; }
/** * mnt_table_parse_fstab: * @tb: table * @filename: overwrites default (/etc/fstab or $LIBMOUNT_FSTAB) or NULL * * This function parses /etc/fstab or /etc/fstab.d and appends new lines to the * @tab. If the system contains classic fstab file and also fstab.d directory * then the fstab file is parsed before the fstab.d directory. * * The fstab.d directory: * - files are sorted by strverscmp(3) * - files that starts with "." are ignored (e.g. ".10foo.fstab") * - files without the ".fstab" extension are ignored * * See also mnt_table_set_parser_errcb(). * * Returns: 0 on success or negative number in case of error. */ int mnt_table_parse_fstab(struct libmnt_table *tb, const char *filename) { FILE *f; assert(tb); if (!tb) return -EINVAL; if (!filename) filename = mnt_get_fstab_path(); tb->fmt = MNT_FMT_FSTAB; f = fopen(filename, "r"); if (f) { int rc = mnt_table_parse_stream(tb, f, filename); fclose(f); if (rc) return rc; if (strcmp(filename, _PATH_MNTTAB)) /* /etc/fstab.d sould be used together with /etc/fstab only */ return 0; } if (!access(_PATH_MNTTAB_DIR, R_OK)) return mnt_table_parse_dir(tb, _PATH_MNTTAB_DIR); return 0; }