static ulong nfs_timeout = NFS_TIMEOUT;
static char dirfh[NFS_FHSIZE]; /* NFSv2 / NFSv3 file handle of directory */
-static char filefh[NFS_FHSIZE]; /* NFSv2 file handle */
-
-static char filefh3[NFS3_FHSIZE]; /* NFSv3 file handle */
-static int filefh3_length; /* (variable) length of filefh3 */
+static char filefh[NFS3_FHSIZE]; /* NFSv2 / NFSv3 file handle */
+static int filefh3_length; /* (variable) length of filefh when NFSv3 */
static enum net_loop_state nfs_download_state;
static struct in_addr nfs_server_ip;
p += (NFS_FHSIZE / 4);
} else { /* NFSV3_FLAG */
*p++ = htonl(filefh3_length);
- memcpy(p, filefh3, filefh3_length);
+ memcpy(p, filefh, filefh3_length);
p += (filefh3_length / 4);
}
*p++ = 0;
} else { /* NFSV3_FLAG */
*p++ = htonl(filefh3_length);
- memcpy(p, filefh3, filefh3_length);
+ memcpy(p, filefh, filefh3_length);
p += (filefh3_length / 4);
*p++ = htonl(0); /* offset is 64-bit long, so fill with 0 */
*p++ = htonl(offset);
/* Minimal supported NFS version */
case 3:
debug("*** Waring: NFS version not supported: Requested: V%d, accepted: min V%d - max V%d\n",
- (supported_nfs_versions & NFSV2_FLAG) ? 2 : 3,
+ (supported_nfs_versions & NFSV2_FLAG) ?
+ 2 : 3,
ntohl(rpc_pkt.u.reply.data[0]),
ntohl(rpc_pkt.u.reply.data[1]));
debug("Will retry with NFSv3\n");
case 4:
default:
printf("*** ERROR: NFS version not supported: Requested: V%d, accepted: min V%d - max V%d\n",
- (supported_nfs_versions & NFSV2_FLAG) ? 2 : 3,
+ (supported_nfs_versions & NFSV2_FLAG) ?
+ 2 : 3,
ntohl(rpc_pkt.u.reply.data[0]),
ntohl(rpc_pkt.u.reply.data[1]));
}
filefh3_length = ntohl(rpc_pkt.u.reply.data[1]);
if (filefh3_length > NFS3_FHSIZE)
filefh3_length = NFS3_FHSIZE;
- memcpy(filefh3, rpc_pkt.u.reply.data + 2, filefh3_length);
+ memcpy(filefh, rpc_pkt.u.reply.data + 2, filefh3_length);
}
return 0;
}
+static int nfs3_get_attributes_offset(uint32_t *data)
+{
+ if (ntohl(data[1]) != 0) {
+ /* 'attributes_follow' flag is TRUE,
+ * so we have attributes on 21 dwords */
+ /* Skip unused values :
+ type; 32 bits value,
+ mode; 32 bits value,
+ nlink; 32 bits value,
+ uid; 32 bits value,
+ gid; 32 bits value,
+ size; 64 bits value,
+ used; 64 bits value,
+ rdev; 64 bits value,
+ fsid; 64 bits value,
+ fileid; 64 bits value,
+ atime; 64 bits value,
+ mtime; 64 bits value,
+ ctime; 64 bits value,
+ */
+ return 22;
+ } else {
+ /* 'attributes_follow' flag is FALSE,
+ * so we don't have any attributes */
+ return 1;
+ }
+}
+
static int nfs_readlink_reply(uchar *pkt, unsigned len)
{
struct rpc_t rpc_pkt;
int rlen;
+ int nfsv3_data_offset = 0;
debug("%s\n", __func__);
rpc_pkt.u.reply.data[0])
return -1;
- if (supported_nfs_versions & NFSV2_FLAG) {
+ if (!(supported_nfs_versions & NFSV2_FLAG)) { /* NFSV3_FLAG */
+ nfsv3_data_offset =
+ nfs3_get_attributes_offset(rpc_pkt.u.reply.data);
+ }
- rlen = ntohl(rpc_pkt.u.reply.data[1]); /* new path length */
+ /* new path length */
+ rlen = ntohl(rpc_pkt.u.reply.data[1 + nfsv3_data_offset]);
- if (*((char *)&(rpc_pkt.u.reply.data[2])) != '/') {
- int pathlen;
- strcat(nfs_path, "/");
- pathlen = strlen(nfs_path);
- 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);
- nfs_path[rlen] = 0;
- }
- } else { /* NFSV3_FLAG */
- int nfsv3_data_offset = 0;
- if (ntohl(rpc_pkt.u.reply.data[1]) != 0) {
- /* 'attributes_follow' flag is TRUE,
- * so we have attributes on 21 bytes */
- /* Skip unused values :
- type; 32 bits value,
- mode; 32 bits value,
- nlink; 32 bits value,
- uid; 32 bits value,
- gid; 32 bits value,
- size; 64 bits value,
- used; 64 bits value,
- rdev; 64 bits value,
- fsid; 64 bits value,
- fileid; 64 bits value,
- atime; 64 bits value,
- mtime; 64 bits value,
- ctime; 64 bits value,
- */
- nfsv3_data_offset = 22;
- } else {
- /* 'attributes_follow' flag is FALSE,
- * so we don't have any attributes */
- nfsv3_data_offset = 1;
- }
+ if (*((char *)&(rpc_pkt.u.reply.data[2 + nfsv3_data_offset])) != '/') {
+ int pathlen;
- /* new path length */
- rlen = ntohl(rpc_pkt.u.reply.data[1+nfsv3_data_offset]);
-
- if (*((char *)&(rpc_pkt.u.reply.data[2+nfsv3_data_offset])) != '/') {
- int pathlen;
- strcat(nfs_path, "/");
- pathlen = strlen(nfs_path);
- memcpy(nfs_path + pathlen,
- (uchar *)&(rpc_pkt.u.reply.data[2+nfsv3_data_offset]),
- rlen);
- nfs_path[pathlen + rlen] = 0;
- } else {
- memcpy(nfs_path,
- (uchar *)&(rpc_pkt.u.reply.data[2+nfsv3_data_offset]),
- rlen);
- nfs_path[rlen] = 0;
- }
+ strcat(nfs_path, "/");
+ pathlen = strlen(nfs_path);
+ memcpy(nfs_path + pathlen,
+ (uchar *)&(rpc_pkt.u.reply.data[2 + nfsv3_data_offset]),
+ rlen);
+ nfs_path[pathlen + rlen] = 0;
+ } else {
+ memcpy(nfs_path,
+ (uchar *)&(rpc_pkt.u.reply.data[2 + nfsv3_data_offset]),
+ rlen);
+ nfs_path[rlen] = 0;
}
return 0;
}
rlen = ntohl(rpc_pkt.u.reply.data[18]);
data_ptr = (uchar *)&(rpc_pkt.u.reply.data[19]);
} else { /* NFSV3_FLAG */
- if (ntohl(rpc_pkt.u.reply.data[1]) != 0) {
- /* 'attributes_follow' is TRUE,
- * so we have attributes on 21 bytes */
- /* Skip unused values :
- type; 32 bits value,
- mode; 32 bits value,
- nlink; 32 bits value,
- uid; 32 bits value,
- gid; 32 bits value,
- size; 64 bits value,
- used; 64 bits value,
- rdev; 64 bits value,
- fsid; 64 bits value,
- fileid; 64 bits value,
- atime; 64 bits value,
- mtime; 64 bits value,
- ctime; 64 bits value,
- */
- rlen = ntohl(rpc_pkt.u.reply.data[23]); /* count value */
- /* Skip unused values :
- EOF: 32 bits value,
- data_size: 32 bits value,
- */
- data_ptr = (uchar *)&(rpc_pkt.u.reply.data[26]);
- } else {
- /* attributes_follow is FALSE, so we don't have any attributes */
- rlen = ntohl(rpc_pkt.u.reply.data[2]); /* count value */
- /* Skip unused values :
- EOF: 32 bits value,
- data_size: 32 bits value,
- */
- data_ptr = (uchar *)&(rpc_pkt.u.reply.data[5]);
- }
+ int nfsv3_data_offset =
+ nfs3_get_attributes_offset(rpc_pkt.u.reply.data);
+
+ /* count value */
+ rlen = ntohl(rpc_pkt.u.reply.data[1 + nfsv3_data_offset]);
+ /* Skip unused values :
+ EOF: 32 bits value,
+ data_size: 32 bits value,
+ */
+ data_ptr = (uchar *)
+ &(rpc_pkt.u.reply.data[4 + nfsv3_data_offset]);
}
if (store_block(data_ptr, nfs_offset, rlen))
puts("*** ERROR: File lookup fail\n");
nfs_state = STATE_UMOUNT_REQ;
nfs_send();
- } else if (reply == -NFS_RPC_PROG_MISMATCH && supported_nfs_versions != 0) {
+ } else if (reply == -NFS_RPC_PROG_MISMATCH &&
+ supported_nfs_versions != 0) {
/* umount */
nfs_state = STATE_UMOUNT_REQ;
nfs_send();