Пример #1
0
void init_directories(struct node *root){
  unsigned int i;
  struct cache *cache = get_cache(root);
  cache->dir = init_directory(root);
  for (i=0; i<root->nb_children; i++){
    init_directories(get_child(root, i));
  }
}
Пример #2
0
static int init_file(char *path, int esize)
{
	int i, file;
	char buf[sizeof(struct traffic_entry)] = { 0 };

	if (init_directory(path))
		return -1;

	if ((file = open(path, O_WRONLY | O_CREAT, 0600)) >= 0)
	{
		for (i = 0; i < STEP_COUNT; i++)
		{
			if (write(file, buf, esize) < 0)
				break;
		}

		close(file);

		return 0;
	}

	return -1;
}
Пример #3
0
int common_open_new_file(void *recco, void *opti, void *acq)
{
  int err;
  int tempflags;
  struct recording_entity *re = (struct recording_entity *)recco;
  struct common_io_info *ioi = (struct common_io_info *)re->opt;
  D("Acquiring new recorder and changing opt");
  ioi->opt = (struct opt_s *)opti;

  if (acq != NULL)
    ioi->file_seqnum = *((unsigned long *)acq);
  else
    {
      E("Getting free, but not setting file_seqnum. Something weird happending");
    }
  if (ioi->opt->optbits & WRITE_TO_SINGLE_FILE)
    {
      sprintf(ioi->curfilename, "%s%i%s%s%s%s", ROOTDIRS, ioi->id, "/",
              ioi->opt->filename, "/", ioi->opt->filename);
      D("Ready to read/write %ld from/to continuous file %s",
        ioi->file_seqnum, ioi->curfilename);
    }
  else
    {
      sprintf(ioi->curfilename, "%s%i%s%s%s%s.%08ld", ROOTDIRS, ioi->id, "/",
              ioi->opt->filename, "/", ioi->opt->filename, ioi->file_seqnum);
    }

  if (ioi->opt->optbits & READMODE)
    tempflags = re->get_r_flags();
  else
    tempflags = re->get_w_flags();

  D("Opening file %s", ioi->curfilename);

  if (ioi->opt->optbits & WRITE_TO_SINGLE_FILE &&
      ioi->opt->singlefile_fd != 0)
    {
      ioi->fd = ioi->opt->singlefile_fd;
      D("Copying old fd %d for use", ioi->fd);
    }
  else
    {
      err = common_open_file(&(ioi->fd), tempflags, ioi->curfilename, 0);
      if (err != 0)
        {
          /* Situation where the directory doesn't yet exist but we're      */
          /* writing so this shouldn't be a failure                                 */
          if ((err & (ENOTDIR | ENOENT)) && !(ioi->opt->optbits & READMODE))
            {
              D("Directory doesn't exist. Creating it");
              err = init_directory(re);
              CHECK_ERR("Init directory");
              err =
                common_open_file(&(ioi->fd), tempflags, ioi->curfilename, 0);
              if (err != 0)
                {
                  E("Init: Error in file open %s", ioi->curfilename);
                  return err;
                }
            }
          else
            {
              E("Init: Error in file open %s", ioi->curfilename);
              return err;
            }
        }
      if (ioi->opt->optbits & WRITE_TO_SINGLE_FILE)
        {
          ioi->opt->singlefile_fd = ioi->fd;
          if (ioi->opt->optbits & READMODE)
            ioi->filesize =
              (ioi->opt->buf_num_elems *
               (ioi->opt->packet_size - ioi->opt->offset_onwrite));
          else
            ioi->filesize =
              (ioi->opt->buf_num_elems *
               (ioi->opt->packet_size - ioi->opt->offset));
        }
      else if (ioi->opt->optbits & READMODE)
        {
          struct stat statinfo;
          err = stat(ioi->curfilename, &statinfo);
          if (err != 0)
            {
              E("Error in statting %s", ioi->curfilename);
              return -1;
            }
          ioi->filesize = statinfo.st_size;
          D("Filesize is %lu", ioi->filesize);
        }
    }

  /* Doh this might be used by other write methods aswell */
  if (ioi->opt->optbits & WRITE_TO_SINGLE_FILE)
    {
      ioi->offset = (CALC_BUFSIZE_FROM_OPT(ioi->opt)) * ioi->file_seqnum;
      D("Continous file, so offset set to %ld", ioi->offset);
    }
  else
    ioi->offset = 0;

  return 0;
}