示例#1
0
/* This function sets up the standard parts of the fs_tab. */
static struct fstable *
fs_tab_init(char *mountp, char *fstype)
{
	struct fstable *nfte;

	/* Create the array if necessary. */
	if (fs_list == -1) {
		fs_list = ar_create(ALLOC_CHUNK,
		    (unsigned)sizeof (struct fstable),
		    "filesystem mount data");
		if (fs_list == -1) {
			progerr(ERR_MALLOC, "fs_list", errno, strerror(errno));
			return (NULL);
		}
	}

	/*
	 * Allocate an fstable entry for this mnttab entry.
	 */
	if ((nfte = *(struct fstable **)ar_next_avail(fs_list))
	    == NULL) {
		progerr(ERR_MALLOC, "nfte", errno, strerror(errno));
		return (NULL);
	}

	/*
	 * Point fs_tab at the head of the array again, since it may have
	 * moved due to realloc in ar_next_avail(). If ar_next_avail() realizes
	 * that there is no more room to grow the array, it reallocates the
	 * array. Because we stored pointer to that array in fs_tab, we need
	 * to make sure that it is updated as well.
	 */
	if ((fs_tab = (struct fstable **)ar_get_head(fs_list)) == NULL) {
		progerr(ERR_NOTABLE, "mount", MOUNT_TABLE, strerror(errno));
		return (NULL);
	}

	/*
	 * Get the length of the 'mount point' name.
	 */
	nfte->namlen = strlen(mountp);
	/*
	 * Allocate space for the 'mount point' name.
	 */
	if ((nfte->name = malloc(nfte->namlen+1)) == NULL) {
		progerr(ERR_MALLOC, "name", errno, strerror(errno));
		return (NULL);
	}
	(void) strcpy(nfte->name, mountp);

	if ((nfte->fstype = malloc(strlen(fstype)+1)) == NULL) {
		progerr(ERR_MALLOC, "fstype", errno, strerror(errno));
		return (NULL);
	}
	(void) strcpy(nfte->fstype, fstype);

	fs_tab_used++;

	return (nfte);
}
示例#2
0
/*
 * Free up the entry in the array indicated by index, but hold onto it for
 * future use.
 */
int
ar_delete(int list_handle, int index)
{
	char **array;
	char *deleted_rec;
	int i;
	struct blk_list_cs *list_ptr, *data_ptr;

	if ((array = ar_get_head(list_handle)) == NULL)
		return (0);

	if (invalid_record(list_handle, index))
		return (0);

	/* Get the pointer to the array control structure. */
	list_ptr = bl_cs_array[list_handle];

	if (!(list_ptr->contiguous))
		return (0);	/* This isn't an array. */

	data_ptr = bl_cs_array[list_ptr->data_handle];

	/*
	 * Since this looks just like an array. Record the pointer being
	 * deleted for insertion into the avail list at the end and move all
	 * elements below it up one.
	 */
	deleted_rec = array[index];

	for (i = index; array[i] != NULL; i++)
		array[i] = array[i+1];

	/*
	 * Now insert the deleted entry into the avails list after the NULL
	 * and adjust the avail_ptr to point to the NULL again.
	 */
	array[i] = deleted_rec;
	list_ptr->alloc_segs->avail_ptr -= list_ptr->struct_size;

	/* Adjust other entries in the control structure. */
	list_ptr->alloc_segs->full = 0;
	list_ptr->total_elem -= 1;

	/* Clear the deleted data area. */
	(void) memset(deleted_rec, '\000', data_ptr->struct_size);

	return (1);
}
示例#3
0
/* Insert a single class into the list. */
void
addlist(struct cl_attr ***listp, char *item)
{
	int	i;

	/* If the list is already there, scan for this item */
	if (*listp) {
		for (i = 0; (*listp)[i]; i++)
			if (strcmp(item, (*listp)[i]->name) == 0)
				return;
	} else {
		i = 0;
	}

	/* Insert the new entry */
	if (new_cl_attr(item) == NULL)
		quit(99);

	/* Point the passed pointer to the head of the list. */
	(*listp) = (struct cl_attr **)ar_get_head(cl_handle);
}
示例#4
0
/*
 * Create a list of all classes involved in this installation as well as
 * their attributes.
 */
int
setlist(struct cl_attr ***plist, char *slist)
{
	struct cl_attr	**list, *struct_ptr;
	char	*pt;
	int	n;
	int	i;
	int	sn = -1;

	/* Initialize the environment scanners. */
	(void) s_verify(NULL);
	(void) d_verify(NULL);
	(void) s_pathtype(NULL);

	n = 0;

	/*
	 * This looks like a serious memory leak, however pkgmk depends on
	 * this creating a second list and forgetting any prior ones. The
	 * pkgmk utility does a reasonable job of keeping track of a prior
	 * list constructed from the prototype file using addlist() above.
	 * Perhaps this should be reviewed later, but I do not believe this
	 * to be a problem from what I've seen. - JST
	 */
	cl_handle = -1;		/* forget other lists */

	/* Isolate the first token. */
	pt = strtok(slist, " \t\n");
	while (pt) {
		if (sn == -1 && strcmp(pt, "none") == 0)
			sn = n;

		/* Add new class to list. */
		if ((struct_ptr = new_cl_attr(pt)) == NULL)
			quit(99);

		/* Next token. */
		n++;
		pt = strtok(NULL, " \t\n");
		if (pt && sn != -1)
			if (strcmp(pt, "none") == 0)
				pt = strtok(NULL, " \t\n");
	}
	/*
	 * According to the ABI, if there is a class "none", it will be
	 * the first class to be installed.  This insures that iff there
	 * is a class "none", it will be the first to be installed.
	 * If there is no class "none", nothing happens!
	 */
	new_order = 0;

	/* Get the head of the array. */
	list = (struct cl_attr **)ar_get_head(cl_handle);

	if (sn > 0) {
		struct_ptr = list[sn];
		for (i = sn; i > 0; i--)
			list[i] = list[i - 1];
		list[0] = struct_ptr;
		new_order++;	/* the order is different now */
	}

	/* Point the passed pointer to the head of the list. */
	*plist = list;

	return (n);
}