fill_dir_slot(fsdata *mydata, dir_entry **dentptr, const char *l_name)
{
dir_slot *slotptr = (dir_slot *)get_vfatname_block;
- __u8 counter, checksum;
+ __u8 counter = 0, checksum;
int idx = 0, ret;
char s_name[16];
int cursect;
int root_cluster, ret = -1, name_len;
char l_filename[VFAT_MAXLEN_BYTES];
+ int write_size = size;
dir_curclust = 0;
dentptr = (dir_entry *) do_fat_read_block;
name_len = strlen(filename);
+ if (name_len >= VFAT_MAXLEN_BYTES)
+ name_len = VFAT_MAXLEN_BYTES - 1;
+
memcpy(l_filename, filename, name_len);
+ l_filename[name_len] = 0; /* terminate the string */
downcase(l_filename);
startsect = mydata->rootdir_sect;
}
ret = set_contents(mydata, retdent, buffer, size);
- if (ret) {
+ if (ret < 0) {
printf("Error: writing contents\n");
goto exit;
}
+ write_size = ret;
+ debug("attempt to write 0x%x bytes\n", write_size);
/* Flush fat buffer */
ret = flush_fat_buffer(mydata);
get_dentfromdir_block,
mydata->clust_size * mydata->sect_size);
if (ret) {
- printf("Error: wrinting directory entry\n");
+ printf("Error: writing directory entry\n");
goto exit;
}
} else {
start_cluster, size, 0x20);
ret = set_contents(mydata, empty_dentptr, buffer, size);
- if (ret) {
+ if (ret < 0) {
printf("Error: writing contents\n");
goto exit;
}
+ write_size = ret;
+ debug("attempt to write 0x%x bytes\n", write_size);
/* Flush fat buffer */
ret = flush_fat_buffer(mydata);
exit:
free(mydata->fatbuf);
- return ret;
+ return ret < 0 ? ret : write_size;
}
int file_fat_write(const char *filename, void *buffer, unsigned long maxsize)