FreeBSD/sbin/newfs_nandfs/newfs_nandfs.c
/*
 * Exit with error if file system is mounted.
 */
Exit with error if file system is mounted.
Exit with error if file system is mounted .
static void
check_mounted(const char *fname, mode_t mode)
{
	struct statfs *mp;
	const char *s1, *s2;
	size_t len;
	int n, r;
	if (!(n = getmntinfo(&mp, MNT_NOWAIT)))
		err(1, "getmntinfo");
	len = strlen(_PATH_DEV);
	s1 = fname;
	if (!strncmp(s1, _PATH_DEV, len))
		s1 += len;
	r = S_ISCHR(mode) && s1 != fname && *s1 == 'r';
	for (; n--; mp++) {
		s2 = mp->f_mntfromname;
		if (!strncmp(s2, _PATH_DEV, len))
			s2 += len;
		if ((r && s2 != mp->f_mntfromname && !strcmp(s1 + 1, s2)) ||
		    !strcmp(s1, s2))
			errx(1, "%s is mounted on %s", fname, mp->f_mntonname);
	}
}
static void check_mounted ( const char * fname , mode_t mode ) { struct statfs * mp ; const char * s1 , * s2 ; size_t len ; int n , r ; if ( ! ( n = getmntinfo ( & mp , MNT_NOWAIT ) ) ) err ( 1 , " " ) ; len = strlen ( _PATH_DEV ) ; s1 = fname ; if ( ! strncmp ( s1 , _PATH_DEV , len ) ) s1 += len ; r = S_ISCHR ( mode ) && s1 != fname && * s1 == ' ' ; for ( ; n -- ; mp ++ ) { s2 = mp -> f_mntfromname ; if ( ! strncmp ( s2 , _PATH_DEV , len ) ) s2 += len ; if ( ( r && s2 != mp -> f_mntfromname && ! strcmp ( s1 + 1 , s2 ) ) || ! strcmp ( s1 , s2 ) ) errx ( 1 , " " , fname , mp -> f_mntonname ) ; } }
Exit with error if file system is mounted.
Exit with error if file system is mounted .