sbin/newfs_msdos/mkfs_msdos.c
/*
 * return -1 with error if file system is mounted.
 */
1 with error if file system is mounted.
1 with error if file system is mounted .
static int
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))) {
	warn("getmntinfo");
	return -1;
    }
    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)) {
	    warnx("%s is mounted on %s", fname, mp->f_mntonname);
	    return -1;
	}
    }
    return 0;
}
static int 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 ) ) ) { warn ( " " ) ; return -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 ) ) { warnx ( " " , fname , mp -> f_mntonname ) ; return -1 ; } } return 0 ; }
return -1 with error if file system is mounted.
return - 1 with error if file system is mounted .