fatfs/src/ff.c
static FRESULT dir_alloc (	/* FR_OK(0):succeeded, !=0:error */
	DIR* dp,				/* Pointer to the directory object */
	UINT nent				/* Number of contiguous entries to allocate */
)
{
	FRESULT res;
	UINT n;
	FATFS *fs = dp->obj.fs;


	res = dir_sdi(dp, 0);
	if (res == FR_OK) {
		n = 0;
		do {
			res = move_window(fs, dp->sect);
			if (res != FR_OK) break;
#if FF_FS_EXFAT
			if ((fs->fs_type == FS_EXFAT) ? (int)((dp->dir[XDIR_Type] & 0x80) == 0) : (int)(dp->dir[DIR_Name] == DDEM || dp->dir[DIR_Name] == 0)) {
#else
			if (dp->dir[DIR_Name] == DDEM || dp->dir[DIR_Name] == 0) {
#endif
				if (++n == nent) break;	/* A block of contiguous free entries is found */
			} else {
				n = 0;					/* Not a blank entry. Restart to search */
			}
			res = dir_next(dp, 1);
		} while (res == FR_OK);	/* Next entry with table stretch enabled */
	}

	if (res == FR_NO_FILE) res = FR_DENIED;	/* No directory entry to allocate */
	return res;
}
/*-----------------------------------------------------------------------*/
/* Directory handling - Reserve a block of directory entries             */
/*-----------------------------------------------------------------------*/
Directory handling - Reserve a block of directory entries
Directory handling - Reserve a block of directory entries
static FRESULT dir_alloc (	
	DIR* dp,				
	UINT nent				
)
{
	FRESULT res;
	UINT n;
	FATFS *fs = dp->obj.fs;
	res = dir_sdi(dp, 0);
	if (res == FR_OK) {
		n = 0;
		do {
			res = move_window(fs, dp->sect);
			if (res != FR_OK) break;
#if FF_FS_EXFAT
			if ((fs->fs_type == FS_EXFAT) ? (int)((dp->dir[XDIR_Type] & 0x80) == 0) : (int)(dp->dir[DIR_Name] == DDEM || dp->dir[DIR_Name] == 0)) {
#else
			if (dp->dir[DIR_Name] == DDEM || dp->dir[DIR_Name] == 0) {
#endif
				if (++n == nent) break;	/* A block of contiguous free entries is found */
			} else {
				n = 0;					
			}
			res = dir_next(dp, 1);
		} while (res == FR_OK);	
	}
	if (res == FR_NO_FILE) res = FR_DENIED;	
	return res;
}
static FRESULT dir_alloc ( DIR * dp , UINT nent ) { FRESULT res ; UINT n ; FATFS * fs = dp -> obj . fs ; res = dir_sdi ( dp , 0 ) ; if ( res == FR_OK ) { n = 0 ; do { res = move_window ( fs , dp -> sect ) ; if ( res != FR_OK ) break ; #if FF_FS_EXFAT if ( ( fs -> fs_type == FS_EXFAT ) ? ( int ) ( ( dp -> dir [ XDIR_Type ] & 0x80 ) == 0 ) : ( int ) ( dp -> dir [ DIR_Name ] == DDEM || dp -> dir [ DIR_Name ] == 0 ) ) { #else 
			if (dp->dir[DIR_Name] == DDEM || dp->dir[DIR_Name] == 0) { #endif 
				if (++n == nent) break;	/* A block of contiguous free entries is found */ } else { n = 0 ; } res = dir_next ( dp , 1 ) ; } while ( res == FR_OK ) ; } if ( res == FR_NO_FILE ) res = FR_DENIED ; return res ; }
Directory handling - Reserve a block of directory entries
Directory handling - Reserve a block of directory entries
/* FR_OK(0):succeeded, !=0:error */ /* Pointer to the directory object */ /* Number of contiguous entries to allocate */ /* Not a blank entry. Restart to search */ /* Next entry with table stretch enabled */ /* No directory entry to allocate */