int qemu_v9fs_synth_add_file(V9fsSynthNode *parent, int mode,

                             const char *name, v9fs_synth_read read,

                             v9fs_synth_write write, void *arg)

{

    int ret;

    V9fsSynthNode *node, *tmp;



    if (!v9fs_synth_fs) {

        return EAGAIN;

    }

    if (!name || (strlen(name) >= NAME_MAX)) {

        return EINVAL;

    }

    if (!parent) {

        parent = &v9fs_synth_root;

    }



    qemu_mutex_lock(&v9fs_synth_mutex);

    QLIST_FOREACH(tmp, &parent->child, sibling) {

        if (!strcmp(tmp->name, name)) {

            ret = EEXIST;

            goto err_out;

        }

    }

    /* Add file type and remove write bits */

    mode = ((mode & 0777) | S_IFREG);

    node = g_malloc0(sizeof(V9fsSynthNode));

    node->attr         = &node->actual_attr;

    node->attr->inode  = v9fs_synth_node_count++;

    node->attr->nlink  = 1;

    node->attr->read   = read;

    node->attr->write  = write;

    node->attr->mode   = mode;

    node->private      = arg;

    strncpy(node->name, name, sizeof(node->name));

    QLIST_INSERT_HEAD_RCU(&parent->child, node, sibling);

    ret = 0;

err_out:

    qemu_mutex_unlock(&v9fs_synth_mutex);

    return ret;

}

int qemu_v9fs_synth_add_file(V9fsSynthNode *parent, int mode,

                             const char *name, v9fs_synth_read read,

                             v9fs_synth_write write, void *arg)

{

    int ret;

    V9fsSynthNode *node, *tmp;



    if (!v9fs_synth_fs) {

        return EAGAIN;

    }

    if (!name || (strlen(name) >= NAME_MAX)) {

        return EINVAL;

    }

    if (!parent) {

        parent = &v9fs_synth_root;

    }



    qemu_mutex_lock(&v9fs_synth_mutex);

    QLIST_FOREACH(tmp, &parent->child, sibling) {

        if (!strcmp(tmp->name, name)) {

            ret = EEXIST;

            goto err_out;

        }

    }

    

    mode = ((mode & 0777) | S_IFREG);

    node = g_malloc0(sizeof(V9fsSynthNode));

    node->attr         = &node->actual_attr;

    node->attr->inode  = v9fs_synth_node_count++;

    node->attr->nlink  = 1;

    node->attr->read   = read;

    node->attr->write  = write;

    node->attr->mode   = mode;

    node->private      = arg;

    strncpy(node->name, name, sizeof(node->name));

    QLIST_INSERT_HEAD_RCU(&parent->child, node, sibling);

    ret = 0;

err_out:

    qemu_mutex_unlock(&v9fs_synth_mutex);

    return ret;

}

    strncpy(node->name, name, sizeof(node->name));     strncpy(node->name, name, sizeof(node->name));
int FUNC_0(V9fsSynthNode *VAR_0, int VAR_1,

                             const char *VAR_2, v9fs_synth_read VAR_3,

                             v9fs_synth_write VAR_4, void *VAR_5)

{

    int VAR_6;

    V9fsSynthNode *node, *tmp;



    if (!v9fs_synth_fs) {

        return EAGAIN;

    }

    if (!VAR_2 || (strlen(VAR_2) >= NAME_MAX)) {

        return EINVAL;

    }

    if (!VAR_0) {

        VAR_0 = &v9fs_synth_root;

    }



    qemu_mutex_lock(&v9fs_synth_mutex);

    QLIST_FOREACH(tmp, &VAR_0->child, sibling) {

        if (!strcmp(tmp->VAR_2, VAR_2)) {

            VAR_6 = EEXIST;

            goto err_out;

        }

    }

    

    VAR_1 = ((VAR_1 & 0777) | S_IFREG);

    node = g_malloc0(sizeof(V9fsSynthNode));

    node->attr         = &node->actual_attr;

    node->attr->inode  = v9fs_synth_node_count++;

    node->attr->nlink  = 1;

    node->attr->VAR_3   = VAR_3;

    node->attr->VAR_4  = VAR_4;

    node->attr->VAR_1   = VAR_1;

    node->private      = VAR_5;

    strncpy(node->VAR_2, VAR_2, sizeof(node->VAR_2));

    QLIST_INSERT_HEAD_RCU(&VAR_0->child, node, sibling);

    VAR_6 = 0;

err_out:

    qemu_mutex_unlock(&v9fs_synth_mutex);

    return VAR_6;

}

int FUNC_0(V9fsSynthNode *VAR_0, int VAR_1,
const char *VAR_2, v9fs_synth_read VAR_3,
v9fs_synth_write VAR_4, void *VAR_5)
{ int VAR_6; V9fsSynthNode *node, *tmp; if (!v9fs_synth_fs) { return EAGAIN; } if (!VAR_2 || (strlen(VAR_2) >= NAME_MAX)) { return EINVAL; } if (!VAR_0) { VAR_0 = &v9fs_synth_root; } qemu_mutex_lock(&v9fs_synth_mutex); QLIST_FOREACH(tmp, &VAR_0->child, sibling) { if (!strcmp(tmp->VAR_2, VAR_2)) { VAR_6 = EEXIST; goto err_out; } } VAR_1 = ((VAR_1 & 0777) | S_IFREG); node = g_malloc0(sizeof(V9fsSynthNode)); node->attr         = &node->actual_attr; node->attr->inode  = v9fs_synth_node_count++; node->attr->nlink  = 1; node->attr->VAR_3   = VAR_3; node->attr->VAR_4  = VAR_4; node->attr->VAR_1   = VAR_1; node->private      = VAR_5; strncpy(node->VAR_2, VAR_2, sizeof(node->VAR_2)); QLIST_INSERT_HEAD_RCU(&VAR_0->child, node, sibling); VAR_6 = 0; err_out:
qemu_mutex_unlock(&v9fs_synth_mutex); return VAR_6; }