EzDoum

찾기
처음으로 | 찾기 | 아카이브 | 글 올리기 | 링크 | 자료실 | 통계 | 연락처 | 자유게시판
이지도움 특집
전체보기
네트워크
TI OMAP35x
TI DaVinci
Analog Blackfin
RobotWar2005
임베디드!
캐쉬의 모든것
메모리 할당 알고리즘
CPU 파이프라이닝
자료구조(Tree)
금융

Login
이름

암호

기억하기


사용자 등록

현재 접속중인 등록 사용자는 0명, 익명 사용자는 4명 입니다.
전체 등록 사용자: 751명

마지막 답장
·libcurl + fuse 조합으로 되는게 많네. (1)
·Linux Ftrace에 관해 (3)
·Android MTP ( Media Transfer Protocol ) (1)
·Lighttpd에 인증을 digest 사용시 IE 오동작 문제? (1)
·Dtrace에 관해 (1)

최근글
·OpenSSL and multi-threads (0)
·ARM 환경에서 OpenCL 사용 (0)
·IoT용 WIFI 모듈 비교 ( MCU ) 클래스 (0)
·Glances - 리눅스 여러 가지 항목을 한 화면에서 모니터링 (0)
·plugin 방식의 로그 분석기 (0)

뜨거운 감자
·나는 인터렉티브한 환경에서 역어셈블 한다. (12)
·GNU REGEX (정규표현식) 프로그래밍 강좌 (7)
·SoCRobotWar 2005 - 신입생 기초 교육자료 (7)
·ASP.NET의 데이터 그리드와 사용자 컨트롤 (7)
·DHTML Editing Control (7)

가장 많이 읽은 글
·[Cache] 2-way Set-Associative 방식이란 무엇일까? (2)
·멀티쓰레드(Pthread) 프로그래밍
·GNU REGEX (정규표현식) 프로그래밍 강좌 (7)
·Sorting Algorithm Animation (2)
·SoCRobotWar 2005 - 신입생 기초 교육자료 (7)

