shithub: riscv

Download patch

ref: 61d1967e74a3796af55bc14ee81599696b86f3bb
parent: 5baafe7307f1c8a0a9026f2091312b9100708c59
author: cinap_lenrek <[email protected]>
date: Sat Oct 6 00:14:48 EDT 2012

tftpfs: add manpage, add -x option

--- /dev/null
+++ b/sys/man/4/tftpfs
@@ -1,0 +1,73 @@
+.TH TFTPFS 4
+.SH NAME
+tftpfs \- trivial file transfer protocol (TFTP) file system
+.SH SYNOPSIS
+.B ip/tftpfs
+[
+.B -D
+] [
+.B -s
+.I srvname
+] [
+.B -m
+.I mtpt
+] [
+.B -x
+.I net
+] [
+.I ipaddr
+]
+.SH DESCRIPTION
+.I Tftpfs
+serves files from a TFTP server as a filesystem. TFTP
+is mostly used by bootloaders to download kernel images for
+network bootstrap (see
+.IR dhcp (8)).
+As the protocol has no way of distinguishing files from
+directories the final path segment needs to conain a dot
+(.) character to be recognized as a file. To access files that
+have no dot in the filename, a trailing dot has to be added
+and will be striped before it is passed to the server.
+.PP
+The
+.B -D
+option enables 9P debugging messages.
+.PP
+The
+.B -s
+option causes 
+.I tftpfs
+to post the 9P service as
+.BI /srv/ srvname
+and disables the default mount.
+.PP
+The default mountpoint
+.BR /n/tftp
+can be changed with the
+.B -B
+.I mtpt
+option.
+.PP
+The
+.B -x
+option specifies an alternate network directory
+.RI ( e.g., 
+.BR /net.alt ).
+.PP
+The ip address of the server can be passed in
+.I ipaddr
+as the last program argument or in the mount spec (see
+.IR bind (1))
+on a per mount basis.
+.SH EXAMPLE
+Boot a kernel from a tftp server. (note the final
+dot in the kernel path).
+.IP
+.EX
+ip/tftpd 10.192.254.53
+echo reboot /n/tftp/386/9pcf. >/dev/reboot
+.EE
+.SH SOURCE
+.B /sys/src/cmd/ip/tftpfs.c
+.SH "SEE ALSO"
+.IR dhcpd (8).
--- a/sys/src/cmd/ip/tftpfs.c
+++ b/sys/src/cmd/ip/tftpfs.c
@@ -16,7 +16,7 @@
 	Tftp_ERROR	= 5,
 	Tftp_OACK	= 6,
 
-	TftpPort		= 69,
+	TftpPort	= 69,
 
 	Segsize		= 512,
 	Maxpath		= 2+2+Segsize-8,
@@ -25,19 +25,19 @@
 typedef struct Tfile Tfile;
 struct Tfile
 {
-	int		id;
+	int	id;
 	uchar	addr[IPaddrlen];
-	char		path[Maxpath];
+	char	path[Maxpath];
 	Channel	*c;
-	Tfile		*next;
+	Tfile	*next;
 	Ref;
 };
 
+char net[Maxpath];
 uchar ipaddr[IPaddrlen];
 static ulong time0;
 Tfile *files;
 
-
 static Tfile*
 tfileget(uchar *addr, char *path)
 {
@@ -148,7 +148,7 @@
 download(void *aux)
 {
 	int fd, cfd, last, block, seq, n, ndata;
-	char *err, adir[40];
+	char *err, adir[40], buf[256];
 	uchar *data;
 	Channel *c;
 	Tfile *f;
@@ -173,7 +173,8 @@
 
 	threadsetname(f->path);
 
-	if((cfd = announce("udp!*!0", adir)) < 0){
+	snprint(buf, sizeof(buf), "%s/udp!*!0", net);
+	if((cfd = announce(buf, adir)) < 0){
 		err = "announce: %r";
 		goto out;
 	}
@@ -264,8 +265,6 @@
 	if(c){
 		while((r != nil) || (r = recvp(c))){
 			if(err){
-				char buf[ERRMAX];
-
 				snprint(buf, sizeof(buf), err);
 				respond(r, buf);
 			} else {
@@ -412,7 +411,7 @@
 
 Srv fs = 
 {
-.attach=		fsattach,
+.attach=	fsattach,
 .destroyfid=	fsdestroyfid,
 .walk1=		fswalk1,
 .clone=		fsclone,
@@ -424,7 +423,7 @@
 void
 usage(void)
 {
-	fprint(2, "usage: tftpfs [-D] [-s srvname] [-m mtpt] [ipaddr]\n");
+	fprint(2, "usage: tftpfs [-D] [-s srvname] [-m mtpt] [-x net] [ipaddr]\n");
 	threadexitsall("usage");
 }
 
@@ -435,6 +434,7 @@
 	char *mtpt = "/n/tftp";
 
 	time0 = time(0);
+	strcpy(net, "/net");
 	ipmove(ipaddr, IPnoaddr);
 
 	ARGBEGIN{
@@ -447,6 +447,9 @@
 		break;
 	case 'm':
 		mtpt = EARGF(usage());
+		break;
+	case 'x':
+		setnetmtpt(net, sizeof net, EARGF(usage()));
 		break;
 	default:
 		usage();