Commit 9f12cd0e062614e19734b2ab37842d387457c5e5
ext4: Prepare API change for files greater than 2GB
Change the internal EXT4 functions to use loff_t for offsets. Signed-off-by: Suriyan Ramasami <suriyan.r@gmail.com> Acked-by: Simon Glass <sjg@chromium.org> [trini: Update common/spl/spl_ext.c] Signed-off-by: Tom Rini <trini@ti.com>
Showing 7 changed files with 97 additions and 93 deletions Side-by-side Diff
... | ... | @@ -61,61 +61,16 @@ |
61 | 61 | |
62 | 62 | #if defined(CONFIG_CMD_EXT4_WRITE) |
63 | 63 | int do_ext4_write(cmd_tbl_t *cmdtp, int flag, int argc, |
64 | - char *const argv[]) | |
64 | + char *const argv[]) | |
65 | 65 | { |
66 | - const char *filename = "/"; | |
67 | - int dev, part; | |
68 | - unsigned long ram_address; | |
69 | - unsigned long file_size; | |
70 | - disk_partition_t info; | |
71 | - block_dev_desc_t *dev_desc; | |
72 | - | |
73 | - if (argc < 6) | |
74 | - return cmd_usage(cmdtp); | |
75 | - | |
76 | - part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1); | |
77 | - if (part < 0) | |
78 | - return 1; | |
79 | - | |
80 | - dev = dev_desc->dev; | |
81 | - | |
82 | - /* get the filename */ | |
83 | - filename = argv[4]; | |
84 | - | |
85 | - /* get the address in hexadecimal format (string to int) */ | |
86 | - ram_address = simple_strtoul(argv[3], NULL, 16); | |
87 | - | |
88 | - /* get the filesize in hexadecimal format */ | |
89 | - file_size = simple_strtoul(argv[5], NULL, 16); | |
90 | - | |
91 | - /* set the device as block device */ | |
92 | - ext4fs_set_blk_dev(dev_desc, &info); | |
93 | - | |
94 | - /* mount the filesystem */ | |
95 | - if (!ext4fs_mount(info.size)) { | |
96 | - printf("Bad ext4 partition %s %d:%d\n", argv[1], dev, part); | |
97 | - goto fail; | |
98 | - } | |
99 | - | |
100 | - /* start write */ | |
101 | - if (ext4fs_write(filename, (unsigned char *)ram_address, file_size)) { | |
102 | - printf("** Error ext4fs_write() **\n"); | |
103 | - goto fail; | |
104 | - } | |
105 | - ext4fs_close(); | |
106 | - | |
107 | - return 0; | |
108 | - | |
109 | -fail: | |
110 | - ext4fs_close(); | |
111 | - | |
112 | - return 1; | |
66 | + return do_save(cmdtp, flag, argc, argv, FS_TYPE_EXT); | |
113 | 67 | } |
114 | 68 | |
115 | -U_BOOT_CMD(ext4write, 6, 1, do_ext4_write, | |
116 | - "create a file in the root directory", | |
117 | - "<interface> <dev[:part]> <addr> <absolute filename path> [sizebytes]\n" | |
118 | - " - create a file in / directory"); | |
69 | +U_BOOT_CMD(ext4write, 7, 1, do_ext4_write, | |
70 | + "create a file in the root directory", | |
71 | + "<interface> <dev[:part]> <addr> <absolute filename path>\n" | |
72 | + " [sizebytes] [file offset]\n" | |
73 | + " - create a file in / directory"); | |
119 | 74 | |
120 | 75 | #endif |
121 | 76 | |
... | ... | @@ -132,7 +87,7 @@ |
132 | 87 | "<interface> <dev[:part]> [directory]\n" |
133 | 88 | " - list files from 'dev' on 'interface' in a 'directory'"); |
134 | 89 | |
135 | -U_BOOT_CMD(ext4load, 6, 0, do_ext4_load, | |
90 | +U_BOOT_CMD(ext4load, 7, 0, do_ext4_load, | |
136 | 91 | "load binary file from a Ext4 filesystem", |
137 | 92 | "<interface> [<dev[:part]> [addr [filename [bytes [pos]]]]]\n" |
138 | 93 | " - load binary file 'filename' from 'dev' on 'interface'\n" |
... | ... | @@ -15,7 +15,7 @@ |
15 | 15 | { |
16 | 16 | s32 err; |
17 | 17 | struct image_header *header; |
18 | - int filelen; | |
18 | + loff_t filelen, actlen; | |
19 | 19 | disk_partition_t part_info = {}; |
20 | 20 | |
21 | 21 | header = (struct image_header *)(CONFIG_SYS_TEXT_BASE - |
22 | 22 | |
... | ... | @@ -37,12 +37,12 @@ |
37 | 37 | goto end; |
38 | 38 | } |
39 | 39 | |
40 | - filelen = err = ext4fs_open(filename); | |
40 | + err = ext4fs_open(filename, &filelen); | |
41 | 41 | if (err < 0) { |
42 | 42 | puts("spl: ext4fs_open failed\n"); |
43 | 43 | goto end; |
44 | 44 | } |
45 | - err = ext4fs_read((char *)header, sizeof(struct image_header)); | |
45 | + err = ext4fs_read((char *)header, sizeof(struct image_header), &actlen); | |
46 | 46 | if (err <= 0) { |
47 | 47 | puts("spl: ext4fs_read failed\n"); |
48 | 48 | goto end; |
... | ... | @@ -50,7 +50,7 @@ |
50 | 50 | |
51 | 51 | spl_parse_image_header(header); |
52 | 52 | |
53 | - err = ext4fs_read((char *)spl_image.load_addr, filelen); | |
53 | + err = ext4fs_read((char *)spl_image.load_addr, filelen, &actlen); | |
54 | 54 | |
55 | 55 | end: |
56 | 56 | #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT |
... | ... | @@ -66,7 +66,7 @@ |
66 | 66 | int spl_load_image_ext_os(block_dev_desc_t *block_dev, int partition) |
67 | 67 | { |
68 | 68 | int err; |
69 | - int filelen; | |
69 | + __maybe_unused loff_t filelen, actlen; | |
70 | 70 | disk_partition_t part_info = {}; |
71 | 71 | __maybe_unused char *file; |
72 | 72 | |
73 | 73 | |
... | ... | @@ -89,12 +89,12 @@ |
89 | 89 | #if defined(CONFIG_SPL_ENV_SUPPORT) && defined(CONFIG_SPL_OS_BOOT) |
90 | 90 | file = getenv("falcon_args_file"); |
91 | 91 | if (file) { |
92 | - filelen = err = ext4fs_open(file); | |
92 | + err = ext4fs_open(file, &filelen); | |
93 | 93 | if (err < 0) { |
94 | 94 | puts("spl: ext4fs_open failed\n"); |
95 | 95 | goto defaults; |
96 | 96 | } |
97 | - err = ext4fs_read((void *)CONFIG_SYS_SPL_ARGS_ADDR, filelen); | |
97 | + err = ext4fs_read((void *)CONFIG_SYS_SPL_ARGS_ADDR, filelen, &actlen); | |
98 | 98 | if (err <= 0) { |
99 | 99 | printf("spl: error reading image %s, err - %d, falling back to default\n", |
100 | 100 | file, err); |
101 | 101 | |
... | ... | @@ -119,11 +119,11 @@ |
119 | 119 | defaults: |
120 | 120 | #endif |
121 | 121 | |
122 | - filelen = err = ext4fs_open(CONFIG_SPL_FS_LOAD_ARGS_NAME); | |
122 | + err = ext4fs_open(CONFIG_SPL_FS_LOAD_ARGS_NAME, &filelen); | |
123 | 123 | if (err < 0) |
124 | 124 | puts("spl: ext4fs_open failed\n"); |
125 | 125 | |
126 | - err = ext4fs_read((void *)CONFIG_SYS_SPL_ARGS_ADDR, filelen); | |
126 | + err = ext4fs_read((void *)CONFIG_SYS_SPL_ARGS_ADDR, filelen, &actlen); | |
127 | 127 | if (err <= 0) { |
128 | 128 | #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT |
129 | 129 | printf("%s: error reading image %s, err - %d\n", |
... | ... | @@ -1892,6 +1892,7 @@ |
1892 | 1892 | { |
1893 | 1893 | unsigned int fpos = 0; |
1894 | 1894 | int status; |
1895 | + loff_t actread; | |
1895 | 1896 | struct ext2fs_node *diro = (struct ext2fs_node *) dir; |
1896 | 1897 | |
1897 | 1898 | #ifdef DEBUG |
... | ... | @@ -1909,8 +1910,8 @@ |
1909 | 1910 | |
1910 | 1911 | status = ext4fs_read_file(diro, fpos, |
1911 | 1912 | sizeof(struct ext2_dirent), |
1912 | - (char *) &dirent); | |
1913 | - if (status < 1) | |
1913 | + (char *)&dirent, &actread); | |
1914 | + if (status < 0) | |
1914 | 1915 | return 0; |
1915 | 1916 | |
1916 | 1917 | if (dirent.namelen != 0) { |
... | ... | @@ -1921,8 +1922,9 @@ |
1921 | 1922 | status = ext4fs_read_file(diro, |
1922 | 1923 | fpos + |
1923 | 1924 | sizeof(struct ext2_dirent), |
1924 | - dirent.namelen, filename); | |
1925 | - if (status < 1) | |
1925 | + dirent.namelen, filename, | |
1926 | + &actread); | |
1927 | + if (status < 0) | |
1926 | 1928 | return 0; |
1927 | 1929 | |
1928 | 1930 | fdiro = zalloc(sizeof(struct ext2fs_node)); |
... | ... | @@ -2004,8 +2006,8 @@ |
2004 | 2006 | printf("< ? > "); |
2005 | 2007 | break; |
2006 | 2008 | } |
2007 | - printf("%10d %s\n", | |
2008 | - __le32_to_cpu(fdiro->inode.size), | |
2009 | + printf("%10u %s\n", | |
2010 | + __le32_to_cpu(fdiro->inode.size), | |
2009 | 2011 | filename); |
2010 | 2012 | } |
2011 | 2013 | free(fdiro); |
... | ... | @@ -2020,6 +2022,7 @@ |
2020 | 2022 | char *symlink; |
2021 | 2023 | struct ext2fs_node *diro = node; |
2022 | 2024 | int status; |
2025 | + loff_t actread; | |
2023 | 2026 | |
2024 | 2027 | if (!diro->inode_read) { |
2025 | 2028 | status = ext4fs_read_inode(diro->data, diro->ino, &diro->inode); |
... | ... | @@ -2036,7 +2039,7 @@ |
2036 | 2039 | } else { |
2037 | 2040 | status = ext4fs_read_file(diro, 0, |
2038 | 2041 | __le32_to_cpu(diro->inode.size), |
2039 | - symlink); | |
2042 | + symlink, &actread); | |
2040 | 2043 | if (status == 0) { |
2041 | 2044 | free(symlink); |
2042 | 2045 | return 0; |
2043 | 2046 | |
... | ... | @@ -2170,11 +2173,10 @@ |
2170 | 2173 | return 1; |
2171 | 2174 | } |
2172 | 2175 | |
2173 | -int ext4fs_open(const char *filename) | |
2176 | +int ext4fs_open(const char *filename, loff_t *len) | |
2174 | 2177 | { |
2175 | 2178 | struct ext2fs_node *fdiro = NULL; |
2176 | 2179 | int status; |
2177 | - int len; | |
2178 | 2180 | |
2179 | 2181 | if (ext4fs_root == NULL) |
2180 | 2182 | return -1; |
2181 | 2183 | |
... | ... | @@ -2191,10 +2193,10 @@ |
2191 | 2193 | if (status == 0) |
2192 | 2194 | goto fail; |
2193 | 2195 | } |
2194 | - len = __le32_to_cpu(fdiro->inode.size); | |
2196 | + *len = __le32_to_cpu(fdiro->inode.size); | |
2195 | 2197 | ext4fs_file = fdiro; |
2196 | 2198 | |
2197 | - return len; | |
2199 | + return 0; | |
2198 | 2200 | fail: |
2199 | 2201 | ext4fs_free_node(fdiro, &ext4fs_root->diropen); |
2200 | 2202 |
... | ... | @@ -50,8 +50,8 @@ |
50 | 50 | |
51 | 51 | int ext4fs_read_inode(struct ext2_data *data, int ino, |
52 | 52 | struct ext2_inode *inode); |
53 | -int ext4fs_read_file(struct ext2fs_node *node, int pos, | |
54 | - unsigned int len, char *buf); | |
53 | +int ext4fs_read_file(struct ext2fs_node *node, loff_t pos, loff_t len, | |
54 | + char *buf, loff_t *actread); | |
55 | 55 | int ext4fs_find_file(const char *path, struct ext2fs_node *rootnode, |
56 | 56 | struct ext2fs_node **foundnode, int expecttype); |
57 | 57 | int ext4fs_iterate_dir(struct ext2fs_node *dir, char *name, |
... | ... | @@ -975,4 +975,36 @@ |
975 | 975 | |
976 | 976 | return -1; |
977 | 977 | } |
978 | + | |
979 | +int ext4_write_file(const char *filename, void *buf, loff_t offset, | |
980 | + loff_t len, loff_t *actwrite) | |
981 | +{ | |
982 | + int ret; | |
983 | + | |
984 | + if (offset != 0) { | |
985 | + printf("** Cannot support non-zero offset **\n"); | |
986 | + return -1; | |
987 | + } | |
988 | + | |
989 | + /* mount the filesystem */ | |
990 | + if (!ext4fs_mount(0)) { | |
991 | + printf("** Error Bad ext4 partition **\n"); | |
992 | + goto fail; | |
993 | + } | |
994 | + | |
995 | + ret = ext4fs_write(filename, buf, len); | |
996 | + | |
997 | + if (ret) { | |
998 | + printf("** Error ext4fs_write() **\n"); | |
999 | + goto fail; | |
1000 | + } | |
1001 | + ext4fs_close(); | |
1002 | + | |
1003 | + return 0; | |
1004 | + | |
1005 | +fail: | |
1006 | + ext4fs_close(); | |
1007 | + | |
1008 | + return -1; | |
1009 | +} |
... | ... | @@ -45,8 +45,8 @@ |
45 | 45 | * Optimized read file API : collects and defers contiguous sector |
46 | 46 | * reads into one potentially more efficient larger sequential read action |
47 | 47 | */ |
48 | -int ext4fs_read_file(struct ext2fs_node *node, int pos, | |
49 | - unsigned int len, char *buf) | |
48 | +int ext4fs_read_file(struct ext2fs_node *node, loff_t pos, | |
49 | + loff_t len, char *buf, loff_t *actread) | |
50 | 50 | { |
51 | 51 | struct ext_filesystem *fs = get_fs(); |
52 | 52 | int i; |
... | ... | @@ -150,7 +150,8 @@ |
150 | 150 | previous_block_number = -1; |
151 | 151 | } |
152 | 152 | |
153 | - return len; | |
153 | + *actread = len; | |
154 | + return 0; | |
154 | 155 | } |
155 | 156 | |
156 | 157 | int ext4fs_ls(const char *dirname) |
157 | 158 | |
158 | 159 | |
159 | 160 | |
160 | 161 | |
... | ... | @@ -176,23 +177,31 @@ |
176 | 177 | |
177 | 178 | int ext4fs_exists(const char *filename) |
178 | 179 | { |
179 | - int file_len; | |
180 | + loff_t file_len; | |
181 | + int ret; | |
180 | 182 | |
181 | - file_len = ext4fs_open(filename); | |
182 | - return file_len >= 0; | |
183 | + ret = ext4fs_open(filename, &file_len); | |
184 | + return ret == 0; | |
183 | 185 | } |
184 | 186 | |
185 | 187 | int ext4fs_size(const char *filename) |
186 | 188 | { |
187 | - return ext4fs_open(filename); | |
189 | + loff_t size; | |
190 | + int ret; | |
191 | + | |
192 | + ret = ext4fs_open(filename, &size); | |
193 | + if (ret) | |
194 | + return ret; | |
195 | + else | |
196 | + return size; | |
188 | 197 | } |
189 | 198 | |
190 | -int ext4fs_read(char *buf, unsigned len) | |
199 | +int ext4fs_read(char *buf, loff_t len, loff_t *actread) | |
191 | 200 | { |
192 | 201 | if (ext4fs_root == NULL || ext4fs_file == NULL) |
193 | 202 | return 0; |
194 | 203 | |
195 | - return ext4fs_read_file(ext4fs_file, 0, len, buf); | |
204 | + return ext4fs_read_file(ext4fs_file, 0, len, buf, actread); | |
196 | 205 | } |
197 | 206 | |
198 | 207 | int ext4fs_probe(block_dev_desc_t *fs_dev_desc, |
199 | 208 | |
... | ... | @@ -210,16 +219,17 @@ |
210 | 219 | |
211 | 220 | int ext4_read_file(const char *filename, void *buf, int offset, int len) |
212 | 221 | { |
213 | - int file_len; | |
214 | - int len_read; | |
222 | + loff_t file_len; | |
223 | + loff_t len_read; | |
224 | + int ret; | |
215 | 225 | |
216 | 226 | if (offset != 0) { |
217 | 227 | printf("** Cannot support non-zero offset **\n"); |
218 | 228 | return -1; |
219 | 229 | } |
220 | 230 | |
221 | - file_len = ext4fs_open(filename); | |
222 | - if (file_len < 0) { | |
231 | + ret = ext4fs_open(filename, &file_len); | |
232 | + if (ret < 0) { | |
223 | 233 | printf("** File not found %s **\n", filename); |
224 | 234 | return -1; |
225 | 235 | } |
226 | 236 | |
... | ... | @@ -227,9 +237,12 @@ |
227 | 237 | if (len == 0) |
228 | 238 | len = file_len; |
229 | 239 | |
230 | - len_read = ext4fs_read(buf, len); | |
240 | + ret = ext4fs_read(buf, len, &len_read); | |
231 | 241 | |
232 | - return len_read; | |
242 | + if (ret) | |
243 | + return ret; | |
244 | + else | |
245 | + return len_read; | |
233 | 246 | } |
234 | 247 | |
235 | 248 | int ext4fs_uuid(char *uuid_str) |
... | ... | @@ -125,12 +125,14 @@ |
125 | 125 | void ext4fs_deinit(void); |
126 | 126 | int ext4fs_filename_check(char *filename); |
127 | 127 | int ext4fs_write(const char *fname, unsigned char *buffer, |
128 | - unsigned long sizebytes); | |
128 | + unsigned long sizebytes); | |
129 | +int ext4_write_file(const char *filename, void *buf, loff_t offset, loff_t len, | |
130 | + loff_t *actwrite); | |
129 | 131 | #endif |
130 | 132 | |
131 | 133 | struct ext_filesystem *get_fs(void); |
132 | -int ext4fs_open(const char *filename); | |
133 | -int ext4fs_read(char *buf, unsigned len); | |
134 | +int ext4fs_open(const char *filename, loff_t *len); | |
135 | +int ext4fs_read(char *buf, loff_t len, loff_t *actread); | |
134 | 136 | int ext4fs_mount(unsigned part_length); |
135 | 137 | void ext4fs_close(void); |
136 | 138 | void ext4fs_reinit_global(void); |
-
mentioned in commit d3e488
-
mentioned in commit d3e488
-
mentioned in commit d3e488
-
mentioned in commit d3e488
-
mentioned in commit d3e488
-
mentioned in commit d3e488
-
mentioned in commit d3e488
-
mentioned in commit d3e488
-
mentioned in commit d3e488
-
mentioned in commit d3e488
-
mentioned in commit d3e488
-
mentioned in commit d3e488
-
mentioned in commit d3e488
-
mentioned in commit d3e488
-
mentioned in commit d3e488
-
mentioned in commit d3e488
-
mentioned in commit d3e488
-
mentioned in commit d3e488
-
mentioned in commit d3e488
-
mentioned in commit d3e488
-
mentioned in commit d3e488
-
mentioned in commit d3e488
-
mentioned in commit d3e488
-
mentioned in commit d3e488
-
mentioned in commit d3e488
-
mentioned in commit d3e488
-
mentioned in commit d3e488
-
mentioned in commit d3e488
-
mentioned in commit d3e488
-
mentioned in commit d3e488
-
mentioned in commit d3e488
-
mentioned in commit d3e488
-
mentioned in commit d3e488
-
mentioned in commit d3e488
-
mentioned in commit d3e488
-
mentioned in commit d3e488
-
mentioned in commit d3e488
-
mentioned in commit d3e488
-
mentioned in commit d3e488
-
mentioned in commit d3e488
-
mentioned in commit d3e488
-
mentioned in commit d3e488
-
mentioned in commit d3e488