Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp1642993lql; Wed, 13 Mar 2024 04:23:47 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUJX5uwrqYvTbiNcp63Rye6DFOtGVqWGK8DxEh7EyKXZaxWBRdm4ricoiFFJjCVJjsItNEaXYU6EuQLCMubZ7DLIAzZ6TP21uqg0VVR9w== X-Google-Smtp-Source: AGHT+IEag/9B15biO612qTBVuhlCY+UiH15E1rpNiR1OC6cKdUIY8cNbo0N40kC57C6o+yoepYoG X-Received: by 2002:a05:6830:11cb:b0:6e5:3748:d4fe with SMTP id v11-20020a05683011cb00b006e53748d4femr3130599otq.16.1710329027404; Wed, 13 Mar 2024 04:23:47 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710329027; cv=pass; d=google.com; s=arc-20160816; b=U9btwN7nty2GHbAi5YNMSH/hhOhOT6n+RbNRFpnwo0r8fndmb6hDgCh/2pcppVdDIC FMTTVVpwSPVFy6bHOR2XziKVRLoVjw3DU4ftwT903GN+U0gMGozxu/5UDXYhHeufZsjh QuZyFOedSPA9CyCRci4hAkZFplCwDDcds++AbfOx39sVmpbOvIF3iqGVo7dpXLCQwHMi ZtrGPQfiSzghNbFrqbr9Pq1IMCVBeemgiLEeFF7CKVi2EFMuQzCMz5VFInTaIfDHe7ef eOwWrBhEmn2Dgt1P/M6W56bqdx72OVE/kci7CqZYn8mlxtay0P/eZIhYElZ7yGfWRXyu 2Nmg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=yM2Z9vaSXa8HrhpKkEVTckQYcJBQU4Wl+RREtQMe3Ko=; fh=nIP8SQRmPmENrERmvbItxwJ1ZXcGbCSzfAoKPtB+zfU=; b=IBu6KvrtUpakkZ6zeC6tzPJlPdqxyCKqxkikpqO+Oy1TuLW1Jc2v0mmEzfH2CxPNM+ 97dEg3yVy7XG+4pEl4MEvxT881oQ6+Zf2i3SLzGUAUxIEt2kUQ/RyEIfiHCEAGUnF1aY pAZJVLq9NAGZpFS3+ZRKzMkvEQpURwCl35FqHW4ffNACqu5kw4jhbco5dLfacyB+PmLz OBglLwdm9xYHgu72mvr8xRzn0hg/ZNvcyu9+m4Z0evvu9d3l55hRLqkMB4PG5TojDfIg 0JBu19g7nltKnt6rTWOzCqU2m6/bklXTPUkZ/VjUnD9E8eZhR+wNtjXHrh465nsmOZz+ IHRg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=fail header.i=@igalia.com header.s=20170329 header.b=Wfa6A5Xw; arc=pass (i=1 spf=pass spfdomain=igalia.com dkim=pass dkdomain=igalia.com); spf=pass (google.com: domain of linux-kernel+bounces-101429-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-101429-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id w3-20020a63d743000000b005ce0474353csi8911048pgi.238.2024.03.13.04.23.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Mar 2024 04:23:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-101429-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=fail header.i=@igalia.com header.s=20170329 header.b=Wfa6A5Xw; arc=pass (i=1 spf=pass spfdomain=igalia.com dkim=pass dkdomain=igalia.com); spf=pass (google.com: domain of linux-kernel+bounces-101429-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-101429-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id AD924B23551 for ; Wed, 13 Mar 2024 11:17:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F232F3F9E1; Wed, 13 Mar 2024 11:17:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="Wfa6A5Xw" Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6CEF93F9C2; Wed, 13 Mar 2024 11:16:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710328623; cv=none; b=VTKKdDDkZDl9KDC3b5bMwYuAh94iD7QHeZvQGyqVrJe9bS7z4hNsxS4gU+/QrGwE4IylOp5OgU1BUCNYBReVND0FFDyeICDXdlKpRRH1jisb5G/hK7hvGI1Rs6Gvq9X4lHTxUsOGE2OwePUxPyu/oVUQ98wuou8hF4KsyiZAioo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710328623; c=relaxed/simple; bh=9xGC4SQpm4zfa3uEPVxx0x3Lkh/v6baabtSuFaG50Ic=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=dODJkE35v417k3S7mgrAbHtsX0jZ7beSRATm6crk664tLBCNXYgAj3W0pptMKHQlYiQaycZp8iNAe3PsJO5ulAt9XPh2ad4GBS8L7B+w3NFyF029PVbpHrWOwTDzPhGLTy+NQ2ehxSjHfF3uDuYKm8qEkWw5oOY00up23ug3Np4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=Wfa6A5Xw; arc=none smtp.client-ip=213.97.179.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=In-Reply-To:Content-Type:MIME-Version:References:Message-ID: Subject:Cc:To:From:Date:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=yM2Z9vaSXa8HrhpKkEVTckQYcJBQU4Wl+RREtQMe3Ko=; b=Wfa6A5XwQ7fgzY/3vhYdJfpudb PIc1E2SkpFaAIJV57oskRVfmokvr5A4VH4pHz9U7TepUqACgYemlFv33mX0oxBSINDE577R8dIWJE NqxRq1pMXopMJ9nKdg0t9qIsb97C6imowZQ7fcTt02/gUTZyu64tG0EU6YOzVFcvmS5mL3S2rQbOL z1tVjSyXUiaKxvJpDbIH+P69t5GFAHUD+6dWkQgYAyp9QyvAVXO1NZYAw0NMtUdx/C22cKkihrS4c 2XHyFugwirV5+eQe+b8xY83IzGuA27hef7lZ7RsggxFZFLRjIFW680jfu+8n94pc40xK5VW2Vqr0y CJlbO9lA==; Received: from 179-125-71-247-dinamico.pombonet.net.br ([179.125.71.247] helo=quatroqueijos.cascardo.eti.br) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1rkMbP-009v3c-HN; Wed, 13 Mar 2024 12:16:56 +0100 Date: Wed, 13 Mar 2024 08:16:50 -0300 From: Thadeu Lima de Souza Cascardo To: OGAWA Hirofumi Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Gwendal Grignou , dlunev@chromium.org Subject: Re: [PATCH] fat: ignore .. subdir and always add a link to dirs Message-ID: References: <87le75s1fg.fsf@mail.parknet.co.jp> <87h6hek50l.fsf@mail.parknet.co.jp> <87cys2jfop.fsf@mail.parknet.co.jp> <878r2mk14a.fsf@mail.parknet.co.jp> <874jdajsqm.fsf@mail.parknet.co.jp> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <874jdajsqm.fsf@mail.parknet.co.jp> On Wed, Mar 13, 2024 at 08:06:41PM +0900, OGAWA Hirofumi wrote: > Thadeu Lima de Souza Cascardo writes: > > >> So you break the mkdir/rmdir link counting, isn't it? > >> > > > > It is off by one on those images with directories without ".." subdir. > > Otherwise, everything else works fine. mkdir/rmdir inside such directories work > > without any issues as rmdir that same directory. > > mkdir() increase link count, rmdir decrease link count. Your change set > a dir link count always 2? So if there are 3 normal subdirs, and rmdir > all those normal dirs, link count underflow. > > Thanks. > No. The main change is as follows: int fat_subdirs(struct inode *dir) { [...] int count = 0; [...] - if (de->attr & ATTR_DIR) + if (de->attr & ATTR_DIR && + strncmp(de->name, MSDOS_DOTDOT, MSDOS_NAME)) count++; [...] return count; } int fat_fill_inode(struct inode *inode, struct msdos_dir_entry *de) { [...] if ((de->attr & ATTR_DIR) && !IS_FREE(de->name)) { [...] - set_nlink(inode, fat_subdirs(inode)); + set_nlink(inode, fat_subdirs(inode) + 1); [...] } That is, when first instatiating a directory inode, its link count was set to the number of subdirs it had, including "." and "..". Now it is set to 1 + the number of subdirs it has ignoring "..". mkdir and rmdir still increment and decrement the parent directory link count. Cascardo. > > If, on the other hand, we left everything as is and only skipped the > > validation, such directories would be created with a link count of 0. Then, > > doing a mkdir inside them would crash the kernel with a BUG as we cannot > > increment the link count of an inode with 0 links. > > > > So the idea of the fix here is that, independently of the existence of "..", > > the link count will always be at least 1. > > -- > OGAWA Hirofumi