]> git.sur5r.net Git - u-boot/blobdiff - fs/ubifs/ubifs.c
microblaze: Enable OF_CONTROL by default
[u-boot] / fs / ubifs / ubifs.c
index 0a7a7bff09f2c73cc89bf89d65220d497912a4c4..50355e988e9716d916579b7a763f9da8237212e7 100644 (file)
@@ -103,8 +103,8 @@ struct crypto_comp {
        int compressor;
 };
 
-static inline struct crypto_comp *crypto_alloc_comp(const char *alg_name,
-                                               u32 type, u32 mask)
+static inline struct crypto_comp
+*crypto_alloc_comp(const char *alg_name, u32 type, u32 mask)
 {
        struct ubifs_compressor *comp;
        struct crypto_comp *ptr;
@@ -124,15 +124,16 @@ static inline struct crypto_comp *crypto_alloc_comp(const char *alg_name,
                i++;
        }
        if (i >= UBIFS_COMPR_TYPES_CNT) {
-               ubifs_err("invalid compression type %s", alg_name);
+               dbg_gen("invalid compression type %s", alg_name);
                free (ptr);
                return NULL;
        }
        return ptr;
 }
-static inline int crypto_comp_decompress(struct crypto_comp *tfm,
-                               const u8 *src, unsigned int slen,
-                               u8 *dst, unsigned int *dlen)
+static inline int
+crypto_comp_decompress(const struct ubifs_info *c, struct crypto_comp *tfm,
+                      const u8 *src, unsigned int slen, u8 *dst,
+                      unsigned int *dlen)
 {
        struct ubifs_compressor *compr = ubifs_compressors[tfm->compressor];
        int err;
@@ -145,7 +146,7 @@ static inline int crypto_comp_decompress(struct crypto_comp *tfm,
 
        err = compr->decompress(src, slen, dst, (size_t *)dlen);
        if (err)
-               ubifs_err("cannot decompress %d bytes, compressor %s, "
+               ubifs_err(c, "cannot decompress %d bytes, compressor %s, "
                          "error %d", slen, compr->name, err);
 
        return err;
@@ -172,21 +173,21 @@ atomic_long_t ubifs_clean_zn_cnt;
  * The length of the uncompressed data is returned in @out_len. This functions
  * returns %0 on success or a negative error code on failure.
  */
-int ubifs_decompress(const void *in_buf, int in_len, void *out_buf,
-                    int *out_len, int compr_type)
+int ubifs_decompress(const struct ubifs_info *c, const void *in_buf,
+                    int in_len, void *out_buf, int *out_len, int compr_type)
 {
        int err;
        struct ubifs_compressor *compr;
 
        if (unlikely(compr_type < 0 || compr_type >= UBIFS_COMPR_TYPES_CNT)) {
-               ubifs_err("invalid compression type %d", compr_type);
+               ubifs_err(c, "invalid compression type %d", compr_type);
                return -EINVAL;
        }
 
        compr = ubifs_compressors[compr_type];
 
        if (unlikely(!compr->capi_name)) {
-               ubifs_err("%s compression is not compiled in", compr->name);
+               ubifs_err(c, "%s compression is not compiled in", compr->name);
                return -EINVAL;
        }
 
@@ -198,13 +199,13 @@ int ubifs_decompress(const void *in_buf, int in_len, void *out_buf,
 
        if (compr->decomp_mutex)
                mutex_lock(compr->decomp_mutex);
-       err = crypto_comp_decompress(compr->cc, in_buf, in_len, out_buf,
+       err = crypto_comp_decompress(c, compr->cc, in_buf, in_len, out_buf,
                                     (unsigned int *)out_len);
        if (compr->decomp_mutex)
                mutex_unlock(compr->decomp_mutex);
        if (err)
-               ubifs_err("cannot decompress %d bytes, compressor %s, error %d",
-                         in_len, compr->name, err);
+               ubifs_err(c, "cannot decompress %d bytes, compressor %s,"
+                         " error %d", in_len, compr->name, err);
 
        return err;
 }
@@ -229,8 +230,9 @@ static int __init compr_init(struct ubifs_compressor *compr)
        if (compr->capi_name) {
                compr->cc = crypto_alloc_comp(compr->capi_name, 0, 0);
                if (IS_ERR(compr->cc)) {
-                       ubifs_err("cannot initialize compressor %s, error %ld",
-                                 compr->name, PTR_ERR(compr->cc));
+                       dbg_gen("cannot initialize compressor %s,"
+                                 " error %ld", compr->name,
+                                 PTR_ERR(compr->cc));
                        return PTR_ERR(compr->cc);
                }
        }
@@ -384,7 +386,7 @@ static int ubifs_printdir(struct file *file, void *dirent)
 
 out:
        if (err != -ENOENT) {
-               ubifs_err("cannot find next direntry, error %d", err);
+               ubifs_err(c, "cannot find next direntry, error %d", err);
                return err;
        }
 
@@ -468,7 +470,7 @@ static int ubifs_finddir(struct super_block *sb, char *dirname,
 
 out:
        if (err != -ENOENT)
-               ubifs_err("cannot find next direntry, error %d", err);
+               dbg_gen("cannot find next direntry, error %d", err);
 
 out_free:
        if (file->private_data)
@@ -570,6 +572,25 @@ static unsigned long ubifs_findfile(struct super_block *sb, char *filename)
        return 0;
 }
 
+int ubifs_set_blk_dev(block_dev_desc_t *rbdd, disk_partition_t *info)
+{
+       if (rbdd) {
+               debug("UBIFS cannot be used with normal block devices\n");
+               return -1;
+       }
+
+       /*
+        * Should never happen since get_device_and_partition() already checks
+        * this, but better safe then sorry.
+        */
+       if (!ubifs_is_mounted()) {
+               debug("UBIFS not mounted, use ubifsmount to mount volume first!\n");
+               return -1;
+       }
+
+       return 0;
+}
+
 int ubifs_ls(const char *filename)
 {
        struct ubifs_info *c = ubifs_sb->s_fs_info;
@@ -618,6 +639,48 @@ out:
        return ret;
 }
 
+int ubifs_exists(const char *filename)
+{
+       struct ubifs_info *c = ubifs_sb->s_fs_info;
+       unsigned long inum;
+
+       c->ubi = ubi_open_volume(c->vi.ubi_num, c->vi.vol_id, UBI_READONLY);
+       inum = ubifs_findfile(ubifs_sb, (char *)filename);
+       ubi_close_volume(c->ubi);
+
+       return inum != 0;
+}
+
+int ubifs_size(const char *filename, loff_t *size)
+{
+       struct ubifs_info *c = ubifs_sb->s_fs_info;
+       unsigned long inum;
+       struct inode *inode;
+       int err = 0;
+
+       c->ubi = ubi_open_volume(c->vi.ubi_num, c->vi.vol_id, UBI_READONLY);
+
+       inum = ubifs_findfile(ubifs_sb, (char *)filename);
+       if (!inum) {
+               err = -1;
+               goto out;
+       }
+
+       inode = ubifs_iget(ubifs_sb, inum);
+       if (IS_ERR(inode)) {
+               printf("%s: Error reading inode %ld!\n", __func__, inum);
+               err = PTR_ERR(inode);
+               goto out;
+       }
+
+       *size = inode->i_size;
+
+       ubifs_iput(inode);
+out:
+       ubi_close_volume(c->ubi);
+       return err;
+}
+
 /*
  * ubifsload...
  */
@@ -654,7 +717,7 @@ static int read_block(struct inode *inode, void *addr, unsigned int block,
 
        dlen = le32_to_cpu(dn->ch.len) - UBIFS_DATA_NODE_SZ;
        out_len = UBIFS_BLOCK_SIZE;
-       err = ubifs_decompress(&dn->data, dlen, addr, &out_len,
+       err = ubifs_decompress(c, &dn->data, dlen, addr, &out_len,
                               le16_to_cpu(dn->compr_type));
        if (err || len != out_len)
                goto dump;
@@ -670,7 +733,7 @@ static int read_block(struct inode *inode, void *addr, unsigned int block,
        return 0;
 
 dump:
-       ubifs_err("bad data node (block %u, inode %lu)",
+       ubifs_err(c, "bad data node (block %u, inode %lu)",
                  block, inode->i_ino);
        ubifs_dump_node(c, dn);
        return -EINVAL;
@@ -772,7 +835,7 @@ static int do_readpage(struct ubifs_info *c, struct inode *inode,
                        dbg_gen("hole");
                        goto out_free;
                }
-               ubifs_err("cannot read page %lu of inode %lu, error %d",
+               ubifs_err(c, "cannot read page %lu of inode %lu, error %d",
                          page->index, inode->i_ino, err);
                goto error;
        }
@@ -875,6 +938,10 @@ out:
        return err;
 }
 
+void ubifs_close(void)
+{
+}
+
 /* Compat wrappers for common/cmd_ubifs.c */
 int ubifs_load(char *filename, u32 addr, u32 size)
 {