~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/archive/azio.c

Removed DBUG symbols and fixed TRUE/FALSE

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>
 
19
 
 
20
/* TODO: For some reason these aren't showing up cleanly in the 
 
21
 *  * includes... why? 
 
22
 *   */
 
23
#if !defined(pread)
 
24
extern ssize_t pread (int __fd, void *__buf, size_t __nbytes,
 
25
                      off_t __offset);
 
26
#endif
 
27
#if !defined(pwrite)
 
28
extern ssize_t pwrite (int __fd, __const void *__buf, size_t __n,
 
29
                       off_t __offset);
 
30
#endif
20
31
 
21
32
static int const az_magic[3] = {0xfe, 0x03, 0x01}; /* az magic header */
22
33
 
23
 
/* gzip flag unsigned char */
 
34
/* gzip flag uchar */
24
35
#define ASCII_FLAG   0x01 /* bit 0 set: file probably ascii text */
25
36
#define HEAD_CRC     0x02 /* bit 1 set: header CRC present */
26
37
#define EXTRA_FIELD  0x04 /* bit 2 set: extra field present */
190
201
    We do our own version of append by nature. 
191
202
    We must always have write access to take card of the header.
192
203
  */
193
 
  assert(Flags | O_APPEND);
194
 
  assert(Flags | O_WRONLY);
 
204
  DBUG_ASSERT(Flags | O_APPEND);
 
205
  DBUG_ASSERT(Flags | O_WRONLY);
195
206
 
196
207
  if (Flags & O_RDWR) 
197
208
    s->mode = 'w';
258
269
  }
259
270
  else if (s->mode == 'w') 
