~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/archive/azio.c

  • Committer: Monty Taylor
  • Date: 2008-07-05 23:05:08 UTC
  • mto: This revision was merged to the branch mainline in revision 77.
  • Revision ID: monty@inaugust.com-20080705230508-9txkg702oln6hxjl
First large swath at getting handler stuff clean.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
#include <stdio.h>
17
17
#include <string.h>
18
18
#include <assert.h>
19
 
#include <unistd.h>
20
19
 
21
20
static int const az_magic[3] = {0xfe, 0x03, 0x01}; /* az magic header */
22
21
 
23
 
/* gzip flag unsigned char */
 
22
/* gzip flag uchar */
24
23
#define ASCII_FLAG   0x01 /* bit 0 set: file probably ascii text */
25
24
#define HEAD_CRC     0x02 /* bit 1 set: header CRC present */
26
25
#define EXTRA_FIELD  0x04 /* bit 2 set: extra field present */
68
67
    if (s->container.ready == AZ_THREAD_DEAD)
69
68
      break;
70
69
 
71
 
    s->container.read_size= pread((int)fd, (void *)buffer,
72
 
                                  (size_t)AZ_BUFSIZE_READ, (off_t)offset);
 
70
    s->container.read_size= pread(fd, (uchar *)buffer, AZ_BUFSIZE_READ, offset);
73
71
 
74
72
    pthread_mutex_lock(&s->container.thresh_mutex);
75
 
    s->container.ready= AZ_THREAD_FINISHED;
 
73
    s->container.ready= AZ_THREAD_FINISHED; 
76
74
    pthread_mutex_unlock(&s->container.thresh_mutex);
77
75
  }
78
76
 
190
188
    We do our own version of append by nature. 
191
189
    We must always have write access to take card of the header.
192
190
  */
193
 
  assert(Flags | O_APPEND);
194
 
  assert(Flags | O_WRONLY);
 
191
  DBUG_ASSERT(Flags | O_APPEND);
 
192
  DBUG_ASSERT(Flags | O_WRONLY);
195
193
 
196
194
  if (Flags & O_RDWR) 
197
195
    s->mode = 'w';
258
256
  }
259
257
  else if (s->mode == 'w') 
