source: mainline/uspace/lib/ext2/libext2_inode.c@ 5352d72

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 5352d72 was 5352d72, checked in by Martin Sucha <sucha14@…>, 14 years ago

Added support for reading and displaying inode contents to ext2info

  • Property mode set to 100644
File size: 3.9 KB
RevLine 
[ce13577]1/*
2 * Copyright (c) 2011 Martin Sucha
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup libext2
30 * @{
31 */
32/**
33 * @file
34 */
35
36#include "libext2.h"
37#include "libext2_inode.h"
38#include <byteorder.h>
39
[5352d72]40/**
41 * Get mode stored in the inode
42 *
43 * @param inode pointer to inode
44 */
45inline uint16_t ext2_inode_get_mode(ext2_inode_t *inode)
46{
47 return uint16_t_le2host(inode->mode);
48}
49
50/**
51 * Get uid this inode is belonging to
52 *
53 * @param inode pointer to inode
54 */
55inline uint32_t ext2_inode_get_user_id(ext2_inode_t *inode)
56{
57 // TODO: use additional OS specific bits
58 return uint16_t_le2host(inode->user_id);
59}
60
61/**
62 * Get size of file
63 *
64 * @param inode pointer to inode
65 */
66inline uint32_t ext2_inode_get_size(ext2_inode_t *inode)
67{
68 // TODO: Directory ACLS!
69 return uint16_t_le2host(inode->size);
70}
71
72/**
73 * Get gid this inode belongs to
74 *
75 * @param inode pointer to inode
76 */
77inline uint32_t ext2_inode_get_group_id(ext2_inode_t *inode)
78{
79 // TODO: use additional OS specific bits
80 return uint16_t_le2host(inode->group_id);
81}
82
83/**
84 * Get usage count (i.e. hard link count)
85 * A value of 1 is common, while 0 means that the inode should be freed
86 *
87 * @param inode pointer to inode
88 */
89inline uint16_t ext2_inode_get_usage_count(ext2_inode_t *inode)
90{
91 return uint16_t_le2host(inode->usage_count);
92}
93
94/**
95 * Get size of inode in 512 byte blocks
96 * TODO: clarify this
97 *
98 * @param inode pointer to inode
99 */
100inline uint32_t ext2_inode_get_reserved_512_blocks(ext2_inode_t *inode)
101{
102 return uint32_t_le2host(inode->reserved_512_blocks);
103}
104
105/**
106 * Get inode flags
107 *
108 * @param inode pointer to inode
109 */
110
111inline uint32_t ext2_inode_get_flags(ext2_inode_t *inode) {
112 return uint32_t_le2host(inode->flags);
113}
114
115/**
116 * Get direct block ID
117 *
118 * @param inode pointer to inode
119 * @param idx Index to block. Valid values are 0 <= idx < 12
120 */
121inline uint32_t ext2_inode_get_direct_block(ext2_inode_t *inode, uint8_t idx)
122{
123 return uint32_t_le2host(inode->direct_blocks[idx]);
124}
125
126/**
127 * Get indirect block ID
128 *
129 * @param inode pointer to inode
130 */
131inline uint32_t ext2_inode_get_single_indirect_block(ext2_inode_t *inode)
132{
133 return uint32_t_le2host(inode->single_indirect_block);
134}
135
136/**
137 * Get double indirect block ID
138 *
139 * @param inode pointer to inode
140 */
141inline uint32_t ext2_inode_get_double_indirect_block(ext2_inode_t *inode)
142{
143 return uint32_t_le2host(inode->double_indirect_block);
144}
145
146/**
147 * Get triple indirect block ID
148 *
149 * @param inode pointer to inode
150 */
151inline uint32_t ext2_inode_get_triple_indirect_block(ext2_inode_t *inode)
152{
153 return uint32_t_le2host(inode->triple_indirect_block);
154}
[ce13577]155
156
157
158/** @}
159 */
Note: See TracBrowser for help on using the repository browser.