260
271
  {
261
 
    unsigned char buffer[AZHEADER_SIZE + AZMETA_BUFFER_SIZE];
 
272
    uchar buffer[AZHEADER_SIZE + AZMETA_BUFFER_SIZE];
262
273
    pread(s->file, buffer, AZHEADER_SIZE + AZMETA_BUFFER_SIZE, 0);
263
274
    read_header(s, buffer);
264
275
    s->pos= (size_t)my_seek(s->file, 0, MY_SEEK_END, MYF(0));
306
317
  int4store(ptr + AZ_COMMENT_LENGTH_POS, s->comment_length); /* COMMENT Block */
307
318
  int4store(ptr + AZ_META_POS, 0); /* Meta Block */
308
319
  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 */
 
320
  int8store(ptr + AZ_START_POS, (unsigned long long)s->start); /* Start of Data Block Index Block */
 
321
  int8store(ptr + AZ_ROW_POS, (unsigned long long)s->rows); /* Start of Data Block Index Block */
 
322
  int8store(ptr + AZ_FLUSH_POS, (unsigned long long)s->forced_flushes); /* Start of Data Block Index Block */
 
323
  int8store(ptr + AZ_CHECK_POS, (unsigned long long)s->check_point); /* Start of Data Block Index Block */
 
324
  int8store(ptr + AZ_AUTOINCREMENT_POS, (unsigned long long)s->auto_increment); /* Start of Data Block Index Block */
314
325
  int4store(ptr+ AZ_LONGEST_POS , s->longest_row); /* Longest row */
315
326
  int4store(ptr+ AZ_SHORTEST_POS, s->shortest_row); /* Shorest row */
316
327
  int4store(ptr+ AZ_FRM_POS, 
318
329
  *(ptr + AZ_DIRTY_POS)= (unsigned char)s->dirty; /* Start of Data Block Index Block */
319
330
 
320
331
  /* Always begin at the begining, and end there as well */
321
 
  pwrite(s->file, (unsigned char*) buffer, AZHEADER_SIZE + AZMETA_BUFFER_SIZE, 0);
 
332
  pwrite(s->file, (uchar*) buffer, AZHEADER_SIZE + AZMETA_BUFFER_SIZE, 0);
322
333
}
323
334
 
324
335
/* ===========================================================================
367
378
  if (len < 2) {
368
379
    if (len) s->inbuf[0] = s->stream.next_in[0];
369
380
    errno = 0;
370
 
    len = (uInt)pread(s->file, (unsigned char *)s->inbuf + len, AZ_BUFSIZE_READ >> len, s->pos);
 
381
    len = (uInt)pread(s->file, (uchar *)s->inbuf + len, AZ_BUFSIZE_READ >> len, s->pos);
371
382
    s->pos+= len;
372
383
    if (len == (uInt)-1) s->z_err = Z_ERRNO;
373
384
    s->stream.avail_in += len;
402
413
    s->minor_version= (unsigned int)buffer[AZ_MINOR_VERSION_POS];
403
414
    s->block_size= 1024 * buffer[AZ_BLOCK_POS];
404
415
    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);
 
416
    s->rows= (unsigned long long)uint8korr(buffer + AZ_ROW_POS);
 
417
    s->check_point= (unsigned long long)uint8korr(buffer + AZ_CHECK_POS);
 
418
    s->forced_flushes= (unsigned long long)uint8korr(buffer + AZ_FLUSH_POS);
 
419
    s->auto_increment= (unsigned long long)uint8korr(buffer + AZ_AUTOINCREMENT_POS);
409
420
    s->longest_row= (unsigned int)uint4korr(buffer + AZ_LONGEST_POS);
410
421
    s->shortest_row= (unsigned int)uint4korr(buffer + AZ_SHORTEST_POS);
411
422
    s->frm_start_pos= (unsigned int)uint4korr(buffer + AZ_FRM_POS);
623
634
    {
624
635
 
625
636
      s->stream.next_out = s->outbuf;
626
 
      if (pwrite(s->file, (unsigned char *)s->outbuf, AZ_BUFSIZE_WRITE, s->pos) != AZ_BUFSIZE_WRITE) 
 
637
      if (pwrite(s->file, (uchar *)s->outbuf, AZ_BUFSIZE_WRITE, s->pos) != AZ_BUFSIZE_WRITE) 
627
638
      {
628
639
        s->z_err = Z_ERRNO;
629
640
        break;
664
675
 
665
676
    if (len != 0) 
666
677
    {
667
 
      if ((uInt)pwrite(s->file, (unsigned char *)s->outbuf, len, s->pos) != len) 
 
678
      if ((uInt)pwrite(s->file, (uchar *)s->outbuf, len, s->pos) != len) 
668
679
      {
669
680
        s->z_err = Z_ERRNO;
670
681
        assert(0);
704
715
 
705
716
static unsigned int azio_enable_aio(azio_stream *s)
706
717
{
707
 
  pthread_cond_init(&s->container.threshhold, NULL);
708
 
  pthread_mutex_init(&s->container.thresh_mutex, NULL);
 
718
  VOID(pthread_cond_init(&s->container.threshhold, NULL));
 
719
  VOID(pthread_mutex_init(&s->container.thresh_mutex, NULL));
709
720
  azio_start(s);
710
721
 
711
722
  return 0;
715
726
{
716
727
  azio_kill(s);
717
728
 
718
 
  pthread_mutex_destroy(&s->container.thresh_mutex);
719
 
  pthread_cond_destroy(&s->container.threshhold);
 
729
  VOID(pthread_mutex_destroy(&s->container.thresh_mutex));
 
730
  VOID(pthread_cond_destroy(&s->container.threshhold));
720
731
 
721
732
  s->method= AZ_METHOD_BLOCK;
722
733
}
730
741
  if (s->mode == 'r') 
731
742
  {
732
743
    unsigned char buffer[AZHEADER_SIZE + AZMETA_BUFFER_SIZE];
733
 
    pread(s->file, (unsigned char*) buffer, AZHEADER_SIZE + AZMETA_BUFFER_SIZE, 0);
 
744
    pread(s->file, (uchar*) buffer, AZHEADER_SIZE + AZMETA_BUFFER_SIZE, 0);
734
745
    read_header(s, buffer); /* skip the .az header */
735
746
    azrewind(s);
736
747
 
888
899
void putLong (azio_stream *s, uLong x)
889
900
{
890
901
  int n;
891
 
  unsigned char buffer[1];
 
902
  uchar buffer[1];
892
903
 
893
904
  for (n = 0; n < 4; n++) 
894
905
  {
974
985
  s->frm_length= length;
975
986
  s->start+= length;
976
987
 
977
 
  pwrite(s->file, (unsigned char*) blob, s->frm_length, s->frm_start_pos);
 
988
  pwrite(s->file, (uchar*) blob, s->frm_length, s->frm_start_pos);
978
989
 
979
990
  write_header(s);
980
991
  s->pos= (size_t)my_seek(s->file, 0, MY_SEEK_END, MYF(0));
984
995
 
985
996
int azread_frm(azio_stream *s, char *blob)
986
997
{
987
 
  pread(s->file, (unsigned char*) blob, s->frm_length, s->frm_start_pos);
 
998
  pread(s->file, (uchar*) blob, s->frm_length, s->frm_start_pos);
988
999
 
989
1000
  return 0;
990
1001
}
1005
1016
  s->comment_length= length;
1006
1017
  s->start+= length;
1007
1018
 
1008
 
  pwrite(s->file, (unsigned char*) blob, s->comment_length, s->comment_start_pos);
 
1019
  pwrite(s->file, (uchar*) blob, s->comment_length, s->comment_start_pos);
1009
1020
 
1010
1021
  write_header(s);
1011
1022
  s->pos= (size_t)my_seek(s->file, 0, MY_SEEK_END, MYF(0));
1015
1026
 
1016
1027
int azread_comment(azio_stream *s, char *blob)
1017
1028
{
1018
 
  pread(s->file, (unsigned char*) blob, s->comment_length, s->comment_start_pos);
 
1029
  pread(s->file, (uchar*) blob, s->comment_length, s->comment_start_pos);
1019
1030
 
1020
1031
  return 0;
1021
1032
}
1069
1080
#ifdef AZIO_AIO
1070
1081
use_pread:
1071
1082
#endif
1072
 
    s->stream.avail_in = (uInt)pread(s->file, (unsigned char *)s->inbuf,
 
1083
    s->stream.avail_in = (uInt)pread(s->file, (uchar *)s->inbuf,
1073
1084
                                     AZ_BUFSIZE_READ, s->pos);
1074
1085
    s->pos+= s->stream.avail_in;
1075
1086
  }