/** * * proxy_Fattr_To_FSAL_dynamic_fsinfo: Converts NFSv4 attributes buffer to a FSAL dynamic fsinfo structure. * * Converts NFSv4 attributes buffer to a FSAL dynamic fsinfo structure. * * @param pdynamicinfo [OUT] pointer to FSAL attributes. * @param Fattr [IN] pointer to NFSv4 attributes. * * @return 1 if successful, 0 if not supported, -1 if argument is badly formed * */ int proxy_Fattr_To_FSAL_dynamic_fsinfo(fsal_dynamicfsinfo_t * pdynamicinfo, fattr4 * Fattr) { u_int LastOffset = 0; unsigned int i = 0; char __attribute__ ((__unused__)) funcname[] = "proxy_Fattr_To_FSAL_dynamic_fsinfo"; uint32_t attrmasklist[FATTR4_MOUNTED_ON_FILEID]; /* List cannot be longer than FATTR4_MOUNTED_ON_FILEID */ uint32_t attrmasklen = 0; uint32_t attribute_to_set = 0; uint64_t tmp_uint64 = 0LL; if(pdynamicinfo == NULL || Fattr == NULL) return -1; /* Check attributes data */ if(Fattr->attr_vals.attrlist4_val == NULL) return -1; /* Convert the attribute bitmap to an attribute list */ nfs4_bitmap4_to_list(&(Fattr->attrmask), &attrmasklen, attrmasklist); LogFullDebug(COMPONENT_NFS_V4, " nfs4_bitmap4_to_list ====> attrmasklen = %d\n", attrmasklen); /* Init */ memset((char *)pdynamicinfo, 0, sizeof(fsal_dynamicfsinfo_t)); for(i = 0; i < attrmasklen; i++) { attribute_to_set = attrmasklist[i]; if(attrmasklist[i] > FATTR4_MOUNTED_ON_FILEID) { /* Erroneous value... skip */ continue; } LogFullDebug(COMPONENT_NFS_V4, "=================> nfs4_Fattr_To_FSAL_attr: i=%u attr=%u\n", i, attrmasklist[i]); LogFullDebug(COMPONENT_NFS_V4, "Flag for Operation = %d|%d is ON, name = %s reply_size = %d\n", attrmasklist[i], fattr4tab[attribute_to_set].val, fattr4tab[attribute_to_set].name, fattr4tab[attribute_to_set].size_fattr4); switch (attribute_to_set) { case FATTR4_FILES_AVAIL: memcpy((char *)&tmp_uint64, (char *)(Fattr->attr_vals.attrlist4_val + LastOffset), sizeof(fattr4_files_avail)); pdynamicinfo->avail_files = nfs_ntohl64(tmp_uint64); LastOffset += fattr4tab[attribute_to_set].size_fattr4; break; case FATTR4_FILES_FREE: memcpy((char *)&tmp_uint64, (char *)(Fattr->attr_vals.attrlist4_val + LastOffset), sizeof(fattr4_files_free)); pdynamicinfo->free_files = nfs_ntohl64(tmp_uint64); LastOffset += fattr4tab[attribute_to_set].size_fattr4; break; case FATTR4_FILES_TOTAL: memcpy((char *)&tmp_uint64, (char *)(Fattr->attr_vals.attrlist4_val + LastOffset), sizeof(fattr4_files_total)); pdynamicinfo->total_files = nfs_ntohl64(tmp_uint64); LastOffset += fattr4tab[attribute_to_set].size_fattr4; break; case FATTR4_SPACE_AVAIL: memcpy((char *)&tmp_uint64, (char *)(Fattr->attr_vals.attrlist4_val + LastOffset), sizeof(fattr4_space_avail)); pdynamicinfo->avail_bytes = nfs_ntohl64(tmp_uint64); LastOffset += fattr4tab[attribute_to_set].size_fattr4; break; case FATTR4_SPACE_FREE: memcpy((char *)&tmp_uint64, (char *)(Fattr->attr_vals.attrlist4_val + LastOffset), sizeof(fattr4_space_free)); pdynamicinfo->free_bytes = nfs_ntohl64(tmp_uint64); LastOffset += fattr4tab[attribute_to_set].size_fattr4; break; case FATTR4_SPACE_TOTAL: memcpy((char *)&tmp_uint64, (char *)(Fattr->attr_vals.attrlist4_val + LastOffset), sizeof(fattr4_space_total)); pdynamicinfo->total_bytes = nfs_ntohl64(tmp_uint64); LastOffset += fattr4tab[attribute_to_set].size_fattr4; break; default: LogFullDebug(COMPONENT_NFS_V4, "SATTR: Attribut no supporte %d name=%s\n", attribute_to_set, fattr4tab[attribute_to_set].name); LastOffset += fattr4tab[attribute_to_set].size_fattr4; break; } /* switch( attribute_to_set ) */ } return 1; } /* proxy_Fattr_To_FSAL_dynamic_fsinfo */
/** * * proxy_Fattr_To_FSAL_attr: Converts NFSv4 attributes buffer to a FSAL attributes structure. * * Converts NFSv4 attributes buffer to a FSAL attributes structure. * * @param pFSAL_attr [OUT] pointer to FSAL attributes. * @param Fattr [IN] pointer to NFSv4 attributes. * * @return 1 if successful, 0 if not supported, -1 if argument is badly formed * */ int proxy_Fattr_To_FSAL_attr(fsal_attrib_list_t * pFSAL_attr, proxyfsal_handle_t * phandle, fattr4 * Fattr) { u_int LastOffset = 0; unsigned int i = 0; char __attribute__ ((__unused__)) funcname[] = "proxy_Fattr_To_FSAL_attr"; uint32_t attrmasklist[FATTR4_MOUNTED_ON_FILEID]; /* List cannot be longer than FATTR4_MOUNTED_ON_FILEID */ uint32_t attrmasklen = 0; uint32_t attribute_to_set = 0; int len; char buffer[MAXNAMLEN]; utf8string utf8buffer; fattr4_type attr_type; fattr4_fsid attr_fsid; fattr4_fileid attr_fileid; fattr4_time_modify_set attr_time_set; fattr4_rdattr_error rdattr_error; nfstime4 attr_time; fattr4_size attr_size; fattr4_change attr_change; fattr4_numlinks attr_numlinks; fattr4_rawdev attr_rawdev; fattr4_space_used attr_space_used; fattr4_time_access attr_time_access; fattr4_time_modify attr_time_modify; fattr4_time_metadata attr_time_metadata; nfs_fh4 nfshandle; bool_t compute_fh = FALSE; if(pFSAL_attr == NULL || Fattr == NULL) return -1; /* Check attributes data */ if(Fattr->attr_vals.attrlist4_val == NULL) return -1; /* Convert the attribute bitmap to an attribute list */ nfs4_bitmap4_to_list(&(Fattr->attrmask), &attrmasklen, attrmasklist); LogFullDebug(COMPONENT_NFS_V4, "nfs4_bitmap4_to_list ====> attrmasklen = %d\n", attrmasklen); /* Init */ pFSAL_attr->asked_attributes = 0; for(i = 0; i < attrmasklen; i++) { attribute_to_set = attrmasklist[i]; if(attrmasklist[i] > FATTR4_MOUNTED_ON_FILEID) { /* Erroneous value... skip */ continue; } LogFullDebug(COMPONENT_NFS_V4, "=================> nfs4_Fattr_To_FSAL_attr: i=%u attr=%u\n", i, attrmasklist[i]); LogFullDebug(COMPONENT_NFS_V4, "Flag for Operation = %d|%d is ON, name = %s reply_size = %d\n", attrmasklist[i], fattr4tab[attribute_to_set].val, fattr4tab[attribute_to_set].name, fattr4tab[attribute_to_set].size_fattr4); switch (attribute_to_set) { case FATTR4_TYPE: /* Used only by FSAL_PROXY to reverse convert */ memcpy((char *)&attr_type, (char *)(Fattr->attr_vals.attrlist4_val + LastOffset), sizeof(fattr4_type)); switch (ntohl(attr_type)) { case NF4REG: pFSAL_attr->type = FSAL_TYPE_FILE; break; case NF4DIR: pFSAL_attr->type = FSAL_TYPE_DIR; break; case NF4BLK: pFSAL_attr->type = FSAL_TYPE_BLK; break; case NF4CHR: pFSAL_attr->type = FSAL_TYPE_CHR; break; case NF4LNK: pFSAL_attr->type = FSAL_TYPE_LNK; break; case NF4SOCK: pFSAL_attr->type = FSAL_TYPE_SOCK; break; case NF4FIFO: pFSAL_attr->type = FSAL_TYPE_FIFO; break; default: /* For wanting of a better solution */ pFSAL_attr->type = 0; break; } /* switch( pattr->type ) */ pFSAL_attr->asked_attributes |= FSAL_ATTR_TYPE; LastOffset += fattr4tab[attribute_to_set].size_fattr4; LogFullDebug(COMPONENT_NFS_V4, "SATTR: On voit le type %d\n", (int)pFSAL_attr->filesize); break; case FATTR4_FILEID: /* Used only by FSAL_PROXY to reverse convert */ /* The analog to the inode number. RFC3530 says "a number uniquely identifying the file within the filesystem" * I use hpss_GetObjId to extract this information from the Name Server's handle */ memcpy((char *)&attr_fileid, (char *)(Fattr->attr_vals.attrlist4_val + LastOffset), sizeof(fattr4_fileid)); pFSAL_attr->fileid = nfs_ntohl64(attr_fileid); pFSAL_attr->asked_attributes |= FSAL_ATTR_FILEID; LastOffset += fattr4tab[attribute_to_set].size_fattr4; break; case FATTR4_FSID: /* Used only by FSAL_PROXY to reverse convert */ memcpy((char *)&attr_fsid, (char *)(Fattr->attr_vals.attrlist4_val + LastOffset), sizeof(fattr4_fsid)); pFSAL_attr->fsid.major = nfs_ntohl64(attr_fsid.major); pFSAL_attr->fsid.minor = nfs_ntohl64(attr_fsid.minor); pFSAL_attr->asked_attributes |= FSAL_ATTR_FSID; LastOffset += fattr4tab[attribute_to_set].size_fattr4; break; case FATTR4_NUMLINKS: /* Used only by FSAL_PROXY to reverse convert */ memcpy((char *)&attr_numlinks, (char *)(Fattr->attr_vals.attrlist4_val + LastOffset), sizeof(fattr4_numlinks)); pFSAL_attr->numlinks = ntohl(attr_numlinks); pFSAL_attr->asked_attributes |= FSAL_ATTR_FILEID; LastOffset += fattr4tab[attribute_to_set].size_fattr4; break; case FATTR4_SIZE: memcpy((char *)&attr_size, (char *)(Fattr->attr_vals.attrlist4_val + LastOffset), sizeof(fattr4_size)); /* Do not forget the XDR marshalling for the fattr4 stuff */ pFSAL_attr->filesize = nfs_ntohl64(attr_size); pFSAL_attr->asked_attributes |= FSAL_ATTR_SIZE; LastOffset += fattr4tab[attribute_to_set].size_fattr4; LogFullDebug(COMPONENT_NFS_V4, "SATTR: On voit la taille %d\n", (int)pFSAL_attr->filesize); break; case FATTR4_MODE: memcpy((char *)&(pFSAL_attr->mode), (char *)(Fattr->attr_vals.attrlist4_val + LastOffset), sizeof(fattr4_mode)); /* Do not forget the XDR marshalling for the fattr4 stuff */ pFSAL_attr->mode = ntohl(pFSAL_attr->mode); pFSAL_attr->asked_attributes |= FSAL_ATTR_MODE; LastOffset += fattr4tab[attribute_to_set].size_fattr4; LogFullDebug(COMPONENT_NFS_V4, "SATTR: On voit le mode 0%o\n", pFSAL_attr->mode); break; case FATTR4_OWNER: memcpy(&len, (char *)(Fattr->attr_vals.attrlist4_val + LastOffset), sizeof(u_int)); len = ntohl(len); /* xdr marshalling on fattr4 */ LastOffset += sizeof(u_int); memcpy(buffer, (char *)(Fattr->attr_vals.attrlist4_val + LastOffset), len); buffer[len] = '\0'; /* Do not forget that xdr_opaque are aligned on 32bit long words */ while((len % 4) != 0) len += 1; LastOffset += len; utf8buffer.utf8string_val = buffer; utf8buffer.utf8string_len = strlen(buffer); utf82uid(&utf8buffer, &(pFSAL_attr->owner)); pFSAL_attr->asked_attributes |= FSAL_ATTR_OWNER; LogFullDebug(COMPONENT_NFS_V4, "SATTR: On voit le owner %s len = %d\n", buffer, len); LogFullDebug(COMPONENT_NFS_V4, "SATTR: On voit le owner %d\n", pFSAL_attr->owner); break; case FATTR4_OWNER_GROUP: memcpy(&len, (char *)(Fattr->attr_vals.attrlist4_val + LastOffset), sizeof(u_int)); len = ntohl(len); LastOffset += sizeof(u_int); memcpy(buffer, (char *)(Fattr->attr_vals.attrlist4_val + LastOffset), len); buffer[len] = '\0'; /* Do not forget that xdr_opaque are aligned on 32bit long words */ while((len % 4) != 0) len += 1; LastOffset += len; utf8buffer.utf8string_val = buffer; utf8buffer.utf8string_len = strlen(buffer); utf82gid(&utf8buffer, &(pFSAL_attr->group)); pFSAL_attr->asked_attributes |= FSAL_ATTR_GROUP; LogFullDebug(COMPONENT_NFS_V4, "SATTR: On voit le owner_group %s len = %d\n", buffer, len); LogFullDebug(COMPONENT_NFS_V4, "SATTR: On voit le owner_group %d\n", pFSAL_attr->group); break; case FATTR4_CHANGE: memcpy((char *)&attr_change, (char *)(Fattr->attr_vals.attrlist4_val + LastOffset), sizeof(fattr4_change)); pFSAL_attr->chgtime.seconds = (uint32_t) nfs_ntohl64(attr_change); pFSAL_attr->chgtime.nseconds = 0; pFSAL_attr->change = nfs_ntohl64(attr_change); pFSAL_attr->asked_attributes |= FSAL_ATTR_CHGTIME; pFSAL_attr->asked_attributes |= FSAL_ATTR_CHANGE; LastOffset += fattr4tab[attribute_to_set].size_fattr4; break; case FATTR4_RAWDEV: /* Used only by FSAL_PROXY to reverse convert */ memcpy((char *)&attr_rawdev, (char *)(Fattr->attr_vals.attrlist4_val + LastOffset), sizeof(fattr4_rawdev)); pFSAL_attr->rawdev.major = (uint32_t) nfs_ntohl64(attr_rawdev.specdata1); pFSAL_attr->rawdev.minor = (uint32_t) nfs_ntohl64(attr_rawdev.specdata2); pFSAL_attr->asked_attributes |= FSAL_ATTR_RAWDEV; LastOffset += fattr4tab[attribute_to_set].size_fattr4; break; case FATTR4_SPACE_USED: /* Used only by FSAL_PROXY to reverse convert */ memcpy((char *)&attr_space_used, (char *)(Fattr->attr_vals.attrlist4_val + LastOffset), sizeof(fattr4_space_used)); pFSAL_attr->spaceused = (uint32_t) nfs_ntohl64(attr_space_used); pFSAL_attr->asked_attributes |= FSAL_ATTR_SPACEUSED; LastOffset += fattr4tab[attribute_to_set].size_fattr4; break; case FATTR4_TIME_ACCESS: /* Used only by FSAL_PROXY to reverse convert */ memcpy((char *)&attr_time_access.seconds, (char *)(Fattr->attr_vals.attrlist4_val + LastOffset), sizeof(uint64_t)); LastOffset += sizeof( uint64_t ) ; memcpy((char *)&attr_time_access.nseconds, (char *)(Fattr->attr_vals.attrlist4_val + LastOffset), sizeof(uint32_t)); LastOffset += sizeof( uint32_t ) ; pFSAL_attr->atime.seconds = (uint32_t) nfs_ntohl64(attr_time_access.seconds); pFSAL_attr->atime.nseconds = (uint32_t) ntohl(attr_time_access.nseconds); pFSAL_attr->asked_attributes |= FSAL_ATTR_ATIME; break; case FATTR4_TIME_METADATA: /* Used only by FSAL_PROXY to reverse convert */ memcpy((char *)&attr_time_metadata.seconds, (char *)(Fattr->attr_vals.attrlist4_val + LastOffset), sizeof(uint64_t)); LastOffset += sizeof( uint64_t ) ; memcpy((char *)&attr_time_metadata.nseconds, (char *)(Fattr->attr_vals.attrlist4_val + LastOffset), sizeof(uint32_t)); LastOffset += sizeof( uint32_t ) ; pFSAL_attr->ctime.seconds = (uint32_t) nfs_ntohl64(attr_time_metadata.seconds); pFSAL_attr->ctime.nseconds = (uint32_t) ntohl(attr_time_metadata.nseconds); pFSAL_attr->asked_attributes |= FSAL_ATTR_CTIME; break; case FATTR4_TIME_MODIFY: /* Used only by FSAL_PROXY to reverse convert */ memcpy( (char *)&attr_time_modify.seconds, (char *)(Fattr->attr_vals.attrlist4_val + LastOffset), sizeof( uint64_t ) ); LastOffset += sizeof( uint64_t ) ; memcpy((char *)&attr_time_modify.nseconds, (char *)(Fattr->attr_vals.attrlist4_val + LastOffset), sizeof(uint32_t) ); LastOffset += sizeof( uint32_t ) ; pFSAL_attr->mtime.seconds = (uint32_t) nfs_ntohl64(attr_time_modify.seconds); pFSAL_attr->mtime.nseconds = (uint32_t) ntohl(attr_time_modify.nseconds); pFSAL_attr->asked_attributes |= FSAL_ATTR_MTIME; break; case FATTR4_TIME_ACCESS_SET: memcpy((char *)&attr_time_set, (char *)(Fattr->attr_vals.attrlist4_val + LastOffset), sizeof(fattr4_time_access_set)); if(ntohl(attr_time_set.set_it) == SET_TO_SERVER_TIME4) { pFSAL_attr->atime.seconds = time(NULL); /* Use current server's time */ pFSAL_attr->atime.nseconds = 0; } else { /* Take care of XDR when dealing with fattr4 */ attr_time = attr_time_set.settime4_u.time; attr_time.seconds = nfs_ntohl64(attr_time.seconds); attr_time.nseconds = ntohl(attr_time.nseconds); pFSAL_attr->atime.seconds = attr_time.seconds; pFSAL_attr->atime.nseconds = attr_time.nseconds; } pFSAL_attr->asked_attributes |= FSAL_ATTR_ATIME; LastOffset += fattr4tab[attribute_to_set].size_fattr4; break; case FATTR4_TIME_MODIFY_SET: memcpy((char *)&attr_time, (char *)(Fattr->attr_vals.attrlist4_val + LastOffset), sizeof(fattr4_time_modify_set)); if(ntohl(attr_time_set.set_it) == SET_TO_SERVER_TIME4) { pFSAL_attr->mtime.seconds = time(NULL); /* Use current server's time */ pFSAL_attr->mtime.nseconds = 0; } else { /* Take care of XDR when dealing with fattr4 */ attr_time = attr_time_set.settime4_u.time; attr_time.seconds = nfs_ntohl64(attr_time.seconds); attr_time.nseconds = ntohl(attr_time.nseconds); pFSAL_attr->mtime.seconds = attr_time.seconds; pFSAL_attr->mtime.nseconds = attr_time.nseconds; } pFSAL_attr->asked_attributes |= FSAL_ATTR_MTIME; LastOffset += fattr4tab[attribute_to_set].size_fattr4; break; case FATTR4_FILEHANDLE: memcpy(&len, (char *)(Fattr->attr_vals.attrlist4_val + LastOffset), sizeof(u_int)); len = ntohl(len); LastOffset += sizeof(u_int); /* Extract the file handle */ nfshandle.nfs_fh4_len = len; nfshandle.nfs_fh4_val = (char *)(Fattr->attr_vals.attrlist4_val + LastOffset); /* Bogus there: FATTR4_FILEHANDLE = 19 < FATTR4_FILEID = 20... This means that the FH is * is processed BEFORE the fileid. At this point, pFSAL_attr->fileid has not yet been set * and has the value 0. A flag is kept in variable compute_fh to add the fileid later */ fsal_internal_proxy_create_fh(&nfshandle, pFSAL_attr->type, pFSAL_attr->fileid, phandle); LastOffset += len; LogFullDebug(COMPONENT_NFS_V4, "SATTR: On a demande le filehandle len =%u\n", len); compute_fh = TRUE; break; case FATTR4_RDATTR_ERROR: memcpy((char *)&rdattr_error, (char *)(Fattr->attr_vals.attrlist4_val + LastOffset), sizeof(fattr4_rdattr_error)); rdattr_error = ntohl(rdattr_error); LastOffset += fattr4tab[attribute_to_set].size_fattr4; break; default: LogFullDebug(COMPONENT_NFS_V4, "SATTR: Attribut no supporte %d name=%s\n", attribute_to_set, fattr4tab[attribute_to_set].name); LastOffset += fattr4tab[attribute_to_set].size_fattr4; /* return 0 ; *//* Should not stop processing */ break; } /* switch */ } /* for */ if(compute_fh) { phandle->data.fileid4 = pFSAL_attr->fileid; } return 1; } /* proxy_Fattr_To_FSAL_attr */