From patchwork Thu Apr 20 08:13:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abdiel Janulgue X-Patchwork-Id: 9689841 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 1DA1860326 for ; Thu, 20 Apr 2017 08:15:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0DE432845C for ; Thu, 20 Apr 2017 08:15:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 02F6928464; Thu, 20 Apr 2017 08:15:17 +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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BEB142845C for ; Thu, 20 Apr 2017 08:15:16 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 088EF6E337; Thu, 20 Apr 2017 08:15:15 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by gabe.freedesktop.org (Postfix) with ESMTPS id 386636E0E0 for ; Thu, 20 Apr 2017 08:15:13 +0000 (UTC) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga104.jf.intel.com with ESMTP; 20 Apr 2017 01:15:13 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.37,225,1488873600"; d="scan'208";a="959064179" Received: from skylake-nuc.fi.intel.com ([10.237.72.145]) by orsmga003.jf.intel.com with ESMTP; 20 Apr 2017 01:15:12 -0700 From: Abdiel Janulgue To: intel-gfx@lists.freedesktop.org Date: Thu, 20 Apr 2017 11:13:47 +0300 Message-Id: <1492676028-15372-3-git-send-email-abdiel.janulgue@linux.intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1492676028-15372-1-git-send-email-abdiel.janulgue@linux.intel.com> References: <1492676028-15372-1-git-send-email-abdiel.janulgue@linux.intel.com> Subject: [Intel-gfx] [i-g-t PATCH 3/4] lib/igt_debugfs: Add helper to return path to device. X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Abdiel Janulgue --- lib/igt_debugfs.c | 26 ++++++++++++++++++++++++++ lib/igt_debugfs.h | 1 + 2 files changed, 27 insertions(+) diff --git a/lib/igt_debugfs.c b/lib/igt_debugfs.c index 7584be5..b019c3b 100644 --- a/lib/igt_debugfs.c +++ b/lib/igt_debugfs.c @@ -22,6 +22,9 @@ * */ +#ifndef ANDROID +#define _GNU_SOURCE +#endif #include #include #include @@ -198,6 +201,29 @@ int igt_debugfs_dir(int device) igt_debug("Opening debugfs directory '%s'\n", path); return open(path, O_RDONLY); } +\ +/** + * igt_debugfs_path: + * @device: fd of the device + * + * Returns: + * The path to the debugfs directory corresponding to device + */ +const char *igt_debugfs_path(int device) +{ + char *path = 0; + + if (!path) { + char *linkname; + int debugfs; + igt_assert((debugfs = igt_debugfs_dir(device)) != -1); + igt_assert(path = calloc(PATH_MAX, sizeof(char))); + igt_assert(asprintf(&linkname, "/proc/self/fd/%d", debugfs) != -1); + igt_assert(readlink(linkname, path, PATH_MAX * sizeof(char)) != -1); + } + + return path; +} /** * igt_debugfs_open: diff --git a/lib/igt_debugfs.h b/lib/igt_debugfs.h index 7b846a8..76cf409 100644 --- a/lib/igt_debugfs.h +++ b/lib/igt_debugfs.h @@ -204,5 +204,6 @@ void igt_enable_prefault(void); */ int igt_get_stable_obj_count(int driver); void igt_debugfs_dump(int device, const char *filename); +const char *igt_debugfs_path(int device); #endif /* __IGT_DEBUGFS_H__ */