From patchwork Wed Dec 21 22:52:12 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 132754 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from acsinet15.oracle.com (acsinet15.oracle.com [141.146.126.227]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "acsinet15.oracle.com", Issuer "VeriSign Class 3 International Server CA - G3" (verified OK)) by ozlabs.org (Postfix) with ESMTPS id BCC13B713B for ; Thu, 22 Dec 2011 09:52:22 +1100 (EST) Received: from ucsinet21.oracle.com (ucsinet21.oracle.com [156.151.31.93]) by acsinet15.oracle.com (Switch-3.4.4/Switch-3.4.4) with ESMTP id pBLMqHfa006643 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 21 Dec 2011 22:52:17 GMT Received: from oss.oracle.com (oss.oracle.com [141.146.12.120]) by ucsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id pBLMqFJ9010147 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 21 Dec 2011 22:52:16 GMT Received: from localhost ([127.0.0.1] helo=oss.oracle.com) by oss.oracle.com with esmtp (Exim 4.63) (envelope-from ) id 1RdV1D-0001tE-SI; Wed, 21 Dec 2011 14:52:15 -0800 Received: from rcsinet12.oracle.com ([148.87.113.124]) by oss.oracle.com with esmtp (Exim 4.63) (envelope-from ) id 1RdV1D-0001t7-1X for fedfs-utils-devel@oss.oracle.com; Wed, 21 Dec 2011 14:52:15 -0800 Received: from mail-yx0-f171.google.com (mail-yx0-f171.google.com [209.85.213.171]) by rcsinet12.oracle.com (Sentrion-MTA-4.2.0/Sentrion-MTA-4.2.0) with ESMTP id pBLMq5pm001070 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Wed, 21 Dec 2011 22:52:14 GMT Received: by mail-yx0-f171.google.com with SMTP id r9so5303914yen.2 for ; Wed, 21 Dec 2011 14:52:14 -0800 (PST) Received: by 10.236.93.4 with SMTP id k4mr11966279yhf.114.1324507934389; Wed, 21 Dec 2011 14:52:14 -0800 (PST) Received: from degas.1015granger.net (adsl-99-26-161-222.dsl.sfldmi.sbcglobal.net. [99.26.161.222]) by mx.google.com with ESMTPS id q5sm11370376yhm.7.2011.12.21.14.52.13 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 21 Dec 2011 14:52:13 -0800 (PST) From: Chuck Lever To: fedfs-utils-devel@oss.oracle.com Date: Wed, 21 Dec 2011 17:52:12 -0500 Message-ID: <20111221225212.23950.32213.stgit@degas.1015granger.net> In-Reply-To: <20111221222832.23950.14134.stgit@degas.1015granger.net> References: <20111221222832.23950.14134.stgit@degas.1015granger.net> User-Agent: StGIT/0.14.3 MIME-Version: 1.0 X-Flow-Control-Info: class=ISPs ip=209.85.213.171 ct-class=G1 ct-vol1=0 ct-vol2=0 ct-vol3=0 ct-risk=0 ct-spam1=0 ct-spam2=0 ct-bulk=0 rcpts=1 size=10220 Subject: [fedfs-utils] [PATCH 6/8] libnsdb: Remove unused FedFsPathName helper utilities X-BeenThere: fedfs-utils-devel@oss.oracle.com X-Mailman-Version: 2.1.9 Precedence: list Reply-To: fedfs-utils Developers List-Id: fedfs-utils Developers List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: fedfs-utils-devel-bounces@oss.oracle.com Errors-To: fedfs-utils-devel-bounces@oss.oracle.com X-Source-IP: ucsinet21.oracle.com [156.151.31.93] X-CT-RefId: str=0001.0A02020B.4EF26322.004F:SCFSTAT3865452, ss=1, re=-6.300, fgs=0 Now that the command line tools have been converted to use the new path_array APIs, the original FedFsPathName helpers are unused and can be removed. Signed-off-by: Chuck Lever --- src/include/nsdb.h | 10 -- src/libnsdb/path.c | 316 ---------------------------------------------------- 2 files changed, 0 insertions(+), 326 deletions(-) diff --git a/src/include/nsdb.h b/src/include/nsdb.h index cbde86f..10558c5 100644 --- a/src/include/nsdb.h +++ b/src/include/nsdb.h @@ -383,18 +383,8 @@ FedFsStatus nsdb_parse_annotation(const char *annotation, size_t len, __attribute_malloc__ char *nsdb_normalize_path(const char *pathname); _Bool nsdb_pathname_is_utf8(const char *pathname); - -FedFsStatus nsdb_fedfspathname_to_posix(const FedFsPathName fpath, - char **pathname); -FedFsStatus nsdb_posix_to_fedfspathname(const char *pathname, - FedFsPathName *fpath); void nsdb_free_fedfspathname(FedFsPathName *fpath); -FedFsStatus nsdb_posix_path_to_xdr(const char *pathname, - struct berval *xdr_path); -FedFsStatus nsdb_xdr_to_posix_path(struct berval *xdr_path, - char **pathname); - FedFsStatus nsdb_path_array_to_xdr(char * const *path_array, struct berval *xdr_path); FedFsStatus nsdb_xdr_to_path_array(const struct berval *xdr_path, diff --git a/src/libnsdb/path.c b/src/libnsdb/path.c index ddb65fc..e5506ea 100644 --- a/src/libnsdb/path.c +++ b/src/libnsdb/path.c @@ -208,170 +208,6 @@ nsdb_pathname_is_utf8(__attribute__((unused)) const char *pathname) } /** - * XDR encode a POSIX path name - * - * @param pathname NUL-terminated C string containing a POSIX path - * @param xdr_path OUT: pointer to XDR-encoded path in a berval - * @return a FedFsStatus code - * - * Caller must free xdr_path->bv_val with free(3) - * - * The XDR encoded result is described by the NSDB protocol draft as - * "an XDR encoded variable length array of variable length opaque - * data." The result of this encoding is a byte stream. - */ -FedFsStatus -nsdb_posix_path_to_xdr(const char *pathname, struct berval *xdr_path) -{ - char *component, *normalized; - unsigned int i, count; - uint32_t *xdrbuf; - size_t length; - - if (pathname == NULL || xdr_path == NULL) { - xlog(L_ERROR, "%s: Invalid argument", __func__); - return FEDFS_ERR_INVAL; - } - - if (!nsdb_pathname_is_utf8(pathname)) { - xlog(D_GENERAL, "%s: Bad character in pathname", __func__); - return FEDFS_ERR_BADCHAR; - } - - normalized = nsdb_normalize_path(pathname); - if (normalized == NULL) - return FEDFS_ERR_SVRFAULT; - - /* - * Calculate the number of path components and the - * number of bytes in the encoded result so that a - * buffer for the result can be allocated. - */ - if (!nsdb_count_components(normalized, &length, &count)) - return FEDFS_ERR_BADNAME; - - /* - * Flatten the POSIX path into an encoded XDR stream - * stored in the allocated buffer - */ - xdrbuf = malloc(length); - if (xdrbuf == NULL) { - xlog(L_ERROR, "%s: Failed to allocate XDR buffer", - __func__); - free(normalized); - return FEDFS_ERR_SVRFAULT; - } - memset(xdrbuf, 0, length); - - i = 1; - xdrbuf[i] = htonl(count); - component = normalized; - for ( ;; ) { - char *next; - - if (*component == '/') - component++; - if (*component == '\0') - break; - next = strchrnul(component, '/'); - length = next - component; - - xdrbuf[i++] = htonl(length); - memcpy(&xdrbuf[i], component, length); - i += nsdb_quadlen(length); - - if (*next == '\0') - break; - component = next; - } - - xdr_path->bv_val = (char *)xdrbuf; - xdr_path->bv_len = (ber_len_t)(i << 2); - - free(normalized); - return FEDFS_OK; -} - -/** - * XDR decode an XDR byte stream into a POSIX path name - * - * @param xdr_path berval containing XDR-encoded path - * @param pathname OUT: pointer to NUL-terminated UTF-8 C string containing a POSIX path name - * @return a FedFsStatus code - * - * Caller must free "pathname" with free(3) - * - * Note that the count of array items is ignored. It's not needed to - * decode the XDR byte stream correctly. The only important thing is - * to avoid reading outside the passed-in XDR byte stream. That can - * result in incorrect results or even segfaults. - */ -FedFsStatus -nsdb_xdr_to_posix_path(struct berval *xdr_path, char **pathname) -{ - const unsigned int buflen = nsdb_quadlen((unsigned int)xdr_path->bv_len); - uint32_t *buf = (uint32_t *)xdr_path->bv_val; - unsigned int i; - uint32_t size; - size_t length; - char *result; - - if (xdr_path == NULL || pathname == NULL) { - xlog(L_ERROR, "%s: Invalid argument", __func__); - return FEDFS_ERR_INVAL; - } - - i = 1; /* skip the count of array elements */ - length = STRLEN_NUL; - for ( ;; ) { - length += STRLEN_SLASH; - if (i >= buflen) - break; - - size = ntohl(buf[i++]); - i += nsdb_quadlen(size); - if (i == buflen) - break; - if (i > buflen) { - xlog(D_GENERAL, "%s: XDR decoding error", __func__); - return FEDFS_ERR_BADXDR; - } - - length += size; - } - - result = malloc(length); - if (result == NULL) { - xlog(L_ERROR, "%s: Failed to allocate pathname buffer", - __func__); - return FEDFS_ERR_SVRFAULT; - } - result[0] = '\0'; - - i = 1; /* skip the count of elements */ - for ( ;; ) { - strcat(result, "/"); - if (i == buflen) - break; - - size = ntohl(buf[i++]); - strncat(result, (char *)&buf[i], size); - i += nsdb_quadlen(size); - if (i == buflen) - break; - } - - if (!nsdb_pathname_is_utf8(result)) { - xlog(D_GENERAL, "%s: Bad character in pathname", __func__); - free(result); - return FEDFS_ERR_BADCHAR; - } - - *pathname = result; - return FEDFS_OK; -} - -/** * Free a FedFsPathComponent allocated by nsdb_new_component * * @param fcomp pointer to FedFsPathComponent to free @@ -421,158 +257,6 @@ nsdb_free_fedfspathname(FedFsPathName *fpath) } /** - * Construct a FedFsPathName from a C string - * - * @param pathname NUL-terminated C string containing a POSIX pathname - * @param fpath OUT: pointer to FedFsPathName in which to construct path - * @return a FedFsStatus code - */ -FedFsStatus -nsdb_posix_to_fedfspathname(const char *pathname, FedFsPathName *fpath) -{ - char *normalized, *component; - unsigned int i, count; - size_t length; - - if (!nsdb_pathname_is_utf8(pathname)) { - xlog(D_GENERAL, "%s: Bad character in pathname", __func__); - return FEDFS_ERR_BADCHAR; - } - - normalized = nsdb_normalize_path(pathname); - if (normalized == NULL) - return FEDFS_ERR_SVRFAULT; - - if (!nsdb_count_components(normalized, &length, &count)) - return FEDFS_ERR_BADNAME; - - /* The path "/" MUST be encoded as an array with zero components. */ - if (count == 0) { - fpath->FedFsPathName_val = NULL; - fpath->FedFsPathName_len = 0; - return FEDFS_OK; - } - - fpath->FedFsPathName_val = calloc(count, sizeof(FedFsPathComponent)); - if (fpath->FedFsPathName_val == NULL) - return FEDFS_ERR_SVRFAULT; - fpath->FedFsPathName_len = count; - - i = 0; - component = normalized; - for (i = 0; ; i++) { - char *next; - - if (*component == '/') - component++; - if (*component == '\0') - break; - next = strchrnul(component, '/'); - length = next - component; - - if (!nsdb_new_component(component, - length, &fpath->FedFsPathName_val[i])) - goto out_err; - - if (*next == '\0') - break; - component = next; - } - - return FEDFS_OK; - -out_err: - xlog(D_GENERAL, "%s: Failed to allocate new pathname component", - __func__); - nsdb_free_fedfspathname(fpath); - return FEDFS_ERR_SVRFAULT; -} - -/** - * Construct a local Posix-style path from a FedFsPathName - * - * @param fpath FedFsPathName from which to construct path - * @param pathname OUT: pointer to NUL-terminated UTF-8 C string containing a Posix-style path - * @return a FedFsStatus code - * - * Caller must free the returned pathname with free(3). - * - * NB: The use of fixed constants for NAME_MAX and PATH_MAX are required - * here because, on the client side, the pathname likely does not - * exist, so pathconf(3) cannot be used. - */ -FedFsStatus -nsdb_fedfspathname_to_posix(const FedFsPathName fpath, char **pathname) -{ - unsigned int i; - char *result; - - result = malloc(PATH_MAX); - if (result == NULL) { - xlog(D_GENERAL, "%s: Failed to allocate buffer for result", - __func__); - return FEDFS_ERR_SVRFAULT; - } - result[0] = '\0'; - - if (fpath.FedFsPathName_len == 0) { - xlog(D_GENERAL, "%s: Zero-component pathname", __func__); - strcat(result, "/"); - *pathname = result; - return FEDFS_OK; - } - - for (i = 0; i < fpath.FedFsPathName_len; i++) { - FedFsPathComponent fcomp = fpath.FedFsPathName_val[i]; - unsigned int len = fcomp.utf8string_len; - char *component = fcomp.utf8string_val; - - if (len == 0) { - xlog(D_GENERAL, "%s: Zero-length component", __func__); - free(result); - return FEDFS_ERR_BADNAME; - } - - if (len > NAME_MAX) { - xlog(D_GENERAL, "%s: Component length too long", - __func__); - free(result); - return FEDFS_ERR_NAMETOOLONG; - } - - if (nsdb_strnchr(component, '/', len) != NULL) { - xlog(D_GENERAL, "%s: Local separator " - "character found in component", - __func__); - free(result); - return FEDFS_ERR_BADNAME; - } - - if (strlen(result) + STRLEN_SLASH + len >= PATH_MAX) { - xlog(D_GENERAL, "%s: FedFsPathName " - "too long", __func__); - free(result); - return FEDFS_ERR_NAMETOOLONG; - } - - strcat(result, "/"); - strcat(result, component); - } - - if (!nsdb_pathname_is_utf8(result)) { - xlog(D_GENERAL, "%s: Bad character in pathname", __func__); - free(result); - return FEDFS_ERR_BADCHAR; - } - - *pathname = nsdb_normalize_path(result); - free(result); - if (*pathname == NULL) - return FEDFS_ERR_SVRFAULT; - return FEDFS_OK; -} - -/** * XDR encode an array of component strings * * @param path_array array of pointers to NUL-terminated C strings