FreeBSD/tools/regression/ufs/uprintf/ufs_uprintf.c
/*
 * Create as many entries in the directory as we can, then once we start
 * hitting ENOSPC, try NUMTRIES additional times.  Note that we don't be able
 * to tell the difference between running out of inodes and running out of
 * room to extend the directory, so this is just a best effort.
 */
Create as many entries in the directory as we can, then once we start
hitting ENOSPC, try NUMTRIES additional times.  Note that we don't be able
to tell the difference between running out of inodes and running out of
room to extend the directory, so this is just a best effort.
Create as many entries in the directory as we can then once we start hitting ENOSPC try NUMTRIES additional times . Note that we don ' t be able to tell the difference between running out of inodes and running out of room to extend the directory so this is just a best effort .
static void
fill_inodes(void)
{
	char path[PATH_MAX];
	int fd, i, max;
	i = 0;
	while (1) {
		snprintf(path, PATH_MAX, "%d", i);
		fd = open(path, O_CREAT | O_TRUNC | O_RDWR, 0600);
		if (fd < 0)
			break;
		close(fd);
		i++;
	}
	max = i;
	if (errno != ENOSPC) {
		warn("fill_inodes: open(%s)", path);
		goto teardown;
	}
	for (i = 0; i < NUMTRIES; i++) {
		fd = open(path, O_CREAT | O_TRUNC | O_RDWR, 0600);
		if (fd < 0 && errno != ENOSPC) {
			warn("fill_inodes: open(%s) after ENOSPC", path);
			goto teardown;
		}
		if (fd >= 0) {
			warnx("fill_inodes: open(%s) after ENOSPC returned "
			    " %d", path, fd);
			close(fd);
			goto teardown;
		}
	}
teardown:
	for (i = 0; i < max; i++) {
		snprintf(path, PATH_MAX, "%d", i);
		(void)unlink(path);
	}
}
static void fill_inodes ( void ) { char path [ PATH_MAX ] ; int fd , i , max ; i = 0 ; while ( 1 ) { snprintf ( path , PATH_MAX , " " , i ) ; fd = open ( path , O_CREAT | O_TRUNC | O_RDWR , 0600 ) ; if ( fd < 0 ) break ; close ( fd ) ; i ++ ; } max = i ; if ( errno != ENOSPC ) { warn ( " " , path ) ; goto teardown ; } for ( i = 0 ; i < NUMTRIES ; i ++ ) { fd = open ( path , O_CREAT | O_TRUNC | O_RDWR , 0600 ) ; if ( fd < 0 && errno != ENOSPC ) { warn ( " " , path ) ; goto teardown ; } if ( fd >= 0 ) { warnx ( " " " " , path , fd ) ; close ( fd ) ; goto teardown ; } } teardown : for ( i = 0 ; i < max ; i ++ ) { snprintf ( path , PATH_MAX , " " , i ) ; ( void ) unlink ( path ) ; } }
Create as many entries in the directory as we can, then once we start
 hitting ENOSPC, try NUMTRIES additional times.
Create as many entries in the directory as we can then once we start hitting ENOSPC try NUMTRIES additional times .
/*
	 * First step, fill the directory.
	 */