Changeset View
Changeset View
Standalone View
Standalone View
stand/libsa/tftp.c
Show All 31 Lines | |||||
*/ | */ | ||||
#include <sys/cdefs.h> | #include <sys/cdefs.h> | ||||
__FBSDID("$FreeBSD$"); | __FBSDID("$FreeBSD$"); | ||||
/* | /* | ||||
* Simple TFTP implementation for libsa. | * Simple TFTP implementation for libsa. | ||||
* Assumes: | * Assumes: | ||||
* - socket descriptor (int) at open_file->f_devdata | * - socket descriptor (int) at dev->d_opendata, dev stored at | ||||
* open_file->f_devdata | |||||
* - server host IP in global rootip | * - server host IP in global rootip | ||||
* Restrictions: | * Restrictions: | ||||
* - read only | * - read only | ||||
* - lseek only with SEEK_SET or SEEK_CUR | * - lseek only with SEEK_SET or SEEK_CUR | ||||
* - no big time differences between transfers (<tftp timeout) | * - no big time differences between transfers (<tftp timeout) | ||||
*/ | */ | ||||
#include <sys/types.h> | #include <sys/types.h> | ||||
▲ Show 20 Lines • Show All 378 Lines • ▼ Show 20 Lines | tftp_getnextblock(struct tftp_handle *h) | ||||
} | } | ||||
return (0); | return (0); | ||||
} | } | ||||
static int | static int | ||||
tftp_open(const char *path, struct open_file *f) | tftp_open(const char *path, struct open_file *f) | ||||
{ | { | ||||
struct devdesc *dev; | |||||
struct tftp_handle *tftpfile; | struct tftp_handle *tftpfile; | ||||
struct iodesc *io; | struct iodesc *io; | ||||
int res; | int res; | ||||
size_t pathsize; | size_t pathsize; | ||||
const char *extraslash; | const char *extraslash; | ||||
if (netproto != NET_TFTP) | if (netproto != NET_TFTP) | ||||
return (EINVAL); | return (EINVAL); | ||||
if (f->f_dev->dv_type != DEVT_NET) | if (f->f_dev->dv_type != DEVT_NET) | ||||
return (EINVAL); | return (EINVAL); | ||||
if (is_open) | if (is_open) | ||||
return (EBUSY); | return (EBUSY); | ||||
tftpfile = calloc(1, sizeof(*tftpfile)); | tftpfile = calloc(1, sizeof(*tftpfile)); | ||||
if (!tftpfile) | if (!tftpfile) | ||||
return (ENOMEM); | return (ENOMEM); | ||||
tftpfile->tftp_blksize = TFTP_REQUESTED_BLKSIZE; | tftpfile->tftp_blksize = TFTP_REQUESTED_BLKSIZE; | ||||
tftpfile->iodesc = io = socktodesc(*(int *)(f->f_devdata)); | dev = f->f_devdata; | ||||
tftpfile->iodesc = io = socktodesc(*(int *)(dev->d_opendata)); | |||||
if (io == NULL) { | if (io == NULL) { | ||||
free(tftpfile); | free(tftpfile); | ||||
return (EINVAL); | return (EINVAL); | ||||
} | } | ||||
io->destip = rootip; | io->destip = rootip; | ||||
tftpfile->off = 0; | tftpfile->off = 0; | ||||
pathsize = (strlen(rootpath) + 1 + strlen(path) + 1) * sizeof(char); | pathsize = (strlen(rootpath) + 1 + strlen(path) + 1) * sizeof(char); | ||||
▲ Show 20 Lines • Show All 296 Lines • Show Last 20 Lines |