* @count: number of directory entries to find
* Return: 0 on success or negative error number
*/
-static int __maybe_unused fat_find_empty_dentries(fat_itr *itr, int count)
+static int fat_find_empty_dentries(fat_itr *itr, int count)
{
unsigned int cluster;
dir_entry *dent;
if (itr->remaining == 0)
flush_dir(itr);
- /* allocate a cluster for more entries */
- if (!next_dent(itr) && !itr->dent)
- if ((itr->is_root && itr->fsdata->fatsize != 32) ||
- new_dir_table(itr))
- return -EIO;
+ next_dent(itr);
+ if (!itr->dent)
+ return -EIO;
}
return 0;
} else {
/* Create a new file */
char shortname[SHORT_NAME_SIZE];
+ int ndent;
if (itr->is_root) {
/* root dir cannot have "." or ".." */
}
/* Check if long name is needed */
- ret = set_name(itr, filename, shortname);
- if (ret < 0)
+ ndent = set_name(itr, filename, shortname);
+ if (ndent < 0) {
+ ret = ndent;
+ goto exit;
+ }
+ ret = fat_find_empty_dentries(itr, ndent);
+ if (ret)
goto exit;
- if (ret > 1) {
+ if (ndent > 1) {
/* Set long name entries */
ret = fill_dir_slot(itr, filename, shortname);
if (ret)
goto exit;
} else {
char shortname[SHORT_NAME_SIZE];
+ int ndent;
if (itr->is_root) {
/* root dir cannot have "." or ".." */
}
/* Check if long name is needed */
- ret = set_name(itr, dirname, shortname);
- if (ret < 0)
+ ndent = set_name(itr, dirname, shortname);
+ if (ndent < 0) {
+ ret = ndent;
+ goto exit;
+ }
+ ret = fat_find_empty_dentries(itr, ndent);
+ if (ret)
goto exit;
- if (ret > 1) {
+ if (ndent > 1) {
/* Set long name entries */
ret = fill_dir_slot(itr, dirname, shortname);
if (ret)