Changes for kernel and Busybox
[tomato.git] / release / src / router / busybox / e2fsprogs / ext2fs / valid_blk.c
blob8ed77ae2acfe10a19819caad79d78a4f3f53e350
1 /* vi: set sw=4 ts=4: */
2 /*
3 * valid_blk.c --- does the inode have valid blocks?
5 * Copyright 1997 by Theodore Ts'o
7 * %Begin-Header%
8 * This file may be redistributed under the terms of the GNU Public
9 * License.
10 * %End-Header%
14 #include <stdio.h>
15 #if HAVE_UNISTD_H
16 #include <unistd.h>
17 #endif
18 #include <string.h>
19 #include <time.h>
21 #include "ext2_fs.h"
22 #include "ext2fs.h"
25 * This function returns 1 if the inode's block entries actually
26 * contain block entries.
28 int ext2fs_inode_has_valid_blocks(struct ext2_inode *inode)
31 * Only directories, regular files, and some symbolic links
32 * have valid block entries.
34 if (!LINUX_S_ISDIR(inode->i_mode) && !LINUX_S_ISREG(inode->i_mode) &&
35 !LINUX_S_ISLNK(inode->i_mode))
36 return 0;
39 * If the symbolic link is a "fast symlink", then the symlink
40 * target is stored in the block entries.
42 if (LINUX_S_ISLNK (inode->i_mode)) {
43 if (inode->i_file_acl == 0) {
44 /* With no EA block, we can rely on i_blocks */
45 if (inode->i_blocks == 0)
46 return 0;
47 } else {
48 /* With an EA block, life gets more tricky */
49 if (inode->i_size >= EXT2_N_BLOCKS*4)
50 return 1; /* definitely using i_block[] */
51 if (inode->i_size > 4 && inode->i_block[1] == 0)
52 return 1; /* definitely using i_block[] */
53 return 0; /* Probably a fast symlink */
56 return 1;