260
258
  {
261
 
    unsigned char buffer[AZHEADER_SIZE + AZMETA_BUFFER_SIZE];
 
259
    uchar buffer[AZHEADER_SIZE + AZMETA_BUFFER_SIZE];
262
260
    pread(s->file, buffer, AZHEADER_SIZE + AZMETA_BUFFER_SIZE, 0);
263
261
    read_header(s, buffer);
264
262
    s->pos= (size_t)my_seek(s->file, 0, MY_SEEK_END, MYF(0));
306
304
  int4store(ptr + AZ_COMMENT_LENGTH_POS, s->comment_length); /* COMMENT Block */
307
305
  int4store(ptr + AZ_META_POS, 0); /* Meta Block */
308
306
  int4store(ptr + AZ_META_LENGTH_POS, 0); /* Meta Block */
309
 
  int8store(ptr + AZ_START_POS, (uint64_t)s->start); /* Start of Data Block Index Block */
310
 
  int8store(ptr + AZ_ROW_POS, (uint64_t)s->rows); /* Start of Data Block Index Block */
311
 
  int8store(ptr + AZ_FLUSH_POS, (uint64_t)s->forced_flushes); /* Start of Data Block Index Block */
312
 
  int8store(ptr + AZ_CHECK_POS, (uint64_t)s->check_point); /* Start of Data Block Index Block */
313
 
  int8store(ptr + AZ_AUTOINCREMENT_POS, (uint64_t)s->auto_increment); /* Start of Data Block Index Block */
 
307
  int8store(ptr + AZ_START_POS, (unsigned long long)s->start); /* Start of Data Block Index Block */
 
308
  int8store(ptr + AZ_ROW_POS, (unsigned long long)s->rows); /* Start of Data Block Index Block */
 
309
  int8store(ptr + AZ_FLUSH_POS, (unsigned long long)s->forced_flushes); /* Start of Data Block Index Block */
 
310
  int8store(ptr + AZ_CHECK_POS, (unsigned long long)s->check_point); /* Start of Data Block Index Block */
 
311
  int8store(ptr + AZ_AUTOINCREMENT_POS, (unsigned long long)s->auto_increment); /* Start of Data Block Index Block */
314
312
  int4store(ptr+ AZ_LONGEST_POS , s->longest_row); /* Longest row */
315
313
  int4store(ptr+ AZ_SHORTEST_POS, s->shortest_row); /* Shorest row */
316
314
  int4store(ptr+ AZ_FRM_POS, 
318
316
  *(ptr + AZ_DIRTY_POS)= (unsigned char)s->dirty; /* Start of Data Block Index Block */
319
317
 
320
318
  /* Always begin at the begining, and end there as well */
321
 
  pwrite(s->file, (unsigned char*) buffer, AZHEADER_SIZE + AZMETA_BUFFER_SIZE, 0);
 
319
  pwrite(s->file, (uchar*) buffer, AZHEADER_SIZE + AZMETA_BUFFER_SIZE, 0);
322
320
}
323
321
 
324
322
/* ===========================================================================
367
365
  if (len < 2) {
368
366
    if (len) s->inbuf[0] = s->stream.next_in[0];
369
367
    errno = 0;
370
 
    len = (uInt)pread(s->file, (unsigned char *)s->inbuf + len, AZ_BUFSIZE_READ >> len, s->pos);
 
368
    len = (uInt)pread(s->file, (uchar *)s->inbuf + len, AZ_BUFSIZE_READ >> len, s->pos);
371
369
    s->pos+= len;
372
370
    if (len == (uInt)-1) s->z_err = Z_ERRNO;
373
371
    s->stream.avail_in += len;
402
400
    s->minor_version= (unsigned int)buffer[AZ_MINOR_VERSION_POS];
403
401
    s->block_size= 1024 * buffer[AZ_BLOCK_POS];
404
402
    s->start= (size_t)uint8korr(buffer + AZ_START_POS);
405
 
    s->rows= (uint64_t)uint8korr(buffer + AZ_ROW_POS);
406
 
    s->check_point= (uint64_t)uint8korr(buffer + AZ_CHECK_POS);
407
 
    s->forced_flushes= (uint64_t)uint8korr(buffer + AZ_FLUSH_POS);
408
 
    s->auto_increment= (uint64_t)uint8korr(buffer + AZ_AUTOINCREMENT_POS);
 
403
    s->rows= (unsigned long long)uint8korr(buffer + AZ_ROW_POS);
 
404
    s->check_point= (unsigned long long)uint8korr(buffer + AZ_CHECK_POS);
 
405
    s->forced_flushes= (unsigned long long)uint8korr(buffer + AZ_FLUSH_POS);
 
406
    s->auto_increment= (unsigned long long)uint8korr(buffer + AZ_AUTOINCREMENT_POS);
409
407
    s->longest_row= (unsigned int)uint4korr(buffer + AZ_LONGEST_POS);
410
408
    s->shortest_row= (unsigned int)uint4korr(buffer + AZ_SHORTEST_POS);
411
409
    s->frm_start_pos= (unsigned int)uint4korr(buffer + AZ_FRM_POS);
623
621
    {
624
622
 
625
623
      s->stream.next_out = s->outbuf;
626
 
      if (pwrite(s->file, (unsigned char *)s->outbuf, AZ_BUFSIZE_WRITE, s->pos) != AZ_BUFSIZE_WRITE) 
 
624
      if (pwrite(s->file, (uchar *)s->outbuf, AZ_BUFSIZE_WRITE, s->pos) != AZ_BUFSIZE_WRITE) 
627
625
      {
628
626
        s->z_err = Z_ERRNO;
629
627
        break;
664
662
 
665
663
    if (len != 0) 
666
664
    {
667
 
      if ((uInt)pwrite(s->file, (unsigned char *)s->outbuf, len, s->pos) != len) 
 
665
      if ((uInt)pwrite(s->file, (uchar *)s->outbuf, len, s->pos) != len) 
668
666
      {
669
667
        s->z_err = Z_ERRNO;
670
668
        assert(0);
704
702
 
705
703
static unsigned int azio_enable_aio(azio_stream *s)
706
704
{
707
 
  pthread_cond_init(&s->container.threshhold, NULL);
708
 
  pthread_mutex_init(&s->container.thresh_mutex, NULL);
 
705
  VOID(pthread_cond_init(&s->container.threshhold, NULL));
 
706
  VOID(pthread_mutex_init(&s->container.thresh_mutex, NULL));
709
707
  azio_start(s);
710
708
 
711
709
  return 0;
712
710
}
713
711
 
714
 
static void azio_disable_aio(azio_stream *s)
 
712
void azio_disable_aio(azio_stream *s)
715
713
{
716
714
  azio_kill(s);
717
715
 
718
 
  pthread_mutex_destroy(&s->container.thresh_mutex);
719
 
  pthread_cond_destroy(&s->container.threshhold);
 
716
  VOID(pthread_mutex_destroy(&s->container.thresh_mutex));
 
717
  VOID(pthread_cond_destroy(&s->container.threshhold));
720
718
 
721
719
  s->method= AZ_METHOD_BLOCK;
722
720
}
730
728
  if (s->mode == 'r') 
731
729
  {
732
730
    unsigned char buffer[AZHEADER_SIZE + AZMETA_BUFFER_SIZE];
733
 
    pread(s->file, (unsigned char*) buffer, AZHEADER_SIZE + AZMETA_BUFFER_SIZE, 0);
 
731
    pread(s->file, (uchar*) buffer, AZHEADER_SIZE + AZMETA_BUFFER_SIZE, 0);
734
732
    read_header(s, buffer); /* skip the .az header */
735
733
    azrewind(s);
736
734
 
888
886
void putLong (azio_stream *s, uLong x)
889
887
{
890
888
  int n;
891
 
  unsigned char buffer[1];
 
889
  uchar buffer[1];
892
890
 
893
891
  for (n = 0; n < 4; n++) 
894
892
  {
974
972
  s->frm_length= length;
975
973
  s->start+= length;
976
974
 
977
 
  pwrite(s->file, (unsigned char*) blob, s->frm_length, s->frm_start_pos);
 
975
  pwrite(s->file, (uchar*) blob, s->frm_length, s->frm_start_pos);
978
976
 
979
977
  write_header(s);
980
978
  s->pos= (size_t)my_seek(s->file, 0, MY_SEEK_END, MYF(0));
984
982
 
985
983
int azread_frm(azio_stream *s, char *blob)
986
984
{
987
 
  pread(s->file, (unsigned char*) blob, s->frm_length, s->frm_start_pos);
 
985
  pread(s->file, (uchar*) blob, s->frm_length, s->frm_start_pos);
988
986
 
989
987
  return 0;
990
988
}
1005
1003
  s->comment_length= length;
1006
1004
  s->start+= length;
1007
1005
 
1008
 
  pwrite(s->file, (unsigned char*) blob, s->comment_length, s->comment_start_pos);
 
1006
  pwrite(s->file, (uchar*) blob, s->comment_length, s->comment_start_pos);
1009
1007
 
1010
1008
  write_header(s);
1011
1009
  s->pos= (size_t)my_seek(s->file, 0, MY_SEEK_END, MYF(0));
1015
1013
 
1016
1014
int azread_comment(azio_stream *s, char *blob)
1017
1015
{
1018
 
  pread(s->file, (unsigned char*) blob, s->comment_length, s->comment_start_pos);
 
1016
  pread(s->file, (uchar*) blob, s->comment_length, s->comment_start_pos);
1019
1017
 
1020
1018
  return 0;
1021
1019
}
1069
1067
#ifdef AZIO_AIO
1070
1068
use_pread:
1071
1069
#endif
1072
 
    s->stream.avail_in = (uInt)pread(s->file, (unsigned char *)s->inbuf,
1073
 
                                     AZ_BUFSIZE_READ, s->pos);
 
1070
    s->stream.avail_in = (uInt)pread(s->file, (uchar *)s->inbuf, AZ_BUFSIZE_READ, s->pos);
1074
1071
    s->pos+= s->stream.avail_in;
1075
1072
  }
1076
1073
}