|
|
|
@ -33,8 +33,8 @@ |
|
|
|
|
#define NFS_RETRY_COUNT 30 |
|
|
|
|
#define NFS_TIMEOUT 2000UL |
|
|
|
|
|
|
|
|
|
static int fs_mounted = 0; |
|
|
|
|
static unsigned long rpc_id = 0; |
|
|
|
|
static int fs_mounted; |
|
|
|
|
static unsigned long rpc_id; |
|
|
|
|
static int nfs_offset = -1; |
|
|
|
|
static int nfs_len; |
|
|
|
|
|
|
|
|
@ -61,7 +61,7 @@ static char *nfs_filename; |
|
|
|
|
static char *nfs_path; |
|
|
|
|
static char nfs_path_buff[2048]; |
|
|
|
|
|
|
|
|
|
static __inline__ int |
|
|
|
|
static inline int |
|
|
|
|
store_block(uchar *src, unsigned offset, unsigned len) |
|
|
|
|
{ |
|
|
|
|
ulong newsize = offset + len; |
|
|
|
@ -148,9 +148,8 @@ static long *rpc_add_credentials (long *p) |
|
|
|
|
*p++ = htonl(hl+20); /* auth length */ |
|
|
|
|
*p++ = htonl(0); /* stamp */ |
|
|
|
|
*p++ = htonl(hostnamelen); /* hostname string */ |
|
|
|
|
if (hostnamelen & 3) { |
|
|
|
|
if (hostnamelen & 3) |
|
|
|
|
*(p + hostnamelen / 4) = 0; /* add zero padding */ |
|
|
|
|
} |
|
|
|
|
memcpy(p, hostname, hostnamelen); |
|
|
|
|
p += hl / 4; |
|
|
|
|
*p++ = 0; /* uid */ |
|
|
|
@ -190,7 +189,8 @@ rpc_req (int rpc_prog, int rpc_proc, uint32_t *data, int datalen) |
|
|
|
|
|
|
|
|
|
pktlen = (char *)p + datalen*sizeof(uint32_t) - (char *)&pkt; |
|
|
|
|
|
|
|
|
|
memcpy ((char *)NetTxPacket + NetEthHdrSize() + IP_HDR_SIZE, (char *)&pkt, pktlen); |
|
|
|
|
memcpy((char *)NetTxPacket + NetEthHdrSize() + IP_HDR_SIZE, |
|
|
|
|
(char *)&pkt, pktlen); |
|
|
|
|
|
|
|
|
|
if (rpc_prog == PROG_PORTMAP) |
|
|
|
|
sport = SUNRPC_PORT; |
|
|
|
@ -199,7 +199,8 @@ rpc_req (int rpc_prog, int rpc_proc, uint32_t *data, int datalen) |
|
|
|
|
else |
|
|
|
|
sport = NfsSrvNfsPort; |
|
|
|
|
|
|
|
|
|
NetSendUDPPacket (NetServerEther, NfsServerIP, sport, NfsOurPort, pktlen); |
|
|
|
|
NetSendUDPPacket(NetServerEther, NfsServerIP, sport, NfsOurPort, |
|
|
|
|
pktlen); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
@ -237,7 +238,8 @@ nfs_mount_req (char *path) |
|
|
|
|
p = (uint32_t *)rpc_add_credentials((long *)p); |
|
|
|
|
|
|
|
|
|
*p++ = htonl(pathlen); |
|
|
|
|
if (pathlen & 3) *(p + pathlen / 4) = 0; |
|
|
|
|
if (pathlen & 3) |
|
|
|
|
*(p + pathlen / 4) = 0; |
|
|
|
|
memcpy(p, path, pathlen); |
|
|
|
|
p += (pathlen + 3) / 4; |
|
|
|
|
|
|
|
|
@ -256,10 +258,9 @@ nfs_umountall_req (void) |
|
|
|
|
uint32_t *p; |
|
|
|
|
int len; |
|
|
|
|
|
|
|
|
|
if ((NfsSrvMountPort == -1) || (!fs_mounted)) { |
|
|
|
|
if ((NfsSrvMountPort == -1) || (!fs_mounted)) |
|
|
|
|
/* Nothing mounted, nothing to umount */ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
p = &(data[0]); |
|
|
|
|
p = (uint32_t *)rpc_add_credentials((long *)p); |
|
|
|
@ -313,7 +314,8 @@ nfs_lookup_req (char *fname) |
|
|
|
|
memcpy(p, dirfh, NFS_FHSIZE); |
|
|
|
|
p += (NFS_FHSIZE / 4); |
|
|
|
|
*p++ = htonl(fnamelen); |
|
|
|
|
if (fnamelen & 3) *(p + fnamelen / 4) = 0; |
|
|
|
|
if (fnamelen & 3) |
|
|
|
|
*(p + fnamelen / 4) = 0; |
|
|
|
|
memcpy(p, fname, fnamelen); |
|
|
|
|
p += (fnamelen + 3) / 4; |
|
|
|
|
|
|
|
|
@ -398,9 +400,8 @@ rpc_lookup_reply (int prog, uchar *pkt, unsigned len) |
|
|
|
|
|
|
|
|
|
if (rpc_pkt.u.reply.rstatus || |
|
|
|
|
rpc_pkt.u.reply.verifier || |
|
|
|
|
rpc_pkt.u.reply.astatus) { |
|
|
|
|
rpc_pkt.u.reply.astatus) |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
switch (prog) { |
|
|
|
|
case PROG_MOUNT: |
|
|
|
@ -429,9 +430,8 @@ nfs_mount_reply (uchar *pkt, unsigned len) |
|
|
|
|
if (rpc_pkt.u.reply.rstatus || |
|
|
|
|
rpc_pkt.u.reply.verifier || |
|
|
|
|
rpc_pkt.u.reply.astatus || |
|
|
|
|
rpc_pkt.u.reply.data[0]) { |
|
|
|
|
rpc_pkt.u.reply.data[0]) |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fs_mounted = 1; |
|
|
|
|
memcpy(dirfh, rpc_pkt.u.reply.data + 1, NFS_FHSIZE); |
|
|
|
@ -453,9 +453,8 @@ nfs_umountall_reply (uchar *pkt, unsigned len) |
|
|
|
|
|
|
|
|
|
if (rpc_pkt.u.reply.rstatus || |
|
|
|
|
rpc_pkt.u.reply.verifier || |
|
|
|
|
rpc_pkt.u.reply.astatus) { |
|
|
|
|
rpc_pkt.u.reply.astatus) |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fs_mounted = 0; |
|
|
|
|
memset(dirfh, 0, sizeof(dirfh)); |
|
|
|
@ -478,9 +477,8 @@ nfs_lookup_reply (uchar *pkt, unsigned len) |
|
|
|
|
if (rpc_pkt.u.reply.rstatus || |
|
|
|
|
rpc_pkt.u.reply.verifier || |
|
|
|
|
rpc_pkt.u.reply.astatus || |
|
|
|
|
rpc_pkt.u.reply.data[0]) { |
|
|
|
|
rpc_pkt.u.reply.data[0]) |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
memcpy(filefh, rpc_pkt.u.reply.data + 1, NFS_FHSIZE); |
|
|
|
|
|
|
|
|
@ -503,9 +501,8 @@ nfs_readlink_reply (uchar *pkt, unsigned len) |
|
|
|
|
if (rpc_pkt.u.reply.rstatus || |
|
|
|
|
rpc_pkt.u.reply.verifier || |
|
|
|
|
rpc_pkt.u.reply.astatus || |
|
|
|
|
rpc_pkt.u.reply.data[0]) { |
|
|
|
|
rpc_pkt.u.reply.data[0]) |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
rlen = ntohl(rpc_pkt.u.reply.data[1]); /* new path length */ |
|
|
|
|
|
|
|
|
@ -513,7 +510,8 @@ nfs_readlink_reply (uchar *pkt, unsigned len) |
|
|
|
|
int pathlen; |
|
|
|
|
strcat(nfs_path, "/"); |
|
|
|
|
pathlen = strlen(nfs_path); |
|
|
|
|
memcpy (nfs_path+pathlen, (uchar *)&(rpc_pkt.u.reply.data[2]), rlen); |
|
|
|
|
memcpy(nfs_path + pathlen, (uchar *)&(rpc_pkt.u.reply.data[2]), |
|
|
|
|
rlen); |
|
|
|
|
nfs_path[pathlen + rlen] = 0; |
|
|
|
|
} else { |
|
|
|
|
memcpy(nfs_path, (uchar *)&(rpc_pkt.u.reply.data[2]), rlen); |
|
|
|
@ -539,24 +537,22 @@ nfs_read_reply (uchar *pkt, unsigned len) |
|
|
|
|
rpc_pkt.u.reply.verifier || |
|
|
|
|
rpc_pkt.u.reply.astatus || |
|
|
|
|
rpc_pkt.u.reply.data[0]) { |
|
|
|
|
if (rpc_pkt.u.reply.rstatus) { |
|
|
|
|
if (rpc_pkt.u.reply.rstatus) |
|
|
|
|
return -9999; |
|
|
|
|
} |
|
|
|
|
if (rpc_pkt.u.reply.astatus) { |
|
|
|
|
if (rpc_pkt.u.reply.astatus) |
|
|
|
|
return -9999; |
|
|
|
|
} |
|
|
|
|
return -ntohl(rpc_pkt.u.reply.data[0]);; |
|
|
|
|
return -ntohl(rpc_pkt.u.reply.data[0]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if ((nfs_offset!=0) && !((nfs_offset) % (NFS_READ_SIZE/2*10*HASHES_PER_LINE))) { |
|
|
|
|
if ((nfs_offset != 0) && !((nfs_offset) % |
|
|
|
|
(NFS_READ_SIZE / 2 * 10 * HASHES_PER_LINE))) |
|
|
|
|
puts("\n\t "); |
|
|
|
|
} |
|
|
|
|
if (!(nfs_offset % ((NFS_READ_SIZE/2)*10))) { |
|
|
|
|
if (!(nfs_offset % ((NFS_READ_SIZE / 2) * 10))) |
|
|
|
|
putc('#'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
rlen = ntohl(rpc_pkt.u.reply.data[18]); |
|
|
|
|
if ( store_block ((uchar *)pkt+sizeof(rpc_pkt.u.reply), nfs_offset, rlen) ) |
|
|
|
|
if (store_block((uchar *)pkt + sizeof(rpc_pkt.u.reply), |
|
|
|
|
nfs_offset, rlen)) |
|
|
|
|
return -9999; |
|
|
|
|
|
|
|
|
|
return rlen; |
|
|
|
@ -586,7 +582,8 @@ NfsHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src, unsigned len) |
|
|
|
|
|
|
|
|
|
debug("%s\n", __func__); |
|
|
|
|
|
|
|
|
|
if (dest != NfsOurPort) return; |
|
|
|
|
if (dest != NfsOurPort) |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
switch (NfsState) { |
|
|
|
|
case STATE_PRCLOOKUP_PROG_MOUNT_REQ: |
|
|
|
@ -657,13 +654,13 @@ NfsHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src, unsigned len) |
|
|
|
|
if (rlen > 0) { |
|
|
|
|
nfs_offset += rlen; |
|
|
|
|
NfsSend(); |
|
|
|
|
} |
|
|
|
|
else if ((rlen == -NFSERR_ISDIR)||(rlen == -NFSERR_INVAL)) { |
|
|
|
|
} else if ((rlen == -NFSERR_ISDIR) || (rlen == -NFSERR_INVAL)) { |
|
|
|
|
/* symbolic link */ |
|
|
|
|
NfsState = STATE_READLINK_REQ; |
|
|
|
|
NfsSend(); |
|
|
|
|
} else { |
|
|
|
|
if ( ! rlen ) NfsDownloadState = NETLOOP_SUCCESS; |
|
|
|
|
if (!rlen) |
|
|
|
|
NfsDownloadState = NETLOOP_SUCCESS; |
|
|
|
|
NfsState = STATE_UMOUNT_REQ; |
|
|
|
|
NfsSend(); |
|
|
|
|
} |
|
|
|
@ -725,7 +722,8 @@ NfsStart (void) |
|
|
|
|
IPaddr_t ServerNet = NetServerIP & NetOurSubnetMask; |
|
|
|
|
|
|
|
|
|
if (OurNet != ServerNet) |
|
|
|
|
printf("; sending through gateway %pI4", &NetOurGatewayIP); |
|
|
|
|
printf("; sending through gateway %pI4", |
|
|
|
|
&NetOurGatewayIP); |
|
|
|
|
} |
|
|
|
|
printf("\nFilename '%s/%s'.", nfs_path, nfs_filename); |
|
|
|
|
|
|
|
|
|