blob: 8ed77ae2acfe10a19819caad79d78a4f3f53e350
1 | /* vi: set sw=4 ts=4: */ |
2 | /* |
3 | * valid_blk.c --- does the inode have valid blocks? |
4 | * |
5 | * Copyright 1997 by Theodore Ts'o |
6 | * |
7 | * %Begin-Header% |
8 | * This file may be redistributed under the terms of the GNU Public |
9 | * License. |
10 | * %End-Header% |
11 | * |
12 | */ |
13 | |
14 | #include <stdio.h> |
15 | #if HAVE_UNISTD_H |
16 | #include <unistd.h> |
17 | #endif |
18 | #include <string.h> |
19 | #include <time.h> |
20 | |
21 | #include "ext2_fs.h" |
22 | #include "ext2fs.h" |
23 | |
24 | /* |
25 | * This function returns 1 if the inode's block entries actually |
26 | * contain block entries. |
27 | */ |
28 | int ext2fs_inode_has_valid_blocks(struct ext2_inode *inode) |
29 | { |
30 | /* |
31 | * Only directories, regular files, and some symbolic links |
32 | * have valid block entries. |
33 | */ |
34 | if (!LINUX_S_ISDIR(inode->i_mode) && !LINUX_S_ISREG(inode->i_mode) && |
35 | !LINUX_S_ISLNK(inode->i_mode)) |
36 | return 0; |
37 | |
38 | /* |
39 | * If the symbolic link is a "fast symlink", then the symlink |
40 | * target is stored in the block entries. |
41 | */ |
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 */ |
54 | } |
55 | } |
56 | return 1; |
57 | } |
58 |