Stefan Roese | 2fc10f6 | 2009-03-19 15:35:05 +0100 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of UBIFS. |
| 3 | * |
| 4 | * Copyright (C) 2006-2008 Nokia Corporation. |
| 5 | * |
Stefan Roese | 28ea29f | 2010-11-01 17:28:00 +0100 | [diff] [blame] | 6 | * (C) Copyright 2008-2010 |
Stefan Roese | 2fc10f6 | 2009-03-19 15:35:05 +0100 | [diff] [blame] | 7 | * Stefan Roese, DENX Software Engineering, sr@denx.de. |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify it |
| 10 | * under the terms of the GNU General Public License version 2 as published by |
| 11 | * the Free Software Foundation. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 14 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 16 | * more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License along with |
| 19 | * this program; if not, write to the Free Software Foundation, Inc., 51 |
| 20 | * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 21 | * |
| 22 | * Authors: Artem Bityutskiy (Битюцкий Артём) |
| 23 | * Adrian Hunter |
| 24 | */ |
| 25 | |
Simon Glass | a87fc0a | 2015-09-02 17:24:57 -0600 | [diff] [blame] | 26 | #include <common.h> |
| 27 | #include <memalign.h> |
Stefan Roese | 2fc10f6 | 2009-03-19 15:35:05 +0100 | [diff] [blame] | 28 | #include "ubifs.h" |
Ricardo Ribalda Delgado | a7a743e | 2009-04-27 18:33:33 +0200 | [diff] [blame] | 29 | #include <u-boot/zlib.h> |
Stefan Roese | 2fc10f6 | 2009-03-19 15:35:05 +0100 | [diff] [blame] | 30 | |
Heiko Schocher | f5895d1 | 2014-06-24 10:10:04 +0200 | [diff] [blame] | 31 | #include <linux/err.h> |
| 32 | #include <linux/lzo.h> |
| 33 | |
Stefan Roese | 2fc10f6 | 2009-03-19 15:35:05 +0100 | [diff] [blame] | 34 | DECLARE_GLOBAL_DATA_PTR; |
| 35 | |
| 36 | /* compress.c */ |
| 37 | |
| 38 | /* |
Ricardo Ribalda Delgado | a7a743e | 2009-04-27 18:33:33 +0200 | [diff] [blame] | 39 | * We need a wrapper for zunzip() because the parameters are |
Stefan Roese | 2fc10f6 | 2009-03-19 15:35:05 +0100 | [diff] [blame] | 40 | * incompatible with the lzo decompressor. |
| 41 | */ |
| 42 | static int gzip_decompress(const unsigned char *in, size_t in_len, |
| 43 | unsigned char *out, size_t *out_len) |
| 44 | { |
Veli-Pekka Peltola | 7b7e155 | 2012-09-05 18:05:14 +0300 | [diff] [blame] | 45 | return zunzip(out, *out_len, (unsigned char *)in, |
| 46 | (unsigned long *)out_len, 0, 0); |
Stefan Roese | 2fc10f6 | 2009-03-19 15:35:05 +0100 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | /* Fake description object for the "none" compressor */ |
| 50 | static struct ubifs_compressor none_compr = { |
| 51 | .compr_type = UBIFS_COMPR_NONE, |
Heiko Schocher | f5895d1 | 2014-06-24 10:10:04 +0200 | [diff] [blame] | 52 | .name = "none", |
Stefan Roese | 2fc10f6 | 2009-03-19 15:35:05 +0100 | [diff] [blame] | 53 | .capi_name = "", |
| 54 | .decompress = NULL, |
| 55 | }; |
| 56 | |
| 57 | static struct ubifs_compressor lzo_compr = { |
| 58 | .compr_type = UBIFS_COMPR_LZO, |
Heiko Schocher | f5895d1 | 2014-06-24 10:10:04 +0200 | [diff] [blame] | 59 | #ifndef __UBOOT__ |
| 60 | .comp_mutex = &lzo_mutex, |
| 61 | #endif |
| 62 | .name = "lzo", |
Stefan Roese | 2fc10f6 | 2009-03-19 15:35:05 +0100 | [diff] [blame] | 63 | .capi_name = "lzo", |
| 64 | .decompress = lzo1x_decompress_safe, |
| 65 | }; |
| 66 | |
| 67 | static struct ubifs_compressor zlib_compr = { |
| 68 | .compr_type = UBIFS_COMPR_ZLIB, |
Heiko Schocher | f5895d1 | 2014-06-24 10:10:04 +0200 | [diff] [blame] | 69 | #ifndef __UBOOT__ |
| 70 | .comp_mutex = &deflate_mutex, |
| 71 | .decomp_mutex = &inflate_mutex, |
| 72 | #endif |
Stefan Roese | 2fc10f6 | 2009-03-19 15:35:05 +0100 | [diff] [blame] | 73 | .name = "zlib", |
| 74 | .capi_name = "deflate", |
| 75 | .decompress = gzip_decompress, |
| 76 | }; |
| 77 | |
| 78 | /* All UBIFS compressors */ |
| 79 | struct ubifs_compressor *ubifs_compressors[UBIFS_COMPR_TYPES_CNT]; |
| 80 | |
Heiko Schocher | f5895d1 | 2014-06-24 10:10:04 +0200 | [diff] [blame] | 81 | |
| 82 | #ifdef __UBOOT__ |
| 83 | /* from mm/util.c */ |
| 84 | |
| 85 | /** |
| 86 | * kmemdup - duplicate region of memory |
| 87 | * |
| 88 | * @src: memory region to duplicate |
| 89 | * @len: memory region length |
| 90 | * @gfp: GFP mask to use |
| 91 | */ |
| 92 | void *kmemdup(const void *src, size_t len, gfp_t gfp) |
| 93 | { |
| 94 | void *p; |
| 95 | |
| 96 | p = kmalloc(len, gfp); |
| 97 | if (p) |
| 98 | memcpy(p, src, len); |
| 99 | return p; |
| 100 | } |
| 101 | |
| 102 | struct crypto_comp { |
| 103 | int compressor; |
| 104 | }; |
| 105 | |
| 106 | static inline struct crypto_comp *crypto_alloc_comp(const char *alg_name, |
| 107 | u32 type, u32 mask) |
| 108 | { |
| 109 | struct ubifs_compressor *comp; |
| 110 | struct crypto_comp *ptr; |
| 111 | int i = 0; |
| 112 | |
Marcel Ziswiler | abc574b | 2015-08-18 13:06:37 +0200 | [diff] [blame] | 113 | ptr = malloc_cache_aligned(sizeof(struct crypto_comp)); |
Heiko Schocher | f5895d1 | 2014-06-24 10:10:04 +0200 | [diff] [blame] | 114 | while (i < UBIFS_COMPR_TYPES_CNT) { |
| 115 | comp = ubifs_compressors[i]; |
| 116 | if (!comp) { |
| 117 | i++; |
| 118 | continue; |
| 119 | } |
| 120 | if (strncmp(alg_name, comp->capi_name, strlen(alg_name)) == 0) { |
| 121 | ptr->compressor = i; |
| 122 | return ptr; |
| 123 | } |
| 124 | i++; |
| 125 | } |
| 126 | if (i >= UBIFS_COMPR_TYPES_CNT) { |
| 127 | ubifs_err("invalid compression type %s", alg_name); |
| 128 | free (ptr); |
| 129 | return NULL; |
| 130 | } |
| 131 | return ptr; |
| 132 | } |
| 133 | static inline int crypto_comp_decompress(struct crypto_comp *tfm, |
| 134 | const u8 *src, unsigned int slen, |
| 135 | u8 *dst, unsigned int *dlen) |
| 136 | { |
| 137 | struct ubifs_compressor *compr = ubifs_compressors[tfm->compressor]; |
| 138 | int err; |
| 139 | |
| 140 | if (compr->compr_type == UBIFS_COMPR_NONE) { |
| 141 | memcpy(dst, src, slen); |
| 142 | *dlen = slen; |
| 143 | return 0; |
| 144 | } |
| 145 | |
| 146 | err = compr->decompress(src, slen, dst, (size_t *)dlen); |
| 147 | if (err) |
| 148 | ubifs_err("cannot decompress %d bytes, compressor %s, " |
| 149 | "error %d", slen, compr->name, err); |
| 150 | |
| 151 | return err; |
| 152 | |
| 153 | return 0; |
| 154 | } |
Anton Habegger | 62e79dd | 2015-01-22 22:29:10 +0100 | [diff] [blame] | 155 | |
| 156 | /* from shrinker.c */ |
| 157 | |
| 158 | /* Global clean znode counter (for all mounted UBIFS instances) */ |
| 159 | atomic_long_t ubifs_clean_zn_cnt; |
| 160 | |
Heiko Schocher | f5895d1 | 2014-06-24 10:10:04 +0200 | [diff] [blame] | 161 | #endif |
| 162 | |
Stefan Roese | 2fc10f6 | 2009-03-19 15:35:05 +0100 | [diff] [blame] | 163 | /** |
| 164 | * ubifs_decompress - decompress data. |
| 165 | * @in_buf: data to decompress |
| 166 | * @in_len: length of the data to decompress |
| 167 | * @out_buf: output buffer where decompressed data should |
| 168 | * @out_len: output length is returned here |
| 169 | * @compr_type: type of compression |
| 170 | * |
| 171 | * This function decompresses data from buffer @in_buf into buffer @out_buf. |
| 172 | * The length of the uncompressed data is returned in @out_len. This functions |
| 173 | * returns %0 on success or a negative error code on failure. |
| 174 | */ |
| 175 | int ubifs_decompress(const void *in_buf, int in_len, void *out_buf, |
| 176 | int *out_len, int compr_type) |
| 177 | { |
| 178 | int err; |
| 179 | struct ubifs_compressor *compr; |
| 180 | |
| 181 | if (unlikely(compr_type < 0 || compr_type >= UBIFS_COMPR_TYPES_CNT)) { |
| 182 | ubifs_err("invalid compression type %d", compr_type); |
| 183 | return -EINVAL; |
| 184 | } |
| 185 | |
| 186 | compr = ubifs_compressors[compr_type]; |
| 187 | |
| 188 | if (unlikely(!compr->capi_name)) { |
| 189 | ubifs_err("%s compression is not compiled in", compr->name); |
| 190 | return -EINVAL; |
| 191 | } |
| 192 | |
| 193 | if (compr_type == UBIFS_COMPR_NONE) { |
| 194 | memcpy(out_buf, in_buf, in_len); |
| 195 | *out_len = in_len; |
| 196 | return 0; |
| 197 | } |
| 198 | |
Heiko Schocher | f5895d1 | 2014-06-24 10:10:04 +0200 | [diff] [blame] | 199 | if (compr->decomp_mutex) |
| 200 | mutex_lock(compr->decomp_mutex); |
| 201 | err = crypto_comp_decompress(compr->cc, in_buf, in_len, out_buf, |
| 202 | (unsigned int *)out_len); |
| 203 | if (compr->decomp_mutex) |
| 204 | mutex_unlock(compr->decomp_mutex); |
Stefan Roese | 2fc10f6 | 2009-03-19 15:35:05 +0100 | [diff] [blame] | 205 | if (err) |
Heiko Schocher | f5895d1 | 2014-06-24 10:10:04 +0200 | [diff] [blame] | 206 | ubifs_err("cannot decompress %d bytes, compressor %s, error %d", |
| 207 | in_len, compr->name, err); |
Stefan Roese | 2fc10f6 | 2009-03-19 15:35:05 +0100 | [diff] [blame] | 208 | |
| 209 | return err; |
| 210 | } |
| 211 | |
| 212 | /** |
| 213 | * compr_init - initialize a compressor. |
| 214 | * @compr: compressor description object |
| 215 | * |
| 216 | * This function initializes the requested compressor and returns zero in case |
| 217 | * of success or a negative error code in case of failure. |
| 218 | */ |
| 219 | static int __init compr_init(struct ubifs_compressor *compr) |
| 220 | { |
| 221 | ubifs_compressors[compr->compr_type] = compr; |
Peter Tyser | 9057cbf | 2009-09-21 11:20:36 -0500 | [diff] [blame] | 222 | |
Wolfgang Denk | d0813e5 | 2010-10-28 20:00:11 +0200 | [diff] [blame] | 223 | #ifdef CONFIG_NEEDS_MANUAL_RELOC |
Stefan Roese | 2fc10f6 | 2009-03-19 15:35:05 +0100 | [diff] [blame] | 224 | ubifs_compressors[compr->compr_type]->name += gd->reloc_off; |
| 225 | ubifs_compressors[compr->compr_type]->capi_name += gd->reloc_off; |
| 226 | ubifs_compressors[compr->compr_type]->decompress += gd->reloc_off; |
Peter Tyser | 9057cbf | 2009-09-21 11:20:36 -0500 | [diff] [blame] | 227 | #endif |
| 228 | |
Heiko Schocher | f5895d1 | 2014-06-24 10:10:04 +0200 | [diff] [blame] | 229 | if (compr->capi_name) { |
| 230 | compr->cc = crypto_alloc_comp(compr->capi_name, 0, 0); |
| 231 | if (IS_ERR(compr->cc)) { |
| 232 | ubifs_err("cannot initialize compressor %s, error %ld", |
| 233 | compr->name, PTR_ERR(compr->cc)); |
| 234 | return PTR_ERR(compr->cc); |
| 235 | } |
| 236 | } |
| 237 | |
Stefan Roese | 2fc10f6 | 2009-03-19 15:35:05 +0100 | [diff] [blame] | 238 | return 0; |
| 239 | } |
| 240 | |
| 241 | /** |
| 242 | * ubifs_compressors_init - initialize UBIFS compressors. |
| 243 | * |
| 244 | * This function initializes the compressor which were compiled in. Returns |
| 245 | * zero in case of success and a negative error code in case of failure. |
| 246 | */ |
| 247 | int __init ubifs_compressors_init(void) |
| 248 | { |
| 249 | int err; |
| 250 | |
| 251 | err = compr_init(&lzo_compr); |
| 252 | if (err) |
| 253 | return err; |
| 254 | |
| 255 | err = compr_init(&zlib_compr); |
| 256 | if (err) |
| 257 | return err; |
| 258 | |
Michael Lawnick | b061701 | 2009-03-19 10:06:41 +0100 | [diff] [blame] | 259 | err = compr_init(&none_compr); |
| 260 | if (err) |
| 261 | return err; |
| 262 | |
Stefan Roese | 2fc10f6 | 2009-03-19 15:35:05 +0100 | [diff] [blame] | 263 | return 0; |
| 264 | } |
| 265 | |
| 266 | /* |
| 267 | * ubifsls... |
| 268 | */ |
| 269 | |
| 270 | static int filldir(struct ubifs_info *c, const char *name, int namlen, |
| 271 | u64 ino, unsigned int d_type) |
| 272 | { |
| 273 | struct inode *inode; |
| 274 | char filetime[32]; |
| 275 | |
| 276 | switch (d_type) { |
| 277 | case UBIFS_ITYPE_REG: |
| 278 | printf("\t"); |
| 279 | break; |
| 280 | case UBIFS_ITYPE_DIR: |
| 281 | printf("<DIR>\t"); |
| 282 | break; |
| 283 | case UBIFS_ITYPE_LNK: |
| 284 | printf("<LNK>\t"); |
| 285 | break; |
| 286 | default: |
| 287 | printf("other\t"); |
| 288 | break; |
| 289 | } |
| 290 | |
| 291 | inode = ubifs_iget(c->vfs_sb, ino); |
| 292 | if (IS_ERR(inode)) { |
| 293 | printf("%s: Error in ubifs_iget(), ino=%lld ret=%p!\n", |
| 294 | __func__, ino, inode); |
| 295 | return -1; |
| 296 | } |
| 297 | ctime_r((time_t *)&inode->i_mtime, filetime); |
| 298 | printf("%9lld %24.24s ", inode->i_size, filetime); |
Heiko Schocher | f5895d1 | 2014-06-24 10:10:04 +0200 | [diff] [blame] | 299 | #ifndef __UBOOT__ |
Stefan Roese | 2fc10f6 | 2009-03-19 15:35:05 +0100 | [diff] [blame] | 300 | ubifs_iput(inode); |
Heiko Schocher | f5895d1 | 2014-06-24 10:10:04 +0200 | [diff] [blame] | 301 | #endif |
Stefan Roese | 2fc10f6 | 2009-03-19 15:35:05 +0100 | [diff] [blame] | 302 | |
| 303 | printf("%s\n", name); |
| 304 | |
| 305 | return 0; |
| 306 | } |
| 307 | |
| 308 | static int ubifs_printdir(struct file *file, void *dirent) |
| 309 | { |
| 310 | int err, over = 0; |
| 311 | struct qstr nm; |
| 312 | union ubifs_key key; |
| 313 | struct ubifs_dent_node *dent; |
| 314 | struct inode *dir = file->f_path.dentry->d_inode; |
| 315 | struct ubifs_info *c = dir->i_sb->s_fs_info; |
| 316 | |
| 317 | dbg_gen("dir ino %lu, f_pos %#llx", dir->i_ino, file->f_pos); |
| 318 | |
| 319 | if (file->f_pos > UBIFS_S_KEY_HASH_MASK || file->f_pos == 2) |
| 320 | /* |
| 321 | * The directory was seek'ed to a senseless position or there |
| 322 | * are no more entries. |
| 323 | */ |
| 324 | return 0; |
| 325 | |
| 326 | if (file->f_pos == 1) { |
| 327 | /* Find the first entry in TNC and save it */ |
| 328 | lowest_dent_key(c, &key, dir->i_ino); |
| 329 | nm.name = NULL; |
| 330 | dent = ubifs_tnc_next_ent(c, &key, &nm); |
| 331 | if (IS_ERR(dent)) { |
| 332 | err = PTR_ERR(dent); |
| 333 | goto out; |
| 334 | } |
| 335 | |
| 336 | file->f_pos = key_hash_flash(c, &dent->key); |
| 337 | file->private_data = dent; |
| 338 | } |
| 339 | |
| 340 | dent = file->private_data; |
| 341 | if (!dent) { |
| 342 | /* |
| 343 | * The directory was seek'ed to and is now readdir'ed. |
| 344 | * Find the entry corresponding to @file->f_pos or the |
| 345 | * closest one. |
| 346 | */ |
| 347 | dent_key_init_hash(c, &key, dir->i_ino, file->f_pos); |
| 348 | nm.name = NULL; |
| 349 | dent = ubifs_tnc_next_ent(c, &key, &nm); |
| 350 | if (IS_ERR(dent)) { |
| 351 | err = PTR_ERR(dent); |
| 352 | goto out; |
| 353 | } |
| 354 | file->f_pos = key_hash_flash(c, &dent->key); |
| 355 | file->private_data = dent; |
| 356 | } |
| 357 | |
| 358 | while (1) { |
| 359 | dbg_gen("feed '%s', ino %llu, new f_pos %#x", |
| 360 | dent->name, (unsigned long long)le64_to_cpu(dent->inum), |
| 361 | key_hash_flash(c, &dent->key)); |
| 362 | ubifs_assert(le64_to_cpu(dent->ch.sqnum) > ubifs_inode(dir)->creat_sqnum); |
| 363 | |
| 364 | nm.len = le16_to_cpu(dent->nlen); |
| 365 | over = filldir(c, (char *)dent->name, nm.len, |
| 366 | le64_to_cpu(dent->inum), dent->type); |
| 367 | if (over) |
| 368 | return 0; |
| 369 | |
| 370 | /* Switch to the next entry */ |
| 371 | key_read(c, &dent->key, &key); |
| 372 | nm.name = (char *)dent->name; |
| 373 | dent = ubifs_tnc_next_ent(c, &key, &nm); |
| 374 | if (IS_ERR(dent)) { |
| 375 | err = PTR_ERR(dent); |
| 376 | goto out; |
| 377 | } |
| 378 | |
| 379 | kfree(file->private_data); |
| 380 | file->f_pos = key_hash_flash(c, &dent->key); |
| 381 | file->private_data = dent; |
| 382 | cond_resched(); |
| 383 | } |
| 384 | |
| 385 | out: |
| 386 | if (err != -ENOENT) { |
| 387 | ubifs_err("cannot find next direntry, error %d", err); |
| 388 | return err; |
| 389 | } |
| 390 | |
| 391 | kfree(file->private_data); |
| 392 | file->private_data = NULL; |
| 393 | file->f_pos = 2; |
| 394 | return 0; |
| 395 | } |
| 396 | |
| 397 | static int ubifs_finddir(struct super_block *sb, char *dirname, |
| 398 | unsigned long root_inum, unsigned long *inum) |
| 399 | { |
| 400 | int err; |
| 401 | struct qstr nm; |
| 402 | union ubifs_key key; |
| 403 | struct ubifs_dent_node *dent; |
| 404 | struct ubifs_info *c; |
| 405 | struct file *file; |
| 406 | struct dentry *dentry; |
| 407 | struct inode *dir; |
Stefan Roese | ac3244a | 2012-08-28 14:00:24 +0200 | [diff] [blame] | 408 | int ret = 0; |
Stefan Roese | 2fc10f6 | 2009-03-19 15:35:05 +0100 | [diff] [blame] | 409 | |
| 410 | file = kzalloc(sizeof(struct file), 0); |
| 411 | dentry = kzalloc(sizeof(struct dentry), 0); |
| 412 | dir = kzalloc(sizeof(struct inode), 0); |
| 413 | if (!file || !dentry || !dir) { |
| 414 | printf("%s: Error, no memory for malloc!\n", __func__); |
| 415 | err = -ENOMEM; |
| 416 | goto out; |
| 417 | } |
| 418 | |
| 419 | dir->i_sb = sb; |
| 420 | file->f_path.dentry = dentry; |
| 421 | file->f_path.dentry->d_parent = dentry; |
| 422 | file->f_path.dentry->d_inode = dir; |
| 423 | file->f_path.dentry->d_inode->i_ino = root_inum; |
| 424 | c = sb->s_fs_info; |
| 425 | |
| 426 | dbg_gen("dir ino %lu, f_pos %#llx", dir->i_ino, file->f_pos); |
| 427 | |
| 428 | /* Find the first entry in TNC and save it */ |
| 429 | lowest_dent_key(c, &key, dir->i_ino); |
| 430 | nm.name = NULL; |
| 431 | dent = ubifs_tnc_next_ent(c, &key, &nm); |
| 432 | if (IS_ERR(dent)) { |
| 433 | err = PTR_ERR(dent); |
| 434 | goto out; |
| 435 | } |
| 436 | |
| 437 | file->f_pos = key_hash_flash(c, &dent->key); |
| 438 | file->private_data = dent; |
| 439 | |
| 440 | while (1) { |
| 441 | dbg_gen("feed '%s', ino %llu, new f_pos %#x", |
| 442 | dent->name, (unsigned long long)le64_to_cpu(dent->inum), |
| 443 | key_hash_flash(c, &dent->key)); |
| 444 | ubifs_assert(le64_to_cpu(dent->ch.sqnum) > ubifs_inode(dir)->creat_sqnum); |
| 445 | |
| 446 | nm.len = le16_to_cpu(dent->nlen); |
| 447 | if ((strncmp(dirname, (char *)dent->name, nm.len) == 0) && |
| 448 | (strlen(dirname) == nm.len)) { |
| 449 | *inum = le64_to_cpu(dent->inum); |
Stefan Roese | ac3244a | 2012-08-28 14:00:24 +0200 | [diff] [blame] | 450 | ret = 1; |
| 451 | goto out_free; |
Stefan Roese | 2fc10f6 | 2009-03-19 15:35:05 +0100 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | /* Switch to the next entry */ |
| 455 | key_read(c, &dent->key, &key); |
| 456 | nm.name = (char *)dent->name; |
| 457 | dent = ubifs_tnc_next_ent(c, &key, &nm); |
| 458 | if (IS_ERR(dent)) { |
| 459 | err = PTR_ERR(dent); |
| 460 | goto out; |
| 461 | } |
| 462 | |
| 463 | kfree(file->private_data); |
| 464 | file->f_pos = key_hash_flash(c, &dent->key); |
| 465 | file->private_data = dent; |
| 466 | cond_resched(); |
| 467 | } |
| 468 | |
| 469 | out: |
Stefan Roese | ac3244a | 2012-08-28 14:00:24 +0200 | [diff] [blame] | 470 | if (err != -ENOENT) |
Stefan Roese | 2fc10f6 | 2009-03-19 15:35:05 +0100 | [diff] [blame] | 471 | ubifs_err("cannot find next direntry, error %d", err); |
Stefan Roese | 2fc10f6 | 2009-03-19 15:35:05 +0100 | [diff] [blame] | 472 | |
Stefan Roese | ac3244a | 2012-08-28 14:00:24 +0200 | [diff] [blame] | 473 | out_free: |
Wolfgang Denk | f9b3a47 | 2011-07-28 15:27:22 +0200 | [diff] [blame] | 474 | if (file->private_data) |
| 475 | kfree(file->private_data); |
Stefan Roese | 2fc10f6 | 2009-03-19 15:35:05 +0100 | [diff] [blame] | 476 | if (file) |
| 477 | free(file); |
| 478 | if (dentry) |
| 479 | free(dentry); |
| 480 | if (dir) |
| 481 | free(dir); |
| 482 | |
Stefan Roese | ac3244a | 2012-08-28 14:00:24 +0200 | [diff] [blame] | 483 | return ret; |
Stefan Roese | 2fc10f6 | 2009-03-19 15:35:05 +0100 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | static unsigned long ubifs_findfile(struct super_block *sb, char *filename) |
| 487 | { |
| 488 | int ret; |
| 489 | char *next; |
| 490 | char fpath[128]; |
Simon Kagstrom | 877501a | 2009-09-15 09:53:29 +0200 | [diff] [blame] | 491 | char symlinkpath[128]; |
Stefan Roese | 2fc10f6 | 2009-03-19 15:35:05 +0100 | [diff] [blame] | 492 | char *name = fpath; |
| 493 | unsigned long root_inum = 1; |
| 494 | unsigned long inum; |
Simon Kagstrom | 877501a | 2009-09-15 09:53:29 +0200 | [diff] [blame] | 495 | int symlink_count = 0; /* Don't allow symlink recursion */ |
Ricardo Ribalda Delgado | 4a2e69c | 2010-12-02 15:02:35 +0100 | [diff] [blame] | 496 | char link_name[64]; |
Stefan Roese | 2fc10f6 | 2009-03-19 15:35:05 +0100 | [diff] [blame] | 497 | |
| 498 | strcpy(fpath, filename); |
| 499 | |
| 500 | /* Remove all leading slashes */ |
| 501 | while (*name == '/') |
| 502 | name++; |
| 503 | |
| 504 | /* |
| 505 | * Handle root-direcoty ('/') |
| 506 | */ |
| 507 | inum = root_inum; |
| 508 | if (!name || *name == '\0') |
| 509 | return inum; |
| 510 | |
| 511 | for (;;) { |
Simon Kagstrom | 877501a | 2009-09-15 09:53:29 +0200 | [diff] [blame] | 512 | struct inode *inode; |
| 513 | struct ubifs_inode *ui; |
| 514 | |
Stefan Roese | 2fc10f6 | 2009-03-19 15:35:05 +0100 | [diff] [blame] | 515 | /* Extract the actual part from the pathname. */ |
| 516 | next = strchr(name, '/'); |
| 517 | if (next) { |
| 518 | /* Remove all leading slashes. */ |
| 519 | while (*next == '/') |
| 520 | *(next++) = '\0'; |
| 521 | } |
| 522 | |
| 523 | ret = ubifs_finddir(sb, name, root_inum, &inum); |
Simon Kagstrom | 877501a | 2009-09-15 09:53:29 +0200 | [diff] [blame] | 524 | if (!ret) |
| 525 | return 0; |
| 526 | inode = ubifs_iget(sb, inum); |
| 527 | |
| 528 | if (!inode) |
| 529 | return 0; |
| 530 | ui = ubifs_inode(inode); |
| 531 | |
| 532 | if ((inode->i_mode & S_IFMT) == S_IFLNK) { |
Simon Kagstrom | 877501a | 2009-09-15 09:53:29 +0200 | [diff] [blame] | 533 | char buf[128]; |
| 534 | |
| 535 | /* We have some sort of symlink recursion, bail out */ |
| 536 | if (symlink_count++ > 8) { |
| 537 | printf("Symlink recursion, aborting\n"); |
| 538 | return 0; |
| 539 | } |
| 540 | memcpy(link_name, ui->data, ui->data_len); |
| 541 | link_name[ui->data_len] = '\0'; |
| 542 | |
| 543 | if (link_name[0] == '/') { |
| 544 | /* Absolute path, redo everything without |
| 545 | * the leading slash */ |
| 546 | next = name = link_name + 1; |
| 547 | root_inum = 1; |
| 548 | continue; |
| 549 | } |
| 550 | /* Relative to cur dir */ |
Simon Kagstrom | 8416736 | 2009-09-25 14:05:57 +0200 | [diff] [blame] | 551 | sprintf(buf, "%s/%s", |
Simon Kagstrom | 877501a | 2009-09-15 09:53:29 +0200 | [diff] [blame] | 552 | link_name, next == NULL ? "" : next); |
| 553 | memcpy(symlinkpath, buf, sizeof(buf)); |
| 554 | next = name = symlinkpath; |
| 555 | continue; |
| 556 | } |
Stefan Roese | 2fc10f6 | 2009-03-19 15:35:05 +0100 | [diff] [blame] | 557 | |
| 558 | /* |
| 559 | * Check if directory with this name exists |
| 560 | */ |
| 561 | |
| 562 | /* Found the node! */ |
Simon Kagstrom | 877501a | 2009-09-15 09:53:29 +0200 | [diff] [blame] | 563 | if (!next || *next == '\0') |
| 564 | return inum; |
Stefan Roese | 2fc10f6 | 2009-03-19 15:35:05 +0100 | [diff] [blame] | 565 | |
| 566 | root_inum = inum; |
| 567 | name = next; |
| 568 | } |
| 569 | |
| 570 | return 0; |
| 571 | } |
| 572 | |
Hans de Goede | b5030b2 | 2015-09-17 18:46:57 -0400 | [diff] [blame^] | 573 | int ubifs_set_blk_dev(block_dev_desc_t *rbdd, disk_partition_t *info) |
| 574 | { |
| 575 | if (rbdd) { |
| 576 | debug("UBIFS cannot be used with normal block devices\n"); |
| 577 | return -1; |
| 578 | } |
| 579 | |
| 580 | /* |
| 581 | * Should never happen since get_device_and_partition() already checks |
| 582 | * this, but better safe then sorry. |
| 583 | */ |
| 584 | if (!ubifs_is_mounted()) { |
| 585 | debug("UBIFS not mounted, use ubifsmount to mount volume first!\n"); |
| 586 | return -1; |
| 587 | } |
| 588 | |
| 589 | return 0; |
| 590 | } |
| 591 | |
Hans de Goede | a164477 | 2015-09-17 18:46:56 -0400 | [diff] [blame] | 592 | int ubifs_ls(const char *filename) |
Stefan Roese | 2fc10f6 | 2009-03-19 15:35:05 +0100 | [diff] [blame] | 593 | { |
| 594 | struct ubifs_info *c = ubifs_sb->s_fs_info; |
| 595 | struct file *file; |
| 596 | struct dentry *dentry; |
| 597 | struct inode *dir; |
| 598 | void *dirent = NULL; |
| 599 | unsigned long inum; |
| 600 | int ret = 0; |
| 601 | |
| 602 | c->ubi = ubi_open_volume(c->vi.ubi_num, c->vi.vol_id, UBI_READONLY); |
Hans de Goede | a164477 | 2015-09-17 18:46:56 -0400 | [diff] [blame] | 603 | inum = ubifs_findfile(ubifs_sb, (char *)filename); |
Stefan Roese | 2fc10f6 | 2009-03-19 15:35:05 +0100 | [diff] [blame] | 604 | if (!inum) { |
| 605 | ret = -1; |
| 606 | goto out; |
| 607 | } |
| 608 | |
| 609 | file = kzalloc(sizeof(struct file), 0); |
| 610 | dentry = kzalloc(sizeof(struct dentry), 0); |
| 611 | dir = kzalloc(sizeof(struct inode), 0); |
| 612 | if (!file || !dentry || !dir) { |
| 613 | printf("%s: Error, no memory for malloc!\n", __func__); |
| 614 | ret = -ENOMEM; |
| 615 | goto out_mem; |
| 616 | } |
| 617 | |
| 618 | dir->i_sb = ubifs_sb; |
| 619 | file->f_path.dentry = dentry; |
| 620 | file->f_path.dentry->d_parent = dentry; |
| 621 | file->f_path.dentry->d_inode = dir; |
| 622 | file->f_path.dentry->d_inode->i_ino = inum; |
| 623 | file->f_pos = 1; |
| 624 | file->private_data = NULL; |
| 625 | ubifs_printdir(file, dirent); |
| 626 | |
| 627 | out_mem: |
| 628 | if (file) |
| 629 | free(file); |
| 630 | if (dentry) |
| 631 | free(dentry); |
| 632 | if (dir) |
| 633 | free(dir); |
| 634 | |
| 635 | out: |
| 636 | ubi_close_volume(c->ubi); |
| 637 | return ret; |
| 638 | } |
| 639 | |
Hans de Goede | b5030b2 | 2015-09-17 18:46:57 -0400 | [diff] [blame^] | 640 | int ubifs_exists(const char *filename) |
| 641 | { |
| 642 | struct ubifs_info *c = ubifs_sb->s_fs_info; |
| 643 | unsigned long inum; |
| 644 | |
| 645 | c->ubi = ubi_open_volume(c->vi.ubi_num, c->vi.vol_id, UBI_READONLY); |
| 646 | inum = ubifs_findfile(ubifs_sb, (char *)filename); |
| 647 | ubi_close_volume(c->ubi); |
| 648 | |
| 649 | return inum != 0; |
| 650 | } |
| 651 | |
| 652 | int ubifs_size(const char *filename, loff_t *size) |
| 653 | { |
| 654 | struct ubifs_info *c = ubifs_sb->s_fs_info; |
| 655 | unsigned long inum; |
| 656 | struct inode *inode; |
| 657 | int err = 0; |
| 658 | |
| 659 | c->ubi = ubi_open_volume(c->vi.ubi_num, c->vi.vol_id, UBI_READONLY); |
| 660 | |
| 661 | inum = ubifs_findfile(ubifs_sb, (char *)filename); |
| 662 | if (!inum) { |
| 663 | err = -1; |
| 664 | goto out; |
| 665 | } |
| 666 | |
| 667 | inode = ubifs_iget(ubifs_sb, inum); |
| 668 | if (IS_ERR(inode)) { |
| 669 | printf("%s: Error reading inode %ld!\n", __func__, inum); |
| 670 | err = PTR_ERR(inode); |
| 671 | goto out; |
| 672 | } |
| 673 | |
| 674 | *size = inode->i_size; |
| 675 | |
| 676 | ubifs_iput(inode); |
| 677 | out: |
| 678 | ubi_close_volume(c->ubi); |
| 679 | return err; |
| 680 | } |
| 681 | |
Stefan Roese | 2fc10f6 | 2009-03-19 15:35:05 +0100 | [diff] [blame] | 682 | /* |
| 683 | * ubifsload... |
| 684 | */ |
| 685 | |
| 686 | /* file.c */ |
| 687 | |
| 688 | static inline void *kmap(struct page *page) |
| 689 | { |
| 690 | return page->addr; |
| 691 | } |
| 692 | |
| 693 | static int read_block(struct inode *inode, void *addr, unsigned int block, |
| 694 | struct ubifs_data_node *dn) |
| 695 | { |
| 696 | struct ubifs_info *c = inode->i_sb->s_fs_info; |
| 697 | int err, len, out_len; |
| 698 | union ubifs_key key; |
| 699 | unsigned int dlen; |
| 700 | |
| 701 | data_key_init(c, &key, inode->i_ino, block); |
| 702 | err = ubifs_tnc_lookup(c, &key, dn); |
| 703 | if (err) { |
| 704 | if (err == -ENOENT) |
| 705 | /* Not found, so it must be a hole */ |
| 706 | memset(addr, 0, UBIFS_BLOCK_SIZE); |
| 707 | return err; |
| 708 | } |
| 709 | |
| 710 | ubifs_assert(le64_to_cpu(dn->ch.sqnum) > ubifs_inode(inode)->creat_sqnum); |
| 711 | |
| 712 | len = le32_to_cpu(dn->size); |
| 713 | if (len <= 0 || len > UBIFS_BLOCK_SIZE) |
| 714 | goto dump; |
| 715 | |
| 716 | dlen = le32_to_cpu(dn->ch.len) - UBIFS_DATA_NODE_SZ; |
| 717 | out_len = UBIFS_BLOCK_SIZE; |
| 718 | err = ubifs_decompress(&dn->data, dlen, addr, &out_len, |
| 719 | le16_to_cpu(dn->compr_type)); |
| 720 | if (err || len != out_len) |
| 721 | goto dump; |
| 722 | |
| 723 | /* |
| 724 | * Data length can be less than a full block, even for blocks that are |
| 725 | * not the last in the file (e.g., as a result of making a hole and |
| 726 | * appending data). Ensure that the remainder is zeroed out. |
| 727 | */ |
| 728 | if (len < UBIFS_BLOCK_SIZE) |
| 729 | memset(addr + len, 0, UBIFS_BLOCK_SIZE - len); |
| 730 | |
| 731 | return 0; |
| 732 | |
| 733 | dump: |
| 734 | ubifs_err("bad data node (block %u, inode %lu)", |
| 735 | block, inode->i_ino); |
Heiko Schocher | f5895d1 | 2014-06-24 10:10:04 +0200 | [diff] [blame] | 736 | ubifs_dump_node(c, dn); |
Stefan Roese | 2fc10f6 | 2009-03-19 15:35:05 +0100 | [diff] [blame] | 737 | return -EINVAL; |
| 738 | } |
| 739 | |
Stefan Roese | 28ea29f | 2010-11-01 17:28:00 +0100 | [diff] [blame] | 740 | static int do_readpage(struct ubifs_info *c, struct inode *inode, |
| 741 | struct page *page, int last_block_size) |
Stefan Roese | 2fc10f6 | 2009-03-19 15:35:05 +0100 | [diff] [blame] | 742 | { |
| 743 | void *addr; |
| 744 | int err = 0, i; |
| 745 | unsigned int block, beyond; |
| 746 | struct ubifs_data_node *dn; |
| 747 | loff_t i_size = inode->i_size; |
| 748 | |
| 749 | dbg_gen("ino %lu, pg %lu, i_size %lld", |
| 750 | inode->i_ino, page->index, i_size); |
| 751 | |
| 752 | addr = kmap(page); |
| 753 | |
| 754 | block = page->index << UBIFS_BLOCKS_PER_PAGE_SHIFT; |
| 755 | beyond = (i_size + UBIFS_BLOCK_SIZE - 1) >> UBIFS_BLOCK_SHIFT; |
| 756 | if (block >= beyond) { |
| 757 | /* Reading beyond inode */ |
| 758 | memset(addr, 0, PAGE_CACHE_SIZE); |
| 759 | goto out; |
| 760 | } |
| 761 | |
| 762 | dn = kmalloc(UBIFS_MAX_DATA_NODE_SZ, GFP_NOFS); |
Daniel Mack | b577580 | 2009-06-04 19:44:12 +0200 | [diff] [blame] | 763 | if (!dn) |
| 764 | return -ENOMEM; |
Stefan Roese | 2fc10f6 | 2009-03-19 15:35:05 +0100 | [diff] [blame] | 765 | |
| 766 | i = 0; |
| 767 | while (1) { |
| 768 | int ret; |
| 769 | |
| 770 | if (block >= beyond) { |
| 771 | /* Reading beyond inode */ |
| 772 | err = -ENOENT; |
| 773 | memset(addr, 0, UBIFS_BLOCK_SIZE); |
| 774 | } else { |
Stefan Roese | 28ea29f | 2010-11-01 17:28:00 +0100 | [diff] [blame] | 775 | /* |
| 776 | * Reading last block? Make sure to not write beyond |
| 777 | * the requested size in the destination buffer. |
| 778 | */ |
| 779 | if (((block + 1) == beyond) || last_block_size) { |
| 780 | void *buff; |
| 781 | int dlen; |
| 782 | |
| 783 | /* |
| 784 | * We need to buffer the data locally for the |
| 785 | * last block. This is to not pad the |
| 786 | * destination area to a multiple of |
| 787 | * UBIFS_BLOCK_SIZE. |
| 788 | */ |
Marcel Ziswiler | abc574b | 2015-08-18 13:06:37 +0200 | [diff] [blame] | 789 | buff = malloc_cache_aligned(UBIFS_BLOCK_SIZE); |
Stefan Roese | 28ea29f | 2010-11-01 17:28:00 +0100 | [diff] [blame] | 790 | if (!buff) { |
| 791 | printf("%s: Error, malloc fails!\n", |
| 792 | __func__); |
| 793 | err = -ENOMEM; |
Stefan Roese | 2fc10f6 | 2009-03-19 15:35:05 +0100 | [diff] [blame] | 794 | break; |
Stefan Roese | 28ea29f | 2010-11-01 17:28:00 +0100 | [diff] [blame] | 795 | } |
| 796 | |
| 797 | /* Read block-size into temp buffer */ |
| 798 | ret = read_block(inode, buff, block, dn); |
| 799 | if (ret) { |
| 800 | err = ret; |
| 801 | if (err != -ENOENT) { |
| 802 | free(buff); |
| 803 | break; |
| 804 | } |
| 805 | } |
Stefan Roese | 2fc10f6 | 2009-03-19 15:35:05 +0100 | [diff] [blame] | 806 | |
Stefan Roese | 28ea29f | 2010-11-01 17:28:00 +0100 | [diff] [blame] | 807 | if (last_block_size) |
| 808 | dlen = last_block_size; |
| 809 | else |
| 810 | dlen = le32_to_cpu(dn->size); |
| 811 | |
| 812 | /* Now copy required size back to dest */ |
| 813 | memcpy(addr, buff, dlen); |
| 814 | |
| 815 | free(buff); |
| 816 | } else { |
| 817 | ret = read_block(inode, addr, block, dn); |
| 818 | if (ret) { |
| 819 | err = ret; |
| 820 | if (err != -ENOENT) |
| 821 | break; |
| 822 | } |
Stefan Roese | 2fc10f6 | 2009-03-19 15:35:05 +0100 | [diff] [blame] | 823 | } |
| 824 | } |
| 825 | if (++i >= UBIFS_BLOCKS_PER_PAGE) |
| 826 | break; |
| 827 | block += 1; |
| 828 | addr += UBIFS_BLOCK_SIZE; |
| 829 | } |
| 830 | if (err) { |
| 831 | if (err == -ENOENT) { |
| 832 | /* Not found, so it must be a hole */ |
| 833 | dbg_gen("hole"); |
| 834 | goto out_free; |
| 835 | } |
| 836 | ubifs_err("cannot read page %lu of inode %lu, error %d", |
| 837 | page->index, inode->i_ino, err); |
| 838 | goto error; |
| 839 | } |
| 840 | |
| 841 | out_free: |
| 842 | kfree(dn); |
| 843 | out: |
| 844 | return 0; |
| 845 | |
| 846 | error: |
| 847 | kfree(dn); |
| 848 | return err; |
| 849 | } |
| 850 | |
Hans de Goede | a164477 | 2015-09-17 18:46:56 -0400 | [diff] [blame] | 851 | int ubifs_read(const char *filename, void *buf, loff_t offset, |
| 852 | loff_t size, loff_t *actread) |
Stefan Roese | 2fc10f6 | 2009-03-19 15:35:05 +0100 | [diff] [blame] | 853 | { |
| 854 | struct ubifs_info *c = ubifs_sb->s_fs_info; |
| 855 | unsigned long inum; |
| 856 | struct inode *inode; |
| 857 | struct page page; |
| 858 | int err = 0; |
| 859 | int i; |
| 860 | int count; |
Stefan Roese | 28ea29f | 2010-11-01 17:28:00 +0100 | [diff] [blame] | 861 | int last_block_size = 0; |
Stefan Roese | 2fc10f6 | 2009-03-19 15:35:05 +0100 | [diff] [blame] | 862 | |
Hans de Goede | a164477 | 2015-09-17 18:46:56 -0400 | [diff] [blame] | 863 | *actread = 0; |
| 864 | |
| 865 | if (offset & (PAGE_SIZE - 1)) { |
| 866 | printf("ubifs: Error offset must be a multple of %d\n", |
| 867 | PAGE_SIZE); |
| 868 | return -1; |
| 869 | } |
| 870 | |
Stefan Roese | 2fc10f6 | 2009-03-19 15:35:05 +0100 | [diff] [blame] | 871 | c->ubi = ubi_open_volume(c->vi.ubi_num, c->vi.vol_id, UBI_READONLY); |
Simon Kagstrom | 877501a | 2009-09-15 09:53:29 +0200 | [diff] [blame] | 872 | /* ubifs_findfile will resolve symlinks, so we know that we get |
| 873 | * the real file here */ |
Hans de Goede | a164477 | 2015-09-17 18:46:56 -0400 | [diff] [blame] | 874 | inum = ubifs_findfile(ubifs_sb, (char *)filename); |
Stefan Roese | 2fc10f6 | 2009-03-19 15:35:05 +0100 | [diff] [blame] | 875 | if (!inum) { |
| 876 | err = -1; |
| 877 | goto out; |
| 878 | } |
| 879 | |
| 880 | /* |
| 881 | * Read file inode |
| 882 | */ |
| 883 | inode = ubifs_iget(ubifs_sb, inum); |
| 884 | if (IS_ERR(inode)) { |
| 885 | printf("%s: Error reading inode %ld!\n", __func__, inum); |
| 886 | err = PTR_ERR(inode); |
| 887 | goto out; |
| 888 | } |
| 889 | |
Hans de Goede | a164477 | 2015-09-17 18:46:56 -0400 | [diff] [blame] | 890 | if (offset > inode->i_size) { |
| 891 | printf("ubifs: Error offset (%lld) > file-size (%lld)\n", |
| 892 | offset, size); |
| 893 | err = -1; |
| 894 | goto put_inode; |
| 895 | } |
| 896 | |
Stefan Roese | 2fc10f6 | 2009-03-19 15:35:05 +0100 | [diff] [blame] | 897 | /* |
Stefan Roese | 2fc10f6 | 2009-03-19 15:35:05 +0100 | [diff] [blame] | 898 | * If no size was specified or if size bigger than filesize |
| 899 | * set size to filesize |
| 900 | */ |
Hans de Goede | a164477 | 2015-09-17 18:46:56 -0400 | [diff] [blame] | 901 | if ((size == 0) || (size > (inode->i_size - offset))) |
| 902 | size = inode->i_size - offset; |
Stefan Roese | 2fc10f6 | 2009-03-19 15:35:05 +0100 | [diff] [blame] | 903 | |
| 904 | count = (size + UBIFS_BLOCK_SIZE - 1) >> UBIFS_BLOCK_SHIFT; |
Stefan Roese | 2fc10f6 | 2009-03-19 15:35:05 +0100 | [diff] [blame] | 905 | |
Hans de Goede | a164477 | 2015-09-17 18:46:56 -0400 | [diff] [blame] | 906 | page.addr = buf; |
| 907 | page.index = offset / PAGE_SIZE; |
Stefan Roese | 2fc10f6 | 2009-03-19 15:35:05 +0100 | [diff] [blame] | 908 | page.inode = inode; |
| 909 | for (i = 0; i < count; i++) { |
Stefan Roese | 28ea29f | 2010-11-01 17:28:00 +0100 | [diff] [blame] | 910 | /* |
| 911 | * Make sure to not read beyond the requested size |
| 912 | */ |
| 913 | if (((i + 1) == count) && (size < inode->i_size)) |
| 914 | last_block_size = size - (i * PAGE_SIZE); |
| 915 | |
| 916 | err = do_readpage(c, inode, &page, last_block_size); |
Stefan Roese | 2fc10f6 | 2009-03-19 15:35:05 +0100 | [diff] [blame] | 917 | if (err) |
| 918 | break; |
| 919 | |
| 920 | page.addr += PAGE_SIZE; |
| 921 | page.index++; |
| 922 | } |
| 923 | |
Hans de Goede | a164477 | 2015-09-17 18:46:56 -0400 | [diff] [blame] | 924 | if (err) { |
Stefan Roese | 2fc10f6 | 2009-03-19 15:35:05 +0100 | [diff] [blame] | 925 | printf("Error reading file '%s'\n", filename); |
Hans de Goede | a164477 | 2015-09-17 18:46:56 -0400 | [diff] [blame] | 926 | *actread = i * PAGE_SIZE; |
| 927 | } else { |
| 928 | *actread = size; |
Bastian Ruppert | fd43edd | 2011-09-05 03:03:57 +0000 | [diff] [blame] | 929 | } |
Stefan Roese | 2fc10f6 | 2009-03-19 15:35:05 +0100 | [diff] [blame] | 930 | |
Hans de Goede | a164477 | 2015-09-17 18:46:56 -0400 | [diff] [blame] | 931 | put_inode: |
Stefan Roese | 2fc10f6 | 2009-03-19 15:35:05 +0100 | [diff] [blame] | 932 | ubifs_iput(inode); |
| 933 | |
| 934 | out: |
| 935 | ubi_close_volume(c->ubi); |
| 936 | return err; |
| 937 | } |
Hans de Goede | a164477 | 2015-09-17 18:46:56 -0400 | [diff] [blame] | 938 | |
Hans de Goede | b5030b2 | 2015-09-17 18:46:57 -0400 | [diff] [blame^] | 939 | void ubifs_close(void) |
| 940 | { |
| 941 | } |
| 942 | |
Hans de Goede | a164477 | 2015-09-17 18:46:56 -0400 | [diff] [blame] | 943 | /* Compat wrappers for common/cmd_ubifs.c */ |
| 944 | int ubifs_load(char *filename, u32 addr, u32 size) |
| 945 | { |
| 946 | loff_t actread; |
| 947 | int err; |
| 948 | |
| 949 | printf("Loading file '%s' to addr 0x%08x...\n", filename, addr); |
| 950 | |
| 951 | err = ubifs_read(filename, (void *)addr, 0, size, &actread); |
| 952 | if (err == 0) { |
| 953 | setenv_hex("filesize", actread); |
| 954 | printf("Done\n"); |
| 955 | } |
| 956 | |
| 957 | return err; |
| 958 | } |
| 959 | |
| 960 | void uboot_ubifs_umount(void) |
| 961 | { |
| 962 | if (ubifs_sb) { |
| 963 | printf("Unmounting UBIFS volume %s!\n", |
| 964 | ((struct ubifs_info *)(ubifs_sb->s_fs_info))->vi.name); |
| 965 | ubifs_umount(ubifs_sb->s_fs_info); |
| 966 | ubifs_sb = NULL; |
| 967 | } |
| 968 | } |