static int v9fs_xattr_write(V9fsState *s, V9fsPDU *pdu, V9fsFidState *fidp,

                            uint64_t off, uint32_t count,

                            struct iovec *sg, int cnt)

{

    int i, to_copy;

    ssize_t err = 0;

    int write_count;

    int64_t xattr_len;

    size_t offset = 7;





    xattr_len = fidp->fs.xattr.len;

    write_count = xattr_len - off;

    if (write_count > count) {

        write_count = count;

    } else if (write_count < 0) {

        /*

         * write beyond XATTR value len specified in

         * xattrcreate

         */

        err = -ENOSPC;

        goto out;

    }

    err = pdu_marshal(pdu, offset, "d", write_count);

    if (err < 0) {

        return err;

    }

    err += offset;

    fidp->fs.xattr.copied_len += write_count;

    /*

     * Now copy the content from sg list

     */

    for (i = 0; i < cnt; i++) {

        if (write_count > sg[i].iov_len) {

            to_copy = sg[i].iov_len;

        } else {

            to_copy = write_count;

        }

        memcpy((char *)fidp->fs.xattr.value + off, sg[i].iov_base, to_copy);

        /* updating vs->off since we are not using below */

        off += to_copy;

        write_count -= to_copy;

    }

out:

    return err;

}

static int v9fs_xattr_write(V9fsState *s, V9fsPDU *pdu, V9fsFidState *fidp,

                            uint64_t off, uint32_t count,

                            struct iovec *sg, int cnt)

{

    int i, to_copy;

    ssize_t err = 0;

    int write_count;

    int64_t xattr_len;

    size_t offset = 7;





    xattr_len = fidp->fs.xattr.len;

    write_count = xattr_len - off;

    if (write_count > count) {

        write_count = count;

    } else if (write_count < 0) {

        







        err = -ENOSPC;

        goto out;

    }

    err = pdu_marshal(pdu, offset, "d", write_count);

    if (err < 0) {

        return err;

    }

    err += offset;

    fidp->fs.xattr.copied_len += write_count;

    





    for (i = 0; i < cnt; i++) {

        if (write_count > sg[i].iov_len) {

            to_copy = sg[i].iov_len;

        } else {

            to_copy = write_count;

        }

        memcpy((char *)fidp->fs.xattr.value + off, sg[i].iov_base, to_copy);

        

        off += to_copy;

        write_count -= to_copy;

    }

out:

    return err;

}

    int64_t xattr_len;     xattr_len = fidp->fs.xattr.len;     int write_count;     int64_t xattr_len;     xattr_len = fidp->fs.xattr.len;     write_count = xattr_len - off;     if (write_count > count) {         write_count = count;     } else if (write_count < 0) {
static int FUNC_0(V9fsState *VAR_0, V9fsPDU *VAR_1, V9fsFidState *VAR_2,

                            uint64_t VAR_3, uint32_t VAR_4,

                            struct iovec *VAR_5, int VAR_6)

{

    int VAR_7, VAR_8;

    ssize_t err = 0;

    int VAR_9;

    int64_t xattr_len;

    size_t offset = 7;





    xattr_len = VAR_2->fs.xattr.len;

    VAR_9 = xattr_len - VAR_3;

    if (VAR_9 > VAR_4) {

        VAR_9 = VAR_4;

    } else if (VAR_9 < 0) {

        







        err = -ENOSPC;

        goto out;

    }

    err = pdu_marshal(VAR_1, offset, "d", VAR_9);

    if (err < 0) {

        return err;

    }

    err += offset;

    VAR_2->fs.xattr.copied_len += VAR_9;

    





    for (VAR_7 = 0; VAR_7 < VAR_6; VAR_7++) {

        if (VAR_9 > VAR_5[VAR_7].iov_len) {

            VAR_8 = VAR_5[VAR_7].iov_len;

        } else {

            VAR_8 = VAR_9;

        }

        memcpy((char *)VAR_2->fs.xattr.value + VAR_3, VAR_5[VAR_7].iov_base, VAR_8);

        

        VAR_3 += VAR_8;

        VAR_9 -= VAR_8;

    }

out:

    return err;

}

static int FUNC_0(V9fsState *VAR_0, V9fsPDU *VAR_1, V9fsFidState *VAR_2,
uint64_t VAR_3, uint32_t VAR_4,
struct iovec *VAR_5, int VAR_6)
{ int VAR_7, VAR_8; ssize_t err = 0; int VAR_9; int64_t xattr_len; size_t offset = 7; xattr_len = VAR_2->fs.xattr.len; VAR_9 = xattr_len - VAR_3; if (VAR_9 > VAR_4) { VAR_9 = VAR_4; } else if (VAR_9 < 0) { err = -ENOSPC; goto out; } err = pdu_marshal(VAR_1, offset, "d", VAR_9); if (err < 0) { return err; } err += offset; VAR_2->fs.xattr.copied_len += VAR_9; for (VAR_7 = 0; VAR_7 < VAR_6; VAR_7++) { if (VAR_9 > VAR_5[VAR_7].iov_len) { VAR_8 = VAR_5[VAR_7].iov_len; } else { VAR_8 = VAR_9; } memcpy((char *)VAR_2->fs.xattr.value + VAR_3, VAR_5[VAR_7].iov_base, VAR_8); VAR_3 += VAR_8; VAR_9 -= VAR_8; } out:
return err; }