Inode number changing
Ganesh Patil
patil.ganesh170 at gmail.com
Fri Mar 9 14:02:06 EST 2012
On Sat, Mar 10, 2012 at 12:18 AM, Manish Katiyar <mkatiyar at gmail.com> wrote:
> > Sir, every time when I modify file content then file's inode get change.
> > Why this is happening?
> > Below I have pasted the output please check inode numbers.
>
> Without looking at the code and knowing what you are doing, its close
> to impossible to say what inode you are accessing or what you are
> doing. On my wildest guess, I can think of that you are probably
> trying to modify something in editor, and the inode number that is
> getting printed is one of the temp files that the editor may be
> creating underneath( similar to .swp files of vi).
>
--
> Thanks -
> Manish
>
Yes sir, I am trying to modify my file in vim editor.
below I have pasted my code :
#include <linux/kernel.h>
#include<linux/module.h>
#include<linux/fs.h>
#include<linux/namei.h>
#include<linux/path.h>
#include<linux/mount.h>
#include<linux/myheader.h>
struct ext4_inode1 {
__le16 i_mode; /* File mode */
__le16 i_uid; /* Low 16 bits of Owner Uid */
__le32 i_size_lo; /* Size in bytes */
__le32 i_atime; /* Access time */
__le32 i_ctime; /* Inode Change time */
__le32 i_mtime; /* Modification time */
__le32 i_dtime; /* Deletion Time */
__le16 i_gid; /* Low 16 bits of Group Id */
__le16 i_links_count; /* Links count */
__le32 i_blocks_lo; /* Blocks count */
__le32 i_flags; /* File flags */
union {
struct {
__le32 l_i_version;
} linux1;
struct {
__u32 h_i_translator;
} hurd1;
struct {
__u32 m_i_reserved1;
} masix1;
} osd1; /* OS dependent 1 */
__le32 i_block[EXT4_N_BLOCKS];/* Pointers to blocks */
__le32 i_generation; /* File version (for NFS) */
__le32 i_file_acl_lo; /* File ACL */
__le32 i_size_high;
__le32 i_obso_faddr; /* Obsoleted fragment address */
union {
struct {
__le16 l_i_blocks_high; /* were l_i_reserved1 */
__le16 l_i_file_acl_high;
__le16 l_i_uid_high; /* these 2 fields */
__le16 l_i_gid_high; /* were reserved2[0] */
__u32 l_i_reserved2;
} linux2;
struct {
__le16 h_i_reserved1; /* Obsoleted fragment
number/size which are removed in ext4 */
__u16 h_i_mode_high;
__u16 h_i_uid_high;
__u16 h_i_gid_high;
__u32 h_i_author;
} hurd2;
struct {
__le16 h_i_reserved1; /* Obsoleted fragment
number/size which are removed in ext4 */
__le16 m_i_file_acl_high;
__u32 m_i_reserved2[2];
} masix2;
} osd2; /* OS dependent 2 */
__le16 i_extra_isize;
__le16 i_pad1;
__le32 i_ctime_extra; /* extra Change time (nsec << 2 |
epoch) */
__le32 i_mtime_extra; /* extra Modification time(nsec << 2 |
epoch) */
__le32 i_atime_extra; /* extra Access time (nsec << 2 |
epoch) */
__le32 i_crtime; /* File Creation time */
__le32 i_crtime_extra; /* extra FileCreationtime (nsec << 2 |
epoch) */
__le32 i_version_hi; /* high 32 bits for 64-bit version */
};
typedef struct ext4_inode ext4_inode1;
extern int ext4_get_inode_loc(struct inode *, struct ext4_iloc *);
int init_module(void)
{
char buf[200]="/mnt/one/a.txt";
struct nameidata nd;
struct path path1;
struct dentry *dentry1;
struct inode *d_inode1;
struct ext4_iloc iloc;
int ret,i;
struct ext4_inode *e4_inode=NULL;
ext4_inode1 *m1;
path_lookup(buf, LOOKUP_CONTINUE, &nd);
path1=nd.path;
dentry1=path1.dentry;
d_inode1=dentry1->d_inode;
m1 = (ext4_inode1 *) kmalloc (sizeof (ext4_inode1), GFP_KERNEL);
//m1->i_ino=d_inode1->i_ino;
printk(KERN_INFO "inode no of file=%ld",d_inode1->i_ino);
ret= ext4_get_inode_loc(d_inode1, &iloc);
e4_inode= ext4_raw_inode(&iloc);
m1->i_size_lo=e4_inode->i_size_lo;
printk(KERN_INFO "size of file =%d",e4_inode->i_size_lo);
printk(KERN_INFO "size of file copied =%d",m1->i_size_lo);
printk(KERN_INFO "data blocks=");
for(i=0;i<5;i++)
{
printk(KERN_INFO "%d",e4_inode->i_block[i]);
}
return 0;
}
void cleanup_module(void)
{
printk(KERN_INFO "Goodbye world 1.\n");
}
--
Regards,
Ganesh Patil.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20120310/00f00636/attachment-0001.html
More information about the Kernelnewbies
mailing list