• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2012 Paulo Alcantara <pcacjr@zytor.com>
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it would be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write the Free Software Foundation,
15  * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
16  */
17 
18 #ifndef XFS_DIR2_H_
19 #define XFS_DIR2_H_
20 
21 #include <core.h>
22 #include <fs.h>
23 
24 #include "xfs.h"
25 
26 const void *xfs_dir2_dirblks_get_cached(struct fs_info *fs, block_t startblock,
27 					xfs_filblks_t c);
28 void xfs_dir2_dirblks_flush_cache(void);
29 
30 uint32_t xfs_dir2_da_hashname(const uint8_t *name, int namelen);
31 
32 block_t xfs_dir2_get_right_blk(struct fs_info *fs, xfs_dinode_t *core,
33 			       block_t fsblkno, int *error);
34 
35 struct inode *xfs_dir2_local_find_entry(const char *dname, struct inode *parent,
36 					xfs_dinode_t *core);
37 struct inode *xfs_dir2_block_find_entry(const char *dname, struct inode *parent,
38 					xfs_dinode_t *core);
39 struct inode *xfs_dir2_leaf_find_entry(const char *dname, struct inode *parent,
40 				       xfs_dinode_t *core);
41 struct inode *xfs_dir2_node_find_entry(const char *dname, struct inode *parent,
42 				       xfs_dinode_t *core);
43 
xfs_dir2_isleaf(struct fs_info * fs,xfs_dinode_t * dip)44 static inline bool xfs_dir2_isleaf(struct fs_info *fs, xfs_dinode_t *dip)
45 {
46     uint64_t last = 0;
47     xfs_bmbt_irec_t irec;
48 
49     bmbt_irec_get(&irec, ((xfs_bmbt_rec_t *)&dip->di_literal_area[0]) +
50 		         be32_to_cpu(dip->di_nextents) - 1);
51     last = irec.br_startoff + irec.br_blockcount;
52 
53     return (last == XFS_INFO(fs)->dirleafblk + (1 << XFS_INFO(fs)->dirblklog));
54 }
55 
xfs_dir2_entry_name_cmp(uint8_t * start,uint8_t * end,const char * name)56 static inline int xfs_dir2_entry_name_cmp(uint8_t *start, uint8_t *end,
57 					  const char *name)
58 {
59     if (!name || (strlen(name) != end - start))
60 	return -1;
61 
62     while (start < end)
63 	if (*start++ != *name++)
64 	    return -1;
65 
66     return 0;
67 }
68 
69 #endif /* XFS_DIR2_H_ */
70