예제 #1
0
파일: csa.c 프로젝트: sadakane/csalib
i64 read_idx(CSA *csa, char *fidx)
{

  i64 isize;
  i64 i,id;
  uchar *p,*q;
  MMAP *mapidx;

//  printf("read_idx: %s\n",fidx);

  mapidx = mymmap(fidx);
  csa->mapidx = (void *)mapidx;
  p = q = mapidx->addr;
  if (p == NULL) {
    printf("read_idx: cannot mmap %s\n", fidx);
    exit(1);
  }
  isize = mapidx->len;

  i = getuint(p,0,4);  p += 4; /* version */
  if (i != VERSION) {
    printf("read_csa: Version %ld is not supported.\n",i);
    exit(1);
  }

  while (1) {
    if (p - q >= isize) break;
    id = getuint(p,0,1);  p += 1;
    //printf("header ID=%ld\n",id);
    switch (id) {
      case ID_HEADER:
        read_header(csa, &p);
        break;

      case ID_SA:
        read_sa(csa, &p);
        break;

      case ID_ISA:
        read_isa(csa, &p);
        break;

      default:
        printf("read_csa: ID %ld is not supported.\n",id);
        break;
    }
  }

  return isize;
}
예제 #2
0
/*
 * Initialize the system. 
 */
