Lines Matching refs:tftpfile
444 struct tftp_handle *tftpfile; in tftp_open() local
459 tftpfile = calloc(1, sizeof(*tftpfile)); in tftp_open()
460 if (!tftpfile) in tftp_open()
463 tftpfile->tftp_blksize = TFTP_REQUESTED_BLKSIZE; in tftp_open()
465 tftpfile->iodesc = io = socktodesc(*(int *)(dev->d_opendata)); in tftp_open()
467 free(tftpfile); in tftp_open()
472 tftpfile->off = 0; in tftp_open()
474 tftpfile->path = malloc(pathsize); in tftp_open()
475 if (tftpfile->path == NULL) { in tftp_open()
476 free(tftpfile); in tftp_open()
483 res = snprintf(tftpfile->path, pathsize, "%s%s%s", in tftp_open()
486 free(tftpfile->path); in tftp_open()
487 free(tftpfile); in tftp_open()
491 res = tftp_makereq(tftpfile); in tftp_open()
494 free(tftpfile->path); in tftp_open()
495 free(tftpfile->pkt); in tftp_open()
496 free(tftpfile); in tftp_open()
499 f->f_fsdata = tftpfile; in tftp_open()
508 struct tftp_handle *tftpfile; in tftp_read() local
514 tftpfile = f->f_fsdata; in tftp_read()
517 if (tftpfile->tftp_tsize > 0 && in tftp_read()
518 tftpfile->off + size > tftpfile->tftp_tsize) { in tftp_read()
519 size = tftpfile->tftp_tsize - tftpfile->off; in tftp_read()
522 if (tftpfile->tftp_cache != NULL) { in tftp_read()
523 bcopy(tftpfile->tftp_cache + tftpfile->off, in tftp_read()
527 tftpfile->off += size; in tftp_read()
537 needblock = tftpfile->off / tftpfile->tftp_blksize + 1; in tftp_read()
539 if (tftpfile->currblock > needblock) { /* seek backwards */ in tftp_read()
540 tftp_senderr(tftpfile, 0, "No error: read aborted"); in tftp_read()
541 rc = tftp_makereq(tftpfile); in tftp_read()
546 while (tftpfile->currblock < needblock) { in tftp_read()
548 rc = tftp_getnextblock(tftpfile); in tftp_read()
553 if (tftpfile->tries > TFTP_TRIES) { in tftp_read()
556 tftpfile->tries++; in tftp_read()
557 tftp_makereq(tftpfile); in tftp_read()
560 if (tftpfile->islastblock) in tftp_read()
564 if (tftpfile->currblock == needblock) { in tftp_read()
567 offinblock = tftpfile->off % tftpfile->tftp_blksize; in tftp_read()
569 inbuffer = tftpfile->validsize - offinblock; in tftp_read()
573 tftpfile->off); in tftp_read()
578 bcopy(tftpfile->tftp_hdr->th_data + offinblock, in tftp_read()
582 tftpfile->off += count; in tftp_read()
586 if ((tftpfile->islastblock) && (count == inbuffer)) in tftp_read()
606 struct tftp_handle *tftpfile; in tftp_close() local
607 tftpfile = f->f_fsdata; in tftp_close()
609 if (tftpfile->lastacksent == false) in tftp_close()
610 tftp_senderr(tftpfile, 0, "No error: file closed"); in tftp_close()
612 if (tftpfile) { in tftp_close()
613 free(tftpfile->path); in tftp_close()
614 free(tftpfile->pkt); in tftp_close()
615 free(tftpfile->tftp_cache); in tftp_close()
616 free(tftpfile); in tftp_close()
625 struct tftp_handle *tftpfile; in tftp_stat() local
626 tftpfile = f->f_fsdata; in tftp_stat()
632 sb->st_size = tftpfile->tftp_tsize; in tftp_stat()
639 struct tftp_handle *tftpfile; in tftp_seek() local
640 tftpfile = f->f_fsdata; in tftp_seek()
644 tftpfile->off = offset; in tftp_seek()
647 tftpfile->off += offset; in tftp_seek()
653 return (tftpfile->off); in tftp_seek()
659 struct tftp_handle *tftpfile; in tftp_preload() local
666 tftpfile = f->f_fsdata; in tftp_preload()
667 cache = malloc(sizeof(char) * tftpfile->tftp_tsize); in tftp_preload()
671 (uintmax_t)sizeof(char) * tftpfile->tftp_tsize); in tftp_preload()
677 printf("Preloading %s ", tftpfile->path); in tftp_preload()
679 if (tftpfile->currblock == 1) in tftp_preload()
680 bcopy(tftpfile->tftp_hdr->th_data, in tftp_preload()
682 tftpfile->validsize); in tftp_preload()
684 tftpfile->currblock = 0; in tftp_preload()
686 while (tftpfile->islastblock == 0) { in tftp_preload()
688 rc = tftp_getnextblock(tftpfile); in tftp_preload()
694 bcopy(tftpfile->tftp_hdr->th_data, in tftp_preload()
695 cache + (tftpfile->tftp_blksize * (tftpfile->currblock - 1)), in tftp_preload()
696 tftpfile->validsize); in tftp_preload()
701 tftpfile->path, (intmax_t)tftpfile->tftp_tsize, in tftp_preload()
705 tftpfile->tftp_cache = cache; in tftp_preload()