Esempio n. 1
0
int inode_lookup_parent (super_block_t *sb, char *child) {
	// assert (sb != NULL);
	// assert (child != NULL);

	if (strcmp (child, "/") == 0)
		return 0;

	int index = 0;

	// assert (strlen (child) < MAX_FILE_SIZE);
	char *buffer = malloc (MAX_FILE_SIZE * sizeof(char));
	int count = path_explode (child, buffer);

	char *p = buffer;
	int i;
	for (i = 0; i < count - 1; i++) {
		int len = strlen (p);
		index = inode_lookup (sb, index, p);

		// not found or found but not dir
		if (index == -1 || strcmp (sb->inodes[index].type, INODE_TYPE_DIR) != 0) {
			free (buffer);
			return -1;
		}

		p += len + 1;
	}

	free (buffer);
	return index;
}
Esempio n. 2
0
int inode_lookup_full (super_block_t *sb, char *fullname) {
	// assert (sb != NULL);
	// assert (fullname != NULL);

	if (strcmp (fullname, "/") == 0)
		return 0;

	int index = 0;

	// assert (strlen (fullname) < MAX_FILE_SIZE);
	char *buffer = malloc (MAX_FILE_SIZE * sizeof(char));
	int count = path_explode (fullname, buffer);

	char *p = buffer;
	int i;
	for (i = 0; i < count; i++) {
		int len = strlen (p);
		index = inode_lookup (sb, index, p);

		// not found
		if (index == -1) {
			free (buffer);
			return -1;
		}

		p += len + 1;
	}

	free (buffer);
	return index;
}
Esempio n. 3
0
struct glfs_object *
glfs_h_create_from_handle (struct glfs *fs, unsigned char *handle, int len,
			   struct stat *stat)
{
	loc_t               loc = {0, };
	int                 ret = -1;
	struct iatt         iatt = {0, };
	inode_t            *newinode = NULL;
	xlator_t           *subvol = NULL;
	struct glfs_object *object = NULL;

	/* validate in args */
	if ((fs == NULL) || (handle == NULL) || (len != GFAPI_HANDLE_LENGTH)) {
		errno = EINVAL;
		return NULL;
	}

	__glfs_entry_fs (fs);

	/* get the active volume */
	subvol = glfs_active_subvol (fs);
	if (!subvol) {
		errno = EIO;
		goto out;
	}

	memcpy (loc.gfid, handle, GFAPI_HANDLE_LENGTH);

	newinode = inode_find (subvol->itable, loc.gfid);
	if (newinode)
		loc.inode = newinode;
	else {
		loc.inode = inode_new (subvol->itable);
		if (!loc.inode) {
			errno = ENOMEM;
			goto out;
		}
	}

	ret = syncop_lookup (subvol, &loc, 0, &iatt, 0, 0);
        DECODE_SYNCOP_ERR (ret);
	if (ret) {
		gf_log (subvol->name, GF_LOG_WARNING,
			"inode refresh of %s failed: %s",
			uuid_utoa (loc.gfid), strerror (errno));
		goto out;
	}

	newinode = inode_link (loc.inode, 0, 0, &iatt);
	if (newinode)
		inode_lookup (newinode);
	else {
		gf_log (subvol->name, GF_LOG_WARNING,
			"inode linking of %s failed: %s",
			uuid_utoa (loc.gfid), strerror (errno));
		errno = EINVAL;
		goto out;
	}

	/* populate stat */
	if (stat)
		glfs_iatt_to_stat (fs, &iatt, stat);

	object = GF_CALLOC (1, sizeof(struct glfs_object),
			    glfs_mt_glfs_object_t);
	if (object == NULL) {
		errno = ENOMEM;
		ret = -1;
		goto out;
	}

	/* populate the return object */
	object->inode = newinode;
	uuid_copy (object->gfid, object->inode->gfid);

out:
	/* TODO: Check where the inode ref is being held? */
	loc_wipe (&loc);

	glfs_subvol_done (fs, subvol);

	return object;
}