kernels/linux-2.4.0/arch/s390/tools/dasdfmt/dasdfmt.c
/* Check if the device we are going to format is mounted.
 * If true, complain and exit.
 */
Check if the device we are going to format is mounted.
If true, complain and exit.
Check if the device we are going to format is mounted . If true complain and exit .
void
check_mounted(int major, int minor)
{
	FILE *f;
	int ishift = 0;
	struct mntent *ment;
	struct stat stbuf;
	char line[128];
	if ((minor % (1U << DASD_PARTN_BITS)) == 0) {
		minor >>= DASD_PARTN_BITS;
		ishift = DASD_PARTN_BITS;
	}
	if (!(f = fopen(_PATH_MOUNTED, "r")))
		ERRMSG_EXIT(EXIT_FAILURE, "%s: %s\n", _PATH_MOUNTED,
			strerror(errno));
	while ((ment = getmntent(f))) {
		if (stat(ment->mnt_fsname, &stbuf) == 0)
			if ((major == MAJOR(stbuf.st_rdev)) &&
				(minor == (MINOR(stbuf.st_rdev)>>ishift))) {
				ERRMSG("%s: device is mounted on %s!!\n",
					prog_name,ment->mnt_dir);
				ERRMSG_EXIT(EXIT_BUSY, "If you really want to "
					"format it, please unmount it.\n");
			}
	}
	fclose(f);
	if (!(f = fopen("/proc/swaps", "r")))
		ERRMSG_EXIT(EXIT_FAILURE, "/proc/swaps: %s", strerror(errno));
	fgets(line, sizeof(line), f);
	while (fgets(line, sizeof(line), f)) {
		char *p;
		for (p = line; *p && (!isspace(*p)); p++) ;
		*p = '\0';
		if (stat(line, &stbuf) == 0)
			if ((major == MAJOR(stbuf.st_rdev)) &&
				(minor == (MINOR(stbuf.st_rdev)>>ishift))) {
				ERRMSG("%s: the device is in use for "
					"swapping!!\n",prog_name);
				ERRMSG_EXIT(EXIT_BUSY, "If you really want to "
					"format it, please use swapoff %s.\n",
					line);
			}
	}
	fclose(f);
}
void check_mounted ( int major , int minor ) { FILE * f ; int ishift = 0 ; struct mntent * ment ; struct stat stbuf ; char line [ 128 ] ; if ( ( minor % ( 1U << DASD_PARTN_BITS ) ) == 0 ) { minor >>= DASD_PARTN_BITS ; ishift = DASD_PARTN_BITS ; } if ( ! ( f = fopen ( _PATH_MOUNTED , " " ) ) ) ERRMSG_EXIT ( EXIT_FAILURE , " \n " , _PATH_MOUNTED , strerror ( errno ) ) ; while ( ( ment = getmntent ( f ) ) ) { if ( stat ( ment -> mnt_fsname , & stbuf ) == 0 ) if ( ( major == MAJOR ( stbuf . st_rdev ) ) && ( minor == ( MINOR ( stbuf . st_rdev ) >> ishift ) ) ) { ERRMSG ( " \n " , prog_name , ment -> mnt_dir ) ; ERRMSG_EXIT ( EXIT_BUSY , " " " \n " ) ; } } fclose ( f ) ; if ( ! ( f = fopen ( " " , " " ) ) ) ERRMSG_EXIT ( EXIT_FAILURE , " " , strerror ( errno ) ) ; fgets ( line , sizeof ( line ) , f ) ; while ( fgets ( line , sizeof ( line ) , f ) ) { char * p ; for ( p = line ; * p && ( ! isspace ( * p ) ) ; p ++ ) ; * p = ' \0 ' ; if ( stat ( line , & stbuf ) == 0 ) if ( ( major == MAJOR ( stbuf . st_rdev ) ) && ( minor == ( MINOR ( stbuf . st_rdev ) >> ishift ) ) ) { ERRMSG ( " " " \n " , prog_name ) ; ERRMSG_EXIT ( EXIT_BUSY , " " " \n " , line ) ; } } fclose ( f ) ; }
Check if the device we are going to format is mounted.
Check if the device we are going to format is mounted .
/* If whole disk to be formatted ... */ /* ... ignore partition-selector */ /*
	 * first, check filesystems
	 */ /*
	 * second, check active swap spaces
	 */ /*
	 * skip header line
	 */