"Robert P. J. Day" | 63fc1a9 | 2006-07-02 19:47:05 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
Mike Frysinger | 1fd98e0 | 2005-05-09 22:10:42 +0000 | [diff] [blame] | 2 | /* |
| 3 | * valid_blk.c --- does the inode have valid blocks? |
| 4 | * |
| 5 | * Copyright 1997 by Theodore Ts'o |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 6 | * |
Mike Frysinger | 1fd98e0 | 2005-05-09 22:10:42 +0000 | [diff] [blame] | 7 | * %Begin-Header% |
| 8 | * This file may be redistributed under the terms of the GNU Public |
| 9 | * License. |
| 10 | * %End-Header% |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 11 | * |
Mike Frysinger | 1fd98e0 | 2005-05-09 22:10:42 +0000 | [diff] [blame] | 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; |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 37 | |
Mike Frysinger | 1fd98e0 | 2005-05-09 22:10:42 +0000 | [diff] [blame] | 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 | } |