bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2006-2018 Dovecot authors, see the included COPYING file */
f3e1593a7d9b02090575fb20db90a235e10145a5Timo Sirainen# include <sys/statvfs.h> /* NetBSD 3.0+, FreeBSD 5.0+ */
b494ffed8ded8d170d9ace3dc607b1d278048241Timo Sirainen/* AIX doesn't have these defined */
26bedc1f8aace67ff8f19f625a403a097017845aTimo Sirainen/* Linux sometimes has mtab entry for "rootfs" as well as the real root
26bedc1f8aace67ff8f19f625a403a097017845aTimo Sirainen entry. Skip the rootfs. */
7c7d2244502af05f77c74736dc1aec0123fdba80Timo Sirainenmountpoint_get_statvfs(const char *path, pool_t pool,
b494ffed8ded8d170d9ace3dc607b1d278048241Timo Sirainen point_r->device_path = p_strdup(pool, buf.f_mntfromname);
b494ffed8ded8d170d9ace3dc607b1d278048241Timo Sirainen point_r->mount_path = p_strdup(pool, buf.f_mntonname);
aff1e150e13980354cfd794c74dac76a791a641eTimo Sirainen point_r->type = p_strdup(pool, getvfsbynumber(buf.f_type));
ad3a1b8f8e2a5596afb1b099a69ae6f688887eecTimo Sirainen point_r->type = p_strdup(pool, buf.f_fstypename);
7c7d2244502af05f77c74736dc1aec0123fdba80Timo Sirainenint mountpoint_get(const char *path, pool_t pool, struct mountpoint *point_r)
7c7d2244502af05f77c74736dc1aec0123fdba80Timo Sirainen /* BSDs, Tru64 */
7c7d2244502af05f77c74736dc1aec0123fdba80Timo Sirainen return mountpoint_get_statvfs(path, pool, point_r);
7c7d2244502af05f77c74736dc1aec0123fdba80Timo Sirainen /* find via mount iteration */
7c7d2244502af05f77c74736dc1aec0123fdba80Timo Sirainen while ((mnt = mountpoint_iter_next(iter)) != NULL) {
7c7d2244502af05f77c74736dc1aec0123fdba80Timo Sirainen point_r->device_path = p_strdup(pool, mnt->device_path);
7c7d2244502af05f77c74736dc1aec0123fdba80Timo Sirainen point_r->mount_path = p_strdup(pool, mnt->mount_path);
e34d170f8f0e084bd94bfbc1a7085ece67e508dfTimo Sirainen if (mountpoint_iter_deinit(&iter) < 0 && mnt == NULL)
7c7d2244502af05f77c74736dc1aec0123fdba80Timo Sirainen#elif defined(MOUNTPOINT_SOLARIS) || defined(MOUNTPOINT_LINUX)
7c7d2244502af05f77c74736dc1aec0123fdba80Timo Sirainenstruct mountpoint_iter *mountpoint_iter_init(void)
7c7d2244502af05f77c74736dc1aec0123fdba80Timo Sirainen struct mountpoint_iter *iter = i_new(struct mountpoint_iter, 1);
7c7d2244502af05f77c74736dc1aec0123fdba80Timo Sirainen while ((count = mntctl(MCTL_QUERY, size, mtab)) == 0) {
7c7d2244502af05f77c74736dc1aec0123fdba80Timo Sirainen i_error("setmntent(%s) failed: %m", MTAB_PATH);
7c7d2244502af05f77c74736dc1aec0123fdba80Timo Sirainen iter->count = getmntinfo(&iter->fs, MNT_NOWAIT);
7c7d2244502af05f77c74736dc1aec0123fdba80Timo Sirainenconst struct mountpoint *mountpoint_iter_next(struct mountpoint_iter *iter)
7c7d2244502af05f77c74736dc1aec0123fdba80Timo Sirainen vmt_hostname = vmt_base + vmt->vmt_data[VMT_HOSTNAME].vmt_off;
7c7d2244502af05f77c74736dc1aec0123fdba80Timo Sirainen vmt_object = vmt_base + vmt->vmt_data[VMT_OBJECT].vmt_off;
7c7d2244502af05f77c74736dc1aec0123fdba80Timo Sirainen vmt_stub = vmt_base + vmt->vmt_data[VMT_STUB].vmt_off;
7c7d2244502af05f77c74736dc1aec0123fdba80Timo Sirainen t_strconcat(vmt_hostname, ":", vmt_object, NULL);
7c7d2244502af05f77c74736dc1aec0123fdba80Timo Sirainen /* unwanted filesystem */
7c7d2244502af05f77c74736dc1aec0123fdba80Timo Sirainen while ((getextmntent(iter->f, &ent.ext, sizeof(ent.ext))) == 0) {
e02846284483d9d3c4b72835cd3dd6cc7f7e6740Timo Sirainen if (hasmntopt(&ent.ent, MNTOPT_IGNORE) != NULL)
e02846284483d9d3c4b72835cd3dd6cc7f7e6740Timo Sirainen /* mnt_type contains tmpfs with swap */
e02846284483d9d3c4b72835cd3dd6cc7f7e6740Timo Sirainen if (strcmp(ent.ent.mnt_special, MNTTYPE_SWAP) == 0)
7c7d2244502af05f77c74736dc1aec0123fdba80Timo Sirainen iter->mnt.dev = makedev(ent.ext.mnt_major, ent.ext.mnt_minor);
b494ffed8ded8d170d9ace3dc607b1d278048241Timo Sirainen if (strcmp(ent->mnt_type, MNTTYPE_SWAP) == 0 ||