Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1656217rwb; Mon, 7 Nov 2022 04:23:59 -0800 (PST) X-Google-Smtp-Source: AMsMyM4K5TZJoZv59gjZUI6szn4yQoxE/CGGJcof12b3lmUy22rRjUYQVtHz3E2FFoQ6B0KMV4J4 X-Received: by 2002:a17:907:c711:b0:7ae:35c9:f07b with SMTP id ty17-20020a170907c71100b007ae35c9f07bmr16156429ejc.423.1667823838811; Mon, 07 Nov 2022 04:23:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667823838; cv=none; d=google.com; s=arc-20160816; b=Utj0SRhl9pJfBuLmqgK/gVre8FhX7FIuj66hFAPqhk3Bzq/i6i1MuPbdZuIB7wrnFN gwvpybxzh/DGkkYZNnFr3A731EC+M3nFryC44JPBhdwKwuL0cXdZJ/XYQ2iIc+O76j4A oQHwwLDJEuB5CgKtaeAlAvkZ3p7pKihEsU/Ie/S6uO3iunHMERxVA1Jiijpv4GCcYoTp yksN+ZMUyVfCGP57NSduN8XUq11XOfSG6lpE5x2Z8UXE9Y2dd1Zy/GMRCXUeBxgTAIjk 2TE8ZTNdHQlxCifhP9ESCxFU7zqFrMnwXzucE0EmoGge7BEHml/Cfm9jLL4T/dILBYr8 Q36Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=S4wVAqt8eOXFjCWV8thKlgvNZ26hyT3uO6MwWqI24NA=; b=pnA3I3kwRIFIiZDZPwLKb+evdYBXIo3CxZKC3EatVRgYJDOyaX5FK8aDz9wkIeiyE4 l4FIcfa1IWcuySZTug5tGGYcRG66U7b5dCkB6hQ2kxbAm+VNbDeX2gm14jn85+dD9cgi 57WHCX5rzwK+ti2Yi6A/q/sEuyVj1oc3d+9vESM2HO2NbuQVO47vr3Xa4H/n6hfejsbK 1p/at9YdO02cvPQfH/DegcEwLs2zpjHM+jl1OY+xzMQEMCqnCSgpQpTb73lgxL0N1Xhf reWcBS/DQbQYbadfHN8wvVLRwltL/f3W7ofThOnMSU4xn5VULTK0MFgaynwcllt5lsY6 E77Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=VHnxedjw; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j23-20020a170906431700b0078fcfc5d24esi6767586ejm.618.2022.11.07.04.23.36; Mon, 07 Nov 2022 04:23:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=VHnxedjw; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232141AbiKGMXB (ORCPT + 99 others); Mon, 7 Nov 2022 07:23:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232070AbiKGMXA (ORCPT ); Mon, 7 Nov 2022 07:23:00 -0500 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D57D1633D for ; Mon, 7 Nov 2022 04:22:59 -0800 (PST) Received: by mail-pj1-x102a.google.com with SMTP id b1-20020a17090a7ac100b00213fde52d49so10121364pjl.3 for ; Mon, 07 Nov 2022 04:22:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=S4wVAqt8eOXFjCWV8thKlgvNZ26hyT3uO6MwWqI24NA=; b=VHnxedjwPZv1GI0Wgl40+f3O/4PJn8vc2zKbiqdic5jC3UCpxjMk8JF9HaNjUUMTWl UHLsBiThTwBtJrlIw4/krc1RVu3SZNqssFbT8q62DEXvPwjo9jgkqFU/BEeK0jnTAZ4Q pp464XtXMsvi+9vfcQbDXXdnzVrTFgIx2mgTm7iB0qeleKW1AkQ9PTiJapk5okWK4MrB 0hmT0SzPGeYLEOPM3HBZLXrqmoYnf/q5cUVOXhFLk2wOJCHoAkAZ8AUGp3tkdqvjamX/ h9gNEZ86KwonSKrZhl0Tt92JNPIkFxIVJAgqelUsPAETDrEpd4VmxusbWyqEuEztLWH9 vOPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=S4wVAqt8eOXFjCWV8thKlgvNZ26hyT3uO6MwWqI24NA=; b=Tjobm/GsRSKJ+vwE4IcpBe5ZnA98U4CCv/ynJSUKX3vlBnCl0sF48cdjSbk4geeiBt fkFOZjluKTN3JAPmch5ySG6URkWdS+ifafa5G8o/rToA4AQmbHH03ePTXZVDb85o3M44 tHbtUx0UzhpscobM897fjSThgbpfcJf6hrFglTmo5jXXjc0OTHSSejk9uNpqNGDn0NbK wb6HmmvJawzzr3MeUQPrFmZfbl3Fq4qTRu3G8MK+kn4rRB1KgXy1++Ahx2tP4Uxq2Qpe u929vzUUXJ9ZogvWnr1FBWRUZ1kqApf4GTu6c7uTPS+97iamymDcGrIgWwWcoOJY5w/o wimQ== X-Gm-Message-State: ACrzQf1ZaLbUZnaRfF0fC/jbnqm5nyr51eOLKnY34WqrOpwq3ZaCr+hq cVCLEGp6oYkq0TD2l3eZaMidzRgNh2o= X-Received: by 2002:a17:90b:3901:b0:213:dfd5:a75f with SMTP id ob1-20020a17090b390100b00213dfd5a75fmr42776009pjb.233.1667823779318; Mon, 07 Nov 2022 04:22:59 -0800 (PST) Received: from localhost ([2406:7400:63:f20b:312d:45b2:85c1:c486]) by smtp.gmail.com with ESMTPSA id y15-20020a62ce0f000000b0056d2e716e01sm4369131pfg.139.2022.11.07.04.22.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Nov 2022 04:22:58 -0800 (PST) From: "Ritesh Harjani (IBM)" To: Theodore Ts'o Cc: linux-ext4@vger.kernel.org, Harshad Shirwadkar , Wang Shilong , Andreas Dilger , Li Xi , Ritesh Harjani Subject: [RFCv1 06/72] dblist: add dblist merge logic Date: Mon, 7 Nov 2022 17:50:54 +0530 Message-Id: <99ecce2af8609cc7bbe79de273472dcb42cca8f5.1667822611.git.ritesh.list@gmail.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org From: Li Xi This adds dblist merge logic. TODO: Add a unit test for core operations of dblist. Currently there is no such test for this. Signed-off-by: Li Xi Signed-off-by: Ritesh Harjani (IBM) --- lib/ext2fs/dblist.c | 36 ++++++++++++++++++++++++++++++++++++ lib/ext2fs/ext2fs.h | 1 + 2 files changed, 37 insertions(+) diff --git a/lib/ext2fs/dblist.c b/lib/ext2fs/dblist.c index bbdb221d..5568b8ec 100644 --- a/lib/ext2fs/dblist.c +++ b/lib/ext2fs/dblist.c @@ -119,6 +119,42 @@ errcode_t ext2fs_copy_dblist(ext2_dblist src, ext2_dblist *dest) return 0; } +/* + * Merge a directory block list @src to @dest + */ +errcode_t ext2fs_merge_dblist(ext2_dblist src, ext2_dblist dest) +{ + unsigned long long src_count = src->count; + unsigned long long dest_count = dest->count; + unsigned long long size = src_count + dest_count; + size_t size_entry = sizeof(struct ext2_db_entry2); + struct ext2_db_entry2 *array, *array2; + errcode_t retval; + + if (src_count == 0) + return 0; + + if (src->sorted || (dest->sorted && dest_count != 0)) + return EINVAL; + + retval = ext2fs_get_array(size, size_entry, &array); + if (retval) + return retval; + + array2 = array; + memcpy(array, src->list, src_count * size_entry); + array += src_count; + memcpy(array, dest->list, dest_count * size_entry); + ext2fs_free_mem(&dest->list); + + dest->list = array2; + dest->count = src_count + dest_count; + dest->size = size; + dest->sorted = 0; + + return 0; +} + /* * Close a directory block list * diff --git a/lib/ext2fs/ext2fs.h b/lib/ext2fs/ext2fs.h index 18dddc2c..443f93d2 100644 --- a/lib/ext2fs/ext2fs.h +++ b/lib/ext2fs/ext2fs.h @@ -1143,6 +1143,7 @@ extern errcode_t ext2fs_add_dir_block(ext2_dblist dblist, ext2_ino_t ino, blk_t blk, int blockcnt); extern errcode_t ext2fs_add_dir_block2(ext2_dblist dblist, ext2_ino_t ino, blk64_t blk, e2_blkcnt_t blockcnt); +extern errcode_t ext2fs_merge_dblist(ext2_dblist src, ext2_dblist dest); extern void ext2fs_dblist_sort(ext2_dblist dblist, EXT2_QSORT_TYPE (*sortfunc)(const void *, const void *)); -- 2.37.3