Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static int
- ospfs_create(struct inode *dir, struct dentry *dentry, int mode, struct nameidata *nd)
- {
- ospfs_inode_t *dir_oi = ospfs_inode(dir->i_ino);
- uint32_t entry_ino = 0;
- ospfs_direntry_t *entry;
- ospfs_inode_t* i_struct = NULL;
- /* EXERCISE: Your code here. */
- if (!dir_oi)
- return -EIO; /* Not sure if that's right error message, but anyway we should
- check for this */
- if (dentry->d_name.len > OSPFS_MAXNAMELEN)
- return -ENAMETOOLONG;
- if (find_direntry(dir_oi, dentry->d_name.name, dentry->d_name.len))
- return -EEXIST;
- //find unused inode
- for (entry_ino = 2; entry_ino < ospfs_super->os_ninodes; entry_ino++) {
- i_struct = ospfs_inode(entry_ino);
- if (i_struct && i_struct->oi_nlink == 0) {
- i_struct->oi_nlink++;
- break;
- }
- }
- if (entry_ino == ospfs_super->os_ninodes || i_struct == NULL)
- return -ENOSPC;
- /* empty file */
- i_struct->oi_size = 0;
- i_struct->oi_ftype = OSPFS_FTYPE_REG;
- i_struct->oi_mode = mode;
- memset(i_struct->oi_direct, 0, 10 * sizeof(uint32_t));
- i_struct->oi_indirect = 0;
- i_struct->oi_indirect2 = 0;
- entry = create_blank_direntry(dir_oi);
- if (IS_ERR(entry)) {
- i_struct->oi_nlink--;
- return PTR_ERR(entry);
- }
- entry->od_ino = entry_ino;
- memcpy(entry->od_name, dentry->d_name.name, dentry->d_name.len);
- entry->od_name[dentry->d_name.len] = 0;
- //return -EINVAL; // Replace this line
- /* Execute this code after your function has successfully created the
- file. Set entry_ino to the created file's inode number before
- getting here. */
- {
- struct inode *i = ospfs_mk_linux_inode(dir->i_sb, entry_ino);
- if (!i)
- return -ENOMEM;
- d_instantiate(dentry, i);
- return 0;
- }
- }
Add Comment
Please, Sign In to add comment