1 /*             ----> DO NOT REMOVE THE FOLLOWING NOTICE <----
2  *
3  *                 Copyright (c) 2014-2015 Datalight, Inc.
4  *                     All Rights Reserved Worldwide.
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; use version 2 of the License.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty
12  *  of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License along
16  *  with this program; if not, write to the Free Software Foundation, Inc.,
17  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 /*  Businesses and individuals that for commercial or other reasons cannot
21  *  comply with the terms of the GPLv2 license may obtain a commercial license
22  *  before incorporating Reliance Edge into proprietary software for
23  *  distribution in any form.  Visit http://www.datalight.com/reliance-edge for
24  *  more information.
25  */
26 
27 /** @file
28  */
29 #ifndef REDCOREMACS_H
30 #define REDCOREMACS_H
31 
32 
33 #define BLOCK_NUM_MASTER            ( 0UL ) /* Block number of the master block. */
34 #define BLOCK_NUM_FIRST_METAROOT    ( 1UL ) /* Block number of the first metaroot. */
35 
36 #define BLOCK_SPARSE                ( 0U )
37 
38 #define DINDIR_POINTERS             ( ( INODE_ENTRIES - REDCONF_DIRECT_POINTERS ) - REDCONF_INDIRECT_POINTERS )
39 #define DINDIR_DATA_BLOCKS          ( INDIR_ENTRIES * INDIR_ENTRIES )
40 
41 #define INODE_INDIR_BLOCKS          ( REDCONF_INDIRECT_POINTERS * INDIR_ENTRIES )
42 #define INODE_DINDIR_BLOCKS         ( DINDIR_POINTERS * DINDIR_DATA_BLOCKS )
43 #define INODE_DATA_BLOCKS           ( REDCONF_DIRECT_POINTERS + INODE_INDIR_BLOCKS + INODE_DINDIR_BLOCKS )
44 #define INODE_SIZE_MAX              ( UINT64_SUFFIX( 1 ) * REDCONF_BLOCK_SIZE * INODE_DATA_BLOCKS )
45 
46 
47 /*  First inode number that can be allocated.
48  */
49 #if REDCONF_API_POSIX == 1
50     #define INODE_FIRST_FREE    ( INODE_FIRST_VALID + 1U )
51 #else
52     #define INODE_FIRST_FREE    ( INODE_FIRST_VALID )
53 #endif
54 
55 /** @brief Determine if an inode number is valid.
56  */
57 #define INODE_IS_VALID( INODENUM )    ( ( ( INODENUM ) >= INODE_FIRST_VALID ) && ( ( INODENUM ) < ( INODE_FIRST_VALID + gpRedVolConf->ulInodeCount ) ) )
58 
59 
60 /*  The number of blocks reserved to allow a truncate or delete operation to
61  *  complete when the disk is otherwise full.
62  *
63  *  The more expensive of the two operations is delete, which has to actually
64  *  write to a file data block to remove the directory entry.
65  */
66 #if REDCONF_READ_ONLY == 1
67     #define RESERVED_BLOCKS        0U
68 #elif ( REDCONF_API_POSIX == 1 ) && ( ( REDCONF_API_POSIX_UNLINK == 1 ) || ( REDCONF_API_POSIX_RMDIR == 1 ) )
69     #if DINDIR_POINTERS > 0U
70         #define RESERVED_BLOCKS    3U
71     #elif REDCONF_INDIRECT_POINTERS > 0U
72         #define RESERVED_BLOCKS    2U
73     #else
74         #define RESERVED_BLOCKS    1U
75     #endif
76 #elif ( ( REDCONF_API_POSIX == 1 ) && ( REDCONF_API_POSIX_FTRUNCATE == 1 ) ) || ( ( REDCONF_API_FSE == 1 ) && ( REDCONF_API_FSE_TRUNCATE == 1 ) )
77     #if DINDIR_POINTERS > 0U
78         #define RESERVED_BLOCKS    2U
79     #elif REDCONF_INDIRECT_POINTERS > 0U
80         #define RESERVED_BLOCKS    1U
81     #else
82         #define RESERVED_BLOCKS    0U
83     #endif
84 #else /* if REDCONF_READ_ONLY == 1 */
85     #define RESERVED_BLOCKS        0U
86 #endif /* if REDCONF_READ_ONLY == 1 */
87 
88 
89 #define CRITICAL_ASSERT( EXP )    ( ( EXP ) ? ( void ) 0 : CRITICAL_ERROR() )
90 #define CRITICAL_ERROR()          RedVolCriticalError( __FILE__, __LINE__ )
91 
92 
93 #endif /* ifndef REDCOREMACS_H */
94