coda_linux.c 5.1 KB

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