source: MondoRescue/branches/stable/mindi-busybox/e2fsprogs/ext2fs/ext_attr.c@ 821

Last change on this file since 821 was 821, checked in by Bruno Cornec, 18 years ago

Addition of busybox 1.2.1 as a mindi-busybox new package
This should avoid delivering binary files in mindi not built there (Fedora and Debian are quite serious about that)

File size: 2.2 KB
Line 
1/*
2 * ext_attr.c --- extended attribute blocks
3 *
4 * Copyright (C) 2001 Andreas Gruenbacher, <a.gruenbacher@computer.org>
5 *
6 * Copyright (C) 2002 Theodore Ts'o.
7 *
8 * %Begin-Header%
9 * This file may be redistributed under the terms of the GNU Public
10 * License.
11 * %End-Header%
12 */
13
14#include <stdio.h>
15#include <unistd.h>
16#include <string.h>
17#include <time.h>
18
19#include "ext2_fs.h"
20#include "ext2_ext_attr.h"
21#include "ext2fs.h"
22
23errcode_t ext2fs_read_ext_attr(ext2_filsys fs, blk_t block, void *buf)
24{
25 errcode_t retval;
26
27 retval = io_channel_read_blk(fs->io, block, 1, buf);
28 if (retval)
29 return retval;
30#if BB_BIG_ENDIAN
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);
34#endif
35 return 0;
36}
37
38errcode_t ext2fs_write_ext_attr(ext2_filsys fs, blk_t block, void *inbuf)
39{
40 errcode_t retval;
41 char *write_buf;
42 char *buf = NULL;
43
44 if (BB_BIG_ENDIAN && ((fs->flags & EXT2_FLAG_SWAP_BYTES) ||
45 (fs->flags & EXT2_FLAG_SWAP_BYTES_WRITE))) {
46 retval = ext2fs_get_mem(fs->blocksize, &buf);
47 if (retval)
48 return retval;
49 write_buf = buf;
50 ext2fs_swap_ext_attr(buf, inbuf, fs->blocksize, 1);
51 } else
52 write_buf = (char *) inbuf;
53 retval = io_channel_write_blk(fs->io, block, 1, write_buf);
54 if (buf)
55 ext2fs_free_mem(&buf);
56 if (!retval)
57 ext2fs_mark_changed(fs);
58 return retval;
59}
60
61/*
62 * This function adjusts the reference count of the EA block.
63 */
64errcode_t ext2fs_adjust_ea_refcount(ext2_filsys fs, blk_t blk,
65 char *block_buf, int adjust,
66 __u32 *newcount)
67{
68 errcode_t retval;
69 struct ext2_ext_attr_header *header;
70 char *buf = 0;
71
72 if ((blk >= fs->super->s_blocks_count) ||
73 (blk < fs->super->s_first_data_block))
74 return EXT2_ET_BAD_EA_BLOCK_NUM;
75
76 if (!block_buf) {
77 retval = ext2fs_get_mem(fs->blocksize, &buf);
78 if (retval)
79 return retval;
80 block_buf = buf;
81 }
82
83 retval = ext2fs_read_ext_attr(fs, blk, block_buf);
84 if (retval)
85 goto errout;
86
87 header = (struct ext2_ext_attr_header *) block_buf;
88 header->h_refcount += adjust;
89 if (newcount)
90 *newcount = header->h_refcount;
91
92 retval = ext2fs_write_ext_attr(fs, blk, block_buf);
93 if (retval)
94 goto errout;
95
96errout:
97 if (buf)
98 ext2fs_free_mem(&buf);
99 return retval;
100}
Note: See TracBrowser for help on using the repository browser.