| Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 1 | /* |
| 2 | * valid_blk.c --- does the inode have valid blocks? |
| 3 | * |
| 4 | * Copyright 1997 by Theodore Ts'o |
| Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 5 | * |
| Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 6 | * %Begin-Header% |
| Theodore Ts'o | 543547a | 2010-05-17 21:31:56 -0400 | [diff] [blame] | 7 | * This file may be redistributed under the terms of the GNU Library |
| 8 | * General Public License, version 2. |
| Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 9 | * %End-Header% |
| Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | #include <stdio.h> |
| Theodore Ts'o | 4cbe8af | 1997-08-10 23:07:40 +0000 | [diff] [blame] | 13 | #if HAVE_UNISTD_H |
| Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 14 | #include <unistd.h> |
| Theodore Ts'o | 4cbe8af | 1997-08-10 23:07:40 +0000 | [diff] [blame] | 15 | #endif |
| Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 16 | #include <string.h> |
| 17 | #include <time.h> |
| Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 18 | |
| Theodore Ts'o | b5abe6f | 1998-01-19 14:47:53 +0000 | [diff] [blame] | 19 | #include "ext2_fs.h" |
| Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 20 | #include "ext2fs.h" |
| 21 | |
| 22 | /* |
| 23 | * This function returns 1 if the inode's block entries actually |
| 24 | * contain block entries. |
| 25 | */ |
| JP Abgrall | e0ed740 | 2014-03-19 19:08:39 -0700 | [diff] [blame^] | 26 | int ext2fs_inode_has_valid_blocks2(ext2_filsys fs, struct ext2_inode *inode) |
| Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 27 | { |
| 28 | /* |
| 29 | * Only directories, regular files, and some symbolic links |
| 30 | * have valid block entries. |
| 31 | */ |
| 32 | if (!LINUX_S_ISDIR(inode->i_mode) && !LINUX_S_ISREG(inode->i_mode) && |
| 33 | !LINUX_S_ISLNK(inode->i_mode)) |
| 34 | return 0; |
| Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 35 | |
| Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 36 | /* |
| 37 | * If the symbolic link is a "fast symlink", then the symlink |
| 38 | * target is stored in the block entries. |
| 39 | */ |
| Theodore Ts'o | 0684a4f | 2002-08-17 10:19:44 -0400 | [diff] [blame] | 40 | if (LINUX_S_ISLNK (inode->i_mode)) { |
| JP Abgrall | e0ed740 | 2014-03-19 19:08:39 -0700 | [diff] [blame^] | 41 | if (ext2fs_file_acl_block(fs, inode) == 0) { |
| Theodore Ts'o | 0684a4f | 2002-08-17 10:19:44 -0400 | [diff] [blame] | 42 | /* With no EA block, we can rely on i_blocks */ |
| 43 | if (inode->i_blocks == 0) |
| 44 | return 0; |
| 45 | } else { |
| 46 | /* With an EA block, life gets more tricky */ |
| 47 | if (inode->i_size >= EXT2_N_BLOCKS*4) |
| 48 | return 1; /* definitely using i_block[] */ |
| Theodore Ts'o | ee50412 | 2002-08-20 01:14:30 -0400 | [diff] [blame] | 49 | if (inode->i_size > 4 && inode->i_block[1] == 0) |
| 50 | return 1; /* definitely using i_block[] */ |
| Theodore Ts'o | 0684a4f | 2002-08-17 10:19:44 -0400 | [diff] [blame] | 51 | return 0; /* Probably a fast symlink */ |
| 52 | } |
| 53 | } |
| Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 54 | return 1; |
| 55 | } |
| JP Abgrall | e0ed740 | 2014-03-19 19:08:39 -0700 | [diff] [blame^] | 56 | |
| 57 | int ext2fs_inode_has_valid_blocks(struct ext2_inode *inode) |
| 58 | { |
| 59 | return ext2fs_inode_has_valid_blocks2(NULL, inode); |
| 60 | } |