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 |
| 5 | * |
| 6 | * %Begin-Header% |
| 7 | * This file may be redistributed under the terms of the GNU Public |
| 8 | * License. |
| 9 | * %End-Header% |
| 10 | * |
| 11 | */ |
| 12 | |
| 13 | #include <stdio.h> |
Theodore Ts'o | 4cbe8af | 1997-08-10 23:07:40 +0000 | [diff] [blame] | 14 | #if HAVE_UNISTD_H |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 15 | #include <unistd.h> |
Theodore Ts'o | 4cbe8af | 1997-08-10 23:07:40 +0000 | [diff] [blame] | 16 | #endif |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 17 | #include <string.h> |
| 18 | #include <time.h> |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 19 | |
Theodore Ts'o | b5abe6f | 1998-01-19 14:47:53 +0000 | [diff] [blame] | 20 | #if EXT2_FLAT_INCLUDES |
| 21 | #include "ext2_fs.h" |
| 22 | #else |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 23 | #include <linux/ext2_fs.h> |
Theodore Ts'o | b5abe6f | 1998-01-19 14:47:53 +0000 | [diff] [blame] | 24 | #endif |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 25 | |
| 26 | #include "ext2fs.h" |
| 27 | |
| 28 | /* |
| 29 | * This function returns 1 if the inode's block entries actually |
| 30 | * contain block entries. |
| 31 | */ |
| 32 | int ext2fs_inode_has_valid_blocks(struct ext2_inode *inode) |
| 33 | { |
| 34 | /* |
| 35 | * Only directories, regular files, and some symbolic links |
| 36 | * have valid block entries. |
| 37 | */ |
| 38 | if (!LINUX_S_ISDIR(inode->i_mode) && !LINUX_S_ISREG(inode->i_mode) && |
| 39 | !LINUX_S_ISLNK(inode->i_mode)) |
| 40 | return 0; |
| 41 | |
| 42 | /* |
| 43 | * If the symbolic link is a "fast symlink", then the symlink |
| 44 | * target is stored in the block entries. |
| 45 | */ |
| 46 | if (LINUX_S_ISLNK (inode->i_mode) && inode->i_blocks == 0 && |
| 47 | inode->i_size < EXT2_N_BLOCKS * sizeof (unsigned long)) |
| 48 | return 0; |
| 49 | |
| 50 | return 1; |
| 51 | } |