From patchwork Tue Dec 20 13:17:34 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 9481551 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 B0713606DB for ; Tue, 20 Dec 2016 13:18:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A29E62841C for ; Tue, 20 Dec 2016 13:18:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 978DC2848D; Tue, 20 Dec 2016 13:18:11 +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=ham 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 635FC2846A for ; Tue, 20 Dec 2016 13:18:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757965AbcLTNSK (ORCPT ); Tue, 20 Dec 2016 08:18:10 -0500 Received: from mail-wm0-f68.google.com ([74.125.82.68]:35553 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757981AbcLTNSI (ORCPT ); Tue, 20 Dec 2016 08:18:08 -0500 Received: by mail-wm0-f68.google.com with SMTP id a20so24365478wme.2 for ; Tue, 20 Dec 2016 05:18:07 -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:in-reply-to:references; bh=EDLCQhLEftdq2tYOOE7/vXI4txhVh0om16h5GuvAgIY=; b=flwAhmSTiMZNAoBxQmN2K0Ug1zkiQ4D7SyYT4kS4nwvnGASXfZViy9wXwSus73LpZH 2uABrTDSc1DUuMCS4NXzwCnzwgsUH5tQ1Ng4LirItTGuCI736O20X4x6yAPaMhCDCzxM L1lyyhf6hE4zs+AcVZY3NKPDikuNc17hMAxo1hOAOA3zU8FF5bJE8K+Gv4uM9pYMoDMN 9NyjjrkU+v0LmqbA1nBlJAGdUwRrWYdBghzI6LKKmPqcVAb5dX+isv+orrokWYUM/wGp w99m35hMhp3uYVnXRimo/ciThYHDWXQVqlOqi2BqTRTQpGwTPH3i28qTbhf1GoeTZG39 98lQ== 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:in-reply-to :references; bh=EDLCQhLEftdq2tYOOE7/vXI4txhVh0om16h5GuvAgIY=; b=qNpVWft6k5OClWipKRsn8Pf+1Ecr+UMY7eoPSDd422Iaqm45WoeqUIo4f8ufYgSVib NHG86JNn6WfAazn05Es20/b5WlXvgtJvW9vwADQFzvjcIF7wTZdGUy14AbTs9OeEK9ng uSBYNLAxmrSCY2wQIJockKRif4ydegs8XfW3GPPZZFCbbHahXOt81flJ6GT5DSv//wx9 TxQWaMe75Xd8z1hmCJwaOwDmG/avTLoeeMUs1FjOvfQTb687vVp1VWebmY8RecXQesbw Rx4R1k7/PwGXfLwRFFcGjt6TFARRiz47NtEhlbnM6/6ukAdDqj7wSuowe34+vPh7pyD0 MMqQ== X-Gm-Message-State: AIkVDXJ0DBy89givFl+Qm6nzx2H85CUFbYhf9Cfsh2ynx8i/oNnZKvT8R807aSA5IYYzhA== X-Received: by 10.28.170.134 with SMTP id t128mr1818041wme.29.1482239886928; Tue, 20 Dec 2016 05:18:06 -0800 (PST) Received: from amir-VirtualBox.ctera.local (bzq-82-81-193-202.cablep.bezeqint.net. [82.81.193.202]) by smtp.gmail.com with ESMTPSA id d64sm22041525wmh.3.2016.12.20.05.18.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 20 Dec 2016 05:18:06 -0800 (PST) From: Amir Goldstein To: Eryu Guan Cc: Dave Chinner , Christoph Hellwig , "Darrick J . Wong" , Miklos Szeredi , fstests@vger.kernel.org Subject: [PATCH v2 2/3] common/rc: add generic file type support check Date: Tue, 20 Dec 2016 15:17:34 +0200 Message-Id: <1482239855-791-3-git-send-email-amir73il@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1482239855-791-1-git-send-email-amir73il@gmail.com> References: <1482239855-791-1-git-send-email-amir73il@gmail.com> Sender: fstests-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP _supports_filetype() helper checks if the filetype feature is enabled for xfs and ext* file sytems. Add a check for the generic case where we don't know how to test file system filetype feature. Introduce a helper utility t_dir_type that lists directory entries filtered by file type. Check for filetype feature by expecting to find no directory entries listed as DT_UNKNOWN inside a test directory. Signed-off-by: Amir Goldstein --- .gitignore | 1 + common/rc | 9 +++++ src/Makefile | 2 +- src/t_dir_type.c | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 src/t_dir_type.c diff --git a/.gitignore b/.gitignore index b8d13a0..7dcea14 100644 --- a/.gitignore +++ b/.gitignore @@ -94,6 +94,7 @@ /src/t_access_root /src/t_dir_offset /src/t_dir_offset2 +/src/t_dir_type /src/t_futimens /src/t_getcwd /src/t_holes diff --git a/common/rc b/common/rc index 288517f..a779c50 100644 --- a/common/rc +++ b/common/rc @@ -278,6 +278,15 @@ _supports_filetype() tune2fs -l $(df --output=source $dir | tail -1) | \ grep -q filetype ;; + *) + testfile=$dir/$$.ftype + touch $testfile + # look for DT_UNKNOWN files + unknowns=$(src/t_dir_type $dir u | wc -l) + rm $testfile + # 0 unknowns is success + return $unknowns + ;; esac } diff --git a/src/Makefile b/src/Makefile index 4056496..94d74aa 100644 --- a/src/Makefile +++ b/src/Makefile @@ -21,7 +21,7 @@ LINUX_TARGETS = xfsctl bstat t_mtab getdevicesize preallo_rw_pattern_reader \ stale_handle pwrite_mmap_blocked t_dir_offset2 seek_sanity_test \ seek_copy_test t_readdir_1 t_readdir_2 fsync-tester nsexec cloner \ renameat2 t_getcwd e4compact test-nextquota punch-alternating \ - attr-list-by-handle-cursor-test listxattr dio-interleaved + attr-list-by-handle-cursor-test listxattr dio-interleaved t_dir_type SUBDIRS = diff --git a/src/t_dir_type.c b/src/t_dir_type.c new file mode 100644 index 0000000..344bef8 --- /dev/null +++ b/src/t_dir_type.c @@ -0,0 +1,108 @@ +/* + * Copyright (C) 2016 CTERA Networks. All Rights Reserved. + * Author: Amir Goldstein + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it would be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/* + * t_dir_type + * + * print directory entries, optionally filtered by d_type + * + * ./t_dir_type [u|f|d|c|b|l|p|s|w] + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +struct linux_dirent64 { + uint64_t d_ino; + int64_t d_off; + unsigned short d_reclen; + unsigned char d_type; + char d_name[0]; +}; + +#define DT_MASK 15 +#define DT_MAX 15 +unsigned char type_to_char[DT_MAX] = { + [DT_UNKNOWN] = 'u', + [DT_DIR] = 'd', + [DT_REG] = 'f', + [DT_LNK] = 'l', + [DT_CHR] = 'c', + [DT_BLK] = 'b', + [DT_FIFO] = 'p', + [DT_SOCK] = 's', + [DT_WHT] = 'w', +}; + +#define DT_CHAR(t) type_to_char[(t)&DT_MASK] + +#define BUF_SIZE 4096 + +int +main(int argc, char *argv[]) +{ + int fd, nread; + char buf[BUF_SIZE]; + struct linux_dirent64 *d; + int bpos; + int type = -1; /* -1 means all types */ + int ret = 1; + + fd = open(argv[1], O_RDONLY | O_DIRECTORY); + if (fd < 0) { + perror("open"); + exit(EXIT_FAILURE); + } + + if (argc > 2 && argv[2][0]) { + char t = argv[2][0]; + + for (type = DT_MAX-1; type >= 0; type--) + if (DT_CHAR(type) == t) + break; + /* no match ends up with type = -1 */ + } + + for ( ; ; ) { + nread = syscall(SYS_getdents64, fd, buf, BUF_SIZE); + if (nread == -1) { + perror("getdents"); + exit(EXIT_FAILURE); + } + + if (nread == 0) + break; + + for (bpos = 0; bpos < nread;) { + d = (struct linux_dirent64 *) (buf + bpos); + if (type < 0 || type == (int)d->d_type) { + ret = 0; + printf("%s %c\n", d->d_name, DT_CHAR(d->d_type)); + } + bpos += d->d_reclen; + } + } + + return ret; +}