From nobody Mon Apr 27 19:15:09 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1F2CBC433EF for ; Fri, 10 Jun 2022 07:58:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346970AbiFJH5y (ORCPT ); Fri, 10 Jun 2022 03:57:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347035AbiFJH5j (ORCPT ); Fri, 10 Jun 2022 03:57:39 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 486BB1CB700 for ; Fri, 10 Jun 2022 00:57:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1654847854; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cPpYHnXIBZc98vfrpGPPeNO4G+nbrOWi/rqlDfKtk/c=; b=YoEMvr7LBNPOAbkEUAIiEdC3paoJBH8lMNTORsdFXDF8pCjT2EkDOtjHcRI7H1Y8LpJ4hm fqYU5VNFYFJ9Xu6B/8w3Uh7K4f+nJ4qDEZ99HP5kDxTsYQlm/ibnADJ5Z8fuu5bLJBeA/r bObfXAtGS7hyVtXo6bnapjfbevVwYgo= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-237-HY0a2PTXPvCLj_4vwjwxLQ-1; Fri, 10 Jun 2022 03:57:33 -0400 X-MC-Unique: HY0a2PTXPvCLj_4vwjwxLQ-1 Received: by mail-wm1-f71.google.com with SMTP id o2-20020a05600c510200b0039747b0216fso964871wms.0 for ; Fri, 10 Jun 2022 00:57:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=cPpYHnXIBZc98vfrpGPPeNO4G+nbrOWi/rqlDfKtk/c=; b=TQTRgEXDCsgk2CFUc1tElrCVlvCAP9KBBQcPWYaTJQ2s9rEBYP0HtU+QJzovPrimpC plL3YSYSjIkqPZIqIDIl5oKX2VPP+S/5qqmTFtluuUYZpuFhGYbR3kUdLHDhssbyyV5M +Eja009bGsgaFSsUA9y6mREn1S+ObPYLATRoH1rd4S07HMb8lzFgzWOLSWvQrE2nC3P/ oN8qGHRqirNa7usuPrXu19hlsg7R5tt3kJCVjLRKgf6ZijcJjDKdI3i16lZ8BS6TEpcF 24eQsbtg0bGnf9aobmoWq1H8SmZBK3wIb3Hkzv+VmKYexgnmbt8B1f8v55TEO9GdZiw3 7/6A== X-Gm-Message-State: AOAM530xoSFu63T1yTnXH7+BXY/Q8n1TEEJXaz97sELozxyCly8Ie6Ft y5nwMHhvScU+9fCfy1wkwY64dXvdiRwaG/prjV9fyxc8ce7zVnpOCsOS3rACYB/aVK4do88CtwS ShzzUIJiyJvrsso00P9QyHjpYv98zE1tvaHSPoyEFpclEAIWpXBL13FW0r7DX8Ck9ZgAh+hbpyD U= X-Received: by 2002:a05:600c:3495:b0:39c:6a72:f286 with SMTP id a21-20020a05600c349500b0039c6a72f286mr7524529wmq.116.1654847852114; Fri, 10 Jun 2022 00:57:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwgWTcfEx07dyJt9OHzUm9JUAGAHTErpr/4wjbKLCjZlo56Z7ixSmHdUFl3hD1fJRT96/dN2w== X-Received: by 2002:a05:600c:3495:b0:39c:6a72:f286 with SMTP id a21-20020a05600c349500b0039c6a72f286mr7524493wmq.116.1654847851725; Fri, 10 Jun 2022 00:57:31 -0700 (PDT) Received: from minerva.home (205.pool92-176-231.dynamic.orange.es. [92.176.231.205]) by smtp.gmail.com with ESMTPSA id l6-20020a5d4bc6000000b0020e615bab7bsm26673363wrt.7.2022.06.10.00.57.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jun 2022 00:57:31 -0700 (PDT) From: Javier Martinez Canillas To: linux-kernel@vger.kernel.org Cc: Christian Kellner , Alberto Ruiz , OGAWA Hirofumi , Peter Jones , Chung-Chiang Cheng , Carlos Maiolino , Lennart Poettering , Alexander Larsson , Colin Walters , Muhammad Usama Anjum , Javier Martinez Canillas Subject: [PATCH v6 1/4] fat: add a vfat_rename2() and make existing .rename callback a helper Date: Fri, 10 Jun 2022 09:57:18 +0200 Message-Id: <20220610075721.1182745-2-javierm@redhat.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220610075721.1182745-1-javierm@redhat.com> References: <20220610075721.1182745-1-javierm@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Currently vfat only supports the RENAME_NOREPLACE flag which is handled by the virtual file system layer but doesn't support the RENAME_EXCHANGE flag. Add a vfat_rename2() function to be used as the .rename callback and move the current vfat_rename() handler to a helper. This is in preparation for implementing the RENAME_NOREPLACE flag using a different helper function. Signed-off-by: Javier Martinez Canillas Acked-by: OGAWA Hirofumi --- (no changes since v1) fs/fat/namei_vfat.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/fs/fat/namei_vfat.c b/fs/fat/namei_vfat.c index c573314806cf..88ccb2ee3537 100644 --- a/fs/fat/namei_vfat.c +++ b/fs/fat/namei_vfat.c @@ -889,9 +889,8 @@ static int vfat_mkdir(struct user_namespace *mnt_userns= , struct inode *dir, return err; } =20 -static int vfat_rename(struct user_namespace *mnt_userns, struct inode *ol= d_dir, - struct dentry *old_dentry, struct inode *new_dir, - struct dentry *new_dentry, unsigned int flags) +static int vfat_rename(struct inode *old_dir, struct dentry *old_dentry, + struct inode *new_dir, struct dentry *new_dentry) { struct buffer_head *dotdot_bh; struct msdos_dir_entry *dotdot_de; @@ -902,9 +901,6 @@ static int vfat_rename(struct user_namespace *mnt_usern= s, struct inode *old_dir, int err, is_dir, update_dotdot, corrupt =3D 0; struct super_block *sb =3D old_dir->i_sb; =20 - if (flags & ~RENAME_NOREPLACE) - return -EINVAL; - old_sinfo.bh =3D sinfo.bh =3D dotdot_bh =3D NULL; old_inode =3D d_inode(old_dentry); new_inode =3D d_inode(new_dentry); @@ -1021,13 +1017,24 @@ static int vfat_rename(struct user_namespace *mnt_u= serns, struct inode *old_dir, goto out; } =20 +static int vfat_rename2(struct user_namespace *mnt_userns, struct inode *o= ld_dir, + struct dentry *old_dentry, struct inode *new_dir, + struct dentry *new_dentry, unsigned int flags) +{ + if (flags & ~RENAME_NOREPLACE) + return -EINVAL; + + /* VFS already handled RENAME_NOREPLACE, handle it as a normal rename */ + return vfat_rename(old_dir, old_dentry, new_dir, new_dentry); +} + static const struct inode_operations vfat_dir_inode_operations =3D { .create =3D vfat_create, .lookup =3D vfat_lookup, .unlink =3D vfat_unlink, .mkdir =3D vfat_mkdir, .rmdir =3D vfat_rmdir, - .rename =3D vfat_rename, + .rename =3D vfat_rename2, .setattr =3D fat_setattr, .getattr =3D fat_getattr, .update_time =3D fat_update_time, --=20 2.36.1 From nobody Mon Apr 27 19:15:09 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 06BCFC43334 for ; Fri, 10 Jun 2022 07:57:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347065AbiFJH5t (ORCPT ); Fri, 10 Jun 2022 03:57:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347037AbiFJH5j (ORCPT ); Fri, 10 Jun 2022 03:57:39 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 21D5B1CB714 for ; Fri, 10 Jun 2022 00:57:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1654847856; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3UvTYFnM/Xxan4k4LuRTmFLCKv7+5+mh7KcxWLzDn8Q=; b=aA57j4xtS2w+uwQHIUZWWOyfBOi6EqPntwOL0kSUja45e0A3AcfbPwjPBicUymYvHqTqBC p6RGvLIdRxx4kYcm5agt0jIiQBGougLeH6l6ZgSz+bATMOl7tK8ZQ7dkCGSWinPxLMcqJU strDudJ4L08JgJuBw0Lt8Vifvi3Hhns= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-333-Cac5y6pBP9OyMFVp2cOiNA-1; Fri, 10 Jun 2022 03:57:34 -0400 X-MC-Unique: Cac5y6pBP9OyMFVp2cOiNA-1 Received: by mail-wm1-f70.google.com with SMTP id z13-20020a7bc7cd000000b0039c4a238eadso4998265wmk.9 for ; Fri, 10 Jun 2022 00:57:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3UvTYFnM/Xxan4k4LuRTmFLCKv7+5+mh7KcxWLzDn8Q=; b=HNYyGCeNfcoTuNMlGLjQEDuYl0ngX7NKjqmVZYAbTULxpaTF31OauA+DEhwPaXLgwP fOd2PKu6/YxdmlEAEVTANqV9ZPspHDR15j8AyRFMsP3EjS55ewCiIV9S7RWDEPwRyxKJ rRYDs5Y50xkBo63twpsD40YCukfvhVPhVWClBlPen9sHIqS0kR4o89WUsSGwWM52sUEd 3jXaKRI7scwwE6gdYjhmKh35WzjtQlD+s92weZalY4IyLcVT4voqt9kL9qzvzTi1ieQY CRPhBmHyytWwE5IXIwYyNAavf3m4jGuG+iUyhe3iNkgXkd4JVlr/VT4hep1AucvJIWf5 rpqA== X-Gm-Message-State: AOAM533GD3MOQG/IXIs7j3eRnJogfoKUY7oyt8WZHsCf54zXuqMZzfng EIvq1resqIyKbDp/NGhbN/uExl56Z8RiJ38q6LTeLYiLndR7VSqqr13dLJIlOujmyGzwHftmUf1 QpdJy80kOdKSbUCZTsdlacyAMqCjTMZ+agkQ+oBcDI1YIqOrXIOHG/1m+Rz5HqmYTZJTdD1eV1u c= X-Received: by 2002:a05:6000:1e1b:b0:219:e32d:cbe8 with SMTP id bj27-20020a0560001e1b00b00219e32dcbe8mr3854635wrb.129.1654847853272; Fri, 10 Jun 2022 00:57:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwY+DGxwn0ElPtJNwPV+uaOQ1b8VDvmoDjAODTofe+2ab5W+KkmtgFAhYjducATm+l32Zd1SQ== X-Received: by 2002:a05:6000:1e1b:b0:219:e32d:cbe8 with SMTP id bj27-20020a0560001e1b00b00219e32dcbe8mr3854605wrb.129.1654847852983; Fri, 10 Jun 2022 00:57:32 -0700 (PDT) Received: from minerva.home (205.pool92-176-231.dynamic.orange.es. [92.176.231.205]) by smtp.gmail.com with ESMTPSA id l6-20020a5d4bc6000000b0020e615bab7bsm26673363wrt.7.2022.06.10.00.57.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jun 2022 00:57:32 -0700 (PDT) From: Javier Martinez Canillas To: linux-kernel@vger.kernel.org Cc: Christian Kellner , Alberto Ruiz , OGAWA Hirofumi , Peter Jones , Chung-Chiang Cheng , Carlos Maiolino , Lennart Poettering , Alexander Larsson , Colin Walters , Muhammad Usama Anjum , Javier Martinez Canillas Subject: [PATCH v6 2/4] fat: factor out reusable code in vfat_rename() as helper functions Date: Fri, 10 Jun 2022 09:57:19 +0200 Message-Id: <20220610075721.1182745-3-javierm@redhat.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220610075721.1182745-1-javierm@redhat.com> References: <20220610075721.1182745-1-javierm@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: OGAWA Hirofumi The vfat_rename() function is quite big and there are code blocks that can be moved into helper functions. This not only simplify the implementation of that function but also allows these helpers to be reused. For example, the helpers can be used by the handler of the RENAME_EXCHANGE flag once this is implemented in a subsequent patch. Signed-off-by: OGAWA Hirofumi Signed-off-by: Javier Martinez Canillas Acked-by: OGAWA Hirofumi --- (no changes since v4) Changes in v4: - Add new patch from OGAWA Hirofumi to use the helpers in vfat_rename(). fs/fat/namei_vfat.c | 89 +++++++++++++++++++++++++++++---------------- 1 file changed, 57 insertions(+), 32 deletions(-) diff --git a/fs/fat/namei_vfat.c b/fs/fat/namei_vfat.c index 88ccb2ee3537..9c04053a8f1c 100644 --- a/fs/fat/namei_vfat.c +++ b/fs/fat/namei_vfat.c @@ -889,16 +889,55 @@ static int vfat_mkdir(struct user_namespace *mnt_user= ns, struct inode *dir, return err; } =20 +static int vfat_get_dotdot_de(struct inode *inode, struct buffer_head **bh, + struct msdos_dir_entry **de) +{ + if (S_ISDIR(inode->i_mode)) { + if (fat_get_dotdot_entry(inode, bh, de)) + return -EIO; + } + return 0; +} + +static int vfat_sync_ipos(struct inode *dir, struct inode *inode) +{ + if (IS_DIRSYNC(dir)) + return fat_sync_inode(inode); + mark_inode_dirty(inode); + return 0; +} + +static int vfat_update_dotdot_de(struct inode *dir, struct inode *inode, + struct buffer_head *dotdot_bh, + struct msdos_dir_entry *dotdot_de) +{ + fat_set_start(dotdot_de, MSDOS_I(dir)->i_logstart); + mark_buffer_dirty_inode(dotdot_bh, inode); + if (IS_DIRSYNC(dir)) + return sync_dirty_buffer(dotdot_bh); + return 0; +} + +static void vfat_update_dir_metadata(struct inode *dir, struct timespec64 = *ts) +{ + inode_inc_iversion(dir); + fat_truncate_time(dir, ts, S_CTIME | S_MTIME); + if (IS_DIRSYNC(dir)) + (void)fat_sync_inode(dir); + else + mark_inode_dirty(dir); +} + static int vfat_rename(struct inode *old_dir, struct dentry *old_dentry, struct inode *new_dir, struct dentry *new_dentry) { struct buffer_head *dotdot_bh; - struct msdos_dir_entry *dotdot_de; + struct msdos_dir_entry *dotdot_de =3D NULL; struct inode *old_inode, *new_inode; struct fat_slot_info old_sinfo, sinfo; struct timespec64 ts; loff_t new_i_pos; - int err, is_dir, update_dotdot, corrupt =3D 0; + int err, is_dir, corrupt =3D 0; struct super_block *sb =3D old_dir->i_sb; =20 old_sinfo.bh =3D sinfo.bh =3D dotdot_bh =3D NULL; @@ -909,15 +948,13 @@ static int vfat_rename(struct inode *old_dir, struct = dentry *old_dentry, if (err) goto out; =20 - is_dir =3D S_ISDIR(old_inode->i_mode); - update_dotdot =3D (is_dir && old_dir !=3D new_dir); - if (update_dotdot) { - if (fat_get_dotdot_entry(old_inode, &dotdot_bh, &dotdot_de)) { - err =3D -EIO; + if (old_dir !=3D new_dir) { + err =3D vfat_get_dotdot_de(old_inode, &dotdot_bh, &dotdot_de); + if (err) goto out; - } } =20 + is_dir =3D S_ISDIR(old_inode->i_mode); ts =3D current_time(old_dir); if (new_inode) { if (is_dir) { @@ -938,21 +975,15 @@ static int vfat_rename(struct inode *old_dir, struct = dentry *old_dentry, =20 fat_detach(old_inode); fat_attach(old_inode, new_i_pos); - if (IS_DIRSYNC(new_dir)) { - err =3D fat_sync_inode(old_inode); - if (err) - goto error_inode; - } else - mark_inode_dirty(old_inode); + err =3D vfat_sync_ipos(new_dir, old_inode); + if (err) + goto error_inode; =20 - if (update_dotdot) { - fat_set_start(dotdot_de, MSDOS_I(new_dir)->i_logstart); - mark_buffer_dirty_inode(dotdot_bh, old_inode); - if (IS_DIRSYNC(new_dir)) { - err =3D sync_dirty_buffer(dotdot_bh); - if (err) - goto error_dotdot; - } + if (dotdot_de) { + err =3D vfat_update_dotdot_de(new_dir, old_inode, dotdot_bh, + dotdot_de); + if (err) + goto error_dotdot; drop_nlink(old_dir); if (!new_inode) inc_nlink(new_dir); @@ -962,12 +993,7 @@ static int vfat_rename(struct inode *old_dir, struct d= entry *old_dentry, old_sinfo.bh =3D NULL; if (err) goto error_dotdot; - inode_inc_iversion(old_dir); - fat_truncate_time(old_dir, &ts, S_CTIME|S_MTIME); - if (IS_DIRSYNC(old_dir)) - (void)fat_sync_inode(old_dir); - else - mark_inode_dirty(old_dir); + vfat_update_dir_metadata(old_dir, &ts); =20 if (new_inode) { drop_nlink(new_inode); @@ -987,10 +1013,9 @@ static int vfat_rename(struct inode *old_dir, struct = dentry *old_dentry, /* data cluster is shared, serious corruption */ corrupt =3D 1; =20 - if (update_dotdot) { - fat_set_start(dotdot_de, MSDOS_I(old_dir)->i_logstart); - mark_buffer_dirty_inode(dotdot_bh, old_inode); - corrupt |=3D sync_dirty_buffer(dotdot_bh); + if (dotdot_de) { + corrupt |=3D vfat_update_dotdot_de(old_dir, old_inode, dotdot_bh, + dotdot_de); } error_inode: fat_detach(old_inode); --=20 2.36.1 From nobody Mon Apr 27 19:15:09 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CB11EC433EF for ; Fri, 10 Jun 2022 07:57:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347053AbiFJH5m (ORCPT ); Fri, 10 Jun 2022 03:57:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41794 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346874AbiFJH5j (ORCPT ); Fri, 10 Jun 2022 03:57:39 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3FD431CB735 for ; Fri, 10 Jun 2022 00:57:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1654847857; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ATkm+EAS67CnW4t/j84Y6CR89852slTzLc67eEvXk84=; b=URwKekbtS3voKHIDNkRRtSaCC3BdrRFeLUXXpG/0Vor8+x2KoaTlsq8+tY/BTrqpoxD0qw hzhmLSlcoNXv64yXS/BZeEgato1XPpZXjo/wYaRw3q8taVzsxmsRkkAc4DnlyhsAMtJNvT AGBhQTmsgUi3DLf+Q9WggEnrmCUOVXk= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-347-vBB-3pHdOH-KFf90kFWZ4A-1; Fri, 10 Jun 2022 03:57:36 -0400 X-MC-Unique: vBB-3pHdOH-KFf90kFWZ4A-1 Received: by mail-wm1-f71.google.com with SMTP id c125-20020a1c3583000000b003978decffedso940900wma.5 for ; Fri, 10 Jun 2022 00:57:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ATkm+EAS67CnW4t/j84Y6CR89852slTzLc67eEvXk84=; b=uU7BAVwMPXOXnvo/ul7xpo9hj9UfyQsGjRhBOeLiPfifN5JY0JHU5E7ZjOMO/Vzqf0 1u7067PfMMbfMuHpa7SbQKZCOyDIExcxGN90Pauk1pno+16qt2NNgAaD9I14Z6BRY6NP oC0NsC1PwB4gHTYMwRP+9IWeTEKg4agry8s3IoGN8TQT7R6IAbsOjgId3FIKaZu7DjXT CurjbKDA/YT0uFgC1MDk/pWPW8MLpGVlQJRK2OI63no7tjNzXpo8VN8wS0oVTyXW/HZF EObkkeXUyZ5+qrOjpbyuYoGU3oeeROpa1AP8C7mnPrS/gdpRH+TS1tVNvdN4ovSC3/X9 YvCQ== X-Gm-Message-State: AOAM532BRQMtvwDTESLY91lwa6oUhET6g8d3i/+GXBZGUFrdmbsMhyXl wGgbEdgqblXorGfF0yrn2S4dXr0b3Z1TBN6U7aoRlFBfm+9gqFyfX2Cwy2wDivHlUpy/nockYiY DZ9FqU4VvT4TkKypWgUMn9tyHzqPNyoBtsLcM6ZYXQnvFpxGRyfTSTleiD4jvvxAMH3hhDEzKGb 4= X-Received: by 2002:a05:6000:1e04:b0:217:88ff:eb86 with SMTP id bj4-20020a0560001e0400b0021788ffeb86mr28802977wrb.351.1654847854699; Fri, 10 Jun 2022 00:57:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxQlwFK+FH4sMjCahy974jb0qPsptlEfGDrmM5xqbhSNgopqZIh4JoK76okVhVbqzw+BLOGCw== X-Received: by 2002:a05:6000:1e04:b0:217:88ff:eb86 with SMTP id bj4-20020a0560001e0400b0021788ffeb86mr28802943wrb.351.1654847854416; Fri, 10 Jun 2022 00:57:34 -0700 (PDT) Received: from minerva.home (205.pool92-176-231.dynamic.orange.es. [92.176.231.205]) by smtp.gmail.com with ESMTPSA id l6-20020a5d4bc6000000b0020e615bab7bsm26673363wrt.7.2022.06.10.00.57.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jun 2022 00:57:34 -0700 (PDT) From: Javier Martinez Canillas To: linux-kernel@vger.kernel.org Cc: Christian Kellner , Alberto Ruiz , OGAWA Hirofumi , Peter Jones , Chung-Chiang Cheng , Carlos Maiolino , Lennart Poettering , Alexander Larsson , Colin Walters , Muhammad Usama Anjum , Javier Martinez Canillas Subject: [PATCH v6 3/4] fat: add renameat2 RENAME_EXCHANGE flag support Date: Fri, 10 Jun 2022 09:57:20 +0200 Message-Id: <20220610075721.1182745-4-javierm@redhat.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220610075721.1182745-1-javierm@redhat.com> References: <20220610075721.1182745-1-javierm@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The renameat2 RENAME_EXCHANGE flag allows to atomically exchange two paths but is currently not supported by the Linux vfat filesystem driver. Add a vfat_rename_exchange() helper function that implements this support. The super block lock is acquired during the operation to ensure atomicity, and in the error path actions made are reversed also with the mutex held. It makes the operation as transactional as possible, within the limitation impossed by vfat due not having a journal with logs to replay. Signed-off-by: Javier Martinez Canillas Acked-by: OGAWA Hirofumi --- Changes in v6: - Simplify logic to determine if nlink have to modified (OGAWA Hirofumi). Changes in v5: - Only update nlink for different parent dirs and file types (OGAWA Hirofum= i). Changes in v4: - Rebase the patch on top of OGAWA Hirofumi proposed changes. - Drop iversion increment for old and new file inodes (OGAWA Hirofumi). Changes in v2: - Only update the new_dir inode version and timestamps if !=3D old_dir (Alex Larsson). - Add some helper functions to avoid duplicating code (OGAWA Hirofumi). - Use braces for multi-lines blocks even if are one statement (OGAWA Hirofu= mi). - Mention in commit message that the operation is as transactional as possi= ble but within the vfat limitations of not having a journal (Colin Walters). fs/fat/namei_vfat.c | 123 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 122 insertions(+), 1 deletion(-) diff --git a/fs/fat/namei_vfat.c b/fs/fat/namei_vfat.c index 9c04053a8f1c..21620054e1c4 100644 --- a/fs/fat/namei_vfat.c +++ b/fs/fat/namei_vfat.c @@ -1042,13 +1042,134 @@ static int vfat_rename(struct inode *old_dir, stru= ct dentry *old_dentry, goto out; } =20 +static void vfat_exchange_ipos(struct inode *old_inode, struct inode *new_= inode, + loff_t old_i_pos, loff_t new_i_pos) +{ + fat_detach(old_inode); + fat_detach(new_inode); + fat_attach(old_inode, new_i_pos); + fat_attach(new_inode, old_i_pos); +} + +static void vfat_move_nlink(struct inode *src, struct inode *dst) +{ + drop_nlink(src); + inc_nlink(dst); +} + +static int vfat_rename_exchange(struct inode *old_dir, struct dentry *old_= dentry, + struct inode *new_dir, struct dentry *new_dentry) +{ + struct buffer_head *old_dotdot_bh =3D NULL, *new_dotdot_bh =3D NULL; + struct msdos_dir_entry *old_dotdot_de =3D NULL, *new_dotdot_de =3D NULL; + struct inode *old_inode, *new_inode; + struct timespec64 ts =3D current_time(old_dir); + loff_t old_i_pos, new_i_pos; + int err, corrupt =3D 0; + struct super_block *sb =3D old_dir->i_sb; + + old_inode =3D d_inode(old_dentry); + new_inode =3D d_inode(new_dentry); + + /* Acquire super block lock for the operation to be atomic */ + mutex_lock(&MSDOS_SB(sb)->s_lock); + + /* if directories are not the same, get ".." info to update */ + if (old_dir !=3D new_dir) { + err =3D vfat_get_dotdot_de(old_inode, &old_dotdot_bh, + &old_dotdot_de); + if (err) + goto out; + + err =3D vfat_get_dotdot_de(new_inode, &new_dotdot_bh, + &new_dotdot_de); + if (err) + goto out; + } + + old_i_pos =3D MSDOS_I(old_inode)->i_pos; + new_i_pos =3D MSDOS_I(new_inode)->i_pos; + + vfat_exchange_ipos(old_inode, new_inode, old_i_pos, new_i_pos); + + err =3D vfat_sync_ipos(old_dir, new_inode); + if (err) + goto error_exchange; + err =3D vfat_sync_ipos(new_dir, old_inode); + if (err) + goto error_exchange; + + /* update ".." directory entry info */ + if (old_dotdot_de) { + err =3D vfat_update_dotdot_de(new_dir, old_inode, old_dotdot_bh, + old_dotdot_de); + if (err) + goto error_old_dotdot; + } + if (new_dotdot_de) { + err =3D vfat_update_dotdot_de(old_dir, new_inode, new_dotdot_bh, + new_dotdot_de); + if (err) + goto error_new_dotdot; + } + + /* if cross directory and only one is a directory, adjust nlink */ + if (!old_dotdot_de !=3D !new_dotdot_de) { + if (old_dotdot_de) + vfat_move_nlink(old_dir, new_dir); + else + vfat_move_nlink(new_dir, old_dir); + } + + vfat_update_dir_metadata(old_dir, &ts); + /* if directories are not the same, update new_dir as well */ + if (old_dir !=3D new_dir) + vfat_update_dir_metadata(new_dir, &ts); + +out: + brelse(old_dotdot_bh); + brelse(new_dotdot_bh); + mutex_unlock(&MSDOS_SB(sb)->s_lock); + + return err; + +error_new_dotdot: + if (new_dotdot_de) { + corrupt |=3D vfat_update_dotdot_de(new_dir, new_inode, + new_dotdot_bh, new_dotdot_de); + } + +error_old_dotdot: + if (old_dotdot_de) { + corrupt |=3D vfat_update_dotdot_de(old_dir, old_inode, + old_dotdot_bh, old_dotdot_de); + } + +error_exchange: + vfat_exchange_ipos(old_inode, new_inode, new_i_pos, old_i_pos); + corrupt |=3D vfat_sync_ipos(new_dir, new_inode); + corrupt |=3D vfat_sync_ipos(old_dir, old_inode); + + if (corrupt < 0) { + fat_fs_error(new_dir->i_sb, + "%s: Filesystem corrupted (i_pos %lld, %lld)", + __func__, old_i_pos, new_i_pos); + } + goto out; +} + static int vfat_rename2(struct user_namespace *mnt_userns, struct inode *o= ld_dir, struct dentry *old_dentry, struct inode *new_dir, struct dentry *new_dentry, unsigned int flags) { - if (flags & ~RENAME_NOREPLACE) + if (flags & ~(RENAME_NOREPLACE | RENAME_EXCHANGE)) return -EINVAL; =20 + if (flags & RENAME_EXCHANGE) { + return vfat_rename_exchange(old_dir, old_dentry, + new_dir, new_dentry); + } + /* VFS already handled RENAME_NOREPLACE, handle it as a normal rename */ return vfat_rename(old_dir, old_dentry, new_dir, new_dentry); } --=20 2.36.1 From nobody Mon Apr 27 19:15:09 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 85EB3C43334 for ; Fri, 10 Jun 2022 07:58:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347081AbiFJH6Q (ORCPT ); Fri, 10 Jun 2022 03:58:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42006 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347049AbiFJH5m (ORCPT ); Fri, 10 Jun 2022 03:57:42 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9F22C5FEA for ; Fri, 10 Jun 2022 00:57:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1654847858; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MR1Gg3APqC3KScgCLB1W8gelo918jbhbexHlcrWCcj0=; b=YPZx2pQsYY1HWzqm06rJw0wa/UhmQmljnAB61qt4rSeYNCM2f/pNvVvA1LaxbhTxGve57h ItG7Y1j7vizERsfIrhniwKRc0ILdNARCjpDnjQaprNmNUbUf/c1Fqr4SDlfl9YL44XG+8v 3zlXHwXUWcsZPo09lLaHnS/fE6I+OEE= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-228-RrchW_gLP3iQj-EUSDZcnA-1; Fri, 10 Jun 2022 03:57:37 -0400 X-MC-Unique: RrchW_gLP3iQj-EUSDZcnA-1 Received: by mail-wm1-f72.google.com with SMTP id bg40-20020a05600c3ca800b00394779649b1so946759wmb.3 for ; Fri, 10 Jun 2022 00:57:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=MR1Gg3APqC3KScgCLB1W8gelo918jbhbexHlcrWCcj0=; b=d+sSHYw10yTp+PdkNrxhcagdsg3PmRYe3Hp9xDRkIpySwY0S3m70oWdi8Ezr5Rbhsq MxzrzlOzSGyQsltggyXPJNjDHGoE22TtRIY6P/tjWdnj5leOp4oT+AGl5Dho9ZBiw9A0 DP9vra6aIsK1jbivzvnPh8i2TO2gf6SZKlMPK8c/fsjX6QZAfoJLHovGza1robQCp77X KuZJUcJYZ8TTInw1YPz0kNBtNYe7Sxncr2qegRzmCBt+lefTpnQ13oVEoU6ke9dfQhcQ xySLD9D/FOQF+aILfqN7gsoytl/Jmtvmckw5n7MZSxYQQ7o1T1Uh9nJ7Rt1ouQ1nUP7Z sgkA== X-Gm-Message-State: AOAM531L5jTnAIRBT25cXxSQVJ/Id03G4H2u+lJvX7Da3kbfwm51xYk+ BZWcenNtkxHWy4mX+zMjF3AnlHQZjEevNe9eyeTj2G/jzbPaTYgj7+jc0gv7emZXvjXS55WZ2BA 6L4J0VvJRBlgRPGKsCFyMEruuaflkvhPwbWtyhJ1Cn07l3+HBWS4pw+p80WWoaX+lwYiXgBZ6/U g= X-Received: by 2002:adf:fc81:0:b0:20e:69c2:30e7 with SMTP id g1-20020adffc81000000b0020e69c230e7mr41777176wrr.536.1654847856013; Fri, 10 Jun 2022 00:57:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxgQCSJvlEbP8jS21D0m9OuwNx5itx+HSu/uxendRX4MoehC7+bVq6SFda6SavlAsHFHM30iA== X-Received: by 2002:adf:fc81:0:b0:20e:69c2:30e7 with SMTP id g1-20020adffc81000000b0020e69c230e7mr41777140wrr.536.1654847855666; Fri, 10 Jun 2022 00:57:35 -0700 (PDT) Received: from minerva.home (205.pool92-176-231.dynamic.orange.es. [92.176.231.205]) by smtp.gmail.com with ESMTPSA id l6-20020a5d4bc6000000b0020e615bab7bsm26673363wrt.7.2022.06.10.00.57.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jun 2022 00:57:35 -0700 (PDT) From: Javier Martinez Canillas To: linux-kernel@vger.kernel.org Cc: Christian Kellner , Alberto Ruiz , OGAWA Hirofumi , Peter Jones , Chung-Chiang Cheng , Carlos Maiolino , Lennart Poettering , Alexander Larsson , Colin Walters , Muhammad Usama Anjum , Javier Martinez Canillas , Shuah Khan , linux-kselftest@vger.kernel.org Subject: [PATCH v6 4/4] selftests/filesystems: add a vfat RENAME_EXCHANGE test Date: Fri, 10 Jun 2022 09:57:21 +0200 Message-Id: <20220610075721.1182745-5-javierm@redhat.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220610075721.1182745-1-javierm@redhat.com> References: <20220610075721.1182745-1-javierm@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add a test for the renameat2 RENAME_EXCHANGE support in vfat, but split it in a tool that just does the rename exchange and a script that is run by the kselftests framework on `make TARGETS=3D"filesystems/fat" kselftest`. That way the script can be easily extended to test other file operations. The script creates a 1 MiB disk image, that is then formated with a vfat filesystem and mounted using a loop device. That way all file operations are done on an ephemeral filesystem. Signed-off-by: Javier Martinez Canillas Acked-by: Muhammad Usama Anjum Acked-by: OGAWA Hirofumi --- (no changes since v4) Changes in v4: - Add Muhammad Usama Anjum Acked-by tag. Changes in v3: - Add a .gitignore for the rename_exchange binary (Muhammad Usama Anjum). - Include $(KHDR_INCLUDES) instead of hardcoding a relative path in Makefile (Muhammad Usama Anjum). Changes in v2: - Call sync to flush the page cache before checking the file contents (Alex Larsson). MAINTAINERS | 1 + tools/testing/selftests/Makefile | 1 + .../selftests/filesystems/fat/.gitignore | 2 + .../selftests/filesystems/fat/Makefile | 7 ++ .../testing/selftests/filesystems/fat/config | 2 + .../filesystems/fat/rename_exchange.c | 37 +++++++++ .../filesystems/fat/run_fat_tests.sh | 82 +++++++++++++++++++ 7 files changed, 132 insertions(+) create mode 100644 tools/testing/selftests/filesystems/fat/.gitignore create mode 100644 tools/testing/selftests/filesystems/fat/Makefile create mode 100644 tools/testing/selftests/filesystems/fat/config create mode 100644 tools/testing/selftests/filesystems/fat/rename_exchange= .c create mode 100755 tools/testing/selftests/filesystems/fat/run_fat_tests.sh diff --git a/MAINTAINERS b/MAINTAINERS index 4fdbbd6c1984..158771bb7755 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -20841,6 +20841,7 @@ M: OGAWA Hirofumi S: Maintained F: Documentation/filesystems/vfat.rst F: fs/fat/ +F: tools/testing/selftests/filesystems/fat/ =20 VFIO DRIVER M: Alex Williamson diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Mak= efile index 0aedcd76cf0f..fc59ad849a90 100644 --- a/tools/testing/selftests/Makefile +++ b/tools/testing/selftests/Makefile @@ -16,6 +16,7 @@ TARGETS +=3D exec TARGETS +=3D filesystems TARGETS +=3D filesystems/binderfs TARGETS +=3D filesystems/epoll +TARGETS +=3D filesystems/fat TARGETS +=3D firmware TARGETS +=3D fpu TARGETS +=3D ftrace diff --git a/tools/testing/selftests/filesystems/fat/.gitignore b/tools/tes= ting/selftests/filesystems/fat/.gitignore new file mode 100644 index 000000000000..b89920ed841c --- /dev/null +++ b/tools/testing/selftests/filesystems/fat/.gitignore @@ -0,0 +1,2 @@ +# SPDX-License-Identifier: GPL-2.0-only +rename_exchange diff --git a/tools/testing/selftests/filesystems/fat/Makefile b/tools/testi= ng/selftests/filesystems/fat/Makefile new file mode 100644 index 000000000000..902033f6ef09 --- /dev/null +++ b/tools/testing/selftests/filesystems/fat/Makefile @@ -0,0 +1,7 @@ +# SPDX-License-Identifier: GPL-2.0 + +TEST_PROGS :=3D run_fat_tests.sh +TEST_GEN_PROGS_EXTENDED :=3D rename_exchange +CFLAGS +=3D -O2 -g -Wall $(KHDR_INCLUDES) + +include ../../lib.mk diff --git a/tools/testing/selftests/filesystems/fat/config b/tools/testing= /selftests/filesystems/fat/config new file mode 100644 index 000000000000..6cf95e787a17 --- /dev/null +++ b/tools/testing/selftests/filesystems/fat/config @@ -0,0 +1,2 @@ +CONFIG_BLK_DEV_LOOP=3Dy +CONFIG_VFAT_FS=3Dy diff --git a/tools/testing/selftests/filesystems/fat/rename_exchange.c b/to= ols/testing/selftests/filesystems/fat/rename_exchange.c new file mode 100644 index 000000000000..e488ad354fce --- /dev/null +++ b/tools/testing/selftests/filesystems/fat/rename_exchange.c @@ -0,0 +1,37 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Program that atomically exchanges two paths using + * the renameat2() system call RENAME_EXCHANGE flag. + * + * Copyright 2022 Red Hat Inc. + * Author: Javier Martinez Canillas + */ + +#define _GNU_SOURCE +#include +#include +#include + +void print_usage(const char *program) +{ + printf("Usage: %s [oldpath] [newpath]\n", program); + printf("Atomically exchange oldpath and newpath\n"); +} + +int main(int argc, char *argv[]) +{ + int ret; + + if (argc !=3D 3) { + print_usage(argv[0]); + exit(EXIT_FAILURE); + } + + ret =3D renameat2(AT_FDCWD, argv[1], AT_FDCWD, argv[2], RENAME_EXCHANGE); + if (ret) { + perror("rename exchange failed"); + exit(EXIT_FAILURE); + } + + exit(EXIT_SUCCESS); +} diff --git a/tools/testing/selftests/filesystems/fat/run_fat_tests.sh b/too= ls/testing/selftests/filesystems/fat/run_fat_tests.sh new file mode 100755 index 000000000000..7f35dc3d15df --- /dev/null +++ b/tools/testing/selftests/filesystems/fat/run_fat_tests.sh @@ -0,0 +1,82 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +# +# Run filesystem operations tests on an 1 MiB disk image that is formatted= with +# a vfat filesystem and mounted in a temporary directory using a loop devi= ce. +# +# Copyright 2022 Red Hat Inc. +# Author: Javier Martinez Canillas + +set -e +set -u +set -o pipefail + +BASE_DIR=3D"$(dirname $0)" +TMP_DIR=3D"$(mktemp -d /tmp/fat_tests_tmp.XXXX)" +IMG_PATH=3D"${TMP_DIR}/fat.img" +MNT_PATH=3D"${TMP_DIR}/mnt" + +cleanup() +{ + mountpoint -q "${MNT_PATH}" && unmount_image + rm -rf "${TMP_DIR}" +} +trap cleanup SIGINT SIGTERM EXIT + +create_loopback() +{ + touch "${IMG_PATH}" + chattr +C "${IMG_PATH}" >/dev/null 2>&1 || true + + truncate -s 1M "${IMG_PATH}" + mkfs.vfat "${IMG_PATH}" >/dev/null 2>&1 +} + +mount_image() +{ + mkdir -p "${MNT_PATH}" + sudo mount -o loop "${IMG_PATH}" "${MNT_PATH}" +} + +rename_exchange_test() +{ + local rename_exchange=3D"${BASE_DIR}/rename_exchange" + local old_path=3D"${MNT_PATH}/old_file" + local new_path=3D"${MNT_PATH}/new_file" + + echo old | sudo tee "${old_path}" >/dev/null 2>&1 + echo new | sudo tee "${new_path}" >/dev/null 2>&1 + sudo "${rename_exchange}" "${old_path}" "${new_path}" >/dev/null 2>&1 + sudo sync -f "${MNT_PATH}" + grep new "${old_path}" >/dev/null 2>&1 + grep old "${new_path}" >/dev/null 2>&1 +} + +rename_exchange_subdir_test() +{ + local rename_exchange=3D"${BASE_DIR}/rename_exchange" + local dir_path=3D"${MNT_PATH}/subdir" + local old_path=3D"${MNT_PATH}/old_file" + local new_path=3D"${dir_path}/new_file" + + sudo mkdir -p "${dir_path}" + echo old | sudo tee "${old_path}" >/dev/null 2>&1 + echo new | sudo tee "${new_path}" >/dev/null 2>&1 + sudo "${rename_exchange}" "${old_path}" "${new_path}" >/dev/null 2>&1 + sudo sync -f "${MNT_PATH}" + grep new "${old_path}" >/dev/null 2>&1 + grep old "${new_path}" >/dev/null 2>&1 +} + +unmount_image() +{ + sudo umount "${MNT_PATH}" &> /dev/null +} + +create_loopback +mount_image +rename_exchange_test +rename_exchange_subdir_test +unmount_image + +exit 0 --=20 2.36.1