I read about inode structure that it always point to data blocks for that file. but in case of character device files created with mknod command doesn't have any data block associated with it. so how kernel understands by using major and minor number a perticular device file. and for character device file what is the structure of inode ?
Major and minor numbers are encoded and stored in the disk block pointers. This is similar to storing the name of a symlink within the inode. As you rightly pointed out, there's no disk block associated with them.
Relevant code for character devices stored on an ext2fs is below (fs/ext2/inode.c)
/* In function ext2_write_inode */ if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode)) { if (old_valid_dev(inode->i_rdev)) { raw_inode->i_block[0] = cpu_to_le32(old_encode_dev(inode->i_rdev)); raw_inode->i_block[1] = 0; } else { raw_inode->i_block[0] = 0; raw_inode->i_block[1] = cpu_to_le32(new_encode_dev(inode->i_rdev)); raw_inode->i_block[2] = 0; } } else for (n = 0; n < EXT2_N_BLOCKS; n++) raw_inode->i_block[n] = ei->i_data[n]; When reading the inode (say with ls -al), following code does the decoding /* In function ext2_read_inode */ ... } else { inode->i_op = &ext2_special_inode_operations; if (raw_inode->i_block[0]) init_special_inode(inode, inode->i_mode, old_decode_dev(le32_to_cpu(raw_inode->i_block[0]))); else init_special_inode(inode, inode->i_mode, new_decode_dev(le32_to_cpu(raw_inode->i_block[1]))); } -- Pradeep Padala http://ppadala.blogspot.com -- Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ FAQ: http://kernelnewbies.org/faq/