From patchwork Sun Apr 1 21:49:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve French X-Patchwork-Id: 10319339 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 9CD6760380 for ; Sun, 1 Apr 2018 21:49:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 865A028C85 for ; Sun, 1 Apr 2018 21:49:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7924528CF1; Sun, 1 Apr 2018 21:49:46 +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.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_TVD_MIME_EPI 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 098D228C85 for ; Sun, 1 Apr 2018 21:49:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753976AbeDAVtp (ORCPT ); Sun, 1 Apr 2018 17:49:45 -0400 Received: from mail-pl0-f46.google.com ([209.85.160.46]:35921 "EHLO mail-pl0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753915AbeDAVto (ORCPT ); Sun, 1 Apr 2018 17:49:44 -0400 Received: by mail-pl0-f46.google.com with SMTP id 91-v6so3033118pld.3 for ; Sun, 01 Apr 2018 14:49:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=DqpJ/i84mg6AjK/5D+RqZ2WAflE95WpuJ4F0+DGUhbs=; b=LLLtzfDr4AH6iOQLYtRzsOfog9voALjivultgkRDjcSA8KbFtxBXGRW122zAsKrtUG hED/yYTPirbUnUqbzRer8h6dNNiF3d1QQjzJFPcU2G0tnSLsOGYhtWa7heKxqUNHt3MZ UmdnVBTLEvCaDvQ5t88C8rWJJ7DAex4e1rn2YBoY41UCD0QT1BhloSr8YQGIQOO4XlMH kmDPVOXPfhglW9IInejNDYYY2D6AaXPFlORqwZKwNVp/NffOlzP1e72nEjcvof7SwLKF g0T7NHcLzPusv549484sF3CRZUVX5HDZJa1eWgeAekpEPWZlPpQAtFstWcPsAe78DUgC 3XvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=DqpJ/i84mg6AjK/5D+RqZ2WAflE95WpuJ4F0+DGUhbs=; b=csIZc5szTVlEK2lzoO094p9XM3PIpSI/5l5ZmztyKQpNhVXe58p1CunochbiXH6NxG X+cPs2Gb1bAuH+zWYdZy4ZzirX1S7gN3jAS0hw/jMKZJL9x/shaQh6xWTBfpoAl3Kspf 5jxrRZ0lPqjOgEYpnTUww0qarVeJlMePPU5bu4fk0LbuQZBSm7xGF5RFY6NtDmfoBnxe jqp1uZdArhJJFjYPlEenkHJmeCTfBaq9uznDdY/lUQvlmJLAh2XIFA0ChhZyaHtCT2yH vxPvVr33DEx+7dFDOsKvdrMvbMJYfgXhZBGZ/ezrbMhk21f/1Ct1YdMmPu7MPyGEKCD7 ujhA== X-Gm-Message-State: AElRT7FT86YuWEC3+jmQDRhFdJh9dWU6dq5bM+nLDocX4TUlLLlWmeCd T1yhdl4qjlufz/xMzxynzr+LirHTB/MohXekv1zWqQ== X-Google-Smtp-Source: AIpwx4+Q9cKnc4AIfjp3tufmnAjYuMzBxqs4pCMKplPfHkRI43+JRujGRy9UsOgNiWjk+OQiu0xyH/Ss46kOkYIrits= X-Received: by 2002:a17:902:1006:: with SMTP id b6-v6mr7495698pla.252.1522619383846; Sun, 01 Apr 2018 14:49:43 -0700 (PDT) MIME-Version: 1.0 Received: by 10.100.152.97 with HTTP; Sun, 1 Apr 2018 14:49:23 -0700 (PDT) In-Reply-To: References: From: Steve French Date: Sun, 1 Apr 2018 16:49:23 -0500 Message-ID: Subject: Re: [SMB3][PATCH] Fake an inode number when server returns inode number zero for the root To: CIFS Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Slightly updated version (shorter by a couple lines) On Sat, Mar 31, 2018 at 6:17 PM, Steve French wrote: > Some servers return inode number zero for the root (ok for all other > inodes), if so > we need to create a non-zero hash instead for it and use that. > > > > -- > Thanks, > > Steve Reviewed-by: Pavel Shilovsky From 0bfedb011d647bb044826f878c711aee8ddb26b7 Mon Sep 17 00:00:00 2001 From: Steve French Date: Sat, 31 Mar 2018 18:13:38 -0500 Subject: [PATCH] Fix root directory when server returns inode number of zero Some servers return inode number zero for the root directory, which causes ls to display incorrect data (missing "." and ".."). If the server returns zero for the inode number of the root directory, fake an inode number for it. Signed-off-by: Steve French --- fs/cifs/cifsglob.h | 1 + fs/cifs/inode.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h index 3e3f86841372..2282562e78a1 100644 --- a/fs/cifs/cifsglob.h +++ b/fs/cifs/cifsglob.h @@ -1470,6 +1470,7 @@ struct dfs_info3_param { #define CIFS_FATTR_NEED_REVAL 0x4 #define CIFS_FATTR_INO_COLLISION 0x8 #define CIFS_FATTR_UNKNOWN_NLINK 0x10 +#define CIFS_FATTR_FAKE_ROOT_INO 0x20 struct cifs_fattr { u32 cf_flags; diff --git a/fs/cifs/inode.c b/fs/cifs/inode.c index c98a852180b1..6718158505ea 100644 --- a/fs/cifs/inode.c +++ b/fs/cifs/inode.c @@ -707,6 +707,18 @@ cifs_get_file_info(struct file *filp) return rc; } +/* Simple function to return a 64 bit hash of string. Rarely called */ +static __u64 simple_hashstr(const char *str) +{ + const __u64 hash_mult = 1125899906842597; /* a big enough prime */ + __u64 hash = 0; + + while (*str) + hash = (hash + (__u64) *str++) * hash_mult; + + return hash; +} + int cifs_get_inode_info(struct inode **inode, const char *full_path, FILE_ALL_INFO *data, struct super_block *sb, int xid, @@ -816,6 +828,14 @@ cifs_get_inode_info(struct inode **inode, const char *full_path, tmprc); fattr.cf_uniqueid = iunique(sb, ROOT_I); cifs_autodisable_serverino(cifs_sb); + } else if ((fattr.cf_uniqueid == 0) && + strlen(full_path) == 0) { + /* some servers ret bad root ino ie 0 */ + cifs_dbg(FYI, "Invalid (0) inodenum\n"); + fattr.cf_flags |= + CIFS_FATTR_FAKE_ROOT_INO; + fattr.cf_uniqueid = + simple_hashstr(tcon->treeName); } } } else @@ -832,6 +852,16 @@ cifs_get_inode_info(struct inode **inode, const char *full_path, &fattr.cf_uniqueid, data); if (tmprc) fattr.cf_uniqueid = CIFS_I(*inode)->uniqueid; + else if ((fattr.cf_uniqueid == 0) && + strlen(full_path) == 0) { + /* + * Reuse existing root inode num since + * inum zero for root causes ls of . and .. to + * not be returned + */ + cifs_dbg(FYI, "Srv ret 0 inode num for root\n"); + fattr.cf_uniqueid = CIFS_I(*inode)->uniqueid; + } } else fattr.cf_uniqueid = CIFS_I(*inode)->uniqueid; } @@ -893,6 +923,9 @@ cifs_get_inode_info(struct inode **inode, const char *full_path, } cgii_exit: + if ((*inode) && ((*inode)->i_ino == 0)) + cifs_dbg(FYI, "inode number of zero returned\n"); + kfree(buf); cifs_put_tlink(tlink); return rc; -- 2.14.1