]>
git.wh0rd.org - sysvinit.git/blob - src/mountpoint.c
2 * mountpoint See if a directory is a mountpoint.
4 * Author: Miquel van Smoorenburg.
6 * Version: @(#)mountpoint 2.85-12 17-Mar-2004 miquels@cistron.nl
8 * This file is part of the sysvinit suite,
9 * Copyright (C) 1991-2004 Miquel van Smoorenburg.
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
35 int dostat(char *path
, struct stat
*st
, int do_lstat
, int quiet
)
46 fprintf(stderr
, "mountpoint: %s: %s\n", path
,
54 fprintf(stderr
, "Usage: mountpoint [-q] [-d] [-x] path\n");
58 int main(int argc
, char **argv
)
68 while ((c
= getopt(argc
, argv
, "dqx")) != EOF
) switch(c
) {
82 if (optind
!= argc
- 1) usage();
85 if (dostat(path
, &st
, !xdev
, quiet
) < 0)
90 if (!S_ISBLK(st
.st_mode
))
92 if (!S_ISBLK(st
.st_mode
) && !S_ISCHR(st
.st_mode
))
98 fprintf(stderr
, "mountpoint: %s: not a block device\n",
102 printf("%u:%u\n", major(st
.st_rdev
), minor(st
.st_rdev
));
106 if (!S_ISDIR(st
.st_mode
)) {
108 fprintf(stderr
, "mountpoint: %s: not a directory\n",
113 memset(buf
, 0, sizeof(buf
));
114 strncpy(buf
, path
, sizeof(buf
) - 4);
116 if (dostat(buf
, &st2
, 0, quiet
) < 0)
119 r
= (st
.st_dev
!= st2
.st_dev
) ||
120 (st
.st_dev
== st2
.st_dev
&& st
.st_ino
== st2
.st_ino
);
122 if (!quiet
&& !showdev
)
123 printf("%s is %sa mountpoint\n", path
, r
? "" : "not ");
125 printf("%u:%u\n", major(st
.st_dev
), minor(st
.st_dev
));