coda_linux.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /*
  2. * Inode operations for Coda filesystem
  3. * Original version: (C) 1996 P. Braam and M. Callahan
  4. * Rewritten for Linux 2.1. (C) 1997 Carnegie Mellon University
  5. *
  6. * Carnegie Mellon encourages users to contribute improvements to
  7. * the Coda project. Contact Peter Braam (coda@cs.cmu.edu).
  8. */
  9. #include <linux/types.h>
  10. #include <linux/kernel.h>
  11. #include <linux/time.h>
  12. #include <linux/fs.h>
  13. #include <linux/stat.h>
  14. #include <linux/errno.h>
  15. #include <linux/uaccess.h>
  16. #include <linux/string.h>
  17. #include <linux/coda.h>
  18. #include <linux/coda_psdev.h>
  19. #include "coda_linux.h"
  20. /* initialize the debugging variables */
  21. int coda_fake_statfs;
  22. /* print a fid */
  23. char * coda_f2s(struct CodaFid *f)
  24. {
  25. static char s[60];
  26. sprintf(s, "(%08x.%08x.%08x.%08x)", f->opaque[0], f->opaque[1], f->opaque[2], f->opaque[3]);
  27. return s;
  28. }
  29. /* recognize special .CONTROL name */
  30. int coda_iscontrol(const char *name, size_t length)
  31. {
  32. return ((CODA_CONTROLLEN == length) &&
  33. (strncmp(name, CODA_CONTROL, CODA_CONTROLLEN) == 0));
  34. }
  35. unsigned short coda_flags_to_cflags(unsigned short flags)
  36. {
  37. unsigned short coda_flags = 0;
  38. if ((flags & O_ACCMODE) == O_RDONLY)
  39. coda_flags |= C_O_READ;
  40. if ((flags & O_ACCMODE) == O_RDWR)
  41. coda_flags |= C_O_READ | C_O_WRITE;
  42. if ((flags & O_ACCMODE) == O_WRONLY)
  43. coda_flags |= C_O_WRITE;
  44. if (flags & O_TRUNC)
  45. coda_flags |= C_O_TRUNC;
  46. if (flags & O_CREAT)
  47. coda_flags |= C_O_CREAT;
  48. if (flags & O_EXCL)
  49. coda_flags |= C_O_EXCL;
  50. return coda_flags;
  51. }
  52. /* utility functions below */
  53. void coda_vattr_to_iattr(struct inode *inode, struct coda_vattr *attr)
  54. {
  55. int inode_type;
  56. /* inode's i_flags, i_ino are set by iget
  57. XXX: is this all we need ??
  58. */
  59. switch (attr->va_type) {
  60. case C_VNON:
  61. inode_type = 0;
  62. break;
  63. case C_VREG:
  64. inode_type = S_IFREG;
  65. break;
  66. case C_VDIR:
  67. inode_type = S_IFDIR;
  68. break;
  69. case C_VLNK:
  70. inode_type = S_IFLNK;
  71. break;
  72. default:
  73. inode_type = 0;
  74. }
  75. inode->i_mode |= inode_type;
  76. if (attr->va_mode != (u_short) -1)
  77. inode->i_mode = attr->va_mode | inode_type;
  78. if (attr->va_uid != -1)
  79. inode->i_uid = make_kuid(&init_user_ns, (uid_t) attr->va_uid);
  80. if (attr->va_gid != -1)
  81. inode->i_gid = make_kgid(&init_user_ns, (gid_t) attr->va_gid);
  82. if (attr->va_nlink != -1)
  83. set_nlink(inode, attr->va_nlink);
  84. if (attr->va_size != -1)
  85. inode->i_size = attr->va_size;
  86. if (attr->va_size != -1)
  87. inode->i_blocks = (attr->va_size + 511) >> 9;
  88. if (attr->va_atime.tv_sec != -1)
  89. inode->i_atime = attr->va_atime;
  90. if (attr->va_mtime.tv_sec != -1)
  91. inode->i_mtime = attr->va_mtime;
  92. if (attr->va_ctime.tv_sec != -1)
  93. inode->i_ctime = attr->va_ctime;
  94. }
  95. /*
  96. * BSD sets attributes that need not be modified to -1.
  97. * Linux uses the valid field to indicate what should be
  98. * looked at. The BSD type field needs to be deduced from linux
  99. * mode.
  100. * So we have to do some translations here.
  101. */
  102. void coda_iattr_to_vattr(struct iattr *iattr, struct coda_vattr *vattr)
  103. {
  104. unsigned int valid;
  105. /* clean out */
  106. vattr->va_mode = -1;
  107. vattr->va_uid = (vuid_t) -1;
  108. vattr->va_gid = (vgid_t) -1;
  109. vattr->va_size = (off_t) -1;
  110. vattr->va_atime.tv_sec = (time_t) -1;
  111. vattr->va_atime.tv_nsec = (time_t) -1;
  112. vattr->va_mtime.tv_sec = (time_t) -1;
  113. vattr->va_mtime.tv_nsec = (time_t) -1;
  114. vattr->va_ctime.tv_sec = (time_t) -1;
  115. vattr->va_ctime.tv_nsec = (time_t) -1;
  116. vattr->va_type = C_VNON;
  117. vattr->va_fileid = -1;
  118. vattr->va_gen = -1;
  119. vattr->va_bytes = -1;
  120. vattr->va_nlink = -1;
  121. vattr->va_blocksize = -1;
  122. vattr->va_rdev = -1;
  123. vattr->va_flags = 0;
  124. /* determine the type */
  125. #if 0
  126. mode = iattr->ia_mode;
  127. if ( S_ISDIR(mode) ) {
  128. vattr->va_type = C_VDIR;
  129. } else if ( S_ISREG(mode) ) {
  130. vattr->va_type = C_VREG;
  131. } else if ( S_ISLNK(mode) ) {
  132. vattr->va_type = C_VLNK;
  133. } else {
  134. /* don't do others */
  135. vattr->va_type = C_VNON;
  136. }
  137. #endif
  138. /* set those vattrs that need change */
  139. valid = iattr->ia_valid;
  140. if ( valid & ATTR_MODE ) {
  141. vattr->va_mode = iattr->ia_mode;
  142. }
  143. if ( valid & ATTR_UID ) {
  144. vattr->va_uid = (vuid_t) from_kuid(&init_user_ns, iattr->ia_uid);
  145. }
  146. if ( valid & ATTR_GID ) {
  147. vattr->va_gid = (vgid_t) from_kgid(&init_user_ns, iattr->ia_gid);
  148. }
  149. if ( valid & ATTR_SIZE ) {
  150. vattr->va_size = iattr->ia_size;
  151. }
  152. if ( valid & ATTR_ATIME ) {
  153. vattr->va_atime = iattr->ia_atime;
  154. }
  155. if ( valid & ATTR_MTIME ) {
  156. vattr->va_mtime = iattr->ia_mtime;
  157. }
  158. if ( valid & ATTR_CTIME ) {
  159. vattr->va_ctime = iattr->ia_ctime;
  160. }
  161. }