writing simple filesystem, Please help.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi All,

I am trying to write a sample file system.

The file system is getting mounted correctly. But, when I do file
creation operation it gives oops. Actually, when close(fd) is called
at that time oops is coming. READ and WRITE operations are working
without any error.

These are my file and inode operations
struct file_operations lfs_file_ops =
{
   .open   = lfs_open,
   .read   = lfs_read_file,
   .write  = lfs_write_file,
   .release = lfs_release_file,
};

struct inode_operations lfs_i_ops =
{
   .lookup     = simple_lookup,
   .create     = lfs_create_file,
   .unlink     = lfs_unlink_file
} ;

/* INODE OPERATIONS */

int lfs_unlink_file ( struct inode *dir, struct dentry *dentry)
{
   dir->i_ctime = dir->i_ctime;
   inode_dec_link_count(dir);
   printk ( KERN_INFO "UNLINK INODE () called.\n" );
   return 0 ;
}

int lfs_create_file (struct inode *dir, struct dentry *dentry, int
mode, struct nameidata *nd)
{
   struct super_block *sb = dir->i_sb ;
   struct inode *inode ;

   inode = lfs_make_inode(sb, mode );
   if (! inode)
       goto out_dput;
   inode->i_fop = &lfs_file_ops;
   inode->i_private = &counter;
   inode->i_ino = inode_counter++;

   insert_inode_hash(inode) ;
   inode_inc_link_count (inode) ;
   mark_inode_dirty(inode);

   d_add(dentry, inode);

   printk ( KERN_INFO "Inode Created : %ld = %s", inode->i_ino,
dentry->d_name.name) ;                    ********* I could see this
msg in the dmesg
   return 0 ;
}
struct inode *lfs_make_inode(struct super_block *sb, int mode)
{
   struct inode *ret = new_inode(sb);

   if (ret)
   {
       ret->i_mode = mode;
       ret->i_uid = ret->i_gid = 0;
       ret->i_blkbits = PAGE_CACHE_SIZE;
       ret->i_blocks = 0;
       ret->i_atime = ret->i_mtime = ret->i_ctime = CURRENT_TIME;
   }
   return ret;
}
/* INODE OPERATIONS */

/* FILE OPERATIONS */

int lfs_release_file ( struct inode *inode, struct file *flip )
{
   inode->i_private = flip->private_data ;
   printk ( KERN_INFO "RELEASE FILE () Called.\n" ) ;
   return 0 ;
}

int lfs_open(struct inode *inode, struct file *filp)
{
   filp->private_data = inode->i_private;
   printk ( KERN_INFO "OPEN Called.\n" ) ;
         ********* I could see this msg in the dmesg
   return 0;
}

ssize_t lfs_read_file(struct file *filp, char *buf, size_t count,
loff_t *offset)
{
   atomic_t *counter = (atomic_t *) filp->private_data;
   int v, len;
   char tmp[TMPSIZE];

   printk ( KERN_INFO "READ Called.\n" ) ;
       ********* I could see this msg in the dmesg

   v = atomic_read(counter);
   if (*offset > 0)
       v -= 1;  /* the value returned when offset was zero */
   else
       atomic_inc(counter);
   len = snprintf(tmp, TMPSIZE, "%d\n", v);
   if (*offset > len)
       return 0;
   if (count > len - *offset)
       count = len - *offset;
   if (copy_to_user(buf, tmp + *offset, count))
       return -EFAULT;
   *offset += count;
   return count;
}

ssize_t lfs_write_file(struct file *filp, const char *buf, size_t
count, loff_t *offset)
{
   atomic_t *counter = (atomic_t *) filp->private_data;
   char tmp[TMPSIZE];

   printk ( KERN_INFO "WRITE Called.\n" ) ;
                        ********* I could see this msg in the dmesg

   if (*offset != 0)
       return -EINVAL;

   if (count >= TMPSIZE)
       return -EINVAL;
   memset(tmp, 0, TMPSIZE);
   if (copy_from_user(tmp, buf, count))
       return -EFAULT;

   atomic_set(counter, simple_strtol(tmp, NULL, 10));
   return count;
}

/* FILE OPERATIONS */

