From patchwork Sun Dec 25 11:23:45 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 9488233 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A69CB60838 for ; Sun, 25 Dec 2016 11:24:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 81E4426246 for ; Sun, 25 Dec 2016 11:24:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7619E26530; Sun, 25 Dec 2016 11:24:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C539D26246 for ; Sun, 25 Dec 2016 11:24:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753269AbcLYLY0 (ORCPT ); Sun, 25 Dec 2016 06:24:26 -0500 Received: from mail-wj0-f196.google.com ([209.85.210.196]:33551 "EHLO mail-wj0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753137AbcLYLYZ (ORCPT ); Sun, 25 Dec 2016 06:24:25 -0500 Received: by mail-wj0-f196.google.com with SMTP id kp2so45820597wjc.0; Sun, 25 Dec 2016 03:24:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=uKcBuctr0eIjlxGAkgEw465WM80RUc3IKwThD3SMQYw=; b=rvrCFUAI3Hg0uVZlvRWoxLq1q4Xw2CQEW3Nf2t2rzKdMcbUnh+jQZh1MmlSghVm3oQ oeDKZo746+Z2jC0iTaiDbTnxDFeieaZTYCvIkYx+gD6O4gx0DZgNJB1eaR2oVWSMJeBn GMD4Xb9ZAps/uSY2J9W9SKNHihEqHwDu44sntFkaCwfEAli8Bq34qGZD30KEdI842Rb5 R/ZuxcawW5VUYyBa7w0tE07BXnKXE7EkGPUfylvLbwA2umZBFcIPOn+nW8b/cZySLQY7 pUZTUvHwCm7G889uON9Ef64i0AxWd4G5tzVpj4k3GWL03/np7GBWavV5w66SMrVNUNn0 snkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=uKcBuctr0eIjlxGAkgEw465WM80RUc3IKwThD3SMQYw=; b=W4gB6bs508BYIbacBh3RZTWLd9NzVTGq1cx04PbhPwP+pYLAk2T70IUEzJxQCCDh4R sOkD7WCqdAszQCwarGr3G0yEjWgjDOQ8UsLEHWuUXp4s15z425BDlRaQn1iUm41iU6v4 lNPirfhdwdReAssFJIXKBg8ioZ4I3ObZ9dQGyndpTizJ58yM0zTU0/mr+Y7c65KY8E6V U7wLnm0KiXwd6azI+zwMPC9sqtrZdm/JoPdyMxq/3sdo3G58E1GHwm7A/o6RYNhT3B7K B3u+isy+LFjQb6mLutcNgiInQCHjxWs/FG1uoytKP5hDhGE8aux+ipwiZ3Ds+hhZ4JDX vQkw== X-Gm-Message-State: AIkVDXK4zTWRlBXWiGL+hDrBi1CiwuGKNq04rVwspPweXUFLtybccYYoQs2BnwP8pV7hnQ== X-Received: by 10.194.236.71 with SMTP id us7mr3357100wjc.7.1482665043296; Sun, 25 Dec 2016 03:24:03 -0800 (PST) Received: from amir-VirtualBox.Home (bzq-79-180-107-203.red.bezeqint.net. [79.180.107.203]) by smtp.gmail.com with ESMTPSA id ab10sm49753864wjc.45.2016.12.25.03.24.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 25 Dec 2016 03:24:02 -0800 (PST) From: Amir Goldstein To: "Darrick J . Wong" Cc: Dave Chinner , Brian Foster , linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v5] xfs: fix the size of xfs_mode_to_ftype table Date: Sun, 25 Dec 2016 13:23:45 +0200 Message-Id: <1482665025-18003-1-git-send-email-amir73il@gmail.com> X-Mailer: git-send-email 2.7.4 Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Fix the size of the xfs_mode_to_ftype conversion table, which was too small to handle an invalid value of mode=S_IFMT. Use a convenience macro S_DT(mode) to convert from mode to dirent file type and change the name of the table to xfs_dtype_to_ftype to correctly describe its index values. Signed-off-by: Amir Goldstein Reviewed-by: Brian Foster --- fs/xfs/libxfs/xfs_dir2.c | 18 +++++++++--------- fs/xfs/libxfs/xfs_dir2.h | 4 +++- fs/xfs/xfs_iops.c | 2 +- 3 files changed, 13 insertions(+), 11 deletions(-) Darrick, I implemented the xfs specific test case to test all possible malformed file type values as you suggested and fixed up some minor nits that Brian pointed out. Tested with generic/396 with -n ftype=0|1. Tested with new xfs/348 test with -n ftype=0|1. Amir. v5: - remove wrong argument about on-disk malformed mode from commit message - address Brian's review comments v4: - independent fix patch for xfs v3: - resort to simpler cleanup with macros DT_MAX and S_DT() - mention the minor bug fix in commit message v2: - add private conversion from common to on-disk values v1: - use common conversion functions to get on-disk values diff --git a/fs/xfs/libxfs/xfs_dir2.c b/fs/xfs/libxfs/xfs_dir2.c index c58d72c..48d7c45 100644 --- a/fs/xfs/libxfs/xfs_dir2.c +++ b/fs/xfs/libxfs/xfs_dir2.c @@ -41,15 +41,15 @@ struct xfs_name xfs_name_dotdot = { (unsigned char *)"..", 2, XFS_DIR3_FT_DIR }; * for file type specification. This will be propagated into the directory * structure if appropriate for the given operation and filesystem config. */ -const unsigned char xfs_mode_to_ftype[S_IFMT >> S_SHIFT] = { - [0] = XFS_DIR3_FT_UNKNOWN, - [S_IFREG >> S_SHIFT] = XFS_DIR3_FT_REG_FILE, - [S_IFDIR >> S_SHIFT] = XFS_DIR3_FT_DIR, - [S_IFCHR >> S_SHIFT] = XFS_DIR3_FT_CHRDEV, - [S_IFBLK >> S_SHIFT] = XFS_DIR3_FT_BLKDEV, - [S_IFIFO >> S_SHIFT] = XFS_DIR3_FT_FIFO, - [S_IFSOCK >> S_SHIFT] = XFS_DIR3_FT_SOCK, - [S_IFLNK >> S_SHIFT] = XFS_DIR3_FT_SYMLINK, +const unsigned char xfs_dtype_to_ftype[S_DT_MAX+1] = { + [0] = XFS_DIR3_FT_UNKNOWN, + [S_DT(S_IFREG)] = XFS_DIR3_FT_REG_FILE, + [S_DT(S_IFDIR)] = XFS_DIR3_FT_DIR, + [S_DT(S_IFCHR)] = XFS_DIR3_FT_CHRDEV, + [S_DT(S_IFBLK)] = XFS_DIR3_FT_BLKDEV, + [S_DT(S_IFIFO)] = XFS_DIR3_FT_FIFO, + [S_DT(S_IFSOCK)] = XFS_DIR3_FT_SOCK, + [S_DT(S_IFLNK)] = XFS_DIR3_FT_SYMLINK, }; /* diff --git a/fs/xfs/libxfs/xfs_dir2.h b/fs/xfs/libxfs/xfs_dir2.h index 0197590..4934d38 100644 --- a/fs/xfs/libxfs/xfs_dir2.h +++ b/fs/xfs/libxfs/xfs_dir2.h @@ -35,7 +35,9 @@ extern struct xfs_name xfs_name_dotdot; * directory filetype conversion tables. */ #define S_SHIFT 12 -extern const unsigned char xfs_mode_to_ftype[]; +#define S_DT(mode) (((mode) & S_IFMT) >> S_SHIFT) +#define S_DT_MAX S_DT(S_IFMT) +extern const unsigned char xfs_dtype_to_ftype[]; /* * directory operations vector for encode/decode routines diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c index 308bebb..d2da9ca 100644 --- a/fs/xfs/xfs_iops.c +++ b/fs/xfs/xfs_iops.c @@ -103,7 +103,7 @@ xfs_dentry_to_name( { namep->name = dentry->d_name.name; namep->len = dentry->d_name.len; - namep->type = xfs_mode_to_ftype[(mode & S_IFMT) >> S_SHIFT]; + namep->type = xfs_dtype_to_ftype[S_DT(mode)]; } STATIC void