GDBM
글쓴이: EzDoum 글쓴날: 2007년 07월 02일 오후 04:27
리눅스



  1. /* testgdbm.c - Driver program to test the database routines and to
  2.    help debug gdbm.  Uses inside information to show "system" information */
  3.  
  4. /*  This file is part of GDBM, the GNU data base manager, by Philip A. Nelson.
  5.     Copyright (C) 1990, 1991, 1993  Free Software Foundation, Inc.
  6.  
  7.     GDBM is free software; you can redistribute it and/or modify
  8.     it under the terms of the GNU General Public License as published by
  9.     the Free Software Foundation; either version 2, or (at your option)
  10.     any later version.
  11.  
  12.     GDBM is distributed in the hope that it will be useful,
  13.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.     GNU General Public License for more details.
  16.  
  17.     You should have received a copy of the GNU General Public License
  18.     along with GDBM; see the file COPYING.  If not, write to
  19.     the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  20.  
  21.     You may contact the author by:
  22.        e-mail:  phil@cs.wwu.edu
  23.       us-mail:  Philip A. Nelson
  24.                 Computer Science Department
  25.                 Western Washington University
  26.                 Bellingham, WA 98226
  27.        
  28. *************************************************************************/
  29.  
  30.  
  31. /* include system configuration before all else. */
  32. #include "autoconf.h"
  33.  
  34. #include "gdbmdefs.h"
  35. #include "gdbmerrno.h"
  36. #include "extern.h"
  37.  
  38. #include "getopt.h"
  39.  
  40. extern const char * gdbm_version;
  41.  
  42. extern const char *gdbm_strerror __P((gdbm_error));
  43.  
  44. gdbm_file_info *gdbm_file;
  45.  
  46. /* Debug procedure to print the contents of the current hash bucket. */
  47. void
  48. print_bucket (bucket, mesg)
  49.      hash_bucket *bucket;
  50.      char *mesg;
  51. {
  52.   int  index;
  53.  
  54.   printf ("******* %s **********\n\nbits = %d\ncount= %d\nHash Table:\n",
  55.          mesg, bucket->bucket_bits, bucket->count);
  56.   printf ("     #    hash value     key size    data size     data adr  home\n");
  57.   for (index = 0; index < gdbm_file->header->bucket_elems; index++)
  58.     printf ("  %4d  %12x  %11d  %11d  %11d %5d\n", index,
  59.            bucket->h_table[index].hash_value,
  60.            bucket->h_table[index].key_size,
  61.            bucket->h_table[index].data_size,
  62.            bucket->h_table[index].data_pointer,
  63.            bucket->h_table[index].hash_value % gdbm_file->header->bucket_elems);
  64.  
  65.   printf ("\nAvail count = %1d\n", bucket->av_count);
  66.   printf ("Avail  adr     size\n");
  67.   for (index = 0; index < bucket->av_count; index++)
  68.     printf ("%9d%9d\n", bucket->bucket_avail[index].av_adr,
  69.                         bucket->bucket_avail[index].av_size);
  70. }
  71.  
  72.  
  73. void
  74. _gdbm_print_avail_list (dbf)
  75.      gdbm_file_info *dbf;
  76. {
  77.   int temp;
  78.   int size;
  79.   avail_block *av_stk;
  80.  
  81.   /* Print the the header avail block.  */
  82.   printf ("\nheader block\nsize  = %d\ncount = %d\n",
  83.           dbf->header->avail.size, dbf->header->avail.count);
  84.   for (temp = 0; temp < dbf->header->avail.count; temp++)
  85.     {
  86.       printf ("  %15d   %10d \n", dbf->header->avail.av_table[temp].av_size,
  87.               dbf->header->avail.av_table[temp].av_adr);
  88.     }
  89.  
  90.   /* Initialize the variables for a pass throught the avail stack. */
  91.   temp = dbf->header->avail.next_block;
  92.   size = ( ( (dbf->header->avail.size * sizeof (avail_elem)) >> 1)
  93.           + sizeof (avail_block));
  94.   av_stk = (avail_block *) malloc (size);
  95.   if (av_stk == NULL)
  96.     {
  97.       printf("Out of memory\n");
  98.       exit (2);
  99.     }
  100.  
  101.   /* Print the stack. */
  102.   while (FALSE)
  103.     {
  104.       lseek (dbf->desc, temp, L_SET);
  105.       read  (dbf->desc, av_stk, size);
  106.  
  107.       /* Print the block! */
  108.       printf ("\nblock = %d\nsize  = %d\ncount = %d\n", temp,
  109.               av_stk->size, av_stk->count);
  110.       for (temp = 0; temp < av_stk->count; temp++)
  111.         {
  112.           printf ("  %15d   %10d \n", av_stk->av_table[temp].av_size,
  113.             av_stk->av_table[temp].av_adr);
  114.         }
  115.       temp = av_stk->next_block;
  116.     }
  117. }
  118.  
  119. void
  120. _gdbm_print_bucket_cache (dbf)
  121.      gdbm_file_info *dbf;
  122. {
  123.   register int index;
  124.   char changed;
  125.  
  126.   if (dbf->bucket_cache != NULL) {
  127.     printf(
  128.       "Bucket Cache (size %d):\n  Index:  Address  Changed  Data_Hash \n",
  129.       dbf->cache_size);
  130.     for (index=0; index < dbf->cache_size; index++) {
  131.       changed = dbf->bucket_cache[index].ca_changed;
  132.       printf ("  %5d:  %7d  %7s  %x\n",
  133.               index,
  134.               dbf->bucket_cache[index].ca_adr,
  135.               (changed ? "True" : "False"),
  136.               dbf->bucket_cache[index].ca_data.hash_val);
  137.     }
  138.   } else
  139.     printf("Bucket cache has not been initialized.\n");
  140. }
  141.  
  142. void
  143. usage (s)
  144.      char *s;
  145. {
  146.   printf(
  147.       "Usage: %s [-r or -ns] [-b block-size] [-c cache-size] [-g gdbm-file]\n",
  148.       s);
  149.   exit (2);
  150. }
  151.  
  152.  
  153. /* The test program allows one to call all the routines plus the hash function.
  154.    The commands are single letter commands.  The user is prompted for all other
  155.    information.  See the help command (?) for a list of all commands. */
  156.  
  157. int
  158. main (argc, argv)
  159.      int argc;
  160.      char *argv[];
  161.  
  162. {
  163.  
  164.   char  cmd_ch;
  165.  
  166.   datum key_data;
  167.   datum data_data;
  168.   datum return_data;
  169.  
  170.   char key_line[500];
  171.   char data_line[1000];
  172.  
  173.   char done = FALSE;
  174.   int  opt;
  175.   char reader = FALSE;
  176.   char newdb = FALSE;
  177.   int  fast  = 0;
  178.  
  179.   int  cache_size = DEFAULT_CACHESIZE;
  180.   int  block_size = 0;
  181.  
  182.   char *file_name = NULL;
  183.  
  184.  
  185.   /* Argument checking. */
  186.   opterr = 0;
  187.   while ((opt = getopt (argc, argv, "srnc:b:g:")) != -1)
  188.     switch (opt) {
  189.     case 's':  fast = GDBM_SYNC;
  190.                if (reader) usage (argv[0]);
  191.                break;
  192.     case 'r':  reader = TRUE;
  193.                if (newdb) usage (argv[0]);
  194.                break;
  195.     case 'n':  newdb = TRUE;
  196.                if (reader) usage (argv[0]);
  197.                break;
  198.     case 'c':  cache_size = atoi(optarg);
  199.                break;
  200.     case 'b':  block_size = atoi(optarg);
  201.                break;
  202.     case 'g':  file_name = optarg;
  203.                break;
  204.     default:  usage(argv[0]);
  205.     }
  206.  
  207.   if(file_name == NULL)
  208.     file_name = "junk.gdbm";
  209.  
  210.   /* Initialize variables. */
  211.   key_data.dptr = NULL;
  212.   data_data.dptr = data_line;
  213.  
  214.   if (reader)
  215.     {
  216.       gdbm_file = gdbm_open (file_name, block_size, GDBM_READER, 00664, NULL);
  217.     }
  218.   else if (newdb)
  219.     {
  220.       gdbm_file =
  221.         gdbm_open (file_name, block_size, GDBM_NEWDB | fast, 00664, NULL);
  222.     }
  223.   else
  224.     {
  225.       gdbm_file =
  226.         gdbm_open (file_name, block_size, GDBM_WRCREAT | fast, 00664, NULL);
  227.     }
  228.   if (gdbm_file == NULL)
  229.     {
  230.       printf("gdbm_open failed, %s\n", gdbm_strerror(gdbm_errno));
  231.       exit (2);
  232.     }
  233.  
  234.   if (gdbm_setopt(gdbm_file, GDBM_CACHESIZE, &cache_size, sizeof(int)) == -1)
  235.     {
  236.       printf("gdbm_setopt failed, %s\n", gdbm_strerror(gdbm_errno));
  237.       exit(2);
  238.     }
  239.  
  240.   /* Welcome message. */
  241.   printf ("\nWelcome to the gdbm test program.  Type ? for help.\n\n");
  242.  
  243.   while (!done)
  244.     {
  245.       printf ("com -> ");
  246.       cmd_ch = getchar ();
  247.       if (cmd_ch != '\n')
  248.         {
  249.           char temp;
  250.           do
  251.               temp = getchar ();
  252.           while (temp != '\n' && temp != EOF);
  253.         }
  254.       if (cmd_ch == EOF) cmd_ch = 'q';
  255.       switch (cmd_ch)
  256.         {
  257.        
  258.         /* Standard cases found in all test{dbm,ndbm,gdbm} programs. */
  259.         case '\n':
  260.           printf ("\n");
  261.           break;
  262.  
  263.         case 'c':
  264.           {
  265.             int temp;
  266.             temp = 0;
  267.             if (key_data.dptr != NULL) free (key_data.dptr);
  268.             return_data = gdbm_firstkey (gdbm_file);
  269.             while (return_data.dptr != NULL)
  270.               {
  271.                 temp++;
  272.                 key_data = return_data;
  273.                 return_data = gdbm_nextkey (gdbm_file, key_data);
  274.                 free (key_data.dptr);
  275.               }
  276.             printf ("There are %d items in the database.\n\n", temp);
  277.             key_data.dptr = NULL;
  278.           }
  279.           break;
  280.  
  281.         case 'd':
  282.           if (key_data.dptr != NULL) free (key_data.dptr);
  283.           printf ("key -> ");
  284.           gets (key_line);
  285.           key_data.dptr = key_line;
  286.           key_data.dsize = strlen (key_line)+1;
  287.           if (gdbm_delete (gdbm_file, key_data) != 0)
  288.             printf ("Item not found or deleted\n");
  289.           printf ("\n");
  290.           key_data.dptr = NULL;
  291.           break;
  292.  
  293.         case 'f':
  294.           if (key_data.dptr != NULL) free (key_data.dptr);
  295.           printf ("key -> ");
  296.           gets (key_line);
  297.           key_data.dptr = key_line;
  298.           key_data.dsize = strlen (key_line)+1;
  299.           return_data = gdbm_fetch (gdbm_file, key_data);
  300.           if (return_data.dptr != NULL)
  301.             {
  302.               printf ("data is ->%s\n\n", return_data.dptr);
  303.               free (return_data.dptr);
  304.             }
  305.           else
  306.             printf ("No such item found.\n\n");
  307.           key_data.dptr = NULL;
  308.           break;
  309.  
  310.         case 'n':
  311.           if (key_data.dptr != NULL) free (key_data.dptr);
  312.           printf ("key -> ");
  313.           gets (key_line);
  314.           key_data.dptr = key_line;
  315.           key_data.dsize = strlen (key_line)+1;
  316.           return_data = gdbm_nextkey (gdbm_file, key_data);
  317.           if (return_data.dptr != NULL)
  318.             {
  319.               key_data = return_data;
  320.               printf ("key is  ->%s\n", key_data.dptr);
  321.               return_data = gdbm_fetch (gdbm_file, key_data);
  322.               printf ("data is ->%s\n\n", return_data.dptr);
  323.               free (return_data.dptr);
  324.             }
  325.           else
  326.             {
  327.               printf ("No such item found.\n\n");
  328.               key_data.dptr = NULL;
  329.             }
  330.           break;
  331.  
  332.         case 'q':
  333.           done = TRUE;
  334.           break;
  335.  
  336.         case 's':
  337.           if (key_data.dptr != NULL) free (key_data.dptr);
  338.           printf ("key -> ");
  339.           gets (key_line);
  340.           key_data.dptr = key_line;
  341.           key_data.dsize = strlen (key_line)+1;
  342.           printf ("data -> ");
  343.           gets (data_line);
  344.           data_data.dsize = strlen (data_line)+1;
  345.           if (gdbm_store (gdbm_file, key_data, data_data, GDBM_REPLACE) != 0)
  346.             printf ("Item not inserted. \n");
  347.           printf ("\n");
  348.           key_data.dptr = NULL;
  349.           break;
  350.  
  351.         case '1':
  352.           if (key_data.dptr != NULL) free (key_data.dptr);
  353.           key_data = gdbm_firstkey (gdbm_file);
  354.           if (key_data.dptr != NULL)
  355.             {
  356.               printf ("key is  ->%s\n", key_data.dptr);
  357.               return_data = gdbm_fetch (gdbm_file, key_data);
  358.               printf ("data is ->%s\n\n", return_data.dptr);
  359.               free (return_data.dptr);
  360.             }
  361.           else
  362.             printf ("No such item found.\n\n");
  363.           break;
  364.  
  365.         case '2':
  366.           return_data = gdbm_nextkey (gdbm_file, key_data);
  367.           if (return_data.dptr != NULL)
  368.             {
  369.               free (key_data.dptr);
  370.               key_data = return_data;
  371.               printf ("key is  ->%s\n", key_data.dptr);
  372.               return_data = gdbm_fetch (gdbm_file, key_data);
  373.               printf ("data is ->%s\n\n", return_data.dptr);
  374.               free (return_data.dptr);
  375.             }
  376.           else
  377.             printf ("No such item found.\n\n");
  378.           break;
  379.  
  380.  
  381.         /* Special cases for the testgdbm program. */
  382.         case 'r':
  383.           {
  384.             if (gdbm_reorganize (gdbm_file))
  385.               printf ("Reorganization failed. \n\n");
  386.             else
  387.               printf ("Reorganization succeeded. \n\n");
  388.           }
  389.           break;
  390.  
  391.         case 'A':
  392.           _gdbm_print_avail_list (gdbm_file);
  393.           printf ("\n");
  394.           break;
  395.  
  396.         case 'B':
  397.           {
  398.             int temp;
  399.             char number[80];
  400.  
  401.             printf ("bucket? ");
  402.             gets (number);
  403.             sscanf (number,"%d",&temp);
  404.  
  405.             if (temp >= gdbm_file->header->dir_size /4)
  406.               {
  407.                 printf ("Not a bucket. \n\n");
  408.                 break;
  409.               }
  410.             _gdbm_get_bucket (gdbm_file, temp);
  411.           }
  412.           printf ("Your bucket is now ");
  413.  
  414.         case 'C':
  415.           print_bucket (gdbm_file->bucket, "Current bucket");
  416.           printf ("\n current directory entry = %d.\n", gdbm_file->bucket_dir);
  417.           printf (" current bucket address  = %d.\n\n",
  418.                   gdbm_file->cache_entry->ca_adr);
  419.           break;
  420.  
  421.         case 'D':
  422.           printf ("Hash table directory.\n");
  423.           printf ("  Size =  %d.  Bits = %d. \n\n",gdbm_file->header->dir_size,
  424.                   gdbm_file->header->dir_bits);
  425.           {
  426.             int temp;
  427.  
  428.             for (temp = 0; temp < gdbm_file->header->dir_size / 4; temp++)
  429.               {
  430.                 printf ("  %10d:  %12d\n", temp, gdbm_file->dir[temp]);
  431.                 if ( (temp+1) % 20 == 0 && isatty (0))
  432.                   {
  433.                     printf ("*** CR to continue: ");
  434.                     while (getchar () != '\n') /* Do nothing. */;
  435.                   }
  436.               }
  437.           }
  438.           printf ("\n");
  439.           break;
  440.  
  441.         case 'F':
  442.           {
  443.             printf ("\nFile Header: \n\n");
  444.             printf ("  table        = %d\n", gdbm_file->header->dir);
  445.             printf ("  table size   = %d\n", gdbm_file->header->dir_size);
  446.             printf ("  table bits   = %d\n", gdbm_file->header->dir_bits);
  447.             printf ("  block size   = %d\n", gdbm_file->header->block_size);
  448.             printf ("  bucket elems = %d\n", gdbm_file->header->bucket_elems);
  449.             printf ("  bucket size  = %d\n", gdbm_file->header->bucket_size);
  450.             printf ("  header magic = %x\n", gdbm_file->header->header_magic);
  451.             printf ("  next block   = %d\n", gdbm_file->header->next_block);
  452.             printf ("  avail size   = %d\n", gdbm_file->header->avail.size);
  453.             printf ("  avail count  = %d\n", gdbm_file->header->avail.count);
  454.             printf ("  avail nx blk = %d\n", gdbm_file->header->avail.next_block);
  455.             printf ("\n");
  456.           }
  457.           break;
  458.  
  459.         case 'H':
  460.           if (key_data.dptr != NULL) free (key_data.dptr);
  461.           printf ("key -> ");
  462.           gets (key_line);
  463.           key_data.dptr = key_line;
  464.           key_data.dsize = strlen (key_line)+1;
  465.           printf ("hash value = %x. \n\n", _gdbm_hash (key_data));
  466.           key_data.dptr = NULL;
  467.           break;
  468.  
  469.         case 'K':
  470.           _gdbm_print_bucket_cache (gdbm_file);
  471.           break;
  472.  
  473.         case 'V':
  474.           printf ("%s\n\n", gdbm_version);
  475.           break;
  476.  
  477.         case '?':
  478.           printf ("c - count (number of entries)\n");
  479.           printf ("d - delete\n");
  480.           printf ("f - fetch\n");
  481.           printf ("n - nextkey\n");
  482.           printf ("q - quit\n");
  483.           printf ("s - store\n");
  484.           printf ("1 - firstkey\n");
  485.           printf ("2 - nextkey on last key (from n, 1 or 2)\n\n");
  486.  
  487.           printf ("r - reorganize\n");
  488.           printf ("A - print avail list\n");
  489.           printf ("B - get and print current bucket n\n");
  490.           printf ("C - print current bucket\n");
  491.           printf ("D - print hash directory\n");
  492.           printf ("F - print file header\n");
  493.           printf ("H - hash value of key\n");
  494.           printf ("K - print the bucket cache\n");
  495.           printf ("V - print version of gdbm\n");
  496.           break;
  497.  
  498.         default:
  499.           printf ("What? \n\n");
  500.           break;
  501.  
  502.         }
  503.     }
  504.  
  505.   /* Quit normally. */
  506.   exit (0);
  507.  
  508. }

  • 첨부 파일: gdbm-1.8.3-1-doc.zip gdbm-1.8.3-1-doc.zip (303 KiB(309,850 Bytes))

  • 관련 링크
  • [분류: 리눅스 인쇄용 페이지 본문 email로 보내기 ]

    <  Blackfin - Pixel Operations | 임베디드 - SPORT UART  >
    GDBM | 답장: 3개 | 본문에 답장
    정렬 :  
    답장 EzDoum 2007년 07월 03일 오후 04:09 [ 이글에 답장 | 본문에 답장 | 책갈피 ]
    A summary of the gdbm API.
    http://www.vivtek.com/gdbm/api.html


    [수정]

    답장 EzDoum 2007년 07월 03일 오후 04:32 [ 이글에 답장 | 본문에 답장 | 책갈피 ]
    1.  
    2. /* gdbmdefs.h - The include file for dbm.  Defines structure and constants. */
    3.  
    4. /*  This file is part of GDBM, the GNU data base manager, by Philip A. Nelson.
    5.     Copyright (C) 1990, 1991, 1993  Free Software Foundation, Inc.
    6.  
    7.     GDBM is free software; you can redistribute it and/or modify
    8.     it under the terms of the GNU General Public License as published by
    9.     the Free Software Foundation; either version 2, or (at your option)
    10.     any later version.
    11.  
    12.     GDBM is distributed in the hope that it will be useful,
    13.     but WITHOUT ANY WARRANTY; without even the implied warranty of
    14.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    15.     GNU General Public License for more details.
    16.  
    17.     You should have received a copy of the GNU General Public License
    18.     along with GDBM; see the file COPYING.  If not, write to
    19.     the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
    20.  
    21.     You may contact the author by:
    22.        e-mail:  phil@cs.wwu.edu
    23.       us-mail:  Philip A. Nelson
    24.                 Computer Science Department
    25.                 Western Washington University
    26.                 Bellingham, WA 98226
    27. *************************************************************************/
    28.  
    29. #include "systems.h"
    30. #include "gdbmconst.h"
    31.  
    32. /* The type definitions are next.  */
    33.  
    34. /* The data and key structure.  This structure is defined for compatibility. */
    35.  
    36. typedef struct {
    37.         char *dptr;
    38.         int   dsize;
    39.       } datum;
    40.  
    41.  
    42. /* The available file space is stored in an "avail" table.  The one with
    43.    most activity is contained in the file header. (See below.)  When that
    44.    one filles up, it is split in half and half is pushed on an "avail
    45.    stack."  When the active avail table is empty and the "avail stack" is
    46.    not empty, the top of the stack is popped into the active avail table. */
    47.  
    48. /* The following structure is the element of the avaliable table.  */
    49. typedef struct {
    50.         int   av_size;                /* The size of the available block. */
    51.         off_t  av_adr;    /* The file address of the available block. */
    52.       } avail_elem;
    53.  
    54. /* This is the actual table. The in-memory images of the avail blocks are
    55.    allocated by malloc using a calculated size.  */
    56. typedef struct {
    57.         int   size;          /* The number of avail elements in the table.*/
    58.         int   count;        /* The number of entries in the table. */
    59.         off_t next_block;       /* The file address of the next avail block. */
    60.         avail_elem av_table[1]; /* The table.  Make it look like an array.  */
    61.       } avail_block;
    62.  
    63. /* The dbm file header keeps track of the current location of the hash
    64.    directory and the free space in the file.  */
    65.  
    66. typedef struct {
    67.         int   header_magic;  /* 0x13579ace to make sure the header is good. */
    68.         int   block_size;    /* The  optimal i/o blocksize from stat. */
    69.         off_t dir;           /* File address of hash directory table. */
    70.         int   dir_size;      /* Size in bytes of the table.  */
    71.         int   dir_bits;      /* The number of address bits used in the table.*/
    72.         int   bucket_size;   /* Size in bytes of a hash bucket struct. */
    73.         int   bucket_elems;  /* Number of elements in a hash bucket. */
    74.         off_t next_block;    /* The next unallocated block address. */
    75.         avail_block avail;   /* This must be last because of the psuedo
    76.                                 array in avail.  This avail grows to fill
    77.                                 the entire block. */
    78.       }  gdbm_file_header;
    79.  
    80.  
    81. /* The dbm hash bucket element contains the full 31 bit hash value, the
    82.    "pointer" to the key and data (stored together) with their sizes.  It also
    83.    has a small part of the actual key value.  It is used to verify the first
    84.    part of the key has the correct value without having to read the actual
    85.    key. */
    86.  
    87. typedef struct {
    88.         int   hash_value;       /* The complete 31 bit value. */
    89.         char  key_start[SMALL]/* Up to the first SMALL bytes of the key.  */
    90.         off_t data_pointer;     /* The file address of the key record. The
    91.                                    data record directly follows the key.  */
    92.         int   key_size;  /* Size of key data in the file. */
    93.         int   data_size;        /* Size of associated data in the file. */
    94.       } bucket_element;
    95.  
    96.  
    97. /* A bucket is a small hash table.  This one consists of a number of
    98.    bucket elements plus some bookkeeping fields.  The number of elements
    99.    depends on the optimum blocksize for the storage device and on a
    100.    parameter given at file creation time.  This bucket takes one block.
    101.    When one of these tables gets full, it is split into two hash buckets.
    102.    The contents are split between them by the use of the first few bits
    103.    of the 31 bit hash function.  The location in a bucket is the hash
    104.    value modulo the size of the bucket.  The in-memory images of the
    105.    buckets are allocated by malloc using a calculated size depending of
    106.    the file system buffer size.  To speed up write, each bucket will have
    107.    BUCKET_AVAIL avail elements with the bucket. */
    108.  
    109. typedef struct {
    110.         int   av_count;     /* The number of bucket_avail entries. */
    111.         avail_elem bucket_avail[BUCKET_AVAIL]/* Distributed avail. */
    112.         int   bucket_bits;         /* The number of bits used to get here. */
    113.         int   count;           /* The number of element buckets full. */
    114.         bucket_element h_table[1]; /* The table.  Make it look like an array.*/
    115.       } hash_bucket;
    116.  
    117. /* We want to keep from reading buckets as much as possible.  The following is
    118.    to implement a bucket cache.  When full, buckets will be dropped in a
    119.    least recently read from disk order.  */
    120.  
    121. /* To speed up fetching and "sequential" access, we need to implement a
    122.    data cache for key/data pairs read from the file.  To find a key, we
    123.    must exactly match the key from the file.  To reduce overhead, the
    124.    data will be read at the same time.  Both key and data will be stored
    125.    in a data cache.  Each bucket cached will have a one element data
    126.    cache.  */
    127.  
    128. typedef struct {
    129.         int   hash_val;
    130.         int   data_size;
    131.         int   key_size;
    132.         char *dptr;
    133.         int   elem_loc;
    134.       }  data_cache_elem;
    135.  
    136. typedef struct {
    137.         hash_bucket *   ca_bucket;
    138.         off_t           ca_adr;
    139.         char        ca_changed;   /* Data in the bucket changed. */
    140.         data_cache_elem ca_data;
    141.       } cache_elem;
    142.  
    143.  
    144.  
    145. /* This final structure contains all main memory based information for
    146.    a gdbm file.  This allows multiple gdbm files to be opened at the same
    147.    time by one program. */
    148.  
    149. typedef struct {
    150.         /* Global variables and pointers to dynamic variables used by gdbm.  */
    151.  
    152.         /* The file name. */
    153.         char *name;
    154.  
    155.         /* The reader/writer status. */
    156.         int read_write;
    157.  
    158.         /* Fast_write is set to 1 if no fsyncs are to be done. */
    159.         int fast_write;
    160.  
    161.         /* Central_free is set if all free blocks are kept in the header. */
    162.         int central_free;
    163.  
    164.         /* Coalesce_blocks is set if we should try to merge free blocks. */
    165.         int coalesce_blocks;
    166.  
    167.         /* Whether or not we should do file locking ourselves. */
    168.         int file_locking;
    169.  
    170.         /* The fatal error handling routine. */
    171.         void (*fatal_err) ();
    172.  
    173.         /* The gdbm file descriptor which is set in gdbm_open.  */
    174.         int desc;
    175.  
    176.         /* The file header holds information about the database. */
    177.         gdbm_file_header *header;
    178.  
    179.         /* The hash table directory from extendible hashing.  See Fagin et al,
    180.            ACM Trans on Database Systems, Vol 4, No 3. Sept 1979, 315-344 */
    181.         off_t *dir;
    182.  
    183.         /* The bucket cache. */
    184.         cache_elem *bucket_cache;
    185.         int cache_size;
    186.         int last_read;
    187.  
    188.         /* Points to the current hash bucket in the cache. */
    189.         hash_bucket *bucket;
    190.  
    191.         /* The directory entry used to get the current hash bucket. */
    192.         int bucket_dir;
    193.  
    194.         /* Pointer to the current bucket's cache entry. */
    195.         cache_elem *cache_entry;
    196.  
    197.  
    198.         /* Bookkeeping of things that need to be written back at the
    199.            end of an update. */
    200.         char  header_changed;
    201.         char  directory_changed;
    202.         char  bucket_changed;
    203.         char  second_changed;
    204.        
    205.       } gdbm_file_info;
    206.  
    207. /* Now define all the routines in use. */

    [수정]

    답장 EzDoum 2007년 07월 03일 오후 04:32 [ 이글에 답장 | 본문에 답장 | 책갈피 ]
    #define GDBM_NO_ERROR					0	//No	error	
    #define GDBM_MALLOC_ERROR				1	//Malloc	error	
    #define GDBM_BLOCK_SIZE_ERROR			2	//Block	size	error	
    #define GDBM_FILE_OPEN_ERROR			3	//File	open	error	
    #define GDBM_FILE_WRITE_ERROR			4	//File	write	error	
    #define GDBM_FILE_SEEK_ERROR			5	//File	seek	error	
    #define GDBM_FILE_READ_ERROR			6	//File	read	error	
    #define GDBM_BAD_MAGIC_NUMBER			7	//Bad	magic	number	
    #define GDBM_EMPTY_DATABASE				8	//Empty	database	
    #define GDBM_CANT_BE_READER				9	//Can't	be	reader	
    #define GDBM_CANT_BE_WRITER				10	//Can't	be	writer	
    #define GDBM_READER_CANT_DELETE			11	//Reader	can't	delete	
    #define GDBM_READER_CANT_STORE			12	//Reader	can't	store	
    #define GDBM_READER_CANT_REORGANIZE			13	//Reader	can't	reorganize	
    #define GDBM_UNKNOWN_UPDATE				14	//Unknown	update	
    #define GDBM_ITEM_NOT_FOUND				15	//Item	not	found	
    #define GDBM_REORGANIZE_FAILED			16	//Reorganize	failed	
    #define GDBM_CANNOT_REPLACE				17	//Cannot	replace	
    #define GDBM_ILLEGAL_DATA				18	//Illegal	data	
    #define GDBM_OPT_ALREADY_SET			19	//Option	already	set	
    #define GDBM_OPT_ILLEGAL				20	//Illegal	option	
    



    [수정]

    GDBM | 답장: 3개 | 본문에 답장
    정렬 :  

    답장 쓰기
    글을 올리시려면 로그인 (사용자 등록) 하셔야 합니다.

    검색
    Google

    분류
    ·공지 (6)
    ·인터넷 (87)
    ·하드웨어 (260)
    ·C/C++ (65)
    ·어셈블리 (7)
    ·리눅스 (136)
    ·리눅스 커널 (67)
    ·윈도우즈 (25)
    ·데이터베이스 (20)
    ·보안 (16)
    ·.NET (25)
    ·그래픽 (13)
    ·책소개 (42)
    ·호기심 천국 (80)
    ·잡담 (111)
    ·사랑 (3)

    전체 본문수: 963
    전체 답장수: 525


    분류 : 리눅스
    최근글
    최근글
    가장 많이 읽은 글
    ·멀티쓰레드(Pthread) 프로그래밍 (0)
    뜨거운 감자
    ·GNU REGEX (정규표현식) 프로그래밍 강좌 (7)

    EzDoum투표
    이지도움 어때요?
    이게 뭐야. 다시 안올란다. --;
    아이 좋아라~ +_+;
    관심없다.
    먼가는 있는거 같은데 뭐하는 곳이지?
    기타 (자유게시판에 글로 남겨 주세요)
    [ 결과 | 투표 ]

    랜덤 링크
    http://kldp.net


     Home ^ BACK TO TOP ^ EzDoum - 도움이 필요하세요~??
     Powered by KorWeblog 1.5.8 Copyleft © 2001 EzDoum, 관리자: EzDoum