void
init_system(void)
{
char    myhost[65];
char    host[80];
int     howbad;
char *hp;
unsigned char *lockoutp;
unsigned char *p;
int size;
register int i;


  tty = isatty(0);
  pid = getpid();

  signal(SIGTSTP, SIG_IGN);
  signal(SIGINT, SIG_IGN);
  signal(SIGIO, s_sigio);
  signal(SIGALRM, s_sigalrm);
  signal(SIGQUIT, s_sigquit);
  signal(SIGTERM, s_sigdie);
  signal(SIGPIPE, s_sigdie);
  signal(SIGHUP, tty ? s_sigdie : s_sigquit);

  alarm(300);

  if (!strncmp(*ARGV, "_clientbbs", 10))
    client = 1;

  if (!tty)
    init_states();

  if (tty)
    myecho(OFF);

  /* Make sure the site is not locked out */
  size = 0;
  if ((lockoutp = p = (unsigned char *)mymmap(LOCKOUT, &size, 0)))
  {
    strcpy(myhost, ARGV[1] ? ARGV[1] : "local");
    for (hp = myhost; *hp; hp++)
      if (*hp >= 'A' && *hp <= 'Z')
        *hp += 32;
    while (p - lockoutp < size)
    {
      for (i = 0; p - lockoutp < size && *p != '\n'; i++, p++)
	host[i] = *p;
      host[i] = 0;
      p++;
      if (*host && *host != '#' && host[strlen(host) - 2] == ' ')
      {
	howbad = host[strlen(host) - 1] - '0' + 1;
	host[strlen(host) - 2] = 0;
        for (hp = host; *hp; hp++)
          if (*hp >= 'A' && *hp <= 'Z')
            *hp += 32;
        hp = strchr(host, '*');
        if ((hp && !strncmp(host, myhost, (int)(hp - host)) && hp++ &&
             !strcmp(hp, myhost + strlen(myhost) - strlen(hp))) ||
            (!hp && !strcmp(host, myhost)))
	  if ((nonew = howbad) == 1)
	  {
            printf("\n\nThe site you are connecting from has been locked out of the BBS.  E-mail any\ninquiries about this to [email protected].\n\n\n");
            my_exit(10);
	  }
      }
    }
    munmap((void *)lockoutp, size);
  }

  lastbcast = msg->lastbcast;
}
예제 #3
0
파일: rrd.c 프로젝트: 4224657/netdata
RRDDIM *rrddim_add(RRDSET *st, const char *id, const char *name, long multiplier, long divisor, int algorithm)
{
	char filename[FILENAME_MAX + 1];
	char fullfilename[FILENAME_MAX + 1];

	char varname[CONFIG_MAX_NAME + 1];
	RRDDIM *rd = NULL;
	unsigned long size = sizeof(RRDDIM) + (st->entries * sizeof(storage_number));

	debug(D_RRD_CALLS, "Adding dimension '%s/%s'.", st->id, id);

	rrdset_strncpyz_name(filename, id, FILENAME_MAX);
	snprintfz(fullfilename, FILENAME_MAX, "%s/%s.db", st->cache_dir, filename);
	if(rrd_memory_mode != RRD_MEMORY_MODE_RAM) rd = (RRDDIM *)mymmap(fullfilename, size, ((rrd_memory_mode == RRD_MEMORY_MODE_MAP)?MAP_SHARED:MAP_PRIVATE), 1);
	if(rd) {
		struct timeval now;
		gettimeofday(&now, NULL);

		if(strcmp(rd->magic, RRDDIMENSION_MAGIC) != 0) {
			errno = 0;
			info("Initializing file %s.", fullfilename);
			bzero(rd, size);
		}
		else if(rd->memsize != size) {
			errno = 0;
			error("File %s does not have the desired size. Clearing it.", fullfilename);
			bzero(rd, size);
		}
		else if(rd->multiplier != multiplier) {
			errno = 0;
			error("File %s does not have the same multiplier. Clearing it.", fullfilename);
			bzero(rd, size);
		}
		else if(rd->divisor != divisor) {
			errno = 0;
			error("File %s does not have the same divisor. Clearing it.", fullfilename);
			bzero(rd, size);
		}
		else if(rd->algorithm != algorithm) {
			errno = 0;
			error("File %s does not have the same algorithm. Clearing it.", fullfilename);
			bzero(rd, size);
		}
		else if(rd->update_every != st->update_every) {
			errno = 0;
			error("File %s does not have the same refresh frequency. Clearing it.", fullfilename);
			bzero(rd, size);
		}
		else if(usecdiff(&now, &rd->last_collected_time) > (rd->entries * rd->update_every * 1000000ULL)) {
			errno = 0;
			error("File %s is too old. Clearing it.", fullfilename);
			bzero(rd, size);
		}
		else if(strcmp(rd->id, id) != 0) {
			errno = 0;
			error("File %s contents are not for dimension %s. Clearing it.", fullfilename, id);
			// munmap(rd, size);
			// rd = NULL;
			bzero(rd, size);
		}
	}

	if(rd) {
		// we have a file mapped for rd
		rd->mapped = rrd_memory_mode;
		rd->flags = 0x00000000;
		rd->next = NULL;
		rd->name = NULL;
	}
	else {
		// if we didn't manage to get a mmap'd dimension, just create one

		rd = calloc(1, size);
		if(!rd) {
			fatal("Cannot allocate RRD_DIMENSION %s/%s.", st->id, id);
			return NULL;
		}

		rd->mapped = RRD_MEMORY_MODE_RAM;
	}
	rd->memsize = size;

	strcpy(rd->magic, RRDDIMENSION_MAGIC);
	strcpy(rd->cache_filename, fullfilename);
	strncpyz(rd->id, id, RRD_ID_LENGTH_MAX);
	rd->hash = simple_hash(rd->id);

	snprintfz(varname, CONFIG_MAX_NAME, "dim %s name", rd->id);
	rd->name = config_get(st->id, varname, (name && *name)?name:rd->id);

	snprintfz(varname, CONFIG_MAX_NAME, "dim %s algorithm", rd->id);
	rd->algorithm = rrddim_algorithm_id(config_get(st->id, varname, rrddim_algorithm_name(algorithm)));

	snprintfz(varname, CONFIG_MAX_NAME, "dim %s multiplier", rd->id);
	rd->multiplier = config_get_number(st->id, varname, multiplier);

	snprintfz(varname, CONFIG_MAX_NAME, "dim %s divisor", rd->id);
	rd->divisor = config_get_number(st->id, varname, divisor);
	if(!rd->divisor) rd->divisor = 1;

	rd->entries = st->entries;
	rd->update_every = st->update_every;

	// prevent incremental calculation spikes
	rd->counter = 0;
	rd->updated = 0;
	rd->calculated_value = 0;
	rd->last_calculated_value = 0;
	rd->collected_value = 0;
	rd->last_collected_value = 0;
	rd->collected_volume = 0;
	rd->stored_volume = 0;
	rd->values[st->current_entry] = pack_storage_number(0, SN_NOT_EXISTS);
	rd->last_collected_time.tv_sec = 0;
	rd->last_collected_time.tv_usec = 0;

	// append this dimension
	pthread_rwlock_wrlock(&st->rwlock);
	if(!st->dimensions)
		st->dimensions = rd;
	else {
		RRDDIM *td = st->dimensions;
		for(; td->next; td = td->next) ;
		td->next = rd;
	}
	pthread_rwlock_unlock(&st->rwlock);

	rrddim_index_add(st, rd);

	return(rd);
}
예제 #4
0
파일: rrd.c 프로젝트: 4224657/netdata
RRDSET *rrdset_create(const char *type, const char *id, const char *name, const char *family, const char *context, const char *title, const char *units, long priority, int update_every, int chart_type)
{
	if(!type || !type[0]) {
		fatal("Cannot create rrd stats without a type.");
		return NULL;
	}

	if(!id || !id[0]) {
		fatal("Cannot create rrd stats without an id.");
		return NULL;
	}

	char fullid[RRD_ID_LENGTH_MAX + 1];
	char fullfilename[FILENAME_MAX + 1];
	RRDSET *st = NULL;

	snprintfz(fullid, RRD_ID_LENGTH_MAX, "%s.%s", type, id);

	st = rrdset_find(fullid);
	if(st) {
		error("Cannot create rrd stats for '%s', it already exists.", fullid);
		return st;
	}

	long entries = config_get_number(fullid, "history", rrd_default_history_entries);
	if(entries < 5) entries = config_set_number(fullid, "history", 5);
	if(entries > RRD_HISTORY_ENTRIES_MAX) entries = config_set_number(fullid, "history", RRD_HISTORY_ENTRIES_MAX);

	int enabled = config_get_boolean(fullid, "enabled", 1);
	if(!enabled) entries = 5;

	unsigned long size = sizeof(RRDSET);
	char *cache_dir = rrdset_cache_dir(fullid);

	debug(D_RRD_CALLS, "Creating RRD_STATS for '%s.%s'.", type, id);

	snprintfz(fullfilename, FILENAME_MAX, "%s/main.db", cache_dir);
	if(rrd_memory_mode != RRD_MEMORY_MODE_RAM) st = (RRDSET *)mymmap(fullfilename, size, ((rrd_memory_mode == RRD_MEMORY_MODE_MAP)?MAP_SHARED:MAP_PRIVATE), 0);
	if(st) {
		if(strcmp(st->magic, RRDSET_MAGIC) != 0) {
			errno = 0;
			info("Initializing file %s.", fullfilename);
			bzero(st, size);
		}
		else if(strcmp(st->id, fullid) != 0) {
			errno = 0;
			error("File %s contents are not for chart %s. Clearing it.", fullfilename, fullid);
			// munmap(st, size);
			// st = NULL;
			bzero(st, size);
		}
		else if(st->memsize != size || st->entries != entries) {
			errno = 0;
			error("File %s does not have the desired size. Clearing it.", fullfilename);
			bzero(st, size);
		}
		else if(st->update_every != update_every) {
			errno = 0;
			error("File %s does not have the desired update frequency. Clearing it.", fullfilename);
			bzero(st, size);
		}
		else if((time(NULL) - st->last_updated.tv_sec) > update_every * entries) {
			errno = 0;
			error("File %s is too old. Clearing it.", fullfilename);
			bzero(st, size);
		}
	}

	if(st) {
		st->name = NULL;
		st->type = NULL;
		st->family = NULL;
		st->context = NULL;
		st->title = NULL;
		st->units = NULL;
		st->dimensions = NULL;
		st->next = NULL;
		st->mapped = rrd_memory_mode;
	}
	else {
		st = calloc(1, size);
		if(!st) {
			fatal("Cannot allocate memory for RRD_STATS %s.%s", type, id);
			return NULL;
		}
		st->mapped = RRD_MEMORY_MODE_RAM;
	}
	st->memsize = size;
	st->entries = entries;
	st->update_every = update_every;

	if(st->current_entry >= st->entries) st->current_entry = 0;

	strcpy(st->cache_filename, fullfilename);
	strcpy(st->magic, RRDSET_MAGIC);

	strcpy(st->id, fullid);
	st->hash = simple_hash(st->id);

	st->cache_dir = cache_dir;

	st->chart_type = rrdset_type_id(config_get(st->id, "chart type", rrdset_type_name(chart_type)));
	st->type       = config_get(st->id, "type", type);
	st->family     = config_get(st->id, "family", family?family:st->type);
	st->context    = config_get(st->id, "context", context?context:st->id);
	st->units      = config_get(st->id, "units", units?units:"");

	st->priority = config_get_number(st->id, "priority", priority);
	st->enabled = enabled;

	st->isdetail = 0;
	st->debug = 0;

	st->last_collected_time.tv_sec = 0;
	st->last_collected_time.tv_usec = 0;
	st->counter_done = 0;

	st->gap_when_lost_iterations_above = (int) (
			config_get_number(st->id, "gap when lost iterations above", RRD_DEFAULT_GAP_INTERPOLATIONS) + 2);

	avl_init_lock(&st->dimensions_index, rrddim_compare);

	pthread_rwlock_init(&st->rwlock, NULL);
	pthread_rwlock_wrlock(&rrdset_root_rwlock);

	if(name && *name) rrdset_set_name(st, name);
	else rrdset_set_name(st, id);

	{
		char varvalue[CONFIG_MAX_VALUE + 1];
		snprintfz(varvalue, CONFIG_MAX_VALUE, "%s (%s)", title?title:"", st->name);
		st->title = config_get(st->id, "title", varvalue);
	}

	st->next = rrdset_root;
	rrdset_root = st;

	rrdset_index_add(st);

	pthread_rwlock_unlock(&rrdset_root_rwlock);

	return(st);
}
예제 #5
0
/**********************************************************************
* edit room description
* Ask user if they want to edit <R>oom aide only, <D>escription only,
* <B>oth, or <Q>uit.
* Contingent on option chosen, edit the item(s).  When done, write
* the description to the descfile.
* raname is taken either from reading the description or set anew.
* If a new aide is chosen, read his/her user file and assign ->usernum
* to be roomaide.
**********************************************************************/
void
editdesc(void)
{
char    choice = '0';
char    descfile[100];
char    newdescfile[100];
int     dfd;		/* desc file descriptor */
int     dummy;		/* readmsg() needs this: returns YES/NO */
int     err;		/* makemessage returns this */
char    raname[MAXALIAS+1];
int	upload;
char   *cp;
struct mheader *mh;
int size;
unsigned char *infop;
struct user *tmpuser;

  sprintf(descfile, "%sroom%d", DESCDIR, curr);
  sprintf(newdescfile, "%sroom%d.NEW", DESCDIR, curr);

  size = 0;
  if (!(infop = (unsigned char *)mymmap(descfile, &size, 0)) || !size)
  {
    colorize("@RDescription doesn't yet exist@G\n");
    choice = 'B';
  }
  else
  {
    readmessage(infop, &dummy, raname, FALSE, 0);
    munmap((void *)infop, size);
  }

  /* if it's a new description, don't bother prompting for choice */
  if (choice != 'B')
  {
    printf("\nEdit <F>orum moderator only, <D>escription only, <B>oth, <Q>uit -> ");
    choice = get_single_quiet("FDBQ \n");
    putchar('\n');
  }
  if (choice == 'Q' || choice == ' ' || choice == '\n')
    return;

  if (choice == 'B' || choice == 'F')
  {
    cp = get_name("\nNew forum moderator -> ", 2);
    if (!*cp)
      return;

    if (!strcmp(cp, "Sysop"))
      msg->room[curr].roomaide = 0;
    else
      if (!(tmpuser = getuser(cp)) || tmpuser->f_invisible)
      {
	if (tmpuser)
	  freeuser(tmpuser);
	printf("\nThere is no user %s on this BBS.\n", cp);
        return;
      }
      else
      {
        msg->room[curr].roomaide = tmpuser->usernum;
	freeuser(tmpuser);
      }

    if (choice == 'F')
      return;
  }

  printf("\nHit Y to upload a description or N to enter it normally (Y/N) -> ");
  if ((upload = yesno(-1)))
    printf("\n(Use control-D to end!)\n");

  printf("\nEnter a new forum description...\n\n");

  err = makemessage(NULL, MES_DESC, upload);

  if (err == ABORT)
    colorize("@RDescription not entered\n@G");
  else if (err != SAVE)
    colorize("@RSome mystical error - can't make description\n@G");
  else if ((dfd = open(newdescfile, O_WRONLY | O_CREAT | O_EXCL, 0640)) < 0)
    printf("error opening desc file to make final copy\n");
  else
  {
    mh = (struct mheader *)(void *)tmpstart;
    write(dfd, tmpstart, mh->hlen + mh->len + 1);
    close(dfd);
    rename(newdescfile, descfile);
  }
  munmap((void *)tmpstart, 53248);
  if (err == SAVE)
  {
    printf("\nMark forum info as having been updated? (Y/N) -> ");
    if (yesno(-1))
      msg->room[curr].descupdate = msg->room[curr].highest;
  }
}
예제 #6
0
파일: psi1.c 프로젝트: rcallahan/csalib
i64 psi1_read(CSA *csa, char *fname)
{
  FILE *f1;
  i64 psize1,psize2;
  i64 n;
  int k,l,id,id2;
  char *fpsi, *fpsd, *fname2;
  psi1 *ps;
  uchar *p,*q;
  
  csa->psi_struc = ps = mymalloc(sizeof(psi1));

  k = strlen(fname);
  fname2 = mymalloc(k-4+1);
  strncpy(fname2,fname,k-4);
  fname2[k-4] = 0;
  k -= 5;

  initranktables();
  mkdecodetable();

  fpsi = mymalloc(k+5+1);
//  fpsd = mymalloc(k+5);

//  sprintf(fpsd,"%s.psd",fname2);
  fpsd = fname;
//  printf("psi_read: read %s\n",fpsd);

  ps->mappsd = mymmap(fpsd);
  if (ps->mappsd->addr==NULL) {
    perror("psi1_read: mmap2\n");
    exit(1);
  }
  p = q = (uchar *)ps->mappsd->addr;
  psize1 = ps->mappsd->len;

  id = getuint(p,0,1);  p += 1;
  if (id != ID_PSI) {
    printf("read_psi: id = %d is not supported.\n",id);
    exit(1);
  }
  ps->k = k = getuint(p,0,1);  p += 1;
  ps->n = n = getuint(p,0,k);  p += k;
  ps->L = l = getuint(p,0,k);  p += k;

  id = getuint(p,0,1);  p += 1;
//  printf("read_psi: psi_id = %d L = %d\n",id,l);
  csa->id = ps->id = id;
  id2 = id & 0x3f;
  switch (id2) {
    case ID_DIFF_GAMMA:
      printf("#psi format = GAMMA L=%d C=%d\n",l,(id>>7));
      sprintf(fpsi,"%s.psi",fname2);
      break;
    case ID_DIFF_GAMMA_RL:
      printf("#psi format = GAMMA_RL L=%d C=%d\n",l,(id>>7));
      sprintf(fpsi,"%s.pri",fname2);
      break;
    case ID_DIFF_GAMMA_SPARSE:
      printf("#psi format = GAMMA_SPARSE L=%d C=%d\n",l,(id>>7));
      sprintf(fpsi,"%s.psi",fname2);
      break;
    case ID_DIFF_GAMMA_RL_SPARSE:
      printf("#psi format = GAMMA_RL_SPARSE L=%d C=%d\n",l,(id>>7));
      sprintf(fpsi,"%s.pri",fname2);
      break;
    case ID_DIFF_GAMMA_RR:
      printf("#psi format = GAMMA_RR L=%d C=%d\n",l,(id>>7));
      sprintf(fpsi,"%s.pxi",fname2);
      break;
    default:
      printf("read_csa: ID %d is not supported.\n",id);
      break;
  }

  if (id & ID_COMPPTR) {
    printf("COMPPTR\n");
    ps->sx = mymalloc(sizeof(SPARSEARRAY));
    ps->sb = mymalloc(sizeof(SPARSEARRAY));
    SPARSEARRAY_read(ps->sx, &p);
    SPARSEARRAY_read(ps->sb, &p);
  } else {
    ps->R = p;
  }
//  printf("psize = %ld\n",psize);

////   read psi
//  printf("psi_read: map %s\n",fpsi);
  ps->mappsi = mymmap(fpsi);
  if (ps->mappsi->addr==NULL) {
    perror("psi1_read: mmap1\n");
    exit(1);
  }
  ps->B = (unsigned short *)ps->mappsi->addr;
  psize2 = ps->mappsi->len;
//  printf("psize2 = %ld\n",psize2);

//  printf("psi1_read: psize1 = %ld psize2 = %ld\n",psize1,psize2);
  ps->psize = psize1 + psize2;

  free(fpsi);
//  free(fpsd);
  free(fname2);

// user-specific functions
  csa->psi = psi1_psi;
  if (id2 == ID_DIFF_GAMMA_RR) {
    csa->psi = psi12_psi;
    csa->psi_pred = csa_psi_pred_naive;
    csa->psi_succ = csa_psi_succ_naive;
  } else {
    if ((id & ID_COMPPTR) || 0) {
      csa->psi_pred = csa_psi_pred_naive;
      csa->psi_succ = csa_psi_succ_naive;
    } else {
      csa->psi_succ = psi1_succ_tmp;
      csa->psi_pred = psi1_pred_tmp;
//    csa->psi_succ = csa_psi_succ_naive;
//    csa->psi_pred = csa_psi_pred_naive;
    }
  }

// default functions
  csa->LF = csa_LF_by_psi;
  csa->lookup = csa_lookup;
  csa->inverse = csa_inverse;
  csa->text = csa_text;
  csa->substring = csa_substring;
  csa->T = csa_T;
  csa->head = csa_head_rank;
  csa->search = csa_search;
  csa->searchsub = csa_searchsub;


  return psize1 + psize2;
}
예제 #7
0
i64 psi2_read(CSA *csa, char *fname)
{
  i64 psize;
  i64 n;
  int k,id;
  psi2 *ps;
  uchar *p, *q;
 
  csa->psi_struc = ps = (psi2 *) mymalloc(sizeof(psi2));

  printf("psi_read: map %s\n",fname);
  ps->mappsi = mymmap(fname);
  if (ps->mappsi->addr==NULL) {
    perror("psi2_read: mmap2\n");
    exit(1);
  }
  p = q = (uchar *)ps->mappsi->addr;

  id = getuint(p,0,1);  p += 1;
  if (id != ID_PSI) {
    printf("read_psi: id = %d is not supported.\n",id);
    exit(1);
  }
  ps->k = k = getuint(p,0,1);  p += 1;
  ps->n = n = getuint(p,0,k);  p += k;

  id = getuint(p,0,1);  p += 1;
//  printf("read_psi: psi_id = %d\n",id);
  csa->id = ps->id = id;
  switch (id) {
  case ID_SPARSE4:
    printf("#psi format = SPARSE4\n");
    break;
  default:
    printf("read_csa: ID %d is not supported.\n",id);
    break;
  }


  ps->sa = (sparsearray4 *) mymalloc(sizeof(*ps->sa));
  sparsearray4_read(ps->sa, &p);
  psize = p - q;

//  printf("psi2_read: psize = %ld\n",psize);
  ps->psize = psize;


// user-specific functions
  csa->psi = psi2_psi;
  csa->psi_succ = csa_psi_succ_naive;
  csa->psi_pred = csa_psi_pred_naive;

// default functions
  csa->lookup = csa_lookup;
  csa->inverse = csa_inverse;
  csa->text = csa_text;
  csa->substring = csa_substring;
  csa->T = csa_T;
  csa->head = csa_head_rank;
  csa->search = csa_search;


  return psize;
}
예제 #8
0
	int csa_read(CSA *SA,char *fname1,char *fname2) {
		int i,n,m;
		FILE *f;
		int psize,isize;
		unsigned char *ptr;

		#ifndef USE_MMAP
		f = fopen(fname1,"rb");
		if (f == NULL) {
			perror("csa2_read1: ");
			exit(1);
		}
		fseek(f,0,SEEK_END);
		psize = ftell(f);
		fseek(f,0,0);
		SA->B = malloc(psize+1);
		if (SA->B == NULL) {
			perror("csa2_read2: ");
			exit(1);
		}
		fread(SA->B,psize+1,1,f);
		fclose(f);
		#else
		SA->mapp = mymmap(fname1);
		if (SA->mapp->addr==NULL) {
			perror("mmap1\n");
			exit(1);
		}
		SA->B = (unsigned short *)SA->mapp->addr;
		SA->p_size = SA->mapp->len;
		psize = SA->mapp->len;
		#endif

		f = fopen(fname2,"rb");
		if (f == NULL) {
			perror("csa2_read3: ");
			exit(1);
		}
		fseek(f,0,SEEK_END);
		isize = ftell(f);
		fseek(f,0,0);
		SA->n = n = readint(f);	 /* eLXg */
		SA->l = readint(f);		 /* psii[ */
		SA->two = readint(f);	 /* SAi[ */
		SA->two2 = readint(f);	 /* ISAi[ */

								 /* At@xbgTCY */
		if ((m=readint(f)) != SIGMA) {
			printf("error sigma=%d\n",m);
		}
		SA->m = m = readint(f);	 /*  */
		isize = 6*sizeof(int);

		for (i = 0; i < SIGMA; i++) {
								 /* -> */
			SA->C[i] = readint(f);
		}
		isize += SIGMA*sizeof(int);
		for (i = 1; i <= m+1; i++) {
								 /* px */
			SA->K[i] = readint(f);
		}
		isize += (m+1)*sizeof(int);
		for (i = 1; i <= m; i++) {
								 /* ->R[h */
			SA->C2[i] = readint(f);
		}
		isize += m*sizeof(int);

		#ifndef USE_MMAP
		SA->R = malloc((n / SA->l + 1)*2*sizeof(int));
		if (SA->R == NULL) {
			perror("csa2_read4: ");
			exit(1);
		}
		for (i = 0; i <= n / SA->l; i++) {
								 /* psil */
			SA->R[i*2] = readint(f);
								 /* psi|C^ */
			SA->R[i*2+1] = readint(f);
		}

		SA->SA = malloc((n / SA->two + 1)*sizeof(int));
		if (SA->SA == NULL) {
			perror("csa2_read6: ");
			exit(1);
		}
		for (i = 0; i <= (n / SA->two); i++) {
			SA->SA[i] = readint(f);
		}
		SA->ISA = malloc((n / SA->two2 + 1)*sizeof(int));
		if (SA->ISA == NULL) {
			perror("csa2_read7: ");
			exit(1);
		}
		for (i = 0; i <= (n-1) / SA->two2; i++) {
			SA->ISA[i] = readint(f);
		}
		fclose(f);
		#else
		fclose(f);

		SA->mapi = mymmap(fname2);
		if (SA->mapi->addr==NULL) {
			perror("mmap2\n");
			exit(1);
		}
		SA->i_size = SA->mapi->len;

		ptr = (unsigned char *)SA->mapi->addr + isize;
		SA->R = (int *)ptr;
		isize += (n / SA->l+1)*2*sizeof(int);
		SA->r_size = (n / SA->l+1)*2;

		ptr = (unsigned char *)SA->mapi->addr + isize;
		SA->SA = (int *)ptr;
		SA->sa_size = (n / SA->two+1);
		isize += (n / SA->two+1)*sizeof(int);

		ptr = (unsigned char *)SA->mapi->addr + isize;
		SA->ISA = (int *)ptr;
		SA->isa_size =(n / SA->two2+1);
		#endif
		return 0;
	}