ufs_vfsops.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. /*-
  2. * Copyright (c) 1991, 1993, 1994
  3. * The Regents of the University of California. All rights reserved.
  4. * (c) UNIX System Laboratories, Inc.
  5. * All or some portions of this file are derived from material licensed
  6. * to the University of California by American Telephone and Telegraph
  7. * Co. or Unix System Laboratories, Inc. and are reproduced herein with
  8. * the permission of UNIX System Laboratories, Inc.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions and the following disclaimer.
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in the
  17. * documentation and/or other materials provided with the distribution.
  18. * 3. Neither the name of the University nor the names of its contributors
  19. * may be used to endorse or promote products derived from this software
  20. * without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  23. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  26. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  27. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  28. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  29. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  30. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  31. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  32. * SUCH DAMAGE.
  33. *
  34. * @(#)ufs_vfsops.c 8.8 (Berkeley) 5/20/95
  35. */
  36. #include "u.h"
  37. #include "port/lib.h"
  38. #include "mem.h"
  39. #include "dat.h"
  40. #include "port/portfns.h"
  41. #include "ufsdat.h"
  42. #include <ufs/libufsdat.h>
  43. #include <ufs/freebsd_util.h>
  44. //#include <ufs/ufs/extattr.h>
  45. //#include <ufs/ufs/quota.h>
  46. #include "ufs/dinode.h"
  47. //#include <ufs/ufs/inode.h>
  48. //#include <ufs/ufs/ufsmount.h>
  49. #include "ffs_extern.h"
  50. //#ifdef UFS_DIRHASH
  51. //#include <ufs/ufs/dir.h>
  52. //#include <ufs/ufs/dirhash.h>
  53. //#endif
  54. //MALLOC_DEFINE(M_UFSMNT, "ufs_mount", "UFS mount structure");
  55. /*
  56. * Return the root of a filesystem.
  57. */
  58. int
  59. ufs_root(MountPoint *mp, int flags, vnode **vpp)
  60. {
  61. vnode *nvp;
  62. int error;
  63. error = ffs_vget(mp, (ino_t)UFS_ROOTINO, flags, &nvp);
  64. if (error)
  65. return (error);
  66. *vpp = nvp;
  67. return (0);
  68. }
  69. #if 0
  70. /*
  71. * Do operations associated with quotas
  72. */
  73. int
  74. ufs_quotactl(mp, cmds, id, arg)
  75. struct mount *mp;
  76. int cmds;
  77. uid_t id;
  78. void *arg;
  79. {
  80. #ifndef QUOTA
  81. if ((cmds >> SUBCMDSHIFT) == Q_QUOTAON)
  82. vfs_unbusy(mp);
  83. return (EOPNOTSUPP);
  84. #else
  85. struct thread *td;
  86. int cmd, type, error;
  87. td = curthread;
  88. cmd = cmds >> SUBCMDSHIFT;
  89. type = cmds & SUBCMDMASK;
  90. if (id == -1) {
  91. switch (type) {
  92. case USRQUOTA:
  93. id = td->td_ucred->cr_ruid;
  94. break;
  95. case GRPQUOTA:
  96. id = td->td_ucred->cr_rgid;
  97. break;
  98. default:
  99. if (cmd == Q_QUOTAON)
  100. vfs_unbusy(mp);
  101. return (EINVAL);
  102. }
  103. }
  104. if ((uint)type >= MAXQUOTAS) {
  105. if (cmd == Q_QUOTAON)
  106. vfs_unbusy(mp);
  107. return (EINVAL);
  108. }
  109. switch (cmd) {
  110. case Q_QUOTAON:
  111. error = quotaon(td, mp, type, arg);
  112. break;
  113. case Q_QUOTAOFF:
  114. error = quotaoff(td, mp, type);
  115. break;
  116. case Q_SETQUOTA32:
  117. error = setquota32(td, mp, id, type, arg);
  118. break;
  119. case Q_SETUSE32:
  120. error = setuse32(td, mp, id, type, arg);
  121. break;
  122. case Q_GETQUOTA32:
  123. error = getquota32(td, mp, id, type, arg);
  124. break;
  125. case Q_SETQUOTA:
  126. error = setquota(td, mp, id, type, arg);
  127. break;
  128. case Q_SETUSE:
  129. error = setuse(td, mp, id, type, arg);
  130. break;
  131. case Q_GETQUOTA:
  132. error = getquota(td, mp, id, type, arg);
  133. break;
  134. case Q_GETQUOTASIZE:
  135. error = getquotasize(td, mp, id, type, arg);
  136. break;
  137. case Q_SYNC:
  138. error = qsync(mp);
  139. break;
  140. default:
  141. error = EINVAL;
  142. break;
  143. }
  144. return (error);
  145. #endif
  146. }
  147. #endif // 0
  148. /*
  149. * Initial UFS filesystems, done only once.
  150. */
  151. int
  152. ufs_init ()
  153. {
  154. #ifdef QUOTA
  155. dqinit();
  156. #endif
  157. #ifdef UFS_DIRHASH
  158. ufsdirhash_init();
  159. #endif
  160. return (0);
  161. }
  162. /*
  163. * Uninitialise UFS filesystems, done before module unload.
  164. */
  165. int
  166. ufs_uninit ()
  167. {
  168. #ifdef QUOTA
  169. dquninit();
  170. #endif
  171. #ifdef UFS_DIRHASH
  172. ufsdirhash_uninit();
  173. #endif
  174. return (0);
  175. }
  176. #if 0
  177. /*
  178. * This is the generic part of fhtovp called after the underlying
  179. * filesystem has validated the file handle.
  180. *
  181. * Call the VFS_CHECKEXP beforehand to verify access.
  182. */
  183. int
  184. ufs_fhtovp (struct mount *mp, struct ufid *ufhp, int flags, struct vnode **vpp)
  185. {
  186. struct inode *ip;
  187. struct vnode *nvp;
  188. int error;
  189. error = VFS_VGET(mp, ufhp->ufid_ino, flags, &nvp);
  190. if (error) {
  191. *vpp = NULLVP;
  192. return (error);
  193. }
  194. ip = VTOI(nvp);
  195. if (ip->i_mode == 0 || ip->i_gen != ufhp->ufid_gen ||
  196. ip->i_effnlink <= 0) {
  197. vput(nvp);
  198. *vpp = NULLVP;
  199. return (ESTALE);
  200. }
  201. *vpp = nvp;
  202. vnode_create_vobject(*vpp, DIP(ip, i_size), curthread);
  203. return (0);
  204. }
  205. #endif // 0