Ejemplo n.º 1
0
static void cmp_top(FILE *fp,t_topology *t1,t_topology *t2,real ftol, real abstol)
{
  int i;
  
  fprintf(fp,"comparing top\n");
  if (t2) {
    cmp_idef(fp,&(t1->idef),&(t2->idef),ftol,abstol);
    cmp_atoms(fp,&(t1->atoms),&(t2->atoms),ftol,abstol);
    cmp_block(fp,&t1->cgs,&t2->cgs,"cgs");
    cmp_block(fp,&t1->mols,&t2->mols,"mols");
    cmp_blocka(fp,&t1->excls,&t2->excls,"excls");
  } else {
    cmp_idef(fp,&(t1->idef),NULL,ftol,abstol);
    cmp_atoms(fp,&(t1->atoms),NULL,ftol,abstol);
  }
}
Ejemplo n.º 2
0
void cmp_top(FILE *fp, const t_topology *t1, const t_topology *t2, real ftol, real abstol)
{
    fprintf(fp, "comparing top\n");
    if (t2)
    {
        cmp_idef(fp, &(t1->idef), &(t2->idef), ftol, abstol);
        cmp_atoms(fp, &(t1->atoms), &(t2->atoms), ftol, abstol);
        cmp_block(fp, &t1->cgs, &t2->cgs, "cgs");
        cmp_block(fp, &t1->mols, &t2->mols, "mols");
        cmp_bool(fp, "bIntermolecularInteractions", -1, t1->bIntermolecularInteractions, t2->bIntermolecularInteractions);
        cmp_blocka(fp, &t1->excls, &t2->excls, "excls");
    }
    else
    {
        cmp_idef(fp, &(t1->idef), NULL, ftol, abstol);
        cmp_atoms(fp, &(t1->atoms), NULL, ftol, abstol);
    }
}
Ejemplo n.º 3
0
static int
cmp (const void *a__, const void *b__)
{
    struct grub_net_buff *a_ = *(struct grub_net_buff **) a__;
    struct grub_net_buff *b_ = *(struct grub_net_buff **) b__;
    struct tftphdr *a = (struct tftphdr *) a_->data;
    struct tftphdr *b = (struct tftphdr *) b_->data;
    /* We want the first elements to be on top.  */
    return -cmp_block (grub_be_to_cpu16 (a->u.data.block), grub_be_to_cpu16 (b->u.data.block));
}
Ejemplo n.º 4
0
static grub_err_t
tftp_receive (grub_net_udp_socket_t sock __attribute__ ((unused)),
              struct grub_net_buff *nb,
              void *f)
{
    grub_file_t file = f;
    struct tftphdr *tftph = (void *) nb->data;
    tftp_data_t data = file->data;
    grub_err_t err;
    grub_uint8_t *ptr;

    if (nb->tail - nb->data < (grub_ssize_t) sizeof (tftph->opcode))
    {
        grub_dprintf ("tftp", "TFTP packet too small\n");
        return GRUB_ERR_NONE;
    }

    tftph = (struct tftphdr *) nb->data;
    switch (grub_be_to_cpu16 (tftph->opcode))
    {
    case TFTP_OACK:
        data->block_size = TFTP_DEFAULTSIZE_PACKET;
        data->have_oack = 1;
        for (ptr = nb->data + sizeof (tftph->opcode); ptr < nb->tail;)
        {
            if (grub_memcmp (ptr, "tsize\0", sizeof ("tsize\0") - 1) == 0)
                data->file_size = grub_strtoul ((char *) ptr + sizeof ("tsize\0")
                                                - 1, 0, 0);
            if (grub_memcmp (ptr, "blksize\0", sizeof ("blksize\0") - 1) == 0)
                data->block_size = grub_strtoul ((char *) ptr + sizeof ("blksize\0")
                                                 - 1, 0, 0);
            while (ptr < nb->tail && *ptr)
                ptr++;
            ptr++;
        }
        data->block = 0;
        grub_netbuff_free (nb);
        err = ack (data, 0);
        grub_error_save (&data->save_err);
        return GRUB_ERR_NONE;
    case TFTP_DATA:
        if (nb->tail - nb->data < (grub_ssize_t) (sizeof (tftph->opcode)
                + sizeof (tftph->u.data.block)))
        {
            grub_dprintf ("tftp", "TFTP packet too small\n");
            return GRUB_ERR_NONE;
        }

        err = grub_priority_queue_push (data->pq, &nb);
        if (err)
            return err;

        {
            struct grub_net_buff **nb_top_p, *nb_top;
            while (1)
            {
                nb_top_p = grub_priority_queue_top (data->pq);
                if (!nb_top_p)
                    return GRUB_ERR_NONE;
                nb_top = *nb_top_p;
                tftph = (struct tftphdr *) nb_top->data;
                if (cmp_block (grub_be_to_cpu16 (tftph->u.data.block), data->block + 1) >= 0)
                    break;
                ack (data, grub_be_to_cpu16 (tftph->u.data.block));
                grub_netbuff_free (nb_top);
                grub_priority_queue_pop (data->pq);
            }
            while (cmp_block (grub_be_to_cpu16 (tftph->u.data.block), data->block + 1) == 0)
            {
                unsigned size;

                grub_priority_queue_pop (data->pq);

                if (file->device->net->packs.count < 50)
                    err = ack (data, data->block + 1);
                else
                {
                    file->device->net->stall = 1;
                    err = 0;
                }
                if (err)
                    return err;

                err = grub_netbuff_pull (nb_top, sizeof (tftph->opcode) +
                                         sizeof (tftph->u.data.block));
                if (err)
                    return err;
                size = nb_top->tail - nb_top->data;

                data->block++;
                if (size < data->block_size)
                {
                    if (data->ack_sent < data->block)
                        ack (data, data->block);
                    file->device->net->eof = 1;
                    file->device->net->stall = 1;
                    grub_net_udp_close (data->sock);
                    data->sock = NULL;
                }
                /* Prevent garbage in broken cards. Is it still necessary
                   given that IP implementation has been fixed?
                 */
                if (size > data->block_size)
                {
                    err = grub_netbuff_unput (nb_top, size - data->block_size);
                    if (err)
                        return err;
                }
                /* If there is data, puts packet in socket list. */
                if ((nb_top->tail - nb_top->data) > 0)
                    grub_net_put_packet (&file->device->net->packs, nb_top);
                else
                    grub_netbuff_free (nb_top);
            }
        }
        return GRUB_ERR_NONE;
    case TFTP_ERROR:
        data->have_oack = 1;
        grub_netbuff_free (nb);
        grub_error (GRUB_ERR_IO, (char *) tftph->u.err.errmsg);
        grub_error_save (&data->save_err);
        return GRUB_ERR_NONE;
    default:
        grub_netbuff_free (nb);
        return GRUB_ERR_NONE;
    }
}