Home | History | Annotate | Download | only in ext2fs
      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 Library
      8  * General Public License, version 2.
      9  * %End-Header%
     10  */
     11 
     12 #include <stdio.h>
     13 #if HAVE_UNISTD_H
     14 #include <unistd.h>
     15 #endif
     16 #include <string.h>
     17 #include <time.h>
     18 
     19 #include "ext2_fs.h"
     20 #include "ext2fs.h"
     21 
     22 /*
     23  * This function returns 1 if the inode's block entries actually
     24  * contain block entries.
     25  */
     26 int ext2fs_inode_has_valid_blocks(struct ext2_inode *inode)
     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;
     35 
     36 	/*
     37 	 * If the symbolic link is a "fast symlink", then the symlink
     38 	 * target is stored in the block entries.
     39 	 */
     40 	if (LINUX_S_ISLNK (inode->i_mode)) {
     41 		if (inode->i_file_acl == 0) {
     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[] */
     49 			if (inode->i_size > 4 && inode->i_block[1] == 0)
     50 				return 1; /* definitely using i_block[] */
     51 			return 0; /* Probably a fast symlink */
     52 		}
     53 	}
     54 	return 1;
     55 }
     56