mountpoint.c revision 26bedc1f8aace67ff8f19f625a403a097017845a
e59faf65ce864fe95dc00f5d52b8323cdbd0608aTimo Sirainen/* Copyright (c) 2006-2010 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. */
b494ffed8ded8d170d9ace3dc607b1d278048241Timo Sirainenint mountpoint_get(const char *path, pool_t pool, struct mountpoint *point_r)
f3e1593a7d9b02090575fb20db90a235e10145a5Timo Sirainen#elif defined (HAVE_STATFS_MNTFROMNAME) || defined(HAVE_STATVFS_MNTFROMNAME)
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);
b494ffed8ded8d170d9ace3dc607b1d278048241Timo Sirainen /* Linux, Solaris: /etc/mtab reading */
b494ffed8ded8d170d9ace3dc607b1d278048241Timo Sirainen const char *device_path = NULL, *mount_path = NULL, *type = NULL;
2978aafcf8c306adc2e012aed00546a63c677784Timo Sirainen char static_mtab[STATIC_MTAB_SIZE], *mtab = static_mtab;
2978aafcf8c306adc2e012aed00546a63c677784Timo Sirainen count = mntctl(MCTL_QUERY, sizeof(static_mtab), mtab);
2978aafcf8c306adc2e012aed00546a63c677784Timo Sirainen while (count == 0) {
2978aafcf8c306adc2e012aed00546a63c677784Timo Sirainen for (i = 0; i < count && device_path == NULL; i++) {
310ef47cf7b913dcae4f7e66e931648dd7435ebdTimo Sirainen const char *vmt_object, *vmt_stub, *vmt_hostname;
2978aafcf8c306adc2e012aed00546a63c677784Timo Sirainen vmt_hostname = vmt_base + vmt->vmt_data[VMT_HOSTNAME].vmt_off;
2978aafcf8c306adc2e012aed00546a63c677784Timo Sirainen vmt_object = vmt_base + vmt->vmt_data[VMT_OBJECT].vmt_off;
2978aafcf8c306adc2e012aed00546a63c677784Timo Sirainen vmt_stub = vmt_base + vmt->vmt_data[VMT_STUB].vmt_off;
b494ffed8ded8d170d9ace3dc607b1d278048241Timo Sirainen /* Solaris */
e02846284483d9d3c4b72835cd3dd6cc7f7e6740Timo Sirainen while ((getextmntent(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)
b494ffed8ded8d170d9ace3dc607b1d278048241Timo Sirainen i_error("setmntent(%s) failed: %m", MTAB_PATH);
b494ffed8ded8d170d9ace3dc607b1d278048241Timo Sirainen if (strcmp(ent->mnt_type, MNTTYPE_SWAP) == 0 ||
b494ffed8ded8d170d9ace3dc607b1d278048241Timo Sirainen point_r->device_path = p_strdup(pool, device_path);