Commit 1ad0b98a067a133c0e8a182649a76a4afd739594
Committed by
Tom Rini
1 parent
64553717bb
Exists in
v2017.01-smarct4x
and in
37 other branches
fat: Prepare API change for files greater than 2GB
Change the internal FAT functions to use loff_t for offsets. Signed-off-by: Suriyan Ramasami <suriyan.r@gmail.com> Acked-by: Simon Glass <sjg@chromium.org> [trini: Fix fs/fat/fat.c for min3 updates] Signed-off-by: Tom Rini <trini@ti.com>
Showing 7 changed files with 128 additions and 100 deletions Side-by-side Diff
board/esd/common/auto_update.c
... | ... | @@ -31,9 +31,6 @@ |
31 | 31 | #define MAX_LOADSZ 0x1c00000 |
32 | 32 | |
33 | 33 | /* externals */ |
34 | -extern int fat_register_device(block_dev_desc_t *, int); | |
35 | -extern int file_fat_detectfs(void); | |
36 | -extern long file_fat_read(const char *, void *, unsigned long); | |
37 | 34 | long do_fat_read (const char *filename, void *buffer, |
38 | 35 | unsigned long maxsize, int dols); |
39 | 36 |
common/cmd_fat.c
... | ... | @@ -100,7 +100,8 @@ |
100 | 100 | static int do_fat_fswrite(cmd_tbl_t *cmdtp, int flag, |
101 | 101 | int argc, char * const argv[]) |
102 | 102 | { |
103 | - long size; | |
103 | + loff_t size; | |
104 | + int ret; | |
104 | 105 | unsigned long addr; |
105 | 106 | unsigned long count; |
106 | 107 | block_dev_desc_t *dev_desc = NULL; |
107 | 108 | |
108 | 109 | |
... | ... | @@ -127,15 +128,15 @@ |
127 | 128 | count = simple_strtoul(argv[5], NULL, 16); |
128 | 129 | |
129 | 130 | buf = map_sysmem(addr, count); |
130 | - size = file_fat_write(argv[4], buf, count); | |
131 | + ret = file_fat_write(argv[4], buf, 0, count, &size); | |
131 | 132 | unmap_sysmem(buf); |
132 | - if (size == -1) { | |
133 | + if (ret < 0) { | |
133 | 134 | printf("\n** Unable to write \"%s\" from %s %d:%d **\n", |
134 | 135 | argv[4], argv[1], dev, part); |
135 | 136 | return 1; |
136 | 137 | } |
137 | 138 | |
138 | - printf("%ld bytes written\n", size); | |
139 | + printf("%llu bytes written\n", size); | |
139 | 140 | |
140 | 141 | return 0; |
141 | 142 | } |
common/env_fat.c
... | ... | @@ -41,6 +41,7 @@ |
41 | 41 | disk_partition_t info; |
42 | 42 | int dev, part; |
43 | 43 | int err; |
44 | + loff_t size; | |
44 | 45 | |
45 | 46 | err = env_export(&env_new); |
46 | 47 | if (err) |
... | ... | @@ -59,7 +60,8 @@ |
59 | 60 | return 1; |
60 | 61 | } |
61 | 62 | |
62 | - err = file_fat_write(FAT_ENV_FILE, (void *)&env_new, sizeof(env_t)); | |
63 | + err = file_fat_write(FAT_ENV_FILE, (void *)&env_new, 0, sizeof(env_t), | |
64 | + &size); | |
63 | 65 | if (err == -1) { |
64 | 66 | printf("\n** Unable to write \"%s\" from %s%d:%d **\n", |
65 | 67 | FAT_ENV_FILE, FAT_ENV_INTERFACE, dev, part); |
fs/fat/fat.c
... | ... | @@ -317,32 +317,32 @@ |
317 | 317 | /* |
318 | 318 | * Read at most 'maxsize' bytes from 'pos' in the file associated with 'dentptr' |
319 | 319 | * into 'buffer'. |
320 | - * Return the number of bytes read or -1 on fatal errors. | |
320 | + * Update the number of bytes read in *gotsize or return -1 on fatal errors. | |
321 | 321 | */ |
322 | 322 | __u8 get_contents_vfatname_block[MAX_CLUSTSIZE] |
323 | 323 | __aligned(ARCH_DMA_MINALIGN); |
324 | 324 | |
325 | -static long | |
326 | -get_contents(fsdata *mydata, dir_entry *dentptr, unsigned long pos, | |
327 | - __u8 *buffer, unsigned long maxsize) | |
325 | +static int get_contents(fsdata *mydata, dir_entry *dentptr, loff_t pos, | |
326 | + __u8 *buffer, loff_t maxsize, loff_t *gotsize) | |
328 | 327 | { |
329 | - unsigned long filesize = FAT2CPU32(dentptr->size), gotsize = 0; | |
328 | + loff_t filesize = FAT2CPU32(dentptr->size); | |
330 | 329 | unsigned int bytesperclust = mydata->clust_size * mydata->sect_size; |
331 | 330 | __u32 curclust = START(dentptr); |
332 | 331 | __u32 endclust, newclust; |
333 | - unsigned long actsize; | |
332 | + loff_t actsize; | |
334 | 333 | |
335 | - debug("Filesize: %ld bytes\n", filesize); | |
334 | + *gotsize = 0; | |
335 | + debug("Filesize: %llu bytes\n", filesize); | |
336 | 336 | |
337 | 337 | if (pos >= filesize) { |
338 | - debug("Read position past EOF: %lu\n", pos); | |
339 | - return gotsize; | |
338 | + debug("Read position past EOF: %llu\n", pos); | |
339 | + return 0; | |
340 | 340 | } |
341 | 341 | |
342 | 342 | if (maxsize > 0 && filesize > pos + maxsize) |
343 | 343 | filesize = pos + maxsize; |
344 | 344 | |
345 | - debug("%ld bytes\n", filesize); | |
345 | + debug("%llu bytes\n", filesize); | |
346 | 346 | |
347 | 347 | actsize = bytesperclust; |
348 | 348 | |
... | ... | @@ -352,7 +352,7 @@ |
352 | 352 | if (CHECK_CLUST(curclust, mydata->fatsize)) { |
353 | 353 | debug("curclust: 0x%x\n", curclust); |
354 | 354 | debug("Invalid FAT entry\n"); |
355 | - return gotsize; | |
355 | + return 0; | |
356 | 356 | } |
357 | 357 | actsize += bytesperclust; |
358 | 358 | } |
... | ... | @@ -364,7 +364,7 @@ |
364 | 364 | |
365 | 365 | /* align to beginning of next cluster if any */ |
366 | 366 | if (pos) { |
367 | - actsize = min(filesize, (unsigned long)bytesperclust); | |
367 | + actsize = min(filesize, (loff_t)bytesperclust); | |
368 | 368 | if (get_cluster(mydata, curclust, get_contents_vfatname_block, |
369 | 369 | (int)actsize) != 0) { |
370 | 370 | printf("Error reading cluster\n"); |
371 | 371 | |
372 | 372 | |
... | ... | @@ -373,16 +373,16 @@ |
373 | 373 | filesize -= actsize; |
374 | 374 | actsize -= pos; |
375 | 375 | memcpy(buffer, get_contents_vfatname_block + pos, actsize); |
376 | - gotsize += actsize; | |
376 | + *gotsize += actsize; | |
377 | 377 | if (!filesize) |
378 | - return gotsize; | |
378 | + return 0; | |
379 | 379 | buffer += actsize; |
380 | 380 | |
381 | 381 | curclust = get_fatent(mydata, curclust); |
382 | 382 | if (CHECK_CLUST(curclust, mydata->fatsize)) { |
383 | 383 | debug("curclust: 0x%x\n", curclust); |
384 | 384 | debug("Invalid FAT entry\n"); |
385 | - return gotsize; | |
385 | + return 0; | |
386 | 386 | } |
387 | 387 | } |
388 | 388 | |
... | ... | @@ -398,7 +398,7 @@ |
398 | 398 | if (CHECK_CLUST(newclust, mydata->fatsize)) { |
399 | 399 | debug("curclust: 0x%x\n", newclust); |
400 | 400 | debug("Invalid FAT entry\n"); |
401 | - return gotsize; | |
401 | + return 0; | |
402 | 402 | } |
403 | 403 | endclust = newclust; |
404 | 404 | actsize += bytesperclust; |
405 | 405 | |
... | ... | @@ -410,14 +410,14 @@ |
410 | 410 | printf("Error reading cluster\n"); |
411 | 411 | return -1; |
412 | 412 | } |
413 | - gotsize += actsize; | |
414 | - return gotsize; | |
413 | + *gotsize += actsize; | |
414 | + return 0; | |
415 | 415 | getit: |
416 | 416 | if (get_cluster(mydata, curclust, buffer, (int)actsize) != 0) { |
417 | 417 | printf("Error reading cluster\n"); |
418 | 418 | return -1; |
419 | 419 | } |
420 | - gotsize += (int)actsize; | |
420 | + *gotsize += (int)actsize; | |
421 | 421 | filesize -= actsize; |
422 | 422 | buffer += actsize; |
423 | 423 | |
... | ... | @@ -425,7 +425,7 @@ |
425 | 425 | if (CHECK_CLUST(curclust, mydata->fatsize)) { |
426 | 426 | debug("curclust: 0x%x\n", curclust); |
427 | 427 | printf("Invalid FAT entry\n"); |
428 | - return gotsize; | |
428 | + return 0; | |
429 | 429 | } |
430 | 430 | actsize = bytesperclust; |
431 | 431 | endclust = curclust; |
... | ... | @@ -633,8 +633,8 @@ |
633 | 633 | } |
634 | 634 | if (doit) { |
635 | 635 | if (dirc == ' ') { |
636 | - printf(" %8ld %s%c\n", | |
637 | - (long)FAT2CPU32(dentptr->size), | |
636 | + printf(" %8u %s%c\n", | |
637 | + FAT2CPU32(dentptr->size), | |
638 | 638 | l_name, |
639 | 639 | dirc); |
640 | 640 | } else { |
... | ... | @@ -690,8 +690,8 @@ |
690 | 690 | |
691 | 691 | if (doit) { |
692 | 692 | if (dirc == ' ') { |
693 | - printf(" %8ld %s%c\n", | |
694 | - (long)FAT2CPU32(dentptr->size), | |
693 | + printf(" %8u %s%c\n", | |
694 | + FAT2CPU32(dentptr->size), | |
695 | 695 | s_name, dirc); |
696 | 696 | } else { |
697 | 697 | printf(" %s%c\n", |
... | ... | @@ -806,9 +806,8 @@ |
806 | 806 | __u8 do_fat_read_at_block[MAX_CLUSTSIZE] |
807 | 807 | __aligned(ARCH_DMA_MINALIGN); |
808 | 808 | |
809 | -long | |
810 | -do_fat_read_at(const char *filename, unsigned long pos, void *buffer, | |
811 | - unsigned long maxsize, int dols, int dogetsize) | |
809 | +int do_fat_read_at(const char *filename, loff_t pos, void *buffer, | |
810 | + loff_t maxsize, int dols, int dogetsize, loff_t *size) | |
812 | 811 | { |
813 | 812 | char fnamecopy[2048]; |
814 | 813 | boot_sector bs; |
... | ... | @@ -821,7 +820,7 @@ |
821 | 820 | __u32 cursect; |
822 | 821 | int idx, isdir = 0; |
823 | 822 | int files = 0, dirs = 0; |
824 | - long ret = -1; | |
823 | + int ret = -1; | |
825 | 824 | int firsttime; |
826 | 825 | __u32 root_cluster = 0; |
827 | 826 | int rootdir_size = 0; |
... | ... | @@ -974,8 +973,8 @@ |
974 | 973 | } |
975 | 974 | if (doit) { |
976 | 975 | if (dirc == ' ') { |
977 | - printf(" %8ld %s%c\n", | |
978 | - (long)FAT2CPU32(dentptr->size), | |
976 | + printf(" %8u %s%c\n", | |
977 | + FAT2CPU32(dentptr->size), | |
979 | 978 | l_name, |
980 | 979 | dirc); |
981 | 980 | } else { |
... | ... | @@ -1032,8 +1031,8 @@ |
1032 | 1031 | } |
1033 | 1032 | if (doit) { |
1034 | 1033 | if (dirc == ' ') { |
1035 | - printf(" %8ld %s%c\n", | |
1036 | - (long)FAT2CPU32(dentptr->size), | |
1034 | + printf(" %8u %s%c\n", | |
1035 | + FAT2CPU32(dentptr->size), | |
1037 | 1036 | s_name, dirc); |
1038 | 1037 | } else { |
1039 | 1038 | printf(" %s%c\n", |
... | ... | @@ -1102,7 +1101,7 @@ |
1102 | 1101 | if (dols == LS_ROOT) { |
1103 | 1102 | printf("\n%d file(s), %d dir(s)\n\n", |
1104 | 1103 | files, dirs); |
1105 | - ret = 0; | |
1104 | + *size = 0; | |
1106 | 1105 | } |
1107 | 1106 | goto exit; |
1108 | 1107 | } |
... | ... | @@ -1141,7 +1140,7 @@ |
1141 | 1140 | if (get_dentfromdir(mydata, startsect, subname, dentptr, |
1142 | 1141 | isdir ? 0 : dols) == NULL) { |
1143 | 1142 | if (dols && !isdir) |
1144 | - ret = 0; | |
1143 | + *size = 0; | |
1145 | 1144 | goto exit; |
1146 | 1145 | } |
1147 | 1146 | |
1148 | 1147 | |
1149 | 1148 | |
... | ... | @@ -1152,21 +1151,23 @@ |
1152 | 1151 | subname = nextname; |
1153 | 1152 | } |
1154 | 1153 | |
1155 | - if (dogetsize) | |
1156 | - ret = FAT2CPU32(dentptr->size); | |
1157 | - else | |
1158 | - ret = get_contents(mydata, dentptr, pos, buffer, maxsize); | |
1159 | - debug("Size: %d, got: %ld\n", FAT2CPU32(dentptr->size), ret); | |
1154 | + if (dogetsize) { | |
1155 | + *size = FAT2CPU32(dentptr->size); | |
1156 | + ret = 0; | |
1157 | + } else { | |
1158 | + ret = get_contents(mydata, dentptr, pos, buffer, maxsize, size); | |
1159 | + } | |
1160 | + debug("Size: %u, got: %llu\n", FAT2CPU32(dentptr->size), *size); | |
1160 | 1161 | |
1161 | 1162 | exit: |
1162 | 1163 | free(mydata->fatbuf); |
1163 | 1164 | return ret; |
1164 | 1165 | } |
1165 | 1166 | |
1166 | -long | |
1167 | -do_fat_read(const char *filename, void *buffer, unsigned long maxsize, int dols) | |
1167 | +int do_fat_read(const char *filename, void *buffer, loff_t maxsize, int dols, | |
1168 | + loff_t *actread) | |
1168 | 1169 | { |
1169 | - return do_fat_read_at(filename, 0, buffer, maxsize, dols, 0); | |
1170 | + return do_fat_read_at(filename, 0, buffer, maxsize, dols, 0, actread); | |
1170 | 1171 | } |
1171 | 1172 | |
1172 | 1173 | int file_fat_detectfs(void) |
1173 | 1174 | |
1174 | 1175 | |
1175 | 1176 | |
1176 | 1177 | |
1177 | 1178 | |
1178 | 1179 | |
1179 | 1180 | |
1180 | 1181 | |
1181 | 1182 | |
1182 | 1183 | |
... | ... | @@ -1233,44 +1234,64 @@ |
1233 | 1234 | |
1234 | 1235 | int file_fat_ls(const char *dir) |
1235 | 1236 | { |
1236 | - return do_fat_read(dir, NULL, 0, LS_YES); | |
1237 | + loff_t size; | |
1238 | + | |
1239 | + return do_fat_read(dir, NULL, 0, LS_YES, &size); | |
1237 | 1240 | } |
1238 | 1241 | |
1239 | 1242 | int fat_exists(const char *filename) |
1240 | 1243 | { |
1241 | - int sz; | |
1242 | - sz = do_fat_read_at(filename, 0, NULL, 0, LS_NO, 1); | |
1243 | - return sz >= 0; | |
1244 | + int ret; | |
1245 | + loff_t size; | |
1246 | + | |
1247 | + ret = do_fat_read_at(filename, 0, NULL, 0, LS_NO, 1, &size); | |
1248 | + return ret == 0; | |
1244 | 1249 | } |
1245 | 1250 | |
1246 | 1251 | int fat_size(const char *filename) |
1247 | 1252 | { |
1248 | - return do_fat_read_at(filename, 0, NULL, 0, LS_NO, 1); | |
1253 | + loff_t size; | |
1254 | + int ret; | |
1255 | + | |
1256 | + ret = do_fat_read_at(filename, 0, NULL, 0, LS_NO, 1, &size); | |
1257 | + if (ret) | |
1258 | + return ret; | |
1259 | + else | |
1260 | + return size; | |
1249 | 1261 | } |
1250 | 1262 | |
1251 | -long file_fat_read_at(const char *filename, unsigned long pos, void *buffer, | |
1252 | - unsigned long maxsize) | |
1263 | +int file_fat_read_at(const char *filename, loff_t pos, void *buffer, | |
1264 | + loff_t maxsize, loff_t *actread) | |
1253 | 1265 | { |
1254 | 1266 | printf("reading %s\n", filename); |
1255 | - return do_fat_read_at(filename, pos, buffer, maxsize, LS_NO, 0); | |
1267 | + return do_fat_read_at(filename, pos, buffer, maxsize, LS_NO, 0, | |
1268 | + actread); | |
1256 | 1269 | } |
1257 | 1270 | |
1258 | -long file_fat_read(const char *filename, void *buffer, unsigned long maxsize) | |
1271 | +int file_fat_read(const char *filename, void *buffer, int maxsize) | |
1259 | 1272 | { |
1260 | - return file_fat_read_at(filename, 0, buffer, maxsize); | |
1273 | + loff_t actread; | |
1274 | + int ret; | |
1275 | + | |
1276 | + ret = file_fat_read_at(filename, 0, buffer, maxsize, &actread); | |
1277 | + if (ret) | |
1278 | + return ret; | |
1279 | + else | |
1280 | + return actread; | |
1261 | 1281 | } |
1262 | 1282 | |
1263 | 1283 | int fat_read_file(const char *filename, void *buf, int offset, int len) |
1264 | 1284 | { |
1265 | - int len_read; | |
1285 | + int ret; | |
1286 | + loff_t actread; | |
1266 | 1287 | |
1267 | - len_read = file_fat_read_at(filename, offset, buf, len); | |
1268 | - if (len_read == -1) { | |
1288 | + ret = file_fat_read_at(filename, offset, buf, len, &actread); | |
1289 | + if (ret) { | |
1269 | 1290 | printf("** Unable to read file %s **\n", filename); |
1270 | - return -1; | |
1291 | + return ret; | |
1271 | 1292 | } |
1272 | 1293 | |
1273 | - return len_read; | |
1294 | + return actread; | |
1274 | 1295 | } |
1275 | 1296 | |
1276 | 1297 | void fat_close(void) |
fs/fat/fat_write.c
... | ... | @@ -660,24 +660,26 @@ |
660 | 660 | /* |
661 | 661 | * Write at most 'maxsize' bytes from 'buffer' into |
662 | 662 | * the file associated with 'dentptr' |
663 | - * Return the number of bytes read or -1 on fatal errors. | |
663 | + * Update the number of bytes written in *gotsize and return 0 | |
664 | + * or return -1 on fatal errors. | |
664 | 665 | */ |
665 | 666 | static int |
666 | 667 | set_contents(fsdata *mydata, dir_entry *dentptr, __u8 *buffer, |
667 | - unsigned long maxsize) | |
668 | + loff_t maxsize, loff_t *gotsize) | |
668 | 669 | { |
669 | - unsigned long filesize = FAT2CPU32(dentptr->size), gotsize = 0; | |
670 | + loff_t filesize = FAT2CPU32(dentptr->size); | |
670 | 671 | unsigned int bytesperclust = mydata->clust_size * mydata->sect_size; |
671 | 672 | __u32 curclust = START(dentptr); |
672 | 673 | __u32 endclust = 0, newclust = 0; |
673 | - unsigned long actsize; | |
674 | + loff_t actsize; | |
674 | 675 | |
675 | - debug("Filesize: %ld bytes\n", filesize); | |
676 | + *gotsize = 0; | |
677 | + debug("Filesize: %llu bytes\n", filesize); | |
676 | 678 | |
677 | 679 | if (maxsize > 0 && filesize > maxsize) |
678 | 680 | filesize = maxsize; |
679 | 681 | |
680 | - debug("%ld bytes\n", filesize); | |
682 | + debug("%llu bytes\n", filesize); | |
681 | 683 | |
682 | 684 | actsize = bytesperclust; |
683 | 685 | endclust = curclust; |
... | ... | @@ -692,7 +694,7 @@ |
692 | 694 | if (CHECK_CLUST(newclust, mydata->fatsize)) { |
693 | 695 | debug("curclust: 0x%x\n", newclust); |
694 | 696 | debug("Invalid FAT entry\n"); |
695 | - return gotsize; | |
697 | + return 0; | |
696 | 698 | } |
697 | 699 | endclust = newclust; |
698 | 700 | actsize += bytesperclust; |
... | ... | @@ -706,7 +708,7 @@ |
706 | 708 | } |
707 | 709 | |
708 | 710 | /* set remaining bytes */ |
709 | - gotsize += (int)actsize; | |
711 | + *gotsize += actsize; | |
710 | 712 | filesize -= actsize; |
711 | 713 | buffer += actsize; |
712 | 714 | actsize = filesize; |
... | ... | @@ -715,7 +717,7 @@ |
715 | 717 | debug("error: writing cluster\n"); |
716 | 718 | return -1; |
717 | 719 | } |
718 | - gotsize += actsize; | |
720 | + *gotsize += actsize; | |
719 | 721 | |
720 | 722 | /* Mark end of file in FAT */ |
721 | 723 | if (mydata->fatsize == 16) |
722 | 724 | |
723 | 725 | |
... | ... | @@ -724,20 +726,20 @@ |
724 | 726 | newclust = 0xfffffff; |
725 | 727 | set_fatent_value(mydata, endclust, newclust); |
726 | 728 | |
727 | - return gotsize; | |
729 | + return 0; | |
728 | 730 | getit: |
729 | 731 | if (set_cluster(mydata, curclust, buffer, (int)actsize) != 0) { |
730 | 732 | debug("error: writing cluster\n"); |
731 | 733 | return -1; |
732 | 734 | } |
733 | - gotsize += (int)actsize; | |
735 | + *gotsize += actsize; | |
734 | 736 | filesize -= actsize; |
735 | 737 | buffer += actsize; |
736 | 738 | |
737 | 739 | if (CHECK_CLUST(curclust, mydata->fatsize)) { |
738 | 740 | debug("curclust: 0x%x\n", curclust); |
739 | 741 | debug("Invalid FAT entry\n"); |
740 | - return gotsize; | |
742 | + return 0; | |
741 | 743 | } |
742 | 744 | actsize = bytesperclust; |
743 | 745 | curclust = endclust = newclust; |
... | ... | @@ -766,7 +768,7 @@ |
766 | 768 | * exceed the size of the block device |
767 | 769 | * Return -1 when overflow occurs, otherwise return 0 |
768 | 770 | */ |
769 | -static int check_overflow(fsdata *mydata, __u32 clustnum, unsigned long size) | |
771 | +static int check_overflow(fsdata *mydata, __u32 clustnum, loff_t size) | |
770 | 772 | { |
771 | 773 | __u32 startsect, sect_num; |
772 | 774 | |
... | ... | @@ -923,8 +925,8 @@ |
923 | 925 | return NULL; |
924 | 926 | } |
925 | 927 | |
926 | -static int do_fat_write(const char *filename, void *buffer, | |
927 | - unsigned long size) | |
928 | +static int do_fat_write(const char *filename, void *buffer, loff_t size, | |
929 | + loff_t *actwrite) | |
928 | 930 | { |
929 | 931 | dir_entry *dentptr, *retdent; |
930 | 932 | __u32 startsect; |
931 | 933 | |
... | ... | @@ -936,8 +938,8 @@ |
936 | 938 | int cursect; |
937 | 939 | int ret = -1, name_len; |
938 | 940 | char l_filename[VFAT_MAXLEN_BYTES]; |
939 | - int write_size = size; | |
940 | 941 | |
942 | + *actwrite = size; | |
941 | 943 | dir_curclust = 0; |
942 | 944 | |
943 | 945 | if (read_bootsectandvi(&bs, &volinfo, &mydata->fatsize)) { |
... | ... | @@ -1015,7 +1017,7 @@ |
1015 | 1017 | |
1016 | 1018 | ret = check_overflow(mydata, start_cluster, size); |
1017 | 1019 | if (ret) { |
1018 | - printf("Error: %ld overflow\n", size); | |
1020 | + printf("Error: %llu overflow\n", size); | |
1019 | 1021 | goto exit; |
1020 | 1022 | } |
1021 | 1023 | |
1022 | 1024 | |
... | ... | @@ -1025,13 +1027,12 @@ |
1025 | 1027 | goto exit; |
1026 | 1028 | } |
1027 | 1029 | |
1028 | - ret = set_contents(mydata, retdent, buffer, size); | |
1030 | + ret = set_contents(mydata, retdent, buffer, size, actwrite); | |
1029 | 1031 | if (ret < 0) { |
1030 | 1032 | printf("Error: writing contents\n"); |
1031 | 1033 | goto exit; |
1032 | 1034 | } |
1033 | - write_size = ret; | |
1034 | - debug("attempt to write 0x%x bytes\n", write_size); | |
1035 | + debug("attempt to write 0x%llx bytes\n", *actwrite); | |
1035 | 1036 | |
1036 | 1037 | /* Flush fat buffer */ |
1037 | 1038 | ret = flush_fat_buffer(mydata); |
... | ... | @@ -1061,7 +1062,7 @@ |
1061 | 1062 | |
1062 | 1063 | ret = check_overflow(mydata, start_cluster, size); |
1063 | 1064 | if (ret) { |
1064 | - printf("Error: %ld overflow\n", size); | |
1065 | + printf("Error: %llu overflow\n", size); | |
1065 | 1066 | goto exit; |
1066 | 1067 | } |
1067 | 1068 | |
1068 | 1069 | |
... | ... | @@ -1069,13 +1070,13 @@ |
1069 | 1070 | fill_dentry(mydata, empty_dentptr, filename, |
1070 | 1071 | start_cluster, size, 0x20); |
1071 | 1072 | |
1072 | - ret = set_contents(mydata, empty_dentptr, buffer, size); | |
1073 | + ret = set_contents(mydata, empty_dentptr, buffer, size, | |
1074 | + actwrite); | |
1073 | 1075 | if (ret < 0) { |
1074 | 1076 | printf("Error: writing contents\n"); |
1075 | 1077 | goto exit; |
1076 | 1078 | } |
1077 | - write_size = ret; | |
1078 | - debug("attempt to write 0x%x bytes\n", write_size); | |
1079 | + debug("attempt to write 0x%llx bytes\n", *actwrite); | |
1079 | 1080 | |
1080 | 1081 | /* Flush fat buffer */ |
1081 | 1082 | ret = flush_fat_buffer(mydata); |
1082 | 1083 | |
1083 | 1084 | |
1084 | 1085 | |
... | ... | @@ -1096,12 +1097,18 @@ |
1096 | 1097 | |
1097 | 1098 | exit: |
1098 | 1099 | free(mydata->fatbuf); |
1099 | - return ret < 0 ? ret : write_size; | |
1100 | + return ret; | |
1100 | 1101 | } |
1101 | 1102 | |
1102 | -int file_fat_write(const char *filename, void *buffer, unsigned long maxsize) | |
1103 | +int file_fat_write(const char *filename, void *buffer, loff_t offset, | |
1104 | + loff_t maxsize, loff_t *actwrite) | |
1103 | 1105 | { |
1106 | + if (offset != 0) { | |
1107 | + printf("Error: non zero offset is currently not suported.\n"); | |
1108 | + return -1; | |
1109 | + } | |
1110 | + | |
1104 | 1111 | printf("writing %s\n", filename); |
1105 | - return do_fat_write(filename, buffer, maxsize); | |
1112 | + return do_fat_write(filename, buffer, maxsize, actwrite); | |
1106 | 1113 | } |
fs/fat/file.c
... | ... | @@ -162,8 +162,7 @@ |
162 | 162 | return filesystems[current_filesystem].ls(arg); |
163 | 163 | } |
164 | 164 | |
165 | -long | |
166 | -file_read(const char *filename, void *buffer, unsigned long maxsize) | |
165 | +int file_read(const char *filename, void *buffer, int maxsize) | |
167 | 166 | { |
168 | 167 | char fullpath[1024]; |
169 | 168 | const char *arg; |
include/fat.h
... | ... | @@ -178,8 +178,8 @@ |
178 | 178 | |
179 | 179 | typedef int (file_detectfs_func)(void); |
180 | 180 | typedef int (file_ls_func)(const char *dir); |
181 | -typedef long (file_read_func)(const char *filename, void *buffer, | |
182 | - unsigned long maxsize); | |
181 | +typedef int (file_read_func)(const char *filename, void *buffer, | |
182 | + int maxsize); | |
183 | 183 | |
184 | 184 | struct filesystem { |
185 | 185 | file_detectfs_func *detect; |
186 | 186 | |
... | ... | @@ -199,14 +199,15 @@ |
199 | 199 | int file_fat_ls(const char *dir); |
200 | 200 | int fat_exists(const char *filename); |
201 | 201 | int fat_size(const char *filename); |
202 | -long file_fat_read_at(const char *filename, unsigned long pos, void *buffer, | |
203 | - unsigned long maxsize); | |
204 | -long file_fat_read(const char *filename, void *buffer, unsigned long maxsize); | |
202 | +int file_fat_read_at(const char *filename, loff_t pos, void *buffer, | |
203 | + loff_t maxsize, loff_t *actread); | |
204 | +int file_fat_read(const char *filename, void *buffer, int maxsize); | |
205 | 205 | const char *file_getfsname(int idx); |
206 | 206 | int fat_set_blk_dev(block_dev_desc_t *rbdd, disk_partition_t *info); |
207 | 207 | int fat_register_device(block_dev_desc_t *dev_desc, int part_no); |
208 | 208 | |
209 | -int file_fat_write(const char *filename, void *buffer, unsigned long maxsize); | |
209 | +int file_fat_write(const char *filename, void *buf, loff_t offset, loff_t len, | |
210 | + loff_t *actwrite); | |
210 | 211 | int fat_read_file(const char *filename, void *buf, int offset, int len); |
211 | 212 | void fat_close(void); |
212 | 213 | #endif /* _FAT_H_ */ |