From patchwork Tue Jul 31 11:48:25 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zheng Liu X-Patchwork-Id: 174249 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 72D302C0083 for ; Tue, 31 Jul 2012 21:40:50 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756039Ab2GaLkr (ORCPT ); Tue, 31 Jul 2012 07:40:47 -0400 Received: from mail-pb0-f46.google.com ([209.85.160.46]:53943 "EHLO mail-pb0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756028Ab2GaLkq (ORCPT ); Tue, 31 Jul 2012 07:40:46 -0400 Received: by mail-pb0-f46.google.com with SMTP id rp8so11540999pbb.19 for ; Tue, 31 Jul 2012 04:40:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=wVYucn8PkYoj7gAj6BUNDa9EwpEG+k+lGvLvC5n3dSk=; b=zjiNMrD66yNwYYoFDrlxL/RV4+YCeef9m9B9pY6nen6S6iIdZiUoWDkXMgB+AcO1zf eI5FnE6Lu8vtRcrXzzEqerchrr8gzGf+IhCMdIQq70XFYkvsF10o83dYmp9g/xMPqJWV 82bjVKqS7IABXO+NDR2o7IMph1terOSYT6l0x8KmY8qHu5ABg8BF1v58xtQfZ5yRW9CU kF7/BS/anJMzc8kBZjEP377+mdcNkT+Yzn7Ku/+RkuzyyzujDKQyxulOedDJzedgZokr rwt8X+by4lh4hz53fk8jX6+ilzt9jJpQFfAODvkh+4idZR3nx9IXBzWy/bn/+CgHGsj2 hfMA== Received: by 10.68.213.234 with SMTP id nv10mr42844799pbc.56.1343734845803; Tue, 31 Jul 2012 04:40:45 -0700 (PDT) Received: from localhost.localdomain ([182.92.247.2]) by mx.google.com with ESMTPS id oo6sm135950pbc.22.2012.07.31.04.40.44 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 31 Jul 2012 04:40:45 -0700 (PDT) From: Zheng Liu To: linux-ext4@vger.kernel.org Cc: Zheng Liu Subject: [PATCH 32/36 v4] libext2fs: add read/write inline data functions Date: Tue, 31 Jul 2012 19:48:25 +0800 Message-Id: <1343735309-30579-33-git-send-email-wenqing.lz@taobao.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1343735309-30579-1-git-send-email-wenqing.lz@taobao.com> References: <1343735309-30579-1-git-send-email-wenqing.lz@taobao.com> Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org From: Zheng Liu Add read/write inline data functions for pass2. Signed-off-by: Zheng Liu --- lib/ext2fs/dirblock.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++ lib/ext2fs/ext2fs.h | 7 +++++ 2 files changed, 69 insertions(+), 0 deletions(-) diff --git a/lib/ext2fs/dirblock.c b/lib/ext2fs/dirblock.c index 54b2777..77e8f39 100644 --- a/lib/ext2fs/dirblock.c +++ b/lib/ext2fs/dirblock.c @@ -62,6 +62,45 @@ errcode_t ext2fs_read_dir_block(ext2_filsys fs, blk_t block, return ext2fs_read_dir_block3(fs, block, buf, 0); } +errcode_t ext2fs_read_dir_inline_data(ext2_filsys fs, ext2_ino_t ino, void *buf) +{ + struct ext2_inode_large *inode; + struct inline_data idata; + + ext2fs_get_mem(EXT2_INODE_SIZE(fs->super), &inode); + ext2fs_read_inode_full(fs, ino, (void *)inode, EXT2_INODE_SIZE(fs->super)); + + if (!(inode->i_flags & EXT4_INLINE_DATA_FL)) + return -1; + + memcpy(buf, inode->i_block, EXT4_MIN_INLINE_DATA_SIZE); + + ext2fs_free_mem(&inode); + return 0; +} + +errcode_t ext2fs_read_dir_inline_data_more(ext2_filsys fs, ext2_ino_t ino, void *buf) +{ + struct ext2_inode_large *inode; + struct inline_data idata; + + ext2fs_get_mem(EXT2_INODE_SIZE(fs->super), &inode); + ext2fs_read_inode_full(fs, ino, (void *)inode, EXT2_INODE_SIZE(fs->super)); + + if (!(inode->i_flags & EXT4_INLINE_DATA_FL)) + return -1; + + ext2fs_iget_extra_inode(fs, inode, &idata); + if (idata.inline_size == EXT4_MIN_INLINE_DATA_SIZE) + return 0; + + memcpy(buf + EXT4_MIN_INLINE_DATA_SIZE, + ext2fs_get_inline_xattr_pos(inode, &idata), + idata.inline_size - EXT4_MIN_INLINE_DATA_SIZE); + + ext2fs_free_mem(&inode); + return 0; +} errcode_t ext2fs_write_dir_block4(ext2_filsys fs, blk64_t block, void *inbuf, int flags EXT2FS_ATTR((unused)), @@ -111,3 +150,26 @@ errcode_t ext2fs_write_dir_block(ext2_filsys fs, blk_t block, return ext2fs_write_dir_block3(fs, block, inbuf, 0); } +errcode_t ext2fs_write_dir_inline_data(ext2_filsys fs, ext2_ino_t ino, void *buf) +{ + struct ext2_inode_large *inode; + struct inline_data idata; + + ext2fs_get_mem(EXT2_INODE_SIZE(fs->super), &inode); + ext2fs_read_inode_full(fs, ino, (void *)inode, EXT2_INODE_SIZE(fs->super)); + + memcpy(inode->i_block, buf, EXT4_MIN_INLINE_DATA_SIZE); + + ext2fs_iget_extra_inode(fs, inode, &idata); + if (idata.inline_size == EXT4_MIN_INLINE_DATA_SIZE) + goto out; + + memcpy(ext2fs_get_inline_xattr_pos(inode, &idata), + buf + EXT4_MIN_INLINE_DATA_SIZE, + idata.inline_size - EXT4_MIN_INLINE_DATA_SIZE); + +out: + ext2fs_write_inode_full(fs, ino, (void *)inode, EXT2_INODE_SIZE(fs->super)); + ext2fs_free_mem(&inode); + return 0; +} diff --git a/lib/ext2fs/ext2fs.h b/lib/ext2fs/ext2fs.h index bacc14d..0bd5023 100644 --- a/lib/ext2fs/ext2fs.h +++ b/lib/ext2fs/ext2fs.h @@ -1060,6 +1060,11 @@ extern errcode_t ext2fs_read_dir_block3(ext2_filsys fs, blk64_t block, void *buf, int flags); extern errcode_t ext2fs_read_dir_block4(ext2_filsys fs, blk64_t block, void *buf, int flags, ext2_ino_t ino); +extern errcode_t ext2fs_read_dir_inline_data(ext2_filsys fs, ext2_ino_t ino, + void *buf); +extern errcode_t ext2fs_read_dir_inline_data_more(ext2_filsys fs, + ext2_ino_t ino, + void *buf); extern errcode_t ext2fs_write_dir_block(ext2_filsys fs, blk_t block, void *buf); extern errcode_t ext2fs_write_dir_block2(ext2_filsys fs, blk_t block, @@ -1068,6 +1073,8 @@ extern errcode_t ext2fs_write_dir_block3(ext2_filsys fs, blk64_t block, void *buf, int flags); extern errcode_t ext2fs_write_dir_block4(ext2_filsys fs, blk64_t block, void *buf, int flags, ext2_ino_t ino); +extern errcode_t ext2fs_write_dir_inline_data(ext2_filsys fs, ext2_ino_t ino, + void *buf); /* dirhash.c */ extern errcode_t ext2fs_dirhash(int version, const char *name, int len,