"Fossies" - the Fresh Open Source Software Archive

Member "coda-6.9.5/coda-src/dir/fid.c" (3 Nov 2006, 4725 Bytes) of package /linux/misc/old/coda-6.9.5.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "fid.c" see the Fossies "Dox" file reference documentation.

    1 /* BLURB gpl
    2 
    3                            Coda File System
    4                               Release 6
    5 
    6           Copyright (c) 1987-2003 Carnegie Mellon University
    7                   Additional copyrights listed below
    8 
    9 This  code  is  distributed "AS IS" without warranty of any kind under
   10 the terms of the GNU General Public Licence Version 2, as shown in the
   11 file  LICENSE.  The  technical and financial  contributors to Coda are
   12 listed in the file CREDITS.
   13 
   14                         Additional copyrights
   15                            none currently
   16 
   17 #*/
   18 
   19 #ifdef HAVE_CONFIG_H
   20 #include <config.h>
   21 #endif
   22 
   23 #include <stdio.h>
   24 #include "coda_string.h"
   25 #include <sys/types.h>
   26 #include <sys/time.h>
   27 #include <netinet/in.h>
   28 #include <fcntl.h>
   29 
   30 
   31 #include "coda_assert.h"
   32 #include "codadir.h"
   33 #include "util.h"
   34 
   35 /*
   36  * Public FID routines: to be taken elsewhere.
   37  */
   38 
   39 void FID_PrintFid(const DirFid *fid)
   40 {
   41     printf("vnode: %08x, unique %08x\n", fid->Vnode, fid->Unique);
   42     return;
   43 }
   44 
   45 void FID_CpyVol(struct ViceFid *target, const struct ViceFid *source)
   46 {
   47     CODA_ASSERT(target && source);
   48     target->Volume = source->Volume;
   49 }
   50 
   51 
   52 void FID_Int2DFid(DirFid *fid, const int vnode, const int unique)
   53 {
   54     CODA_ASSERT(fid);
   55 
   56     fid->Vnode = vnode;
   57     fid->Unique = unique;
   58     return;
   59 }
   60 
   61 void FID_NFid2Int(const struct DirNFid *fid, VnodeId *vnode, Unique_t *unique)
   62 {
   63     *vnode = ntohl(fid->dnf_vnode);
   64     *unique = ntohl(fid->dnf_unique);
   65     return;
   66 }
   67 
   68 void FID_VFid2DFid(const struct ViceFid *vf, DirFid *df)
   69 {
   70     CODA_ASSERT( vf && df );
   71     df->Vnode = vf->Vnode;
   72     df->Unique = vf->Unique;
   73 
   74 }
   75 
   76 void FID_DFid2VFid(const DirFid *df, struct ViceFid *vf)
   77 {
   78     CODA_ASSERT( vf && df );
   79     vf->Vnode = df->Vnode;
   80     vf->Unique = df->Unique;
   81 }
   82 
   83 int FID_Cmp(const struct ViceFid *fa, const struct ViceFid *fb) 
   84 {
   85     if ((fa->Volume) < (fb->Volume)) 
   86         return(-1);
   87     if ((fa->Volume) > (fb->Volume)) 
   88         return(1);
   89     if ((fa->Vnode) < (fb->Vnode)) 
   90         return(-1);
   91     if ((fa->Vnode) > (fb->Vnode)) 
   92         return(1);
   93     if ((fa->Unique) < (fb->Unique)) 
   94         return(-1);
   95     if ((fa->Unique) > (fb->Unique)) 
   96         return(1);
   97     return(0);
   98 }
   99 
  100 int FID_EQ(const struct ViceFid *fa, const struct ViceFid *fb)
  101 {
  102     if  (fa->Volume != fb->Volume) 
  103         return 0;
  104     if  (fa->Vnode != fb->Vnode) 
  105         return 0;
  106     if  (fa->Unique != fb->Unique) 
  107         return 0;
  108     return 1;
  109 }
  110 
  111 int FID_VolEQ(const struct ViceFid *fa, const struct ViceFid *fb)
  112 {
  113     if  (fa->Volume != fb->Volume) 
  114         return 0;
  115     return 1;
  116 }
  117 
  118 /* to determine if the volume is the local copy during a repair/conflict */
  119 static VolumeId LocalFakeVid = 0xffffffff;
  120 
  121 /* was this fid created during a disconnection */
  122 static VnodeId LocalFileVnode = 0xfffffffe;
  123 static VnodeId LocalDirVnode  = 0xffffffff;
  124 int FID_IsDisco(const struct ViceFid *x)
  125 {
  126   return  ( (x->Vnode == LocalFileVnode) || (x->Vnode == LocalDirVnode));
  127 }
  128 
  129 int FID_IsLocalDir(const struct ViceFid *fid)
  130 {
  131     return fid->Vnode == LocalDirVnode;
  132 }
  133 
  134 int FID_IsLocalFile(const struct ViceFid *fid)
  135 {
  136     return fid->Vnode == LocalFileVnode;
  137 }
  138 
  139 void FID_MakeDiscoFile(struct ViceFid *fid, VolumeId vid, 
  140                   Unique_t unique)
  141 {
  142     fid->Volume = vid;
  143     fid->Vnode = LocalFileVnode;
  144     fid->Unique = unique;
  145 
  146 }
  147 
  148 void FID_MakeDiscoDir(struct ViceFid *fid, VolumeId vid,
  149                  Unique_t unique)
  150 {
  151     fid->Volume = vid;
  152     fid->Vnode = LocalDirVnode;
  153     fid->Unique = unique;
  154 
  155 }
  156 
  157 static VnodeId FakeVnode = 0xfffffffc;
  158 
  159 void FID_MakeSubtreeRoot(struct ViceFid *fid, VolumeId vid, 
  160                 Unique_t unique)
  161 {
  162     fid->Volume = vid;
  163     fid->Vnode = FakeVnode;
  164     fid->Unique = unique;
  165 }
  166                 
  167 /* Local stuff is for the repair tree arising from client copies */
  168 void FID_MakeLocalDir(struct ViceFid *fid, Unique_t unique)
  169 {
  170     fid->Volume = LocalFakeVid;
  171     fid->Vnode = LocalDirVnode;
  172     fid->Unique = unique;
  173 
  174 }
  175 
  176 
  177 
  178 void FID_MakeLocalFile(struct ViceFid *fid, Unique_t unique)
  179 {
  180     fid->Volume = LocalFakeVid;
  181     fid->Vnode = LocalFileVnode;
  182     fid->Unique = unique;
  183 
  184 }
  185 
  186 /* directory vnode number for dangling links during conflicts:
  187    top of the local subtree expanded by repair.*/
  188 int FID_IsFakeRoot(struct ViceFid *fid) 
  189 {
  190     return ((fid)->Vnode == FakeVnode);
  191 }
  192 
  193 void FID_MakeLocalSubtreeRoot(struct ViceFid *fid, Unique_t unique)
  194 {
  195     fid->Volume = LocalFakeVid;
  196     fid->Vnode = FakeVnode;
  197     fid->Unique = unique;
  198 
  199 }
  200 
  201 
  202 /* Roots of volumes */
  203 static VnodeId ROOT_VNODE = 1;
  204 static Unique_t ROOT_UNIQUE = 1;
  205 
  206 void FID_MakeRoot(struct ViceFid *fid)
  207 {
  208     fid->Vnode = ROOT_VNODE;
  209     fid->Unique = ROOT_UNIQUE;
  210 }
  211 
  212 int FID_IsVolRoot(const struct ViceFid *fid)
  213 {
  214     return ((fid->Vnode == ROOT_VNODE) && (fid->Unique == ROOT_UNIQUE));
  215 
  216 }
  217 
  218 char *FID_(const struct ViceFid *fid)
  219 {
  220     static char buf[4][28];
  221     static int i = 0;
  222     if (++i >= 4) i = 0;
  223     sprintf(buf[i], "%x.%x.%x", (unsigned)fid->Volume,
  224         (unsigned)fid->Vnode, (unsigned)fid->Unique);
  225     return buf[i];
  226 }
  227