slotptr--;
counter--;
- if (itr->remaining == 0)
- flush_dir(itr);
+ if (!itr->remaining) {
+ /* Write directory table to device */
+ ret = flush_dir(itr);
+ if (ret)
+ return ret;
+ }
next_dent(itr);
if (!itr->dent)
buffer, size);
}
-static int
-flush_dir(fat_itr *itr)
+/**
+ * flush_dir() - flush directory
+ *
+ * @itr: directory iterator
+ * Return: 0 for success, -EIO on error
+ */
+static int flush_dir(fat_itr *itr)
{
fsdata *mydata = itr->fsdata;
u32 startsect, sect_offset, nsects;
+ int ret;
- if (!itr->is_root || mydata->fatsize == 32)
- return set_cluster(mydata, itr->clust, itr->block,
- mydata->clust_size * mydata->sect_size);
+ if (!itr->is_root || mydata->fatsize == 32) {
+ ret = set_cluster(mydata, itr->clust, itr->block,
+ mydata->clust_size * mydata->sect_size);
+ goto out;
+ }
sect_offset = itr->clust * mydata->clust_size;
startsect = mydata->rootdir_sect + sect_offset;
nsects = min_t(u32, mydata->clust_size,
mydata->rootdir_size - sect_offset);
- return set_sectors(mydata, startsect, itr->block,
- nsects * mydata->sect_size);
+ ret = set_sectors(mydata, startsect, itr->block,
+ nsects * mydata->sect_size);
+out:
+ if (ret) {
+ log_err("Error: writing directory entry\n");
+ return -EIO;
+ }
+ return 0;
}
/*
/* Write directory table to device */
ret = flush_dir(itr);
- if (ret) {
- printf("Error: writing directory entry\n");
- ret = -EIO;
- }
exit:
free(filename_copy);
memset(dent, 0, sizeof(*dent));
dent->name[0] = DELETED_FLAG;
- if (!itr->remaining) {
- if (flush_dir(itr)) {
- printf("error: writing directory entry\n");
- return -EIO;
- }
- }
+ if (!itr->remaining)
+ return flush_dir(itr);
return 0;
}
}
/* Delete short name */
delete_single_dentry(itr);
- if (flush_dir(itr)) {
- printf("error: writing directory entry\n");
- return -EIO;
- }
-
- return 0;
+ return flush_dir(itr);
}
int fat_unlink(const char *filename)
ret = flush_dirty_fat_buffer(mydata);
if (ret) {
printf("Error: flush fat buffer\n");
+ ret = -EIO;
goto exit;
}
/* Write directory table to device */
ret = flush_dir(itr);
- if (ret)
- printf("Error: writing directory entry\n");
exit:
free(dirname_copy);