Here is the oops msg.

[ 4960.322267] Inode Created : 17190 = test<1>BUG: unable to handle
kernel NULL pointer dereference at virtual address 00000000
[ 4960.322328] printing eip:
[ 4960.322332] c01f3ffe
[ 4960.322335] *pde = 00000000
[ 4960.322341] Oops: 0000 [#2]
[ 4960.322344] SMP
[ 4960.322350] Modules linked in: fs cpufreq_stats
cpufreq_ondemandfreq_table ac evdev thermal processor fan
[ 4960.322370] CPU: 1
[ 4960.322372] EIP: 0060:[<c01f3ffe>] Not tainted VLI
[ 4960.322376] EFLAGS: 00010282 (2.6.20 #8)
[ 4960.322386
] EIP is at list_del+0xa/0x61
[ 4960.322391] eax: f8868080   ebx: f8868044   ecx: 00000000   edx:
e75ef5cc
[ 4960.322398] esi: f8868080   edi: 00000000   ebp: e9464f30   esp:
e9464f20
[
4960.322403
] ds: 007b   es: 007b   ss: 0068
[ 4960.322409] Process bash (pid: 6062, ti=e9464000 task=f751b4f0
task.ti=e9464000)
[ 4960.322415] Stack: e75ef5cc e9464f30 c0344186 f8868044 e9464f48

c0179342 e75ef5cc 00000008
[ 4960.322430]        f599e03c e75ef5cc e9464f70 c0155b0a 00000000
00000000 e826b1cc dfff0988
[ 4960.322445]        f599e03c e75ef5cc f7baaca8 00000000 e9464f78
c0155bd8 e9464f90 c0153610
[ 4960.322459
] Call Trace:
[ 4960.322462]  [<c01048a2>] show_trace_log_lvl+0x1a/0x2f
[ 4960.322472]  [<c0104954>] show_stack_log_lvl+0x9d/0xa5
[ 4960.322481]  [<c0104af1>] show_registers+0x195/0x26b
[ 4960.322489]  [<c0104ce0>] die+0x119/0x21a
[ 4960.322496]  [<c034713d>] do_page_fault+0x443/0x514
[ 4960.322504]  [<c034597c>] error_code+0x7c/0x84
[ 4960.322511]  [<c0179342>] eventpoll_release_file+0x25/0x69
[ 4960.322519]  [<c0155b0a>] __fput+0xa3/0x15a
[ 4960.322526]  [<c0155bd8>] fput+0x17/0x19
[ 4960.322532]  [<c0153610>] filp_close+0x54/0x5c
[ 4960.322539]  [<c015e6e9>] sys_dup2+0xd0/0xfc
[ 4960.322547]  [<c0103854>] sysenter_past_esp+0x5d/0x99
[ 4960.322555]  =======================
[ 4960.322558] Code: 00 00 8d 4b 0c 8b 51 04 8d 46 0c e8 72 00 00 00
89 f8 e8 87 fe ff ff 83 c4 10 5b 5e 5f 5d c3 90 90 55 89 e5 53 83 ec
0c 8b 48 04 <8b> 11 39 c2 74 18 89 54 24 08 89 44 24 04 c7 04 24 92 37
3e c0
[ 4960.322635] EIP: [<c01f3ffe>] list_del+0xa/0x61 SS:ESP 0068:e9464f20

I went through the code in fput(), __fput().

_fput() --> calls eventpoll_release(file); Where it is panicking in my case.

after eventpoll_release(file); returns
__fput() --> calls file->f_op->release(inode, file); thats why my
file_operations->release() is not getting called.

A flow of functions in eventpoll_release(file)
eventpoll_release(file)
{
     Calls    eventpoll_release_file(file);
      /* BUT IT A INLINE FUNCTION */
}

eventpoll_release_file(file);
{
ep_list_del(&epi->fllink);
        /* it finally results into list_del */
ep_remove(ep, epi);
         /* it finally results into list_del */
}

Only this far I could reach. But, I am not getting what I have done wrong.
I am stuck here. Please tell me how should I proceed further?

Thanks and Regards,
Prasad.
-
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [Samba]     [Device Mapper]     [CEPH Development]
  Powered by Linux