*
* Acknowledgements:
* * Luc van OostenRyck for numerous patches.
- * * Nick Bane for patches marked NCB.
+ * * Nick Bane for numerous patches.
* * Some code bodily lifted from JFFS2.
*/
static void yaffs_read_inode (struct inode *inode);
static struct super_block *yaffs_read_super(struct super_block * sb, void * data, int silent);
static void yaffs_put_inode (struct inode *inode);
+static void yaffs_delete_inode(struct inode *);
+static void yaffs_clear_inode(struct inode *);
+
static int yaffs_readpage(struct file *file, struct page * page);
static int yaffs_prepare_write(struct file *f, struct page *pg, unsigned offset, unsigned to);
-
static struct address_space_operations yaffs_file_address_operations = {
readpage: yaffs_readpage,
prepare_write: yaffs_prepare_write,
read_inode: yaffs_read_inode,
put_inode: yaffs_put_inode,
put_super: yaffs_put_super,
-// read_inode:
// remount_fs:
-// clear_inode:
+ delete_inode: yaffs_delete_inode,
+ clear_inode: yaffs_clear_inode,
};
if(inode)
{
- T((KERN_DEBUG"yaffs_loookup looks good\n"));
- // try to fix ln -s prob dget(dentry); // try to solve directory bug
+ T((KERN_DEBUG"yaffs_loookup dentry \n"));
+ //dget(dentry); // try to solve directory bug
d_add(dentry,inode);
yaffs_GrossUnlock(dev);
- return dentry;
+ // return dentry;
+ return NULL;
}
}
yaffs_GrossUnlock(dev);
return NULL;
+ // return (ERR_PTR(-EIO));
}
// For now put inode is just for debugging
+// Put inode is called when the inode **structure** is put.
static void yaffs_put_inode(struct inode *inode)
{
T(("yaffs_put_inode: ino %d, count %d\n",(int)inode->i_ino, atomic_read(&inode->i_count)));
- // yaffs_FlushFile(yaffs_InodeToObject(inode));
+}
+
+// clear is called to tell the fs to release any per-inode data it holds
+static void yaffs_clear_inode(struct inode *inode)
+{
+ yaffs_Object *obj = yaffs_InodeToObject(inode);
+
+ T(("yaffs_clear_inode: ino %d, count %d %s\n",(int)inode->i_ino, atomic_read(&inode->i_count),
+ obj ? "object exists" : "null object"));
+
+ if(obj)
+ {
+ obj->myInode = NULL;
+ inode->u.generic_ip = NULL;
+ }
+
}
+// delete is called when the link count is zero and the inode
+// is put (ie. nobody wants to know about it anymore, time to
+// delete the file).
+// NB Must call clear_inode()
+static void yaffs_delete_inode(struct inode *inode)
+{
+ yaffs_Object *obj = yaffs_InodeToObject(inode);
+ yaffs_Device *dev;
+
+ T(("yaffs_delete_inode: ino %d, count %d %s\n",(int)inode->i_ino, atomic_read(&inode->i_count),
+ obj ? "object exists" : "null object"));
+
+ if(obj)
+ {
+ dev = obj->myDev;
+ yaffs_GrossLock(dev);
+ yaffs_DeleteFile(obj);
+ yaffs_GrossUnlock(dev);
+ }
+ clear_inode(inode);
+}
+
static int yaffs_file_flush(struct file* file)
{
inode->u.generic_ip = obj;
+ obj->myInode = inode;
}
else
inode = iget(sb,obj->objectId);
// NB Side effect: iget calls back to yaffs_read_inode().
-
+ // iget also increments the inode's i_count
+
return inode;
}
static int yaffs_unlink(struct inode * dir, struct dentry *dentry)
{
int retVal;
+ int nlinks;
+
yaffs_Device *dev;
dev = yaffs_InodeToObject(dir)->myDev;
yaffs_GrossLock(dev);
+
+ nlinks =
+
retVal = yaffs_Unlink(yaffs_InodeToObject(dir),dentry->d_name.name);
+
+
yaffs_GrossUnlock(dev);
if( retVal == YAFFS_OK)
{
+ dentry->d_inode->i_nlink--;
return 0;
}
else
link = yaffs_Link(yaffs_InodeToObject(dir),dentry->d_name.name,obj);
+
+ if(link)
+ {
+ old_dentry->d_inode->i_nlink = yaffs_GetObjectLinkCount(obj);
+ d_instantiate(dentry, old_dentry->d_inode);
+ atomic_inc(&old_dentry->d_inode->i_count);
+ T((KERN_DEBUG"yaffs_link link count %d i_count %d\n",
+ old_dentry->d_inode->i_nlink,atomic_read(&old_dentry->d_inode->i_count)));
+
+ }
+
yaffs_GrossUnlock(dev);
+
if(link)
{
+
return 0;
}
/*
* The VFS layer already does all the dentry stuff for rename.
+ *
+ * NB: POSIX says you can rename an object over an old object of the same name
*/
static int yaffs_rename(struct inode * old_dir, struct dentry *old_dentry, struct inode * new_dir,struct dentry *new_dentry)
{
buf->f_type = YAFFS_MAGIC;
buf->f_bsize = sb->s_blocksize;
buf->f_namelen = 255;
- buf->f_blocks = dev->nBlocks * YAFFS_CHUNKS_PER_BLOCK/
+ buf->f_blocks = (dev->endBlock - dev->startBlock + 1) * YAFFS_CHUNKS_PER_BLOCK/
(sb->s_blocksize/YAFFS_BYTES_PER_CHUNK);
buf->f_files = 0;
buf->f_ffree = 0;
static struct super_block *yaffs_internal_read_super(int useRam, struct super_block * sb, void * data, int silent)
{
+ int nBlocks;
struct inode * inode;
struct dentry * root;
yaffs_Device *dev;
memset(dev,0,sizeof(yaffs_Device));
dev->genericDevice = NULL; // Not used for RAM emulation.
- dev->nBlocks = YAFFS_RAM_EMULATION_SIZE / (YAFFS_CHUNKS_PER_BLOCK * YAFFS_BYTES_PER_CHUNK);
+ nBlocks = YAFFS_RAM_EMULATION_SIZE / (YAFFS_CHUNKS_PER_BLOCK * YAFFS_BYTES_PER_CHUNK);
dev->startBlock = 1; // Don't use block 0
- dev->endBlock = dev->nBlocks - 1;
+ dev->endBlock = nBlocks - 1;
dev->writeChunkToNAND = nandemul_WriteChunkToNAND;
dev->readChunkFromNAND = nandemul_ReadChunkFromNAND;
// Set up the memory size parameters....
-// NCB dev->nBlocks = YAFFS_RAM_EMULATION_SIZE / (YAFFS_CHUNKS_PER_BLOCK * YAFFS_BYTES_PER_CHUNK);
- dev->nBlocks = mtd->size / (YAFFS_CHUNKS_PER_BLOCK * YAFFS_BYTES_PER_CHUNK);
+ nBlocks = mtd->size / (YAFFS_CHUNKS_PER_BLOCK * YAFFS_BYTES_PER_CHUNK);
dev->startBlock = 1; // Don't use block 0
- dev->endBlock = dev->nBlocks - 1;
+ dev->endBlock = nBlocks - 1;
// ... and the functions.
dev->writeChunkToNAND = nandmtd_WriteChunkToNAND;
static struct proc_dir_entry *my_proc_entry;
+static struct proc_dir_entry *my_proc_ram_write_entry;
static int yaffs_proc_read(
return strlen(my_buffer);
}
+
+static int yaffs_proc_ram_write(
+ char *page,
+ char **start,
+ off_t offset,
+ int count,
+ int *eof,
+ void *data
+ )
+{
+
+ printk(KERN_DEBUG "yaffs write size %d\n",count);
+ return count;
+}
+
static int __init init_yaffs_fs(void)
{
int error = 0;
#ifdef CONFIG_YAFFS_RAM_ENABLED
+ my_proc_ram_write_entry = create_proc_entry("yaffs_ram",
+ S_IRUGO | S_IFREG,
+ &proc_root);
+
+ if(!my_proc_ram_write_entry)
+ {
+ return -ENOMEM;
+ }
+ else
+ {
+ my_proc_ram_write_entry->write_proc = yaffs_proc_ram_write;
+ }
error = register_filesystem(&yaffs_ram_fs_type);
if(error)
{