2013-08-16 06:00:43 -04:00
|
|
|
/* See LICENSE file for copyright and license details. */
|
2013-08-29 14:05:09 -04:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <unistd.h>
|
2013-08-16 06:00:43 -04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "grabmntinfo.h"
|
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
static void
|
|
|
|
usage(void)
|
|
|
|
{
|
2013-08-29 13:48:52 -04:00
|
|
|
eprintf("usage: %s [-q] target\n", argv0);
|
2013-08-16 06:00:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
int i;
|
2013-08-29 13:48:52 -04:00
|
|
|
int qflag = 0;
|
2013-08-16 06:00:43 -04:00
|
|
|
struct mntinfo *minfo = NULL;
|
|
|
|
int siz;
|
|
|
|
int ret = 0;
|
2013-08-29 14:17:58 -04:00
|
|
|
struct stat st1, st2;
|
2013-08-16 06:00:43 -04:00
|
|
|
|
|
|
|
ARGBEGIN {
|
2013-08-29 13:48:52 -04:00
|
|
|
case 'q':
|
|
|
|
qflag = 1;
|
|
|
|
break;
|
2013-08-16 06:00:43 -04:00
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
} ARGEND;
|
|
|
|
|
|
|
|
if (argc < 1)
|
|
|
|
usage();
|
|
|
|
|
2013-08-29 14:17:58 -04:00
|
|
|
if (stat(argv[0], &st1) < 0)
|
2013-08-29 14:05:09 -04:00
|
|
|
eprintf("stat %s:", argv[0]);
|
|
|
|
|
2013-08-29 14:17:58 -04:00
|
|
|
if (!S_ISDIR(st1.st_mode))
|
2013-08-29 14:05:09 -04:00
|
|
|
eprintf("lstat %s: not a directory\n", argv[0]);
|
|
|
|
|
2013-08-16 06:00:43 -04:00
|
|
|
siz = grabmntinfo(&minfo);
|
|
|
|
if (!siz)
|
|
|
|
eprintf("grabmntinfo:");
|
2013-08-29 14:17:58 -04:00
|
|
|
for (i = 0; i < siz; i++) {
|
|
|
|
if (stat(minfo[i].mntdir, &st2) < 0)
|
|
|
|
eprintf("stat %s:", minfo[i].mntdir);
|
|
|
|
if (st1.st_dev == st2.st_dev &&
|
|
|
|
st1.st_ino == st2.st_ino)
|
2013-08-16 06:00:43 -04:00
|
|
|
break;
|
2013-08-29 14:17:58 -04:00
|
|
|
}
|
2013-08-16 06:00:43 -04:00
|
|
|
free(minfo);
|
|
|
|
|
|
|
|
if (i == siz)
|
|
|
|
ret = 1;
|
|
|
|
|
2013-08-29 13:48:52 -04:00
|
|
|
if (!qflag)
|
|
|
|
printf("%s %s a mountpoint\n", argv[0],
|
|
|
|
!ret ? "is" : "is not");
|
|
|
|
|
2013-08-16 06:00:43 -04:00
|
|
|
return ret;
|
|
|
|
}
|