Guest User

Untitled

a guest
Jun 18th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. static int
  2. ospfs_create(struct inode *dir, struct dentry *dentry, int mode, struct nameidata *nd)
  3. {
  4. ospfs_inode_t *dir_oi = ospfs_inode(dir->i_ino);
  5. uint32_t entry_ino = 0;
  6. ospfs_direntry_t *entry;
  7. ospfs_inode_t* i_struct = NULL;
  8.  
  9. /* EXERCISE: Your code here. */
  10. if (!dir_oi)
  11. return -EIO; /* Not sure if that's right error message, but anyway we should
  12. check for this */
  13.  
  14. if (dentry->d_name.len > OSPFS_MAXNAMELEN)
  15. return -ENAMETOOLONG;
  16.  
  17. if (find_direntry(dir_oi, dentry->d_name.name, dentry->d_name.len))
  18. return -EEXIST;
  19.  
  20. //find unused inode
  21. for (entry_ino = 2; entry_ino < ospfs_super->os_ninodes; entry_ino++) {
  22. i_struct = ospfs_inode(entry_ino);
  23. if (i_struct && i_struct->oi_nlink == 0) {
  24. i_struct->oi_nlink++;
  25. break;
  26. }
  27. }
  28. if (entry_ino == ospfs_super->os_ninodes || i_struct == NULL)
  29. return -ENOSPC;
  30.  
  31. /* empty file */
  32. i_struct->oi_size = 0;
  33. i_struct->oi_ftype = OSPFS_FTYPE_REG;
  34. i_struct->oi_mode = mode;
  35. memset(i_struct->oi_direct, 0, 10 * sizeof(uint32_t));
  36. i_struct->oi_indirect = 0;
  37. i_struct->oi_indirect2 = 0;
  38.  
  39. entry = create_blank_direntry(dir_oi);
  40. if (IS_ERR(entry)) {
  41. i_struct->oi_nlink--;
  42. return PTR_ERR(entry);
  43. }
  44.  
  45. entry->od_ino = entry_ino;
  46. memcpy(entry->od_name, dentry->d_name.name, dentry->d_name.len);
  47. entry->od_name[dentry->d_name.len] = 0;
  48.  
  49. //return -EINVAL; // Replace this line
  50.  
  51. /* Execute this code after your function has successfully created the
  52. file. Set entry_ino to the created file's inode number before
  53. getting here. */
  54. {
  55. struct inode *i = ospfs_mk_linux_inode(dir->i_sb, entry_ino);
  56. if (!i)
  57. return -ENOMEM;
  58. d_instantiate(dentry, i);
  59. return 0;
  60. }
  61. }
Add Comment
Please, Sign In to add comment