struct inode *samplefs_get_inode(struct super_block *sb, int mode, dev_t dev) { struct inode * inode = new_inode(sb); struct samplefs_sb_info * sfs_sb = SFS_SB(sb); if (inode) { inode->i_mode = mode; inode->i_uid = current->fsuid; inode->i_gid = current->fsgid; inode->i_blocks = 0; inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME; printk(KERN_INFO "about to set inode ops\n"); switch (mode & S_IFMT) { default: init_special_inode(inode, mode, dev); break; case S_IFREG: printk(KERN_INFO "file inode\n"); inode->i_op = &sfs_file_inode_ops; break; case S_IFDIR: printk(KERN_INFO "directory inode sfs_sb: %p\n",sfs_sb); inode->i_op = &sfs_dir_inode_ops; inode->i_fop = &simple_dir_operations; /* link == 2 (for initial ".." and "." entries) */ inode->i_nlink++; break; } } return inode; }
static int samplefs_fill_super(struct super_block * sb, void * data, int silent) { struct inode * inode; struct samplefs_sb_info * sfs_sb; sb->s_maxbytes = MAX_LFS_FILESIZE; /* NB: may be too large for mem */ sb->s_blocksize = PAGE_CACHE_SIZE; sb->s_blocksize_bits = PAGE_CACHE_SHIFT; sb->s_magic = SAMPLEFS_MAGIC; sb->s_op = &samplefs_super_ops; sb->s_time_gran = 1; /* 1 nanosecond time granularity */ printk(KERN_INFO "samplefs: fill super\n"); inode = samplefs_get_inode(sb, S_IFDIR | 0755, 0); /* inode = iget(sb, SAMPLEFS_ROOT_I); was oopsing here */ if (!inode) return -ENOMEM; #ifdef CONFIG_SAMPLEFS_DEBUG printk(KERN_INFO "samplefs: about to alloc s_fs_info\n"); #endif sb->s_fs_info = kzalloc(sizeof(struct samplefs_sb_info), GFP_KERNEL); sfs_sb = SFS_SB(sb); if (!sfs_sb) { iput(inode); return -ENOMEM; } printk(KERN_INFO "samplefs: about to alloc root inode\n"); sb->s_root = d_make_root(inode); if (!sb->s_root) { iput(inode); kfree(sfs_sb); return -ENOMEM; } /* below not needed for many fs - but an example of per fs sb data */ sfs_sb->local_nls = load_nls_default(); samplefs_parse_mount_options(data, sfs_sb); /* FS-FILLIN your filesystem specific mount logic/checks here */ return 0; }
static int sfs_ci_hash(const struct dentry *dentry, struct qstr *q) { struct nls_table *codepage = SFS_SB(dentry->d_inode->i_sb)->local_nls; unsigned long hash; int i; hash = init_name_hash(); for (i = 0; i < q->len; i++) hash = partial_name_hash(nls_tolower(codepage, q->name[i]), hash); q->hash = end_name_hash(hash); return 0; }
struct sfs_inode *sfs_get_inode(struct super_block *sb, ino_t ino, struct buffer_head **p) { struct sfs_sb_info *sbi = SFS_SB(sb); size_t block, offset; block = sfs_inode_block(sbi, ino); offset = sfs_inode_offset(sbi, ino); *p = sb_bread(sb, block); if (!*p) { pr_debug("Unable to read inode block\n"); return NULL; } return (struct sfs_inode *)((*p)->b_data + offset); }
static void samplefs_put_super(struct super_block *sb) { struct samplefs_sb_info *sfs_sb; sfs_sb = SFS_SB(sb); if (sfs_sb == NULL) { /* Empty superblock info passed to unmount */ return; } unload_nls(sfs_sb->local_nls); /* FS-FILLIN your fs specific umount logic here */ kfree(sfs_sb); }
static int sfs_ci_compare(struct dentry *dentry, struct qstr *a, struct qstr *b) { struct nls_table *codepage = SFS_SB(dentry->d_inode->i_sb)->local_nls; if ((a->len == b->len) && (nls_strnicmp(codepage, a->name, b->name, a->len) == 0)) { /* * To preserve case, don't let an existing negative dentry's * case take precedence. If a is not a negative dentry, this * should have no side effects */ memcpy((unsigned char *)a->name, b->name, a->len); return 0; } return 1; }
struct inode *sfs_iget(struct super_block *sb, ino_t ino) { struct sfs_sb_info *sbi = SFS_SB(sb); struct buffer_head *bh; struct sfs_inode *di; struct sfs_inode_info *si; struct inode *inode; size_t block, offset; inode = iget_locked(sb, ino); if (!inode) return ERR_PTR(-ENOMEM); if (!(inode->i_state & I_NEW)) return inode; si = SFS_INODE(inode); block = sfs_inode_block(sbi, ino); offset = sfs_inode_offset(sbi, ino); pr_debug("sfs reads inode %lu from %lu block with offset %lu\n", (unsigned long)ino, (unsigned long)block, (unsigned long)offset); bh = sb_bread(sb, block); if (!bh) { pr_err("cannot read block %lu\n", (unsigned long)block); goto read_error; } di = (struct sfs_inode *)(bh->b_data + offset); sfs_inode_fill(si, di); brelse(bh); sfs_set_inode(inode, new_decode_dev(le32_to_cpu(si->blkaddr[0]))); unlock_new_inode(inode); return inode; read_error: pr_err("sfs cannot read inode %lu\n", (unsigned long)ino); iget_failed(inode); return ERR_PTR(-EIO); }
static int samplefs_fill_super(struct super_block *sb, void *data, int silent) { struct inode *inode; struct samplefs_sb_info *sfs_sb; sb->s_maxbytes = MAX_LFS_FILESIZE; /* NB: may be too large for mem */ sb->s_blocksize = PAGE_SIZE; sb->s_blocksize_bits = PAGE_SHIFT; sb->s_magic = SAMPLEFS_MAGIC; sb->s_op = &samplefs_super_ops; sb->s_time_gran = 1; /* 1 nanosecond time granularity */ /* Eventually replace iget with: inode = samplefs_get_inode(sb, S_IFDIR | 0755, 0); */ inode = iget_locked(sb, SAMPLEFS_ROOT_I); if (!inode) return -ENOMEM; unlock_new_inode(inode); sb->s_fs_info = kzalloc(sizeof(struct samplefs_sb_info), GFP_KERNEL); sfs_sb = SFS_SB(sb); if (!sfs_sb) { iput(inode); return -ENOMEM; } sb->s_root = d_make_root(inode); if (!sb->s_root) { iput(inode); kfree(sfs_sb); return -ENOMEM; } /* below not needed for many fs - but an example of per fs sb data */ sfs_sb->local_nls = load_nls_default(); samplefs_parse_mount_options(data, sfs_sb); /* FS-FILLIN your filesystem specific mount logic/checks here */ return 0; }