blob: 8ed77ae2acfe10a19819caad79d78a4f3f53e350 [file] [log] [blame]
"Robert P. J. Day"63fc1a92006-07-02 19:47:05 +00001/* vi: set sw=4 ts=4: */
Mike Frysinger1fd98e02005-05-09 22:10:42 +00002/*
3 * valid_blk.c --- does the inode have valid blocks?
4 *
5 * Copyright 1997 by Theodore Ts'o
Tim Rikerc1ef7bd2006-01-25 00:08:53 +00006 *
Mike Frysinger1fd98e02005-05-09 22:10:42 +00007 * %Begin-Header%
8 * This file may be redistributed under the terms of the GNU Public
9 * License.
10 * %End-Header%
Tim Rikerc1ef7bd2006-01-25 00:08:53 +000011 *
Mike Frysinger1fd98e02005-05-09 22:10:42 +000012 */
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 */
28int 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 Rikerc1ef7bd2006-01-25 00:08:53 +000037
Mike Frysinger1fd98e02005-05-09 22:10:42 +000038 /*
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}