Message ID | 20240222203013.2649457-1-cascardo@igalia.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-77319-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp193603dyb; Thu, 22 Feb 2024 12:31:00 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWy6wME28PxbAIstcn6vA9Tv84i4JBCpMwXZ/Sucw7cybepnatw8ipDAIaBqjOTEDnVpmMeVr32D0hcXJwMdm/wk/OkvA== X-Google-Smtp-Source: AGHT+IGfewER4XyA6Ge3Ry5Vrx/Hb2/kaNWHD09Vab0G/ooZ6UAhAHM8I2Qtvhk9TsdqhQ/Yp4oU X-Received: by 2002:a1f:e043:0:b0:4c9:98f8:83ce with SMTP id x64-20020a1fe043000000b004c998f883cemr125854vkg.6.1708633860417; Thu, 22 Feb 2024 12:31:00 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708633860; cv=pass; d=google.com; s=arc-20160816; b=0ZKsMNvndvbW+N1CaNWtTcsKNaDdT1sS8icLVLbtC8Up94EmEqoOji1RYOamTBFgin KwSQlFUnYlXpUqC6kxz4x2wqENdezr//CxOWSN2reCjQAipfh32X0nWSitHZARHMWiNu FrQZrtt1QbqaGasvb9V0bjkCL3Y+fh5YQNG+oi2WSPsIaR2p5vd4mOL5a8Igw7ynF5Qk OSdGCofXDkOfWTl/IhEZWkp87CpzlLjWlgqc0qBAMYbnNd3m1ynfvYw8NB+LmADqf+7L XVziQ0junclMVdd10LeKjoMKW5Fv5P3kS8kM7oIs6nd1SMCStFVqNEn2NWher8kI5ygB ZvFg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=uDD88zaVrMvSV7jyXIjccldv2PnZ3aOybLZ9ITuOEPM=; fh=M1BFU8D0M2wMFJadttQKyYzLyw/x/ilOfFHLuf+olwQ=; b=tYgFHDrDCHsxBEeQZC1YuvQ8NUDkvL3P/5vUmjylKXDc7p89dFwhGt7Deh7bltY8TZ Jl+8n3oKzdA62sb76rCL6gWA+UcJr6UByscRe2wMsqMcyvOQNFALftBX9pqlVSudHRjw CXpmnZqYMmcP2DZycWUd54GF1WU1U1z7+KZq7zEi1eSyWe/WTXJz3UkchMutZ9msJacB XNM52599ii3/X20+7KxJJMRoRGhFFGPiZYezFeCQZTJW0dVVzuPmRM3+NmbgFTQH7n/a 2/yceJ1K6bgqZKr1m1CLgnrT+wkvzUO+dSmW4aA5sUdpM9kx0fmtzTLTNfZ6iFCg1O5p EbGg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=fail header.i=@igalia.com header.s=20170329 header.b=JGZc1gqk; arc=pass (i=1 spf=pass spfdomain=igalia.com dkim=pass dkdomain=igalia.com); spf=pass (google.com: domain of linux-kernel+bounces-77319-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-77319-ouuuleilei=gmail.com@vger.kernel.org" Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id n187-20020a1fd6c4000000b004c01a32f9e0si2259980vkg.22.2024.02.22.12.31.00 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 12:31:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-77319-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=fail header.i=@igalia.com header.s=20170329 header.b=JGZc1gqk; arc=pass (i=1 spf=pass spfdomain=igalia.com dkim=pass dkdomain=igalia.com); spf=pass (google.com: domain of linux-kernel+bounces-77319-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-77319-ouuuleilei=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 ny.mirrors.kernel.org (Postfix) with ESMTPS id EB0B31C20DC4 for <ouuuleilei@gmail.com>; Thu, 22 Feb 2024 20:30:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B567E7175F; Thu, 22 Feb 2024 20:30:46 +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="JGZc1gqk" 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 F325C29CEA; Thu, 22 Feb 2024 20:30:28 +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=1708633843; cv=none; b=XTV5ZlyFKumEBfyILuZbHIPMMMc51vcPETUmQzOd3Waz9Qks+x4Q8MUsnDVuUbUL/LaQSJV/DLRVt0YaF4qeJfr8tz8yw/wPhbrzL9kXm4ZsimAIkOBe/NLRLiZ9ZaAW5qQOJwGGDknNV7n2fFHw+0+HPBLSLEok1XZ6mK8TG2I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708633843; c=relaxed/simple; bh=PGw/6elJRjzjT5oami1yJD74wKwg8urvYRLz170UPWU=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=a0gMP9lMZvuMcpFVCY6yzKw8SuTGC80XtmjIlCuWbBs7LzpMGoAtdxoI5gwFy5tRTNBAfFC/rTRtGnrgHFNwUOOrrvAGklvO0J96m5z4slSmOujeA7rlWktXYdEBLAFfErSUoPcdbyUwRlPiqCqnU/+vYr5Wjen8sEZe3dH8YEE= 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=JGZc1gqk; 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=Content-Transfer-Encoding:MIME-Version:Message-Id:Date:Subject: Cc:To:From:Sender:Reply-To:Content-Type:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=uDD88zaVrMvSV7jyXIjccldv2PnZ3aOybLZ9ITuOEPM=; b=JGZc1gqkZdMeL5Y4Bsdn/FPyaq DFOTfRXZTGmrEQmBgQ5yBj0Dbf9dCT8o6LG1NZ7WjVclxxUFMHtPouewiUtOBODiJaaefLnY6LK74 wVx+P36s6ULKZM2OqnQX2+63eY3fP4Sda0nDOHVqFGm6/hTL2xwheMFdsp9jSvVN3jeqtddSS9kdS wdG7m+AgLId0wB3PGptDb5agHuynLsV9VSrPbxGJIp9pvk7TCbjMGCzM4zx4z6rfRAla3N6mFFSn3 OSSUPSWcdYyrEPhPB8qnL+l75+Sbcc26ihMXCNfye6Uyh3b391GsEFcx9TNbnV8zAQL5/a+U1wovK zRamh19Q==; Received: from 179-125-75-196-dinamico.pombonet.net.br ([179.125.75.196] helo=quatroqueijos.lan) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1rdFi4-002SRK-9F; Thu, 22 Feb 2024 21:30:24 +0100 From: Thadeu Lima de Souza Cascardo <cascardo@igalia.com> To: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp> Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Gwendal Grignou <gwendal@chromium.org>, dlunev@chromium.org, Thadeu Lima de Souza Cascardo <cascardo@igalia.com> Subject: [PATCH] fat: ignore .. subdir and always add a link to dirs Date: Thu, 22 Feb 2024 17:30:13 -0300 Message-Id: <20240222203013.2649457-1-cascardo@igalia.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791632458876537937 X-GMAIL-MSGID: 1791632458876537937 |
Series |
fat: ignore .. subdir and always add a link to dirs
|
|
Commit Message
Thadeu Lima de Souza Cascardo
Feb. 22, 2024, 8:30 p.m. UTC
The tools used for creating images for the Lego Mindstrom EV3 are not
adding '.' and '..' entry in the 'Projects' directory.
Without this fix, the kernel can not fill the inode structure for
'Projects' directory.
See https://github.com/microsoft/pxt-ev3/issues/980
And https://github.com/microsoft/uf2-linux/issues/6
When counting the number of subdirs, ignore .. subdir and add one when
setting the initial link count for directories. This way, when .. is
present, it is still accounted for, and when neither . or .. are present, a
single link is still done, as it should, since this link would be the one
from the parent directory.
With this fix applied, we can mount an image with such empty directories,
access them, create subdirectories and remove them.
Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@igalia.com>
Cc: Gwendal Grignou <gwendal@chromium.org>
Link: https://lore.kernel.org/all/20220204062232.3410036-1-gwendal@chromium.org/
Cc: dlunev@chromium.org
---
fs/fat/dir.c | 3 ++-
fs/fat/inode.c | 12 +++++++++---
2 files changed, 11 insertions(+), 4 deletions(-)
Comments
Thadeu Lima de Souza Cascardo <cascardo@igalia.com> writes: > The tools used for creating images for the Lego Mindstrom EV3 are not > adding '.' and '..' entry in the 'Projects' directory. > > Without this fix, the kernel can not fill the inode structure for > 'Projects' directory. > > See https://github.com/microsoft/pxt-ev3/issues/980 > And https://github.com/microsoft/uf2-linux/issues/6 > > When counting the number of subdirs, ignore .. subdir and add one when > setting the initial link count for directories. This way, when .. is > present, it is still accounted for, and when neither . or .. are present, a > single link is still done, as it should, since this link would be the one > from the parent directory. > > With this fix applied, we can mount an image with such empty directories, > access them, create subdirectories and remove them. This looks like the bug of those tools, isn't it? Thanks.
On Fri, Feb 23, 2024 at 10:52:12AM +0900, OGAWA Hirofumi wrote: > Thadeu Lima de Souza Cascardo <cascardo@igalia.com> writes: > > > The tools used for creating images for the Lego Mindstrom EV3 are not > > adding '.' and '..' entry in the 'Projects' directory. > > > > Without this fix, the kernel can not fill the inode structure for > > 'Projects' directory. > > > > See https://github.com/microsoft/pxt-ev3/issues/980 > > And https://github.com/microsoft/uf2-linux/issues/6 > > > > When counting the number of subdirs, ignore .. subdir and add one when > > setting the initial link count for directories. This way, when .. is > > present, it is still accounted for, and when neither . or .. are present, a > > single link is still done, as it should, since this link would be the one > > from the parent directory. > > > > With this fix applied, we can mount an image with such empty directories, > > access them, create subdirectories and remove them. > > This looks like the bug of those tools, isn't it? > > Thanks. > -- > OGAWA Hirofumi <hirofumi@mail.parknet.co.jp> Which they refused to fix, arguing that there are already filesystems out there in the world like that. Also, there is argument that this works on Windows, though I haven't been able to test this. https://github.com/microsoft/pxt-ev3/issues/980 https://github.com/microsoft/uf2-linux/issues/6 Thanks. Cascardo.
Thadeu Lima de Souza Cascardo <cascardo@igalia.com> writes: > On Fri, Feb 23, 2024 at 10:52:12AM +0900, OGAWA Hirofumi wrote: >> Thadeu Lima de Souza Cascardo <cascardo@igalia.com> writes: >> >> > The tools used for creating images for the Lego Mindstrom EV3 are not >> > adding '.' and '..' entry in the 'Projects' directory. >> > >> > Without this fix, the kernel can not fill the inode structure for >> > 'Projects' directory. >> > >> > See https://github.com/microsoft/pxt-ev3/issues/980 >> > And https://github.com/microsoft/uf2-linux/issues/6 >> > >> > When counting the number of subdirs, ignore .. subdir and add one when >> > setting the initial link count for directories. This way, when .. is >> > present, it is still accounted for, and when neither . or .. are present, a >> > single link is still done, as it should, since this link would be the one >> > from the parent directory. >> > >> > With this fix applied, we can mount an image with such empty directories, >> > access them, create subdirectories and remove them. >> >> This looks like the bug of those tools, isn't it? >> >> Thanks. >> -- >> OGAWA Hirofumi <hirofumi@mail.parknet.co.jp> > > Which they refused to fix, arguing that there are already filesystems out there > in the world like that. Also, there is argument that this works on Windows, > though I haven't been able to test this. > > https://github.com/microsoft/pxt-ev3/issues/980 > https://github.com/microsoft/uf2-linux/issues/6 OK. If you want to add the workaround for this, it must emulate the correct format. I.e. sane link count even if without "."/"..". And furthermore it works for any operations. Thanks.
OGAWA Hirofumi <hirofumi@mail.parknet.co.jp> writes: > OK. > > If you want to add the workaround for this, it must emulate the correct > format. I.e. sane link count even if without "."/"..". And furthermore > it works for any operations. Of course, it must not affect the correct format. And it should not accept the other really corrupted format.
On Fri, Feb 23, 2024 at 05:32:47PM +0900, OGAWA Hirofumi wrote: > OGAWA Hirofumi <hirofumi@mail.parknet.co.jp> writes: > > > OK. > > > > If you want to add the workaround for this, it must emulate the correct > > format. I.e. sane link count even if without "."/"..". And furthermore > > it works for any operations. > > Of course, it must not affect the correct format. And it should not > accept the other really corrupted format. > -- > OGAWA Hirofumi <hirofumi@mail.parknet.co.jp> So far, I have only seen expected correct behavior here: mkdir/rmdir inside the "bogus" directory works. rmdir of the "bogus" directory works. The only idiosyncrasies I can think of is that if neither "." or ".." are present, the directory will have a link of 1, instead of 2. And when listing the directory, those entries will not show up. Do you expect any of these to be corrected? It will require a more convoluted change. Right now, I think accepting the idiosyncratic behavior for the bogus filesystems is fine, as long as the correct filesystems continue to behave as before. Which seems to be the case here as far as my testing has shown. Thank you. Cascardo.
Thadeu Lima de Souza Cascardo <cascardo@igalia.com> writes: > So far, I have only seen expected correct behavior here: mkdir/rmdir inside the > "bogus" directory works. rmdir of the "bogus" directory works. > > The only idiosyncrasies I can think of is that if neither "." or ".." are > present, the directory will have a link of 1, instead of 2. And when listing > the directory, those entries will not show up. > > Do you expect any of these to be corrected? It will require a more convoluted > change. > > Right now, I think accepting the idiosyncratic behavior for the bogus > filesystems is fine, as long as the correct filesystems continue to behave as > before. Which seems to be the case here as far as my testing has shown. There are many corrupted images, and attacks. Allowing too wide is danger for fs. BTW, this image works and pass fsck on windows? When I quickly tested ev3fs.zip (https://github.com/microsoft/pxt-ev3/issues/980) on windows on qemu, it didn't seem recognized as FAT. I can wrongly tested though. Thanks.
On Fri, Feb 23, 2024 at 09:29:35PM +0900, OGAWA Hirofumi wrote: > Thadeu Lima de Souza Cascardo <cascardo@igalia.com> writes: > > > So far, I have only seen expected correct behavior here: mkdir/rmdir inside the > > "bogus" directory works. rmdir of the "bogus" directory works. > > > > The only idiosyncrasies I can think of is that if neither "." or ".." are > > present, the directory will have a link of 1, instead of 2. And when listing > > the directory, those entries will not show up. > > > > Do you expect any of these to be corrected? It will require a more convoluted > > change. > > > > Right now, I think accepting the idiosyncratic behavior for the bogus > > filesystems is fine, as long as the correct filesystems continue to behave as > > before. Which seems to be the case here as far as my testing has shown. > > There are many corrupted images, and attacks. Allowing too wide is > danger for fs. > > BTW, this image works and pass fsck on windows? When I quickly tested > ev3fs.zip (https://github.com/microsoft/pxt-ev3/issues/980) on windows > on qemu, it didn't seem recognized as FAT. I can wrongly tested though. > > Thanks. > -- > OGAWA Hirofumi <hirofumi@mail.parknet.co.jp> That image was further corrupted by mounting it on linux, as is mentioned in one of the github issues. Let me see if I can arrange the Windows testing of images I was able to test with. I can later attach them too, as they should compress very well. Cascardo.
On Fri, Feb 23, 2024 at 09:29:35PM +0900, OGAWA Hirofumi wrote: > Thadeu Lima de Souza Cascardo <cascardo@igalia.com> writes: > > > So far, I have only seen expected correct behavior here: mkdir/rmdir inside the > > "bogus" directory works. rmdir of the "bogus" directory works. > > > > The only idiosyncrasies I can think of is that if neither "." or ".." are > > present, the directory will have a link of 1, instead of 2. And when listing > > the directory, those entries will not show up. > > > > Do you expect any of these to be corrected? It will require a more convoluted > > change. > > > > Right now, I think accepting the idiosyncratic behavior for the bogus > > filesystems is fine, as long as the correct filesystems continue to behave as > > before. Which seems to be the case here as far as my testing has shown. > > There are many corrupted images, and attacks. Allowing too wide is > danger for fs. > > BTW, this image works and pass fsck on windows? When I quickly tested > ev3fs.zip (https://github.com/microsoft/pxt-ev3/issues/980) on windows > on qemu, it didn't seem recognized as FAT. I can wrongly tested though. > > Thanks. > -- > OGAWA Hirofumi <hirofumi@mail.parknet.co.jp> Testing on FreeDOS, it is able to access the directory and create subdirectories there. "." and ".." are missing when using "DIR" command. And dosfsck complains about the missing "." and ".." but states it is not able to fix those yet. But accessing the directory works nonetheless. Cascardo.
On Fri, Feb 23, 2024 at 09:29:35PM +0900, OGAWA Hirofumi wrote: > Thadeu Lima de Souza Cascardo <cascardo@igalia.com> writes: > > > So far, I have only seen expected correct behavior here: mkdir/rmdir inside the > > "bogus" directory works. rmdir of the "bogus" directory works. > > > > The only idiosyncrasies I can think of is that if neither "." or ".." are > > present, the directory will have a link of 1, instead of 2. And when listing > > the directory, those entries will not show up. > > > > Do you expect any of these to be corrected? It will require a more convoluted > > change. > > > > Right now, I think accepting the idiosyncratic behavior for the bogus > > filesystems is fine, as long as the correct filesystems continue to behave as > > before. Which seems to be the case here as far as my testing has shown. > > There are many corrupted images, and attacks. Allowing too wide is > danger for fs. > > BTW, this image works and pass fsck on windows? When I quickly tested > ev3fs.zip (https://github.com/microsoft/pxt-ev3/issues/980) on windows > on qemu, it didn't seem recognized as FAT. I can wrongly tested though. > > Thanks. > -- > OGAWA Hirofumi <hirofumi@mail.parknet.co.jp> The test image I managed to create mounts just fine on Windows. New subdirectories can be created there just as well. Regards. Cascardo.
Thadeu Lima de Souza Cascardo <cascardo@igalia.com> writes: >> There are many corrupted images, and attacks. Allowing too wide is >> danger for fs. >> >> BTW, this image works and pass fsck on windows? When I quickly tested >> ev3fs.zip (https://github.com/microsoft/pxt-ev3/issues/980) on windows >> on qemu, it didn't seem recognized as FAT. I can wrongly tested though. >> >> Thanks. >> -- >> OGAWA Hirofumi <hirofumi@mail.parknet.co.jp> > > The test image I managed to create mounts just fine on Windows. New > subdirectories can be created there just as well. Can you share the image somehow? And fsck (chkdsk, etc.) works without any complain? Thanks.
On Wed, Feb 28, 2024 at 12:38:43PM +0900, OGAWA Hirofumi wrote: > Thadeu Lima de Souza Cascardo <cascardo@igalia.com> writes: > > >> There are many corrupted images, and attacks. Allowing too wide is > >> danger for fs. > >> > >> BTW, this image works and pass fsck on windows? When I quickly tested > >> ev3fs.zip (https://github.com/microsoft/pxt-ev3/issues/980) on windows > >> on qemu, it didn't seem recognized as FAT. I can wrongly tested though. > >> > >> Thanks. > >> -- > >> OGAWA Hirofumi <hirofumi@mail.parknet.co.jp> > > > > The test image I managed to create mounts just fine on Windows. New > > subdirectories can be created there just as well. > > Can you share the image somehow? And fsck (chkdsk, etc.) works without > any complain? > > Thanks. > -- > OGAWA Hirofumi <hirofumi@mail.parknet.co.jp> Checking the filesystem on Windows runs without any complains, but it turns the directory into an useless lump of data. Without checking the filesystem, creating and reading files from that directory works just fine. I tried to use gzip or xz to compress the very sparse filesystem image that I got, but they made it larger on disk than it really was. So here is a script and pieces of the filesystem that will create a sparse 8GB image. Thank you for looking into this. Cascardo.
diff --git a/fs/fat/dir.c b/fs/fat/dir.c index 00235b8a1823..fcdb652efc53 100644 --- a/fs/fat/dir.c +++ b/fs/fat/dir.c @@ -937,7 +937,8 @@ int fat_subdirs(struct inode *dir) bh = NULL; cpos = 0; while (fat_get_short_entry(dir, &cpos, &bh, &de) >= 0) { - if (de->attr & ATTR_DIR) + if (de->attr & ATTR_DIR && + strncmp(de->name, MSDOS_DOTDOT, MSDOS_NAME)) count++; } brelse(bh); diff --git a/fs/fat/inode.c b/fs/fat/inode.c index 1fac3dabf130..9a3bd38a4494 100644 --- a/fs/fat/inode.c +++ b/fs/fat/inode.c @@ -494,8 +494,14 @@ static int fat_validate_dir(struct inode *dir) { struct super_block *sb = dir->i_sb; - if (dir->i_nlink < 2) { - /* Directory should have "."/".." entries at least. */ + if (dir->i_nlink < 1) { + /* + * Though it is expected that directories have at least + * "."/".." entries, there are filesystems in the field that + * don't have either. Even in those cases, at least one link + * is necessary, as otherwise, when trying to increment it, + * VFS would BUG. + */ fat_fs_error(sb, "corrupted directory (invalid entries)"); return -EIO; } @@ -534,7 +540,7 @@ int fat_fill_inode(struct inode *inode, struct msdos_dir_entry *de) return error; MSDOS_I(inode)->mmu_private = inode->i_size; - set_nlink(inode, fat_subdirs(inode)); + set_nlink(inode, fat_subdirs(inode) + 1); error = fat_validate_dir(inode); if (error < 0)