X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=fs%2Ffat%2Ffat_write.c;h=7afc8388b236f765b99ca3191b56b763965f28e6;hb=5a1a8a63be8f7262a300eddafb18020926b12fb6;hp=320a8a7a87d4bfb485bbfcf71c357cb7e266d498;hpb=336d4615f8fa774557d14f9b3245daa9e5fe3dbc;p=platform%2Fkernel%2Fu-boot.git diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c index 320a8a7..7afc838 100644 --- a/fs/fat/fat_write.c +++ b/fs/fat/fat_write.c @@ -9,9 +9,11 @@ #include #include #include +#include #include #include #include +#include #include #include #include @@ -48,8 +50,11 @@ static int disk_write(__u32 block, __u32 nr_blocks, void *buf) return ret; } -/* - * Set short name in directory entry +/** + * set_name() - set short name in directory entry + * + * @dirent: directory entry + * @filename: long file name */ static void set_name(dir_entry *dirent, const char *filename) { @@ -64,7 +69,8 @@ static void set_name(dir_entry *dirent, const char *filename) if (len == 0) return; - strcpy(s_name, filename); + strncpy(s_name, filename, VFAT_MAXLEN_BYTES - 1); + s_name[VFAT_MAXLEN_BYTES - 1] = '\0'; uppercase(s_name, len); period = strchr(s_name, '.'); @@ -85,6 +91,11 @@ static void set_name(dir_entry *dirent, const char *filename) memcpy(dirent->name, s_name, period_location); } else { memcpy(dirent->name, s_name, 6); + /* + * TODO: Translating two long names with the same first six + * characters to the same short name is utterly wrong. + * Short names must be unique. + */ dirent->name[6] = '~'; dirent->name[7] = '1'; } @@ -249,9 +260,8 @@ fill_dir_slot(fat_itr *itr, const char *l_name) flush_dir(itr); /* allocate a cluster for more entries */ - if (!fat_itr_next(itr)) - if (!itr->dent && - (!itr->is_root || itr->fsdata->fatsize == 32) && + if (!fat_itr_next(itr) && !itr->dent) + if ((itr->is_root && itr->fsdata->fatsize != 32) || new_dir_table(itr)) return -1; } @@ -489,8 +499,6 @@ flush_dir(fat_itr *itr) nsects * mydata->sect_size); } -static __u8 tmpbuf_cluster[MAX_CLUSTSIZE] __aligned(ARCH_DMA_MINALIGN); - /* * Read and modify data on existing and consecutive cluster blocks */ @@ -498,6 +506,7 @@ static int get_set_cluster(fsdata *mydata, __u32 clustnum, loff_t pos, __u8 *buffer, loff_t size, loff_t *gotsize) { + static u8 *tmpbuf_cluster; unsigned int bytesperclust = mydata->clust_size * mydata->sect_size; __u32 startsect; loff_t wsize; @@ -507,6 +516,12 @@ get_set_cluster(fsdata *mydata, __u32 clustnum, loff_t pos, __u8 *buffer, if (!size) return 0; + if (!tmpbuf_cluster) { + tmpbuf_cluster = memalign(ARCH_DMA_MINALIGN, MAX_CLUSTSIZE); + if (!tmpbuf_cluster) + return -1; + } + assert(pos < bytesperclust); startsect = clust_to_sect(mydata, clustnum); @@ -795,6 +810,8 @@ set_contents(fsdata *mydata, dir_entry *dentptr, loff_t pos, __u8 *buffer, newclust = get_fatent(mydata, endclust); + if (newclust != endclust + 1) + break; if (IS_LAST_CLUST(newclust, mydata->fatsize)) break; if (CHECK_CLUST(newclust, mydata->fatsize)) { @@ -812,7 +829,9 @@ set_contents(fsdata *mydata, dir_entry *dentptr, loff_t pos, __u8 *buffer, offset = 0; else offset = pos - cur_pos; - wsize = min(cur_pos + actsize, filesize) - pos; + wsize = min_t(unsigned long long, actsize, filesize - cur_pos); + wsize -= offset; + if (get_set_cluster(mydata, curclust, offset, buffer, wsize, &actsize)) { printf("Error get-and-setting cluster\n"); @@ -825,8 +844,6 @@ set_contents(fsdata *mydata, dir_entry *dentptr, loff_t pos, __u8 *buffer, if (filesize <= cur_pos) break; - /* CHECK: newclust = get_fatent(mydata, endclust); */ - if (IS_LAST_CLUST(newclust, mydata->fatsize)) /* no more clusters */ break; @@ -1174,7 +1191,8 @@ int file_fat_write_at(const char *filename, loff_t pos, void *buffer, } /* Set short name entry */ - fill_dentry(itr->fsdata, itr->dent, filename, 0, size, 0x20); + fill_dentry(itr->fsdata, itr->dent, filename, 0, size, + ATTR_ARCH); retdent = itr->dent; }