Merge branch 'next' of ../next
[oweals/u-boot.git] / fs / cramfs / cramfs.c
index 1e3510461c97b4d254828d20aeb83c58cfde9bcf..2956d390da048f899f3cbb54389eb93907f9a636 100644 (file)
 
 #include <common.h>
 #include <malloc.h>
-
-#if (CONFIG_COMMANDS & CFG_CMD_JFFS2)
-
 #include <asm/byteorder.h>
 #include <linux/stat.h>
+#include <jffs2/jffs2.h>
 #include <jffs2/load_kernel.h>
-#include "cramfs_fs.h"
+#include <cramfs/cramfs_fs.h>
 
 /* These two macros may change in future, to provide better st_ino
    semantics. */
 
 struct cramfs_super super;
 
+/* CPU address space offset calculation macro, struct part_info offset is
+ * device address space offset, so we need to shift it by a device start address. */
+extern flash_info_t flash_info[];
+#define PART_OFFSET(x) (x->offset + flash_info[x->dev->id->num].start[0])
+
 static int cramfs_read_super (struct part_info *info)
 {
        unsigned long root_offset;
 
        /* Read the first block and get the superblock from it */
-       memcpy (&super, (void *) info->offset, sizeof (super));
+       memcpy (&super, (void *) PART_OFFSET(info), sizeof (super));
 
        /* Do sanity checks on the superblock */
        if (super.magic != CRAMFS_32 (CRAMFS_MAGIC)) {
                /* check at 512 byte offset */
-               memcpy (&super, (void *) info->offset + 512, sizeof (super));
+               memcpy (&super, (void *) PART_OFFSET(info) + 512, sizeof (super));
                if (super.magic != CRAMFS_32 (CRAMFS_MAGIC)) {
                        printf ("cramfs: wrong magic\n");
                        return -1;
@@ -86,7 +89,7 @@ static int cramfs_read_super (struct part_info *info)
        return 0;
 }
 
-static unsigned long cramfs_resolve (char *begin, unsigned long offset,
+static unsigned long cramfs_resolve (unsigned long begin, unsigned long offset,
                                     unsigned long size, int raw,
                                     char *filename)
 {
@@ -149,7 +152,7 @@ static unsigned long cramfs_resolve (char *begin, unsigned long offset,
        return 0;
 }
 
-static int cramfs_uncompress (char *begin, unsigned long offset,
+static int cramfs_uncompress (unsigned long begin, unsigned long offset,
                              unsigned long loadoffset)
 {
        struct cramfs_inode *inode = (struct cramfs_inode *) (begin + offset);
@@ -186,7 +189,7 @@ int cramfs_load (char *loadoffset, struct part_info *info, char *filename)
        if (cramfs_read_super (info))
                return -1;
 
-       offset = cramfs_resolve (info->offset,
+       offset = cramfs_resolve (PART_OFFSET(info),
                                 CRAMFS_GET_OFFSET (&(super.root)) << 2,
                                 CRAMFS_24 (super.root.size), 0,
                                 strtok (filename, "/"));
@@ -194,44 +197,14 @@ int cramfs_load (char *loadoffset, struct part_info *info, char *filename)
        if (offset <= 0)
                return offset;
 
-       return cramfs_uncompress (info->offset, offset,
+       return cramfs_uncompress (PART_OFFSET(info), offset,
                                  (unsigned long) loadoffset);
 }
 
-static char *mkmodestr (unsigned long mode, char *str)
-{
-       static const char *l = "xwr";
-       int mask = 1, i;
-       char c;
-
-       switch (mode & S_IFMT) {
-       case S_IFDIR:   str[0] = 'd'; break;
-       case S_IFBLK:   str[0] = 'b'; break;
-       case S_IFCHR:   str[0] = 'c'; break;
-       case S_IFIFO:   str[0] = 'f'; break;
-       case S_IFLNK:   str[0] = 'l'; break;
-       case S_IFSOCK:  str[0] = 's'; break;
-       case S_IFREG:   str[0] = '-'; break;
-       default: str[0] = '?'; break;
-       }
-
-       for (i = 0; i < 9; i++) {
-               c = l[i % 3];
-               str[9 - i] = (mode & mask) ? c : '-';
-               mask = mask << 1;
-       }
-
-       if (mode & S_ISUID) str[3] = (mode & S_IXUSR) ? 's' : 'S';
-       if (mode & S_ISGID) str[6] = (mode & S_IXGRP) ? 's' : 'S';
-       if (mode & S_ISVTX) str[9] = (mode & S_IXOTH) ? 't' : 'T';
-       str[10] = '\0';
-       return str;
-}
-
 static int cramfs_list_inode (struct part_info *info, unsigned long offset)
 {
        struct cramfs_inode *inode = (struct cramfs_inode *)
-               (info->offset + offset);
+               (PART_OFFSET(info) + offset);
        char *name, str[20];
        int namelen, nextoff;
 
@@ -262,7 +235,7 @@ static int cramfs_list_inode (struct part_info *info, unsigned long offset)
                unsigned long size = CRAMFS_24 (inode->size);
                char *link = malloc (size);
 
-               if (link != NULL && cramfs_uncompress (info->offset, offset,
+               if (link != NULL && cramfs_uncompress (PART_OFFSET(info), offset,
                                                       (unsigned long) link)
                    == size)
                        printf (" -> %*.*s\n", (int) size, (int) size, link);
@@ -291,7 +264,7 @@ int cramfs_ls (struct part_info *info, char *filename)
                size = CRAMFS_24 (super.root.size);
        } else {
                /* Resolve the path */
-               offset = cramfs_resolve (info->offset,
+               offset = cramfs_resolve (PART_OFFSET(info),
                                         CRAMFS_GET_OFFSET (&(super.root)) <<
                                         2, CRAMFS_24 (super.root.size), 1,
                                         strtok (filename, "/"));
@@ -300,7 +273,7 @@ int cramfs_ls (struct part_info *info, char *filename)
                        return offset;
 
                /* Resolving was successful. Examine the inode */
-               inode = (struct cramfs_inode *) (info->offset + offset);
+               inode = (struct cramfs_inode *) (PART_OFFSET(info) + offset);
                if (!S_ISDIR (CRAMFS_16 (inode->mode))) {
                        /* It's not a directory - list it, and that's that */
                        return (cramfs_list_inode (info, offset) > 0);
@@ -313,7 +286,7 @@ int cramfs_ls (struct part_info *info, char *filename)
 
        /* List the given directory */
        while (inodeoffset < size) {
-               inode = (struct cramfs_inode *) (info->offset + offset +
+               inode = (struct cramfs_inode *) (PART_OFFSET(info) + offset +
                                                 inodeoffset);
 
                nextoffset = cramfs_list_inode (info, offset + inodeoffset);
@@ -353,16 +326,17 @@ int cramfs_info (struct part_info *info)
 
 int cramfs_check (struct part_info *info)
 {
-       struct cramfs_super *sb = (struct cramfs_super *) info->offset;
+       struct cramfs_super *sb;
 
+       if (info->dev->id->type != MTD_DEV_TYPE_NOR)
+               return 0;
+
+       sb = (struct cramfs_super *) PART_OFFSET(info);
        if (sb->magic != CRAMFS_32 (CRAMFS_MAGIC)) {
                /* check at 512 byte offset */
-               sb = (struct cramfs_super *) (info->offset + 512);
-               if (sb->magic != CRAMFS_32 (CRAMFS_MAGIC)) {
+               sb = (struct cramfs_super *) (PART_OFFSET(info) + 512);
+               if (sb->magic != CRAMFS_32 (CRAMFS_MAGIC))
                        return 0;
-               }
        }
        return 1;
 }
-
-#endif /* CFG_FS_CRAMFS */