From patchwork Tue Sep 16 05:51:10 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve French X-Patchwork-Id: 4914981 Return-Path: X-Original-To: patchwork-cifs-client@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 8282FBEEA5 for ; Tue, 16 Sep 2014 05:51:36 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DBAC1201DE for ; Tue, 16 Sep 2014 05:51:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 052B420166 for ; Tue, 16 Sep 2014 05:51:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752046AbaIPFvb (ORCPT ); Tue, 16 Sep 2014 01:51:31 -0400 Received: from mail-qg0-f42.google.com ([209.85.192.42]:51985 "EHLO mail-qg0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751897AbaIPFvb (ORCPT ); Tue, 16 Sep 2014 01:51:31 -0400 Received: by mail-qg0-f42.google.com with SMTP id q107so5222544qgd.1 for ; Mon, 15 Sep 2014 22:51:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=BGwuoUt2jq7fzlpRlxGyaAL0mi7kD6siK2oVNtfENVQ=; b=Jh9KW891hMbyqTS51Qv/joE5O6hLhHtu0nSgNZdmrcnesEfspfjSpvJTKqzUmEOvHT tCzplBhT47LS/636g3i/CYhuNteDo1npQyhwsll8D+hN5ZFrV2xseoOVyFWSG5tz6jud 7BtmXOgEZ21GiR6+aMKLhvcG7GJuuSal4BaUUced4QeTB0bNXnbI4yiVTkdiYtYjieM/ vCAuiJW5gSEC5QbQGOTUYpJ3fjSkJZ+bwBRLlTIXmWXAD6OeKSi2vhw3XyPcUmMYD71A UnC3MmoDHHuZpa0qjy5sLxpi8pKZ+aIey8VoWWXFQhG5RfzR94AJQpG0B7fp+cGNJpSm N0QA== X-Received: by 10.224.103.65 with SMTP id j1mr43999653qao.17.1410846690523; Mon, 15 Sep 2014 22:51:30 -0700 (PDT) MIME-Version: 1.0 Received: by 10.140.32.116 with HTTP; Mon, 15 Sep 2014 22:51:10 -0700 (PDT) In-Reply-To: <20140915171405.GA21353@infradead.org> References: <20140915171405.GA21353@infradead.org> From: Steve French Date: Tue, 16 Sep 2014 00:51:10 -0500 Message-ID: Subject: Re: [PATCH][v2][CIFS] Fix setting time before epoch (negative time values) To: Christoph Hellwig Cc: "linux-cifs@vger.kernel.org" , samba-technical Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, T_TVD_MIME_EPI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Resending as attachment to avoid mailer issues On Mon, Sep 15, 2014 at 12:14 PM, Christoph Hellwig wrote: >> /* Subtract the NTFS time offset, then convert to 1s intervals. */ >> - u64 t; >> + s64 t = le64_to_cpu(ntutc) - NTFS_TIME_OFFSET; >> + >> + /* > > The patch looks whitespace damaged. > From 2ae83bf93882d1ec0cd775c489bd1bee611f792e Mon Sep 17 00:00:00 2001 From: Steve French Date: Sun, 14 Sep 2014 17:06:36 -0500 Subject: [PATCH 1/4] [CIFS] Fix setting time before epoch (negative time values) xfstest generic/258 sets the time on a file to a negative value (before 1970) which fails since do_div can not handle negative numbers. In addition 'normal' division of 64 bit values does not build on 32 bit arch so have to workaround this by special casing negative values in cifs_NTtimeToUnix Samba server also has a bug with this (see samba bugzilla 7771) but it works to Windows server. Signed-off-by: Steve French --- fs/cifs/netmisc.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/fs/cifs/netmisc.c b/fs/cifs/netmisc.c index 6834b9c..b333ff6 100644 --- a/fs/cifs/netmisc.c +++ b/fs/cifs/netmisc.c @@ -925,11 +925,23 @@ cifs_NTtimeToUnix(__le64 ntutc) /* BB what about the timezone? BB */ /* Subtract the NTFS time offset, then convert to 1s intervals. */ - u64 t; + s64 t = le64_to_cpu(ntutc) - NTFS_TIME_OFFSET; + + /* + * Unfortunately can not use normal 64 bit division on 32 bit arch, but + * the alternative, do_div, does not work with negative numbers so have + * to special case them + */ + if (t < 0) { + t = -t; + ts.tv_nsec = (long)(do_div(t, 10000000) * 100); + ts.tv_nsec = -ts.tv_nsec; + ts.tv_sec = -t; + } else { + ts.tv_nsec = (long)do_div(t, 10000000) * 100; + ts.tv_sec = t; + } - t = le64_to_cpu(ntutc) - NTFS_TIME_OFFSET; - ts.tv_nsec = do_div(t, 10000000) * 100; - ts.tv_sec = t; return ts; } -- 1.9.1