]> git.ipfire.org Git - thirdparty/e2fsprogs.git/blame - lib/ext2fs/dirblock.c
Merge remote-tracking branch 'josch/libarchive' into josch-libarchive
[thirdparty/e2fsprogs.git] / lib / ext2fs / dirblock.c
CommitLineData
50e1e10f
TT
1/*
2 * dirblock.c --- directory block routines.
efc6f628 3 *
21c84b71
TT
4 * Copyright (C) 1995, 1996 Theodore Ts'o.
5 *
6 * %Begin-Header%
543547a5
TT
7 * This file may be redistributed under the terms of the GNU Library
8 * General Public License, version 2.
21c84b71 9 * %End-Header%
50e1e10f
TT
10 */
11
d1154eb4 12#include "config.h"
50e1e10f 13#include <stdio.h>
4cbe8af4 14#if HAVE_UNISTD_H
50e1e10f 15#include <unistd.h>
4cbe8af4 16#endif
21c84b71 17#include <string.h>
50e1e10f 18#include <time.h>
50e1e10f 19
b5abe6fa 20#include "ext2_fs.h"
50e1e10f
TT
21#include "ext2fs.h"
22
81683c6a
DW
23errcode_t ext2fs_read_dir_block4(ext2_filsys fs, blk64_t block,
24 void *buf, int flags EXT2FS_ATTR((unused)),
25 ext2_ino_t ino)
50e1e10f
TT
26{
27 errcode_t retval;
81683c6a 28 int corrupt = 0;
50e1e10f 29
57e2467d 30 retval = io_channel_read_blk64(fs->io, block, 1, buf);
50e1e10f
TT
31 if (retval)
32 return retval;
126a291c 33
81683c6a
DW
34 if (!(fs->flags & EXT2_FLAG_IGNORE_CSUM_ERRORS) &&
35 !ext2fs_dir_block_csum_verify(fs, ino,
36 (struct ext2_dir_entry *)buf))
37 corrupt = 1;
38
f9190c8a 39#ifdef WORDS_BIGENDIAN
81683c6a 40 retval = ext2fs_dirent_swab_in(fs, buf, flags);
5df55d7f 41#endif
81683c6a
DW
42 if (!retval && corrupt)
43 retval = EXT2_ET_DIR_CSUM_INVALID;
1cca4d60 44 return retval;
50e1e10f
TT
45}
46
81683c6a
DW
47errcode_t ext2fs_read_dir_block3(ext2_filsys fs, blk64_t block,
48 void *buf, int flags EXT2FS_ATTR((unused)))
49{
50 return ext2fs_read_dir_block4(fs, block, buf, flags, 0);
51}
52
57e2467d
JS
53errcode_t ext2fs_read_dir_block2(ext2_filsys fs, blk_t block,
54 void *buf, int flags EXT2FS_ATTR((unused)))
55{
56 return ext2fs_read_dir_block3(fs, block, buf, flags);
57}
58
f9190c8a
TT
59errcode_t ext2fs_read_dir_block(ext2_filsys fs, blk_t block,
60 void *buf)
50e1e10f 61{
57e2467d 62 return ext2fs_read_dir_block3(fs, block, buf, 0);
f9190c8a
TT
63}
64
65
81683c6a
DW
66errcode_t ext2fs_write_dir_block4(ext2_filsys fs, blk64_t block,
67 void *inbuf, int flags EXT2FS_ATTR((unused)),
68 ext2_ino_t ino)
f9190c8a 69{
50e1e10f 70 errcode_t retval;
81683c6a 71 char *buf = inbuf;
50e1e10f 72
81683c6a 73#ifdef WORDS_BIGENDIAN
c4e3d3f3 74 retval = ext2fs_get_mem(fs->blocksize, &buf);
f9190c8a
TT
75 if (retval)
76 return retval;
77 memcpy(buf, inbuf, fs->blocksize);
81683c6a
DW
78 retval = ext2fs_dirent_swab_out(fs, buf, flags);
79 if (retval)
80 return retval;
81#endif
82 retval = ext2fs_dir_block_csum_set(fs, ino,
83 (struct ext2_dir_entry *)buf);
84 if (retval)
85 goto out;
86
57e2467d 87 retval = io_channel_write_blk64(fs->io, block, 1, buf);
81683c6a
DW
88
89out:
90#ifdef WORDS_BIGENDIAN
c4e3d3f3 91 ext2fs_free_mem(&buf);
f9190c8a 92#endif
81683c6a
DW
93 return retval;
94}
95
96errcode_t ext2fs_write_dir_block3(ext2_filsys fs, blk64_t block,
97 void *inbuf, int flags EXT2FS_ATTR((unused)))
98{
99 return ext2fs_write_dir_block4(fs, block, inbuf, flags, 0);
50e1e10f
TT
100}
101
57e2467d
JS
102errcode_t ext2fs_write_dir_block2(ext2_filsys fs, blk_t block,
103 void *inbuf, int flags EXT2FS_ATTR((unused)))
104{
105 return ext2fs_write_dir_block3(fs, block, inbuf, flags);
106}
50e1e10f 107
f9190c8a
TT
108errcode_t ext2fs_write_dir_block(ext2_filsys fs, blk_t block,
109 void *inbuf)
110{
57e2467d 111 return ext2fs_write_dir_block3(fs, block, inbuf, 0);
f9190c8a
TT
112}
113