blob: 3a0cb3ebe945ce4c3c487707948415768ff79828 [file] [log] [blame]
Theodore Ts'o19c78dc1997-04-29 16:17:09 +00001/*
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>
14#include <unistd.h>
15#include <stdlib.h>
16#include <string.h>
17#include <time.h>
18#ifdef HAVE_ERRNO_H
19#include <errno.h>
20#endif
21
22#include <linux/ext2_fs.h>
23
24#include "ext2fs.h"
25
26/*
27 * This function returns 1 if the inode's block entries actually
28 * contain block entries.
29 */
30int ext2fs_inode_has_valid_blocks(struct ext2_inode *inode)
31{
32 /*
33 * Only directories, regular files, and some symbolic links
34 * have valid block entries.
35 */
36 if (!LINUX_S_ISDIR(inode->i_mode) && !LINUX_S_ISREG(inode->i_mode) &&
37 !LINUX_S_ISLNK(inode->i_mode))
38 return 0;
39
40 /*
41 * If the symbolic link is a "fast symlink", then the symlink
42 * target is stored in the block entries.
43 */
44 if (LINUX_S_ISLNK (inode->i_mode) && inode->i_blocks == 0 &&
45 inode->i_size < EXT2_N_BLOCKS * sizeof (unsigned long))
46 return 0;
47
48 return 1;
49}