mountpoint.c revision 5a580c3a38ced62d4bcc95b8ac7c4f2935b5d294
/* Copyright (c) 2006-2013 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "mountpoint.h"
#ifdef HAVE_SYS_VMOUNT_H
# include <stdio.h>
# define MOUNTPOINT_AIX_MNTCTL
#elif defined(HAVE_STATVFS_MNTFROMNAME)
# define STATVFS_STR "statvfs"
# define MOUNTPOINT_STATVFS
#elif defined(HAVE_STATFS_MNTFROMNAME)
# define STATVFS_STR "statfs"
# define MOUNTPOINT_STATVFS
#elif defined(HAVE_MNTENT_H)
# include <stdio.h>
# include <mntent.h> /* Linux */
# define MOUNTPOINT_LINUX
#elif defined(HAVE_SYS_MNTTAB_H)
# include <stdio.h>
# define MOUNTPOINT_SOLARIS
#else
# define MOUNTPOINT_UNKNOWN
#endif
#ifdef MOUNTPOINT_SOLARIS
#else
#endif
/* AIX doesn't have these defined */
#ifndef MNTTYPE_SWAP
# define MNTTYPE_SWAP "swap"
#endif
#ifndef MNTTYPE_IGNORE
# define MNTTYPE_IGNORE "ignore"
#endif
#ifndef MNTTYPE_JFS
# define MNTTYPE_JFS "jfs"
#endif
#ifndef MNTTYPE_NFS
# define MNTTYPE_NFS "nfs"
#endif
/* Linux sometimes has mtab entry for "rootfs" as well as the real root
entry. Skip the rootfs. */
#ifndef MNTTYPE_ROOTFS
# define MNTTYPE_ROOTFS "rootfs"
#endif
#ifdef MOUNTPOINT_STATVFS
static int
struct mountpoint *point_r)
{
return 0;
return -1;
}
#ifdef __osf__ /* Tru64 */
#else
#endif
return 1;
}
#endif
{
#ifdef MOUNTPOINT_UNKNOWN
return -1;
#elif defined (MOUNTPOINT_STATVFS)
/* BSDs, Tru64 */
#else
/* find via mount iteration */
struct mountpoint_iter *iter;
const struct mountpoint *mnt;
return 0;
return -1;
}
iter = mountpoint_iter_init();
break;
}
}
return -1;
#endif
}
struct mountpoint_iter {
#ifdef MOUNTPOINT_AIX_MNTCTL
char *mtab;
int count;
FILE *f;
int count;
#endif
struct mountpoint mnt;
bool failed;
};
struct mountpoint_iter *mountpoint_iter_init(void)
{
#ifdef MOUNTPOINT_AIX_MNTCTL
unsigned int size = STATIC_MTAB_SIZE;
char *mtab;
int count;
}
if (count < 0) {
i_error("mntctl(MCTL_QUERY) failed: %m");
return iter;
}
#elif defined(MOUNTPOINT_SOLARIS)
return iter;
}
resetmnttab(iter->f);
#elif defined(MOUNTPOINT_LINUX)
}
i_error("getmntinfo() failed: %m");
}
#else
#endif
return iter;
}
{
#ifdef MOUNTPOINT_AIX_MNTCTL
return NULL;
switch (vmt->vmt_gfstype) {
case MNT_NFS:
case MNT_NFS3:
case MNT_NFS4:
case MNT_RFS4:
break;
case MNT_J2:
case MNT_JFS:
break;
default:
/* unwanted filesystem */
return mountpoint_iter_next(iter);
}
}
#elif defined (MOUNTPOINT_SOLARIS)
union {
} ent;
return NULL;
continue;
/* mnt_type contains tmpfs with swap */
continue;
}
return NULL;
#elif defined (MOUNTPOINT_LINUX)
return NULL;
continue;
}
}
return NULL;
#ifdef __osf__ /* Tru64 */
#else
#endif
}
return NULL;
#else
return NULL;
#endif
}
{
#ifdef MOUNTPOINT_AIX_MNTCTL
#elif defined (MOUNTPOINT_SOLARIS)
#elif defined (MOUNTPOINT_LINUX)
#endif
return ret;
}