예제 #1
0
void merge_iindex(char **p) {

  while (*p != NULL && *(p+1) != NULL && *(p+2) != NULL && *(p+3) != NULL) {
    p = merge_files(p);
    if (p == NULL) {
      printf("Merge Failed!\n");
      return;
    }
  }

  char filename[256] = {'\0'};
  bzero(filename,256);

  if (*(p+1) != NULL) {
    snprintf(filename, 256, "%s%s%s%s", get_basedir(), "output/", "final", ".git");
    rename(*(p+1), filename);
  }

  bzero(filename,256);

  if (*(p+2) != NULL) {
    snprintf(filename, 256, "%s%s%s%s", get_basedir(), "output/", "final", ".mit");
    rename(*(p+2), filename);
  }
  compress_docid();
  return;
}
예제 #2
0
void compress_docid(){
  char filename[256] = {'\0'};
  char filename_new[256] = {'\0'};

  bzero(filename_new, 256);
  snprintf(filename_new, 256, "%s%s%s%s", get_basedir(), "output/", "final", ".mit.new");
  FILE * f_mit_new = fopen(filename_new, "wb");
  if (f_mit_new == NULL) {
    printf("Compress Doc ID failed");
    return;
  }

  bzero(filename, 256);
  snprintf(filename, 256, "%s%s%s%s", get_basedir(), "output/", "final", ".git");
  FILE * f_git = fopen(filename, "rb");
  if (f_git == NULL) {
    printf("Compress Doc ID failed");
    return;
  }

  bzero(filename, 256);
  snprintf(filename, 256, "%s%s%s%s", get_basedir(), "output/", "final", ".mit");
  FILE * f_mit = fopen(filename, "rb");
  if (f_mit == NULL) {
    printf("Compress Doc ID failed");
    return;
  }

  MIT_T * mit_buf = NULL;
  int n_docs = 0;
  GIT_T * git_buf = (GIT_T *)calloc(1, sizeof(GIT_T));
  int i = 0;
  int last = 0;
  while (!feof(f_git)) {
    last = 0;
    fread(git_buf , sizeof(GIT_T), 1, f_git);
    n_docs = git_buf->n_docs;
    mit_buf = (MIT_T *)calloc(n_docs, sizeof(MIT_T));
    fread(mit_buf, sizeof(MIT_T), n_docs, f_mit);

    for (i = 0; i < n_docs; i++) {
      mit_buf[i].docid -= last;
      last += mit_buf[i].docid;
    }

    fwrite(mit_buf, sizeof(MIT_T), n_docs, f_mit_new);
    free(mit_buf);
  }

  free(git_buf);
  fclose(f_mit);
  fclose(f_git);
  fclose(f_mit_new);

  remove(filename);
  rename(filename_new, filename);
  return;
}
예제 #3
0
static int
readspace(char *spacefile, int *error)
{
	FILE	*fp;
	char	line[LSIZE];
	long	blocks, nodes;
	int	n;

	if (spacefile == NULL)
		return (0);

	if ((fp = fopen(spacefile, "r")) == NULL) {
		progerr(gettext("unable to open spacefile %s"), spacefile);
		return (-1);
	}

	while (fgets(line, LSIZE, fp)) {
		struct fstable *fs_tab;
		char *pt, path[PATH_MAX];

		blocks = nodes = 0;
		for (pt = line; isspace(*pt); /* void */)
			pt++;
		if (*pt == '#' || *pt == '\0')
			continue;

		(void) sscanf(line, "%s %ld %ld", path, &blocks, &nodes);
		mappath(2, path);
		basepath(path, get_basedir(), get_inst_root());
		canonize(path);

		n = resolved_fsys(path);
		if (fsys_stat(n)) {
			(*error)++;
			continue;
		}

		/*
		 * Don't accumulate space requirements on read-only
		 * remote filesystems. NOTE: For some reason, this
		 * used to check for !remote && read only. If this
		 * blows up later, then maybe that was correct -- JST
		 */
		if (is_remote_fs_n(n) && !is_fs_writeable_n(n))
			continue;

		fs_tab = get_fs_entry(n);

		fs_tab->bused += blocks;
		fs_tab->fused += nodes;
	}
	(void) fclose(fp);
	return (0);
}
예제 #4
0
/******************************************************************************

	start_defaults()

	Start setting the defaults.

******************************************************************************/
void start_defaults(int argc, char *argv[])
{
    struct stat buf;
    int i;

    // default options
    static char *default_options[] =
    {
        "--no-defaults",
        "--defaults-file=",
        "--defaults-extra-file=",
        NULL
    };

    // autoclose
    autoclose = FALSE;

    // basedir
    get_basedir(argv[0], basedir);

    // hostname
    if (gethostname(hostname,PATH_MAX) < 0)
    {
        // default
        strcpy(hostname,"mysql");
    }

    // default option
    default_option[0] = NULL;
    for (i=0; (argc > 1) && default_options[i]; i++)
    {
        if(!strnicmp(argv[1], default_options[i], strlen(default_options[i])))
        {
            strncpy(default_option, argv[1], PATH_MAX);
            break;
        }
    }

    // set after basedir is established
    datadir[0] = NULL;
    err_log[0] = NULL;
    out_log[0] = NULL;
    mysqld[0] = NULL;
    sql_file[0] = NULL;
}
예제 #5
0
파일: xml.c 프로젝트: kolyshkin/ploop
int ploop_read_dd(struct ploop_disk_images_data *di)
{
	int ret;
	char basedir[PATH_MAX];
	const char *fname;
	struct stat st;
	xmlDoc *doc = NULL;
	xmlNode *root_element = NULL;

	LIBXML_TEST_VERSION

	if (!di || !di->runtime || !di->runtime->xml_fname) {
		ploop_err(0, "DiskDescriptor.xml is not opened");
		return -1;
	}
	ploop_clear_dd(di);

	fname = di->runtime->xml_fname;
	if (stat(fname, &st)) {
		ploop_err(errno, "Can't stat %s", fname);
		return -1;
	}

	/* workaround libxml2 SIGSEGV on empty document */
	if (st.st_size == 0) {
		ploop_err(0, "Can't parse %s", fname);
		return -1;
	}

	doc = xmlReadFile(fname, NULL, 0);
	if (doc == NULL) {
		ploop_err(0, "Can't parse %s", fname);
		return -1;
	}
	root_element = xmlDocGetRootElement(doc);

	get_basedir(fname, basedir, sizeof(basedir));
	ret = parse_xml(basedir, root_element, di);
	if (ret == 0)
		ret = validate_disk_descriptor(di);

	xmlFreeDoc(doc);

	return ret;
}
예제 #6
0
int
sortmap(struct cfextra ***extlist, VFP_T *pkgmapVfp,
        PKGserver pkgserver, VFP_T *tmpvfp, char *a_zoneName)
{
    int	i, n, nparts;
    char *db_mrg = "unable to merge package and system information";

    if (a_zoneName == (char *)NULL) {
        echo(gettext("## Processing package information."));
    } else {
        echo(gettext("## Processing package information in zone <%s>."),
             a_zoneName);
    }

    /*
     * The following instruction puts the client-relative basedir
     * into the environment iff it's a relocatable package and
     * we're installing to a client. Otherwise, it uses the regular
     * basedir. The only reason for this is so that mappath() upon
     * finding $BASEDIR in a path will properly resolve it to the
     * client-relative path. This way eval_path() can properly
     * construct the server-relative path.
     */
    if (is_relocatable() && is_an_inst_root())
        putparam("BASEDIR", get_info_basedir());

    /*
     * read the pkgmap provided by this package into
     * memory; map parameters specified in the pathname
     * and sort in memory by pathname
     */

    vfpRewind(pkgmapVfp);		/* rewind input file */

    *extlist = pkgobjmap(pkgmapVfp, 2, NULL);

    if (*extlist == NULL) {
        progerr(gettext("unable to process pkgmap"));
        quit(99);
    }

    /* Make all paths client-relative if necessary. */
    if (is_an_inst_root()) {
        (void) client_refer(*extlist);
    }

    if (a_zoneName == (char *)NULL) {
        echo(gettext("## Processing system information."));
    } else {
        echo(gettext("## Processing system information in zone <%s>."),
             a_zoneName);
    }

    /*
     * calculate the number of parts in this package
     * by locating the entry with the largest "volno"
     * associated with it
     */
    nparts = 0;
    if (is_depend_pkginfo_DB() == B_FALSE) {
        for (i = 0; (*extlist)[i]; i++) {
            n = (*extlist)[i]->cf_ent.volno;
            if (n > nparts)
                nparts = n;
        }

        vfpTruncate(tmpvfp);

        dbchg = pkgdbmerg(pkgserver, tmpvfp, *extlist);
        if (dbchg < 0) {
            progerr(gettext(db_mrg));
            quit(99);
        }
    }

    /* Restore the original BASEDIR. */
    if (is_relocatable() && is_an_inst_root())
        putparam("BASEDIR", get_basedir());

    if (is_an_inst_root()) {
        (void) server_refer(*extlist);
    }

    return (nparts);
}
예제 #7
0
파일: xml.c 프로젝트: kolyshkin/ploop
int ploop_store_diskdescriptor(const char *fname, struct ploop_disk_images_data *di)
{
	int i, rc = -1;
	xmlTextWriterPtr writer = NULL;
	xmlDocPtr doc = NULL;
	char tmp[PATH_MAX];
	char basedir[PATH_MAX];
	FILE *fp = NULL;

	ploop_log(0, "Storing %s", fname);

	if (convert_disk_descriptor(di))
		return -1;

	if (di->runtime->xml_fname == NULL)
		di->runtime->xml_fname = strdup(fname);

	get_basedir(fname, tmp, sizeof(tmp));
	if (tmp[0] == '\0')
		strcpy(tmp, "./");

	if (realpath(tmp, basedir) == NULL) {
		ploop_err(errno, "Can't resolve %s", tmp);
		return -1;
	}

	doc = xmlNewDoc(BAD_CAST XML_DEFAULT_VERSION);
	if (doc == NULL) {
		ploop_err(0, "Error creating xml document tree");
		return -1;
	}

	/* Create a new XmlWriter for DOM tree, with no compression. */
	writer = xmlNewTextWriterTree(doc, NULL, 0);
	if (writer == NULL) {
		ploop_err(0, "Error creating xml writer");
		goto err;
	}

	/* Start the document with the xml default for the version,
	 * encoding ISO 8859-1 and the default for the standalone
	 * declaration. */
	rc = xmlTextWriterStartDocument(writer, NULL, NULL, NULL);
	if (rc < 0) {
		ploop_err(0, "Error at xmlTextWriterStartDocument");
		goto err;
	}
	rc = xmlTextWriterStartElement(writer, BAD_CAST "Parallels_disk_image");
	if (rc < 0) {
		ploop_err(0, "Error at xmlTextWriterStartDocument");
		goto err;
	}
	/*********************************************
	 *	Disk_Parameters
	 ********************************************/
	rc = xmlTextWriterStartElement(writer, BAD_CAST "Disk_Parameters");
	if (rc < 0) {
		ploop_err(0, "Error at xmlTextWriter Disk_Parameters");
		goto err;
	}
	rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "Disk_size", "%llu", di->size);
	if (rc < 0) {
		ploop_err(0, "Error at xmlTextWriter Disk_size");
		goto err;
	}

	if (di->max_delta_size != 0) {
		rc = xmlTextWriterWriteFormatElement(writer,
				BAD_CAST "Max_delta_size", "%llu", di->max_delta_size);
		if (rc < 0) {
			ploop_err(0, "Error at xmlTextWriter Max_delta_size");
			goto err;
		}
	}

	rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "Cylinders", "%u", di->cylinders);
	if (rc < 0) {
		ploop_err(0, "Error at xmlTextWriter Cylinders");
		goto err;
	}
	rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "Heads", "%u", di->heads);
	if (rc < 0) {
		ploop_err(0, "Error at xmlTextWriter Heads");
		goto err;
	}
	rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "Sectors", "%llu",
			di->size /(di->cylinders * di->heads));
	if (rc < 0) {
		ploop_err(0, "Error at xmlTextWriter Sectors");
		goto err;
	}
	rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "Padding", "%u", 0);
	if (rc < 0) {
		ploop_err(0, "Error at xmlTextWriter Padding");
		goto err;
	}

	/* Close   Disk_Parameters */
	rc = xmlTextWriterEndElement(writer);
	if (rc < 0) {
		ploop_err(0, "Error at xmlTextWriterEndElement");
		goto err;
	}
	/****************************************
	 * StorageData
	 ****************************************/
	rc = xmlTextWriterStartElement(writer, BAD_CAST "StorageData");
	if (rc < 0) {
		ploop_err(0, "Error at xmlTextWriter StorageData");
		goto err;
	}
	/* Start an element named "Storage" as child of StorageData. */
	rc = xmlTextWriterStartElement(writer, BAD_CAST "Storage");
	if (rc < 0) {
		ploop_err(0, "Error at xmlTextWriter Storage");
		goto err;
	}
	rc = xmlTextWriterWriteElement(writer, BAD_CAST "Start",  BAD_CAST "0");
	if (rc < 0) {
		ploop_err(0, "Error at xmlTextWriter Start");
		goto err;
	}
	rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "End", "%llu", di->size);
	if (rc < 0) {
		ploop_err(0, "Error at xmlTextWriter End");
		goto err;
	}
	rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "Blocksize", "%d",
			di->blocksize);
	if (rc < 0) {
		ploop_err(0, "Error at xmlTextWriter Blocksize");
		goto err;
	}
	if (di->mode == PLOOP_EXPANDED_PREALLOCATED_MODE) {
		rc = xmlTextWriterWriteElement(writer, BAD_CAST "Preallocated",
				BAD_CAST "1");
		if (rc < 0) {
			ploop_err(0, "Error at xmlTextWriter Preallocated");
			goto err;
		}
	}
	/****************************************
	 *	Images
	 ****************************************/
	for (i = 0; i < di->nimages; i++) {
		rc = xmlTextWriterStartElement(writer, BAD_CAST "Image");
		if (rc < 0) {
			ploop_err(0, "Error at xmlTextWriter Image");
			goto err;
		}

		rc = xmlTextWriterWriteElement(writer, BAD_CAST "GUID",
				BAD_CAST di->images[i]->guid);
		if (rc < 0) {
			ploop_err(0, "Error at xmlTextWriter GUID");
			goto err;
		}
		rc = xmlTextWriterWriteElement(writer, BAD_CAST "Type",
			BAD_CAST (di->mode == PLOOP_RAW_MODE ? "Plain" : "Compressed"));
		if (rc < 0) {
			ploop_err(0, "Error at xmlTextWriter Type");
			goto err;
		}

		normalize_image_name(basedir, di->images[i]->file, tmp, sizeof(tmp));
		rc = xmlTextWriterWriteElement(writer, BAD_CAST "File",
				BAD_CAST tmp);
		if (rc < 0) {
			ploop_err(0, "Error at xmlTextWriter File");
			goto err;
		}

		/*  Close  Image */
		rc = xmlTextWriterEndElement(writer);
		if (rc < 0) {
			ploop_err(0, "Error at xmlTextWriterEndElement");
			goto err;
		}
	}

	/* Close Storage */
	rc = xmlTextWriterEndElement(writer);
	if (rc < 0) {
		ploop_err(0, "Error at xmlTextWriterEndElement");
		goto err;
	}
	/* Close StorageData. */
	rc = xmlTextWriterEndElement(writer);
	if (rc < 0) {
		ploop_err(0, "Error at xmlTextWriterEndElement");
		goto err;
	}
	/****************************************
	 *	Snapshots
	 ****************************************/
	rc = xmlTextWriterStartElement(writer, BAD_CAST "Snapshots");
	if (rc < 0) {
		ploop_err(0, "Error at xmlTextWriter Snapshots");
		goto err;
	}

	if (di->top_guid != NULL) {
		rc = xmlTextWriterWriteElement(writer, BAD_CAST "TopGUID",
				BAD_CAST di->top_guid);
		if (rc < 0) {
			ploop_err(0, "Error at xmlTextWriter TopGUID");
			goto err;
		}
	}

	/****************************************
	 *      Shot
	 ****************************************/
	for (i = 0; i < di->nsnapshots; i++) {
		rc = xmlTextWriterStartElement(writer, BAD_CAST "Shot");
		if (rc < 0) {
			ploop_err(0, "Error at xmlTextWriter Shot");
			goto err;
		}

		rc = xmlTextWriterWriteElement(writer, BAD_CAST "GUID",
				BAD_CAST di->snapshots[i]->guid);
		if (rc < 0) {
			ploop_err(0, "Error at xmlTextWriterWrite GUID");
			goto err;
		}
		rc = xmlTextWriterWriteElement(writer, BAD_CAST "ParentGUID",
				BAD_CAST di->snapshots[i]->parent_guid);
		if (rc < 0) {
			ploop_err(0, "Error at xmlTextWriter ParentGUID");
			goto err;
		}

		if (di->snapshots[i]->temporary) {
			rc = xmlTextWriterWriteElement(writer, BAD_CAST "Temporary",  BAD_CAST "");
			if (rc < 0) {
				ploop_err(0, "Error at xmlTextWriter Temporary");
				goto err;
			}
		}

		/*  Close Shot */
		rc = xmlTextWriterEndElement(writer);
		if (rc < 0) {
			ploop_err(0, "Error at xmlTextWriterEndElement");
			goto err;
		}
	}
	/* Close Snapshots */
	rc = xmlTextWriterEndElement(writer);
	if (rc < 0) {
		ploop_err(0, "Error at xmlTextWriterEndElement");
		goto err;
	}

	/* Close Parallels_disk_image */
	rc = xmlTextWriterEndElement(writer);
	if (rc < 0) {
		ploop_err(0, "Error at xmlTextWriterEndElement");
		goto err;
	}
	xmlFreeTextWriter(writer);
	writer = NULL;

	snprintf(tmp, sizeof(tmp), "%s.tmp", fname);
	fp = fopen(tmp, "w+");
	if (fp == NULL) {
		ploop_err(errno, "Can't open %s", tmp);
		goto err;
	}

	rc = xmlDocFormatDump(fp, doc, 1);
	if (rc < 0) {
		ploop_err(0, "Error at xmlDocFormatDump %s", tmp);
		goto err;
	}

	rc = fsync(fileno(fp));
	if (rc) {
		ploop_err(errno, "Failed to sync %s", tmp);
		goto err;
	}
	fclose(fp);
	fp = NULL;

	rc = rename(tmp, fname);
	if (rc < 0) {
		ploop_err(errno, "Can't rename %s to %s", tmp, fname);
		goto err;
	}

	rc = 0;
err:
	if (fp)
		fclose(fp);

	if (writer)
		xmlFreeTextWriter(writer);
	if (doc)
		xmlFreeDoc(doc);
	if (rc)
		return SYSEXIT_DISKDESCR;

	return 0;
}