*** empty log message ***
[yaffs/.git] / yaffs_fs.c
index 29c84089cb0a155aeffaca204f514bf258b2aee3..9be8428cad8cff648e75494dea064f36ff75a0e1 100644 (file)
  * Acknowledgements:
  * * Luc van OostenRyck for numerous patches.
  * * Nick Bane for numerous patches.
+ * * Andras Toth for mknod rdev issue.
  * * Some code bodily lifted from JFFS2.
  */
 
 
+const char *yaffs_fs_c_version = "$Id: yaffs_fs.c,v 1.17 2002-10-02 02:11:25 charles Exp $";
+extern const char *yaffs_guts_c_version;
+
 #include <linux/config.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
@@ -361,7 +365,7 @@ static int yaffs_readpage_nolock(struct file *f, struct page * pg)
        yaffs_Device *dev;
        
        T((KERN_DEBUG"yaffs_readpage at %08x, size %08x\n", 
-                     pg->index << PAGE_CACHE_SHIFT, PAGE_CACHE_SIZE));
+                     (unsigned)(pg->index << PAGE_CACHE_SHIFT), (unsigned)PAGE_CACHE_SIZE));
 
        obj  = yaffs_DentryToObject(f->f_dentry);
 
@@ -431,7 +435,7 @@ static int yaffs_commit_write(struct file *f, struct page *pg, unsigned offset,
        int nWritten;
        
        unsigned spos = pos;
-       unsigned saddr = addr;
+       unsigned saddr = (unsigned)addr;
 
        T((KERN_DEBUG"yaffs_commit_write addr %x pos %x nBytes %d\n",saddr,spos,nBytes));
        
@@ -613,7 +617,7 @@ static ssize_t yaffs_file_write(struct file *f, const char *buf, size_t n, loff_
                        inode->i_size = ipos;
                        inode->i_blocks = (ipos + inode->i_blksize - 1)/ inode->i_blksize;
                        
-                       T((KERN_DEBUG"yaffs_file_write size updated to %d bytes, %d blocks\n",ipos,inode->i_blocks));
+                       T((KERN_DEBUG"yaffs_file_write size updated to %d bytes, %d blocks\n",ipos,(int)(inode->i_blocks)));
                }
                
        }
@@ -704,7 +708,7 @@ static int yaffs_readdir(struct file *f, void *dirent, filldir_t filldir)
 /*
  * File creation. Allocate an inode, and we're done..
  */
-static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode, int dev)
+static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode, int rdev)
 {
        struct inode *inode;
        
@@ -727,7 +731,7 @@ static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode, int d
        }
        
        T(("yaffs_mknod: making oject for %s, mode %x dev %x\n",
-                                       dentry->d_name.name, mode,dev));
+                                       dentry->d_name.name, mode,rdev));
 
        dev = parent->myDev;
        
@@ -738,7 +742,7 @@ static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode, int d
                default:
                        // Special (socket, fifo, device...)
                        T((KERN_DEBUG"yaffs_mknod: making special\n"));
-                       obj = yaffs_MknodSpecial(parent,dentry->d_name.name,mode,current->uid, current->gid,dev);
+                       obj = yaffs_MknodSpecial(parent,dentry->d_name.name,mode,current->uid, current->gid,rdev);
                        break;
                case S_IFREG:   // file         
                        T((KERN_DEBUG"yaffs_mknod: making file\n"));
@@ -756,7 +760,7 @@ static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode, int d
        
        if(obj)
        {
-               inode = yaffs_get_inode(dir->i_sb, mode, dev, obj);
+               inode = yaffs_get_inode(dir->i_sb, mode, rdev, obj);
                d_instantiate(dentry, inode);
                T((KERN_DEBUG"yaffs_mknod created object %d count = %d\n",obj->objectId,atomic_read(&inode->i_count)));
                error = 0;
@@ -802,13 +806,12 @@ static int yaffs_unlink(struct inode * dir, struct dentry *dentry)
        yaffs_Device *dev;
        
        
-       T((KERN_DEBUG"yaffs_unlink %d:%s\n",dir->i_ino,dentry->d_name.name));
+       T((KERN_DEBUG"yaffs_unlink %d:%s\n",(int)(dir->i_ino),dentry->d_name.name));
        
        dev = yaffs_InodeToObject(dir)->myDev;
        
        yaffs_GrossLock(dev);
        
-       nlinks = 
        
        retVal = yaffs_Unlink(yaffs_InodeToObject(dir),dentry->d_name.name);
        
@@ -930,6 +933,10 @@ static int yaffs_rename(struct inode * old_dir, struct dentry *old_dentry, struc
 
        yaffs_GrossLock(dev);
        
+       // Unlink the target if it exists
+       yaffs_Unlink(yaffs_InodeToObject(new_dir),new_dentry->d_name.name);
+
+       
        retVal =  yaffs_RenameObject(yaffs_InodeToObject(old_dir),old_dentry->d_name.name,
                                         yaffs_InodeToObject(new_dir),new_dentry->d_name.name);
        yaffs_GrossUnlock(dev);
@@ -1012,6 +1019,12 @@ static void yaffs_read_inode (struct inode *inode)
 }
 
 
+
+static yaffs_Device *yaffs_dev;
+static yaffs_Device *yaffsram_dev;
+
+
+
 static void yaffs_put_super(struct super_block *sb)
 {
        yaffs_Device *dev = yaffs_SuperToDevice(sb);
@@ -1023,7 +1036,10 @@ static void yaffs_put_super(struct super_block *sb)
        }
        yaffs_Deinitialise(dev);
        yaffs_GrossUnlock(dev);
-       
+
+       if(dev == yaffs_dev) yaffs_dev = NULL;
+       if(dev == yaffsram_dev) yaffsram_dev = NULL;
+               
        kfree(dev);
 }
 
