From patchwork Tue May 9 19:09:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yauheni Kaliuta X-Patchwork-Id: 9718879 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 26C3760236 for ; Tue, 9 May 2017 19:09:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 19D742845E for ; Tue, 9 May 2017 19:09:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0EB3D28464; Tue, 9 May 2017 19:09:30 +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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI 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 A009F2845E for ; Tue, 9 May 2017 19:09:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754261AbdEITJ3 (ORCPT ); Tue, 9 May 2017 15:09:29 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53650 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753431AbdEITJ2 (ORCPT ); Tue, 9 May 2017 15:09:28 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 71F7AC04B94A; Tue, 9 May 2017 19:09:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 71F7AC04B94A Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=yauheni.kaliuta@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 71F7AC04B94A Received: from astarta.redhat.com (ovpn-116-244.ams2.redhat.com [10.36.116.244]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 943BB17B9F; Tue, 9 May 2017 19:09:27 +0000 (UTC) From: Yauheni Kaliuta To: Lucas De Marchi Cc: linux-modules Subject: [PATCHv2 1/4] depmod: create depmod dir independent search function Date: Tue, 9 May 2017 22:09:21 +0300 Message-Id: <20170509190924.9087-2-yauheni.kaliuta@redhat.com> In-Reply-To: <20170509190924.9087-1-yauheni.kaliuta@redhat.com> References: <20170509190924.9087-1-yauheni.kaliuta@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 09 May 2017 19:09:28 +0000 (UTC) Sender: owner-linux-modules@vger.kernel.org Precedence: bulk List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Prepare to implement external directories support. The patch splits depmod_modules_search() function to two functions: depmod_modules_search(), called by the high level with intention to search all possible modules, and depmod_module_search_path(), which takes path as a parameter and scans modules under the path only. Initially it is used to scan the same depmod->cfg->dirname path only. Signed-off-by: Yauheni Kaliuta --- tools/depmod.c | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/tools/depmod.c b/tools/depmod.c index ded64500a50f..cfed864ff6c1 100644 --- a/tools/depmod.c +++ b/tools/depmod.c @@ -1191,29 +1191,42 @@ static int depmod_modules_search_dir(struct depmod *depmod, DIR *d, size_t basel return err; } -static int depmod_modules_search(struct depmod *depmod) +static int depmod_modules_search_path(struct depmod *depmod, + const char *path) { - char path[PATH_MAX]; - DIR *d = opendir(depmod->cfg->dirname); + char path_buf[PATH_MAX]; + DIR *d; size_t baselen; int err; + + d = opendir(path); if (d == NULL) { err = -errno; - ERR("could not open directory %s: %m\n", depmod->cfg->dirname); + ERR("could not open directory %s: %m\n", path); return err; } - baselen = depmod->cfg->dirnamelen; - memcpy(path, depmod->cfg->dirname, baselen); - path[baselen] = '/'; + baselen = strlen(path); + memcpy(path_buf, path, baselen); + path_buf[baselen] = '/'; baselen++; - path[baselen] = '\0'; + path_buf[baselen] = '\0'; - err = depmod_modules_search_dir(depmod, d, baselen, path); + err = depmod_modules_search_dir(depmod, d, baselen, path_buf); closedir(d); return err; } +static int depmod_modules_search(struct depmod *depmod) +{ + int err; + + err = depmod_modules_search_path(depmod, depmod->cfg->dirname); + if (err < 0) + return err; + return 0; +} + static int mod_cmp(const void *pa, const void *pb) { const struct mod *a = *(const struct mod **)pa; const struct mod *b = *(const struct mod **)pb;