"Fossies" - the Fresh Open Source Software Archive

Member "coda-6.9.5/coda-src/vol/vldb.cc" (1 Aug 2007, 5311 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 "vldb.cc" 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 
   16 #*/
   17 
   18 /*
   19                          IBM COPYRIGHT NOTICE
   20 
   21                           Copyright (C) 1986
   22              International Business Machines Corporation
   23                          All Rights Reserved
   24 
   25 This  file  contains  some  code identical to or derived from the 1986
   26 version of the Andrew File System ("AFS"), which is owned by  the  IBM
   27 Corporation.   This  code is provided "AS IS" and IBM does not warrant
   28 that it is free of infringement of  any  intellectual  rights  of  any
   29 third  party.    IBM  disclaims  liability of any kind for any damages
   30 whatsoever resulting directly or indirectly from use of this  software
   31 or  of  any  derivative work.  Carnegie Mellon University has obtained
   32 permission to  modify,  distribute and sublicense this code,  which is
   33 based on Version 2  of  AFS  and  does  not  contain  the features and
   34 enhancements that are part of  Version 3 of  AFS.  Version 3 of AFS is
   35 commercially   available   and  supported  by   Transarc  Corporation,
   36 Pittsburgh, PA.
   37 
   38 */
   39 
   40 #ifdef __cplusplus
   41 extern "C" {
   42 #endif
   43 
   44 #include <ctype.h>
   45 #include <sys/param.h>
   46 #include <errno.h>
   47 #include <sys/stat.h>
   48 #include <stdio.h>
   49 #include <sys/file.h>
   50 #include <netinet/in.h>
   51 #include <unistd.h>
   52 #include <stdlib.h>
   53 
   54 #include <lwp/lock.h>
   55 #include <lwp/lwp.h>
   56 #include <util.h>
   57 
   58 #ifdef __cplusplus
   59 }
   60 #endif
   61 
   62 #include <vice.h>
   63 #include "cvnode.h"
   64 #include "volume.h"
   65 #include "partition.h"
   66 #include "vutil.h"
   67 #include "vldb.h"
   68 
   69 
   70 static int VLDB_fd = -1;
   71 static int VLDB_size = 0;
   72 
   73 struct vldb *VLDBLookup(char *key);
   74 
   75 int VCheckVLDB() 
   76 {
   77     struct vldbHeader header;
   78 
   79     VLog(19, "Checking VLDB...");
   80     if (VLDB_fd != -1)
   81     close(VLDB_fd);
   82 
   83     VLDB_fd = open(VLDB_PATH, O_RDONLY, 0);
   84     if (VLDB_fd == -1) {
   85     VLog(0, "VCheckVLDB:  could not open VLDB");
   86     return (-1);
   87     }
   88     if (read(VLDB_fd, (char *)&header, sizeof(header)) != sizeof(header) || ntohl(header.magic) != VLDB_MAGIC) {
   89     VLog(0, "VCheckVLDB:  bad VLDB!");
   90     close(VLDB_fd);
   91     VLDB_fd = -1;
   92     return (-1);
   93     }
   94     VLDB_size = ntohl(header.hashSize);
   95     return (0);
   96 }
   97 
   98 /* Lookup vldb record from a file */
   99 struct vldb *VLDBLookup(char *key)
  100 {
  101     static struct vldb VLDB_records[8];
  102     int rc;
  103 
  104     if (VLDB_size == 0) {
  105     VLog(0, "VLDBLookup: VLDB_size unset. Calling VCheckVLDB()");
  106     rc = VCheckVLDB();
  107     if ( rc != 0 ) {
  108         VLog(0, "VLDBLookup: No or bad vldb.");
  109         return 0;
  110     }
  111     }
  112     int index = HashString(key, VLDB_size);
  113     VLog(9, "VLDBLookup: index = %d, VLDB_size = %d, LOG_VLDBSIZE = %d",
  114             index, VLDB_size, LOG_VLDBSIZE);
  115     for (;;) {
  116         int n;
  117     int i=0, nRecords=0;
  118     if (lseek(VLDB_fd, index << LOG_VLDBSIZE, L_SET) == -1) {
  119         VLog(9, "VLDBLookup: lseek failed for VLDB");
  120         return 0;
  121     }
  122     n = read(VLDB_fd, (char *)VLDB_records, sizeof(VLDB_records));
  123     if (n <= 0) {
  124         VLog(0, "VLDBLookup: read failed for VLDB");
  125         return 0;
  126     }
  127     VLog(29, "VLDBLookup: read succeeded, n = %d", n>>LOG_VLDBSIZE);
  128     nRecords = (n>>LOG_VLDBSIZE);    
  129     for (i = 0; i<nRecords; ) {
  130         struct vldb *vldp = &VLDB_records[i];
  131         if (vldp->key[0] == key[0] && strcmp(vldp->key, key) == 0) {
  132         VLog(39, "VLDBLookup: found VLDB record, VID = %u type = %x, servers = %d, server0 = %d, server1 = %x, server2 = %x",
  133             ntohl(vldp->volumeId[vldp->volumeType]), vldp->volumeType,
  134             vldp->nServers, vldp->serverNumber[0],
  135             vldp->serverNumber[1], vldp->serverNumber[2]);
  136         return vldp;
  137         }
  138         else {  /* key mismatch; generate log message */
  139         VLog(9, "VLDBLookup: vldp->key = %s, key = %s", 
  140             vldp->key, key);
  141         }
  142         if (!vldp->hashNext) {
  143         VLog(0, "VLDB_Lookup: cannot find \"%s\"", key);
  144         return 0;
  145         }
  146         i += vldp->hashNext;
  147     }
  148     index += i;
  149     }
  150 }    
  151 
  152 
  153 int VLDBPrint()
  154 {
  155     struct vldb VLDB_records[8];
  156 
  157     if (VLDB_fd == -1) 
  158       if (VCheckVLDB() == -1)    /* Close and reopen the db file and reset */
  159       return(-1);            /* the fd to after the header */
  160 
  161     if (lseek(VLDB_fd, 0, L_SET) == -1) {
  162     VLog(129, "VLDBPrint:  lseek failed for VLDB!");
  163     close(VLDB_fd);
  164     VLDB_fd = -1;
  165     return (-1);
  166     }
  167 
  168     VLog(100, "VLDBPrint: ");
  169     for (;;) {
  170         int n;
  171     int i=0, nRecords=0;
  172     n = read(VLDB_fd, (char *)VLDB_records, sizeof(VLDB_records));
  173     if (n < 0) 
  174         VLog(129, "VLDBPrint: read failed for VLDB");
  175     if (n <= 0)
  176         return 0;
  177 
  178     VLog(129, "VLDBPrint: read succeeded, n = %d", n>>LOG_VLDBSIZE);
  179     nRecords = (n>>LOG_VLDBSIZE);    
  180     for (i = 0; i<nRecords; i++) {
  181         struct vldb *vldp = &VLDB_records[i];
  182         if (ntohl(vldp->volumeId[vldp->volumeType]) != 0)
  183         VLog(100, "VID = %x type = %x, servers = %d, server0 = %x, server1 = %x, server2 = %x, key= %s",
  184             ntohl(vldp->volumeId[vldp->volumeType]), vldp->volumeType,
  185             vldp->nServers, vldp->serverNumber[0],
  186             vldp->serverNumber[1], vldp->serverNumber[2], vldp->key);
  187       } 
  188       }
  189 }    
  190