@@ -1045,6 +1061,7 @@ static void  yaffs_MTDPutSuper(struct super_block *sb)
 
 #endif
 
+
 static struct super_block *yaffs_internal_read_super(int useRam, struct super_block * sb, void * data, int silent)
 {
        int nBlocks;
@@ -1073,7 +1090,7 @@ static struct super_block *yaffs_internal_read_super(int useRam, struct super_bl
        sb->s_blocksize = PAGE_CACHE_SIZE;
        sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
 #endif
-       T(("yaffs_read_super: %s block size %d\n", useRam ? "RAM" : "MTD",sb->s_blocksize));
+       T(("yaffs_read_super: %s block size %d\n", useRam ? "RAM" : "MTD",(int)(sb->s_blocksize)));
 
 #ifdef CONFIG_YAFFS_DISABLE_WRITE_VERIFY
        T(("yaffs: Write verification disabled. All guarantees null and void\n");
@@ -1106,6 +1123,8 @@ static struct super_block *yaffs_internal_read_super(int useRam, struct super_bl
                dev->readChunkFromNAND = nandemul_ReadChunkFromNAND;
                dev->eraseBlockInNAND = nandemul_EraseBlockInNAND;
                dev->initialiseNAND = nandemul_InitialiseNAND;
+
+               yaffsram_dev = dev;
                
 #endif
 
@@ -1132,13 +1151,13 @@ static struct super_block *yaffs_internal_read_super(int useRam, struct super_bl
                        return NULL;
                }
 
-               printk(KERN_DEBUG" erase %x\n",mtd->erase);
-               printk(KERN_DEBUG" read %x\n",mtd->read);
-               printk(KERN_DEBUG" write %x\n",mtd->write);
-               printk(KERN_DEBUG" readoob %x\n",mtd->read_oob);
-               printk(KERN_DEBUG" writeoob %x\n",mtd->write_oob);
-               printk(KERN_DEBUG" oobblock %x\n",mtd->oobblock);
-               printk(KERN_DEBUG" oobsize %x\n",mtd->oobsize);
+               //printk(KERN_DEBUG" erase %x\n",mtd->erase);
+               //printk(KERN_DEBUG" read %x\n",mtd->read);
+               //printk(KERN_DEBUG" write %x\n",mtd->write);
+               //printk(KERN_DEBUG" readoob %x\n",mtd->read_oob);
+               //printk(KERN_DEBUG" writeoob %x\n",mtd->write_oob);
+               //printk(KERN_DEBUG" oobblock %x\n",mtd->oobblock);
+               //printk(KERN_DEBUG" oobsize %x\n",mtd->oobsize);
 
 
                if(!mtd->erase ||
@@ -1185,8 +1204,11 @@ static struct super_block *yaffs_internal_read_super(int useRam, struct super_bl
                dev->readChunkFromNAND = nandmtd_ReadChunkFromNAND;
                dev->eraseBlockInNAND = nandmtd_EraseBlockInNAND;
                dev->initialiseNAND = nandmtd_InitialiseNAND;
-               
+                               
                dev->putSuperFunc = yaffs_MTDPutSuper;
+
+               yaffs_dev = dev;
+               
 #endif
        }
 
@@ -1246,6 +1268,37 @@ static DECLARE_FSTYPE(yaffs_ram_fs_type, "yaffsram", yaffs_ram_read_super, FS_SI
 static struct proc_dir_entry *my_proc_entry;
 static struct proc_dir_entry *my_proc_ram_write_entry;
 
+static char * yaffs_dump_dev(char *buf,yaffs_Device *dev,char *name)
+{
+       buf +=sprintf(buf,"\nDevice %s\n",name);
+       buf +=sprintf(buf,"startBlock......... %d\n",dev->startBlock);
+       buf +=sprintf(buf,"endBlock........... %d\n",dev->endBlock);
+       buf +=sprintf(buf,"chunkGroupBits..... %d\n",dev->chunkGroupBits);
+       buf +=sprintf(buf,"chunkGroupSize..... %d\n",dev->chunkGroupSize);
+       buf +=sprintf(buf,"nErasedBlocks...... %d\n",dev->nErasedBlocks);
+       buf +=sprintf(buf,"nTnodesCreated..... %d\n",dev->nTnodesCreated);
+       buf +=sprintf(buf,"nFreeTnodes........ %d\n",dev->nFreeTnodes);
+       buf +=sprintf(buf,"nObjectsCreated.... %d\n",dev->nObjectsCreated);
+       buf +=sprintf(buf,"nFreeObjects....... %d\n",dev->nFreeObjects);
+       buf +=sprintf(buf,"nFreeChunks........ %d\n",dev->nFreeChunks);
+       buf +=sprintf(buf,"nPageWrites........ %d\n",dev->nPageWrites);
+       buf +=sprintf(buf,"nPageReads......... %d\n",dev->nPageReads);
+       buf +=sprintf(buf,"nBlockErasures..... %d\n",dev->nBlockErasures);
+       buf +=sprintf(buf,"nGCCopies.......... %d\n",dev->nGCCopies);
+       buf +=sprintf(buf,"garbageCollections. %d\n",dev->garbageCollections);
+       buf +=sprintf(buf,"nRetriedWrites..... %d\n",dev->nRetriedWrites);
+       buf +=sprintf(buf,"nRetireBlocks...... %d\n",dev->nRetiredBlocks);
+       buf +=sprintf(buf,"eccFixed........... %d\n",dev->eccFixed);
+       buf +=sprintf(buf,"eccUnfixed......... %d\n",dev->eccUnfixed);
+       buf +=sprintf(buf,"tagsEccFixed....... %d\n",dev->tagsEccFixed);
+       buf +=sprintf(buf,"tagsEccUnfixed..... %d\n",dev->tagsEccUnfixed);
+       buf +=sprintf(buf,"cacheHits.......... %d\n",dev->cacheHits);
+       buf +=sprintf(buf,"nDeletedFiles...... %d\n",dev->nDeletedFiles);
+       buf +=sprintf(buf,"nUnlinkedFiles..... %d\n",dev->nUnlinkedFiles);
+       buf +=sprintf(buf,"nBackgroudDeletions %d\n",dev->nBackgroundDeletions);
+       
+       return buf;     
+}
 
 static int  yaffs_proc_read(
         char *page,
@@ -1257,15 +1310,18 @@ static int  yaffs_proc_read(
        )
 {
 
-       static char my_buffer[1000];
+       char my_buffer[3000];
+       char *buf;
+       buf = my_buffer;
 
        if (offset > 0) return 0;
 
        /* Fill the buffer and get its length */
-       sprintf( my_buffer, 
-               "YAFFS built:"__DATE__ " "__TIME__"\n"
-               
-       );
+       buf +=sprintf(buf,"YAFFS built:"__DATE__ " "__TIME__"\n%s\n%s\n", yaffs_fs_c_version,yaffs_guts_c_version);
+       
+       if(yaffs_dev) buf = yaffs_dump_dev(buf,yaffs_dev,"yaffs");
+       if(yaffsram_dev) buf = yaffs_dump_dev(buf,yaffsram_dev,"yaffsram");
+       
 
        strcpy(page,my_buffer);
        return strlen(my_buffer);
@@ -1290,6 +1346,8 @@ static int __init init_yaffs_fs(void)
 {
        int error = 0;
        
+       yaffs_dev = yaffsram_dev = NULL;
+       
        printk(KERN_DEBUG "yaffs " __DATE__ " " __TIME__ " Initialisation\n");
 #ifdef CONFIG_YAFFS_USE_GENERIC_RW
        printk(KERN_DEBUG "yaffs is using generic read/write (caching)\n");
@@ -1310,7 +1368,7 @@ static int __init init_yaffs_fs(void)
     }
 
 #ifdef CONFIG_YAFFS_RAM_ENABLED
-
+#if 0
     my_proc_ram_write_entry = create_proc_entry("yaffs_ram",
                                            S_IRUGO | S_IFREG,
                                           &proc_root);
@@ -1323,6 +1381,8 @@ static int __init init_yaffs_fs(void)
     {
        my_proc_ram_write_entry->write_proc = yaffs_proc_ram_write;
     }
+#endif
+
     error = register_filesystem(&yaffs_ram_fs_type);
     if(error)
     {