Received: by 2002:a89:413:0:b0:1fd:dba5:e537 with SMTP id m19csp410984lqs; Thu, 13 Jun 2024 13:48:28 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV5x3+VNgrfHWUglFSaFY/UhAvpEdWdybg7wfNUFf+wJVSI+TbqGM3pyRoqpzgCWG2gZw5FnzQy3bNcNSnwmFijbBRw2E/qQeW5Pyndow== X-Google-Smtp-Source: AGHT+IFZvScfyYotU65KQrcs5QsPKP+H+cGwAflEaFLoL5B6f7gUTTzb24bBJntgV+z9TqC5HSy7 X-Received: by 2002:a17:90a:e68b:b0:2c2:dee2:ed41 with SMTP id 98e67ed59e1d1-2c4db242582mr921883a91.19.1718311708253; Thu, 13 Jun 2024 13:48:28 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718311708; cv=pass; d=google.com; s=arc-20160816; b=aRwywAKL8Fk/TLc+B1Ga99HhFyaC5D2czQ9uGZcBzdHylepOhTKsMXVlTew52RnQwN Fi14XmHFUNL3W/59fFLxn9ssNp1yZzxIPoj17cbbc8Jnwa1uxskUnVPMhg1vrywTL4HT 1T4qOSy9cNp8a6jfxP/X24i0hnHxUKfsfxAz9p5BIcSQSZZgS46o9H5HXIOmLOrZOBCC j22VNyOfuWt9PGIQPKcgj5081S3I7Fp4LlmDORpV+hR+OFZA2fpISK3cI36+2OvK1zyj p3b8X5AXs1tr4sfQ/AjsSGD55SGkCXMNktuqHiHZaK9vzjO/Phz0qXuN/KGij52FVcut k0EQ== 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=z8gz6DxLT5yhvPl6EJHfnDjIivJ1OPPCYGvBRj7cC5A=; fh=aqJxh9QDxoBTQY2Fp/2IEB9knvP5ukX49d42kLnIG10=; b=ba2UBNVzmRw0Re95Ykv4nhlFcgL3iMHsMSRtrKqFAbvRUPIh4aePYhxCUxazWXpwmV PKfUtCjXcLzmlvOnZiBxyXVpfWWA4LsBBnrLDGeaBcBfOIiUOkbpZlkVYJUs2WcetUgS UsBbg6Ju5BWhZ+B0yGZcs5EbGqJ4NGvC48FDG/zwXs3FYkJm39vQnnQ+0hZvey5tQ+4t 88aCzMAbUvn/gL6tL4PXesXtx8jwQlQqXynycOBHvuziGypEo1aSnmceh+K7r4Ep+EUA ve9UztWo2NqIUzLYp4qpQPxj5np+8Zm058mVdkSCVKfMVkVyoRh16lDXAsLifcCL80bS iWhg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=f7zv0nTn; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-213994-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-213994-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id 98e67ed59e1d1-2c4c4705caasi2149762a91.118.2024.06.13.13.48.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 13:48:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-213994-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=pass header.i=@gmail.com header.s=20230601 header.b=f7zv0nTn; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-213994-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-213994-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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 5662EB20C20 for ; Thu, 13 Jun 2024 20:27:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 13B3713A24B; Thu, 13 Jun 2024 20:27:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="f7zv0nTn" Received: from mail-oo1-f50.google.com (mail-oo1-f50.google.com [209.85.161.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D87A1137902 for ; Thu, 13 Jun 2024 20:26:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718310419; cv=none; b=lYyYPaicirTLUS3Jh7b9d4/oGPESP5+Sjcadf+/xKEXE4dvTflVX9MHWFO+JXIfj5TNsXx0+ajTmxfTQX7dJhg/z7VwpI9jLLKc0M19us2KgGDlfy4q9ftyIx1mFPCE7PPhzXQZyGWoAMaxZik+GBR6a6BeTpFWG88w2mmURxiU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718310419; c=relaxed/simple; bh=467aTyVqOm1A+Q0r7xGR8nUtJ7JjD0p8ner9YV8wIis=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=VBKsoKs7+5DpSxtr54FuLipiil1D1RwJSXFDghL7yGyZdqg11bx7Uodc59y7l2AReULYl871ZzUhAZwI8xLZ54oCdQ756vFttBiddarDFyAHz5KK0eqfQV6gpEbeH7c3RcXgtJp0f9EwH1C8BB7l9nB2Dr0gzuazkGK57QoKG5A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=f7zv0nTn; arc=none smtp.client-ip=209.85.161.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-oo1-f50.google.com with SMTP id 006d021491bc7-5b9a5be6668so790579eaf.1 for ; Thu, 13 Jun 2024 13:26:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718310417; x=1718915217; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=z8gz6DxLT5yhvPl6EJHfnDjIivJ1OPPCYGvBRj7cC5A=; b=f7zv0nTnuY+pfCTYtV5BE406UhKn5lAUSnkZcucgfmxpqyRH2Fk01pdbbC3qvhJrdO 5j729+Yt+LTg7Lw4yB2VjJQXig945H+qPIl2NNn/4m9N//nQXLnenIEB+CxJAoNOoiPb qHmKOR5ldUePV86CRwsGagBgakujW3A/vECebyet6BoX67I3wkO+9jp5i5FX/OIm5saH aANOhTugrVZ1SgMLaXlKxA5SJJM+IZKMMadihUd+hVI4VUm2HcN4H8CR9wkMOY/Q5bN+ vsEtVzv/IPsMALQAWL8R7DckQeFN3rn2jcuaMcCloDt5xIn4zGyVNIsSBWQTI3KbWq8d lV/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718310417; x=1718915217; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=z8gz6DxLT5yhvPl6EJHfnDjIivJ1OPPCYGvBRj7cC5A=; b=GpCfC5ePLNKwXQLmrKE/OIfsMq2CYo1KTN3zsP7+wh5dZO2YhhCeM9lCGPvieFzA3x 4y5mh+4JSQzhjypjjaARItXHThetktiA1kW0zpIhS0IkD84U3UGsEVL1BDhg7SSL4dij nx6Vt3J+1YzLveq21K1wkLxj7Hlm2BkmwQJWttxxv+xejlhVnLOdXSz8kUpFcsF2Tc2+ SuKh0uxgjYiejHDW7UNaSfoIY2oZU5fgiXTh5QiyPg9e4Qpu2RXgpM1ALR5MKWYT4OyV LuaIZL05wIkzEbCDVh/7idtKoK9YDqutB1Y3sM6fenIZ7kwREQWwYIpVYL5IcjVNP+qZ w5Gg== X-Forwarded-Encrypted: i=1; AJvYcCWTSlv6oeOVturOKbacF/GYwO+zp+IBnkP8/pt6Abv3SUZ9uhLziAk417pPJLjdQ2Bd4VvNrl1ZC1UhGyyjG8w+8adk/lIR9ap0VQCI X-Gm-Message-State: AOJu0YylvNIErBfLQqa/DFO3mm6nzTaFpaB+wD983YcuuXebH6f9WaZJ WA5sA2o7I4D5ZdyaWkNMC4lDzHzxpRplA0AlKLgE26UL+4wrmj/n7C2YpouI X-Received: by 2002:a05:6359:4c82:b0:19f:5612:cf4c with SMTP id e5c5f4694b2df-19fa9dcfac7mr104211455d.1.1718310416798; Thu, 13 Jun 2024 13:26:56 -0700 (PDT) Received: from dev0.. ([49.43.162.104]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-6fedf49d7b1sm1496677a12.51.2024.06.13.13.26.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 13:26:56 -0700 (PDT) From: Abhinav Jain To: dushistov@mail.ru, linux-kernel@vger.kernel.org Cc: skhan@linuxfoundation.org, javier.carrasco.cruz@gmail.com, jain.abhinav177@gmail.com Subject: [PATCH] ufs: Add table lookup to set d_type based on mode & S_IFMT Date: Thu, 13 Jun 2024 20:26:50 +0000 Message-Id: <20240613202650.39739-1-jain.abhinav177@gmail.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Add usf_de_type_mapping structure to map file mode masks to dir entries. Add a static ufs_type_table array to map file mode to dir entries. Remove switch and add a table based lookup for the mapping. Add ARRAY_SIZE macro on ufs_type_table to eliminate checkpatch warning. Signed-off-by: Abhinav Jain --- fs/ufs/util.h | 57 +++++++++++++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/fs/ufs/util.h b/fs/ufs/util.h index 0ecd2ed792f5..8a941d69270a 100644 --- a/fs/ufs/util.h +++ b/fs/ufs/util.h @@ -9,7 +9,28 @@ #include #include +#include #include "swab.h" +#include "ufs_fs.h" + +#ifndef ARRAY_SIZE +#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) +#endif + +struct ufs_de_type_mapping { + umode_t mode_mask; + unsigned char d_type; +}; + +static const struct ufs_de_type_mapping ufs_type_table[] = { + { S_IFSOCK, DT_SOCK }, + { S_IFLNK, DT_LNK }, + { S_IFREG, DT_REG }, + { S_IFBLK, DT_BLK }, + { S_IFDIR, DT_DIR }, + { S_IFCHR, DT_CHR }, + { S_IFIFO, DT_FIFO }, +}; /* * functions used for retyping @@ -153,32 +174,18 @@ ufs_set_de_type(struct super_block *sb, struct ufs_dir_entry *de, int mode) return; /* - * TODO turn this into a table lookup + * Table lookup to set d_type based on mode & S_IFMT */ - switch (mode & S_IFMT) { - case S_IFSOCK: - de->d_u.d_44.d_type = DT_SOCK; - break; - case S_IFLNK: - de->d_u.d_44.d_type = DT_LNK; - break; - case S_IFREG: - de->d_u.d_44.d_type = DT_REG; - break; - case S_IFBLK: - de->d_u.d_44.d_type = DT_BLK; - break; - case S_IFDIR: - de->d_u.d_44.d_type = DT_DIR; - break; - case S_IFCHR: - de->d_u.d_44.d_type = DT_CHR; - break; - case S_IFIFO: - de->d_u.d_44.d_type = DT_FIFO; - break; - default: - de->d_u.d_44.d_type = DT_UNKNOWN; + + size_t i; + /* Default to DT_UNKNOWN if not found */ + de->d_u.d_44.d_type = DT_UNKNOWN; + + for (i = 0; i < ARRAY_SIZE(ufs_type_table); i++) { + if ((mode & S_IFMT) == ufs_type_table[i].mode_mask) { + de->d_u.d_44.d_type = ufs_type_table[i].d_type; + break; + } } } -- 2.34.1