From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 29643C433EF for ; Thu, 14 Jul 2022 00:43:23 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 75C1482068; Thu, 14 Jul 2022 02:43:21 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="udut7GoS"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8892784031; Thu, 14 Jul 2022 02:43:19 +0200 (CEST) Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 515CC810FE for ; Thu, 14 Jul 2022 02:43:15 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=takahiro.akashi@linaro.org Received: by mail-pf1-x436.google.com with SMTP id a15so431957pfv.13 for ; Wed, 13 Jul 2022 17:43:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:mail-followup-to:references :mime-version:content-disposition:in-reply-to; bh=sQPqjNq/kjitSfDejxbtVUDgYiZarVie0Wy+hbIFdKM=; b=udut7GoSJiRPq2yepJfJIWF5uIpJZfAQ20DVtFcR05Gpdmij9ngKdbl2nMZPWZECvD k5vL7dLCP4gpfgFpb0BMTapHHAtYAsxFFvVjX9SEW64xP18ifhe9f5RqOOU9CrPYHPlo KCdCqDi6iXZ0KnT/fsTKPBJKaHMnRLx/xVWdxO/iTCKjJ9XcRjBzvT/ncNYQDf5ObcOK JC0Elk/R8S7kKm3/HRaJlpWJB1FINvq3RyjUUeM5K9TjZPNTe+cq6+cORj3O21uZAio5 wYsiKKV0/3wdbWLJYkM3m+VNNBLymOBlIibJtGDSXk/zzKMnuqZUMBjbHyqwmZCWX8Q3 Q66w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id :mail-followup-to:references:mime-version:content-disposition :in-reply-to; bh=sQPqjNq/kjitSfDejxbtVUDgYiZarVie0Wy+hbIFdKM=; b=OF470eFH/qCFZbfpjqeZqq33SAtZBSABIPj2NYOUAiXbggSPtB5JPd5UuU8mJ90nb2 loOj0wo1Bqo0cgX2twI0+zB1A1LYUyvMXCypyoX0WF7NOTNE1C8IVymqlTkuRtT5lTE3 GybORJq0NEEQomwpX63WVx4WJyHq8SgUcjNmEcJ87lF/3s4EPVhq3Z5k0h3kfhJVMdzJ azG2SGnvSY29BSLJZmgPliTI2Za5OAI2wmE/AEEdqjoBOI1voGGjN5SxZXjxcjSOViZb elCeczRdrLc8Y0mGfizBNqtwnnOJa4KW/B0HAtTGArldkoR5qjQKuIT5dSuIzhWddKgl ZiNg== X-Gm-Message-State: AJIora9ipKxKBYPJ+zgA8SS+NByK49IRG/8fnZz1IoolB7oPGHn4gwOF ehYXZl7G0k+YUjmm35HvJUPuud1za4CkOg== X-Google-Smtp-Source: AGRyM1v2F61HuvEcX9ATcSpzeaRjEkiycHjL7LJMMx9vKSdcoWdDu+1w0v+vwa1kACGrTx61Fs2g3g== X-Received: by 2002:a05:6a00:1c94:b0:52a:b71d:5c65 with SMTP id y20-20020a056a001c9400b0052ab71d5c65mr5927923pfw.65.1657759393217; Wed, 13 Jul 2022 17:43:13 -0700 (PDT) Received: from laputa ([2400:4050:c3e1:100:c57c:842f:2db2:bf43]) by smtp.gmail.com with ESMTPSA id b132-20020a621b8a000000b0052a75004c51sm154921pfb.146.2022.07.13.17.43.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jul 2022 17:43:12 -0700 (PDT) Date: Thu, 14 Jul 2022 09:43:09 +0900 From: AKASHI Takahiro To: Heinrich Schuchardt Cc: Tom Rini , u-boot@lists.denx.de Subject: Re: [PATCH 3/3] fs: fat: carve out fat_create_dir_entry() Message-ID: <20220714004309.GB42596@laputa> Mail-Followup-To: AKASHI Takahiro , Heinrich Schuchardt , Tom Rini , u-boot@lists.denx.de References: <20220712223314.20530-1-xypron.glpk@gmx.de> <20220712223314.20530-4-xypron.glpk@gmx.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220712223314.20530-4-xypron.glpk@gmx.de> X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean On Tue, Jul 12, 2022 at 10:33:14PM +0000, Heinrich Schuchardt wrote: > fat_mkdir() and file_fat_write_at() use identical code to create a new > directory entry. Carve out a new function fat_create_dir_entry() to avoid > this code duplication. Why not merge your patch[1] here as you're going to newly introduce fat_create_dir_entry()? [1] https://lists.denx.de/pipermail/u-boot/2022-July/488693.html -Takahiro Akashi > Signed-off-by: Heinrich Schuchardt > --- > fs/fat/fat_write.c | 93 ++++++++++++++++++++-------------------------- > 1 file changed, 40 insertions(+), 53 deletions(-) > > diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c > index 57522f96a8..a25b2283d4 100644 > --- a/fs/fat/fat_write.c > +++ b/fs/fat/fat_write.c > @@ -1314,6 +1314,43 @@ static int normalize_longname(char *l_filename, const char *filename) > return 0; > } > > +/** > + * fat_create_dir_entry() - create directory entry > + * > + * @itr: directory iterator > + * @basename: name of file or directory to be created > + * @size: file size > + * @attr: file or directory attributes > + * Return: 0 for success, -EIO on error > + */ > +static int fat_create_dir_entry(fat_itr *itr, const char *basename, > + loff_t size, u8 attr) > +{ > + /* Create a new file */ > + char shortname[SHORT_NAME_SIZE]; > + int ndent; > + int ret; > + > + /* Check if long name is needed */ > + ndent = set_name(itr, basename, shortname); > + if (ndent < 0) > + return ndent; > + ret = fat_find_empty_dentries(itr, ndent); > + if (ret) > + return ret; > + if (ndent > 1) { > + /* Set long name entries */ > + ret = fill_dir_slot(itr, basename, shortname); > + if (ret) > + return ret; > + } > + > + /* Set short name entry */ > + fill_dentry(itr->fsdata, itr->dent, shortname, 0, size, attr); > + > + return 0; > +} > + > int file_fat_write_at(const char *filename, loff_t pos, void *buffer, > loff_t size, loff_t *actwrite) > { > @@ -1383,8 +1420,6 @@ int file_fat_write_at(const char *filename, loff_t pos, void *buffer, > retdent->size = cpu_to_le32(pos + size); > } else { > /* Create a new file */ > - char shortname[SHORT_NAME_SIZE]; > - int ndent; > > if (pos) { > /* No hole allowed */ > @@ -1392,25 +1427,7 @@ int file_fat_write_at(const char *filename, loff_t pos, void *buffer, > goto exit; > } > > - /* Check if long name is needed */ > - ndent = set_name(itr, basename, shortname); > - if (ndent < 0) { > - ret = ndent; > - goto exit; > - } > - ret = fat_find_empty_dentries(itr, ndent); > - if (ret) > - goto exit; > - if (ndent > 1) { > - /* Set long name entries */ > - ret = fill_dir_slot(itr, basename, shortname); > - if (ret) > - goto exit; > - } > - > - /* Set short name entry */ > - fill_dentry(itr->fsdata, itr->dent, shortname, 0, size, > - ATTR_ARCH); > + ret = fat_create_dir_entry(itr, basename, size, ATTR_ARCH); > > retdent = itr->dent; > } > @@ -1693,38 +1710,8 @@ int fat_mkdir(const char *dirname) > ret = -EEXIST; > goto exit; > } else { > - char shortname[SHORT_NAME_SIZE]; > - int ndent; > - > - if (itr->is_root) { > - /* root dir cannot have "." or ".." */ > - if (!strcmp(l_dirname, ".") || > - !strcmp(l_dirname, "..")) { > - ret = -EINVAL; > - goto exit; > - } > - } > - > - /* Check if long name is needed */ > - ndent = set_name(itr, basename, shortname); > - if (ndent < 0) { > - ret = ndent; > - goto exit; > - } > - ret = fat_find_empty_dentries(itr, ndent); > - if (ret) > - goto exit; > - if (ndent > 1) { > - /* Set long name entries */ > - ret = fill_dir_slot(itr, basename, shortname); > - if (ret) > - goto exit; > - } > - > - /* Set attribute as archive for regular file */ > - fill_dentry(itr->fsdata, itr->dent, shortname, 0, 0, > - ATTR_DIR | ATTR_ARCH); > - > + ret = fat_create_dir_entry(itr, basename, 0, > + ATTR_DIR | ATTR_ARCH); > retdent = itr->dent; > } > > -- > 2.30.2 >