2 * ext_attr.c --- extended attribute blocks
4 * Copyright (C) 2001 Andreas Gruenbacher, <a.gruenbacher@computer.org>
6 * Copyright (C) 2002 Theodore Ts'o.
9 * This file may be redistributed under the terms of the GNU Public
20 #include "ext2_ext_attr.h"
23 errcode_t ext2fs_read_ext_attr(ext2_filsys fs, blk_t block, void *buf)
27 retval = io_channel_read_blk(fs->io, block, 1, buf);
31 if ((fs->flags & (EXT2_FLAG_SWAP_BYTES|
32 EXT2_FLAG_SWAP_BYTES_READ)) != 0)
33 ext2fs_swap_ext_attr(buf, buf, fs->blocksize, 1);
38 errcode_t ext2fs_write_ext_attr(ext2_filsys fs, blk_t block, void *inbuf)
45 if ((fs->flags & EXT2_FLAG_SWAP_BYTES) ||
46 (fs->flags & EXT2_FLAG_SWAP_BYTES_WRITE)) {
47 retval = ext2fs_get_mem(fs->blocksize, &buf);
51 ext2fs_swap_ext_attr(buf, inbuf, fs->blocksize, 1);
54 write_buf = (char *) inbuf;
55 retval = io_channel_write_blk(fs->io, block, 1, write_buf);
57 ext2fs_free_mem(&buf);
59 ext2fs_mark_changed(fs);
64 * This function adjusts the reference count of the EA block.
66 errcode_t ext2fs_adjust_ea_refcount(ext2_filsys fs, blk_t blk,
67 char *block_buf, int adjust,
71 struct ext2_ext_attr_header *header;
74 if ((blk >= fs->super->s_blocks_count) ||
75 (blk < fs->super->s_first_data_block))
76 return EXT2_ET_BAD_EA_BLOCK_NUM;
79 retval = ext2fs_get_mem(fs->blocksize, &buf);
85 retval = ext2fs_read_ext_attr(fs, blk, block_buf);
89 header = (struct ext2_ext_attr_header *) block_buf;
90 header->h_refcount += adjust;
92 *newcount = header->h_refcount;
94 retval = ext2fs_write_ext_attr(fs, blk, block_buf);
100 ext2fs_free_mem(&buf);