From patchwork Wed Nov 23 15:23:37 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yauheni Kaliuta X-Patchwork-Id: 9443607 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 18775600BA for ; Wed, 23 Nov 2016 15:22:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0CB2B26D19 for ; Wed, 23 Nov 2016 15:22:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 01324271CB; Wed, 23 Nov 2016 15:22:45 +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 A99142705B for ; Wed, 23 Nov 2016 15:22:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S938710AbcKWPWp (ORCPT ); Wed, 23 Nov 2016 10:22:45 -0500 Received: from mx1.redhat.com ([209.132.183.28]:56990 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935350AbcKWPWo (ORCPT ); Wed, 23 Nov 2016 10:22:44 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 650BA31B333; Wed, 23 Nov 2016 15:22:44 +0000 (UTC) Received: from astarta.redhat.com (vpn1-6-30.ams2.redhat.com [10.36.6.30]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id uANFMevL023117 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 23 Nov 2016 10:22:43 -0500 From: Yauheni Kaliuta To: linux-modules@vger.kernel.org Cc: aris@redhat.com, Lucas De Marchi , yauheni.kaliuta@redhat.com Subject: [PATCH RFC 1/3] depmod: create depmod dir independent search function Date: Wed, 23 Nov 2016 17:23:37 +0200 Message-Id: <20161123152339.27531-2-yauheni.kaliuta@redhat.com> In-Reply-To: <20161123152339.27531-1-yauheni.kaliuta@redhat.com> References: <20161123152339.27531-1-yauheni.kaliuta@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 23 Nov 2016 15:22:44 +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 f2b370f146bb..a96501d1cbfb 100644 --- a/tools/depmod.c +++ b/tools/depmod.c @@ -1186,29 +1186,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;