mountpoint.c revision 2978aafcf8c306adc2e012aed00546a63c677784
5f5870385cff47efd2f58e7892f251cf13761528Timo Sirainen/* Copyright (c) 2006-2008 Dovecot authors, see the included COPYING file */
f6d57a2c182f63cd52819f0abb3c3d9f828afe19Timo Sirainen# include <sys/statvfs.h> /* NetBSD 3.0+, FreeBSD 5.0+ */
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen/* AIX doesn't have these defined */
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainenint mountpoint_get(const char *path, pool_t pool, struct mountpoint *point_r)
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen#elif defined (HAVE_STATFS_MNTFROMNAME) || defined(HAVE_STATVFS_MNTFROMNAME)
cbc61fcb33b370d049c16a3c44568b4deb4e2b33Timo Sirainen point_r->device_path = p_strdup(pool, buf.f_mntfromname);
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen point_r->mount_path = p_strdup(pool, buf.f_mntonname);
cd83124e5d070a016c590bb0b1096d7828c7b6adTimo Sirainen point_r->type = p_strdup(pool, getvfsbynumber(buf.f_type));
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen point_r->type = p_strdup(pool, buf.f_fstypename);
cbc61fcb33b370d049c16a3c44568b4deb4e2b33Timo Sirainen /* Linux, Solaris: /etc/mtab reading */
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen const char *device_path = NULL, *mount_path = NULL, *type = NULL;
bbd4c4cf902539c25c471157eb9849459734759cTimo Sirainen char static_mtab[STATIC_MTAB_SIZE], *mtab = static_mtab;
bbd4c4cf902539c25c471157eb9849459734759cTimo Sirainen count = mntctl(MCTL_QUERY, sizeof(static_mtab), mtab);
bbd4c4cf902539c25c471157eb9849459734759cTimo Sirainen while (count == 0) {
d66be2bebfa96e7d3d20e2153f60e6e25dcc9a18Timo Sirainen for (i = 0; i < count && device_path == NULL; i++) {
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen const char *vmt_base, *vmt_object, *vmt_stub, *vmt_hostname;
f6d57a2c182f63cd52819f0abb3c3d9f828afe19Timo Sirainen vmt_hostname = vmt_base + vmt->vmt_data[VMT_HOSTNAME].vmt_off;
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen vmt_object = vmt_base + vmt->vmt_data[VMT_OBJECT].vmt_off;
73b50eecfc31750a312e2f940023f522eb07178cTimo Sirainen vmt_stub = vmt_base + vmt->vmt_data[VMT_STUB].vmt_off;
eddd9bf1a1369aea4a2715f6be1137da6d17d293Timo Sirainen /* Solaris */
3e7565a7b39694bcdf448d8eb2a7f0774733297bTimo Sirainen while ((getextmntent(f, &ent.ext, sizeof(ent.ext))) == 0) {
3e7565a7b39694bcdf448d8eb2a7f0774733297bTimo Sirainen if (hasmntopt(&ent.ent, MNTOPT_IGNORE) != NULL)
3e7565a7b39694bcdf448d8eb2a7f0774733297bTimo Sirainen /* mnt_type contains tmpfs with swap */
3e7565a7b39694bcdf448d8eb2a7f0774733297bTimo Sirainen if (strcmp(ent.ent.mnt_special, MNTTYPE_SWAP) == 0)
2e263a9d901483a902720a30c474761bd3324fe8Timo Sirainen i_error("setmntent(%s) failed: %m", MTAB_PATH);
eddd9bf1a1369aea4a2715f6be1137da6d17d293Timo Sirainen if (strcmp(ent->mnt_type, MNTTYPE_SWAP) == 0 ||
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen point_r->device_path = p_strdup(pool, device_path);