kqid.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #include <linux/fs.h>
  2. #include <linux/quota.h>
  3. #include <linux/export.h>
  4. /**
  5. * qid_eq - Test to see if to kquid values are the same
  6. * @left: A qid value
  7. * @right: Another quid value
  8. *
  9. * Return true if the two qid values are equal and false otherwise.
  10. */
  11. bool qid_eq(struct kqid left, struct kqid right)
  12. {
  13. if (left.type != right.type)
  14. return false;
  15. switch(left.type) {
  16. case USRQUOTA:
  17. return uid_eq(left.uid, right.uid);
  18. case GRPQUOTA:
  19. return gid_eq(left.gid, right.gid);
  20. case PRJQUOTA:
  21. return projid_eq(left.projid, right.projid);
  22. default:
  23. BUG();
  24. }
  25. }
  26. EXPORT_SYMBOL(qid_eq);
  27. /**
  28. * qid_lt - Test to see if one qid value is less than another
  29. * @left: The possibly lesser qid value
  30. * @right: The possibly greater qid value
  31. *
  32. * Return true if left is less than right and false otherwise.
  33. */
  34. bool qid_lt(struct kqid left, struct kqid right)
  35. {
  36. if (left.type < right.type)
  37. return true;
  38. if (left.type > right.type)
  39. return false;
  40. switch (left.type) {
  41. case USRQUOTA:
  42. return uid_lt(left.uid, right.uid);
  43. case GRPQUOTA:
  44. return gid_lt(left.gid, right.gid);
  45. case PRJQUOTA:
  46. return projid_lt(left.projid, right.projid);
  47. default:
  48. BUG();
  49. }
  50. }
  51. EXPORT_SYMBOL(qid_lt);
  52. /**
  53. * from_kqid - Create a qid from a kqid user-namespace pair.
  54. * @targ: The user namespace we want a qid in.
  55. * @kqid: The kernel internal quota identifier to start with.
  56. *
  57. * Map @kqid into the user-namespace specified by @targ and
  58. * return the resulting qid.
  59. *
  60. * There is always a mapping into the initial user_namespace.
  61. *
  62. * If @kqid has no mapping in @targ (qid_t)-1 is returned.
  63. */
  64. qid_t from_kqid(struct user_namespace *targ, struct kqid kqid)
  65. {
  66. switch (kqid.type) {
  67. case USRQUOTA:
  68. return from_kuid(targ, kqid.uid);
  69. case GRPQUOTA:
  70. return from_kgid(targ, kqid.gid);
  71. case PRJQUOTA:
  72. return from_kprojid(targ, kqid.projid);
  73. default:
  74. BUG();
  75. }
  76. }
  77. EXPORT_SYMBOL(from_kqid);
  78. /**
  79. * from_kqid_munged - Create a qid from a kqid user-namespace pair.
  80. * @targ: The user namespace we want a qid in.
  81. * @kqid: The kernel internal quota identifier to start with.
  82. *
  83. * Map @kqid into the user-namespace specified by @targ and
  84. * return the resulting qid.
  85. *
  86. * There is always a mapping into the initial user_namespace.
  87. *
  88. * Unlike from_kqid from_kqid_munged never fails and always
  89. * returns a valid projid. This makes from_kqid_munged
  90. * appropriate for use in places where failing to provide
  91. * a qid_t is not a good option.
  92. *
  93. * If @kqid has no mapping in @targ the kqid.type specific
  94. * overflow identifier is returned.
  95. */
  96. qid_t from_kqid_munged(struct user_namespace *targ, struct kqid kqid)
  97. {
  98. switch (kqid.type) {
  99. case USRQUOTA:
  100. return from_kuid_munged(targ, kqid.uid);
  101. case GRPQUOTA:
  102. return from_kgid_munged(targ, kqid.gid);
  103. case PRJQUOTA:
  104. return from_kprojid_munged(targ, kqid.projid);
  105. default:
  106. BUG();
  107. }
  108. }
  109. EXPORT_SYMBOL(from_kqid_munged);
  110. /**
  111. * qid_valid - Report if a valid value is stored in a kqid.
  112. * @qid: The kernel internal quota identifier to test.
  113. */
  114. bool qid_valid(struct kqid qid)
  115. {
  116. switch (qid.type) {
  117. case USRQUOTA:
  118. return uid_valid(qid.uid);
  119. case GRPQUOTA:
  120. return gid_valid(qid.gid);
  121. case PRJQUOTA:
  122. return projid_valid(qid.projid);
  123. default:
  124. BUG();
  125. }
  126. }
  127. EXPORT_SYMBOL(qid_valid);