1 | /* |
---|
2 | * IMFS_stat |
---|
3 | * |
---|
4 | * This routine provides a stat for the IMFS file system. |
---|
5 | * |
---|
6 | * COPYRIGHT (c) 1989-1999. |
---|
7 | * On-Line Applications Research Corporation (OAR). |
---|
8 | * |
---|
9 | * Modifications to support reference counting in the file system are |
---|
10 | * Copyright (c) 2012 embedded brains GmbH. |
---|
11 | * |
---|
12 | * The license and distribution terms for this file may be |
---|
13 | * found in the file LICENSE in this distribution or at |
---|
14 | * http://www.rtems.com/license/LICENSE. |
---|
15 | * |
---|
16 | * $Id$ |
---|
17 | */ |
---|
18 | |
---|
19 | #if HAVE_CONFIG_H |
---|
20 | #include "config.h" |
---|
21 | #endif |
---|
22 | |
---|
23 | #include "imfs.h" |
---|
24 | |
---|
25 | #include <dirent.h> |
---|
26 | #include <string.h> |
---|
27 | |
---|
28 | static size_t IMFS_directory_size( const IMFS_jnode_t *the_jnode ) |
---|
29 | { |
---|
30 | size_t size = 0; |
---|
31 | const rtems_chain_control *chain = &the_jnode->info.directory.Entries; |
---|
32 | const rtems_chain_node *current = rtems_chain_immutable_first( chain ); |
---|
33 | const rtems_chain_node *tail = rtems_chain_immutable_tail( chain ); |
---|
34 | |
---|
35 | while ( current != tail ) { |
---|
36 | size += sizeof(struct dirent); |
---|
37 | current = rtems_chain_immutable_next( current ); |
---|
38 | } |
---|
39 | |
---|
40 | return size; |
---|
41 | } |
---|
42 | |
---|
43 | int IMFS_stat( |
---|
44 | const rtems_filesystem_location_info_t *loc, |
---|
45 | struct stat *buf |
---|
46 | ) |
---|
47 | { |
---|
48 | IMFS_fs_info_t *fs_info = loc->mt_entry->fs_info; |
---|
49 | IMFS_jnode_t *the_jnode = loc->node_access; |
---|
50 | IMFS_device_t *io = &the_jnode->info.device; |
---|
51 | |
---|
52 | if ( IMFS_type( the_jnode ) == IMFS_HARD_LINK ) { |
---|
53 | the_jnode = the_jnode->info.hard_link.link_node; |
---|
54 | } |
---|
55 | |
---|
56 | switch ( IMFS_type( the_jnode ) ) { |
---|
57 | |
---|
58 | case IMFS_DEVICE: |
---|
59 | buf->st_rdev = rtems_filesystem_make_dev_t( io->major, io->minor ); |
---|
60 | break; |
---|
61 | |
---|
62 | case IMFS_LINEAR_FILE: |
---|
63 | case IMFS_MEMORY_FILE: |
---|
64 | buf->st_size = the_jnode->info.file.size; |
---|
65 | break; |
---|
66 | |
---|
67 | case IMFS_DIRECTORY: |
---|
68 | buf->st_size = IMFS_directory_size( the_jnode ); |
---|
69 | break; |
---|
70 | |
---|
71 | case IMFS_SYM_LINK: |
---|
72 | buf->st_size = strlen( the_jnode->info.sym_link.name ); |
---|
73 | break; |
---|
74 | |
---|
75 | case IMFS_FIFO: |
---|
76 | break; |
---|
77 | |
---|
78 | default: |
---|
79 | rtems_set_errno_and_return_minus_one( ENOTSUP ); |
---|
80 | break; |
---|
81 | } |
---|
82 | |
---|
83 | /* |
---|
84 | * The device number of the IMFS is the major number and the minor is the |
---|
85 | * instance. |
---|
86 | */ |
---|
87 | buf->st_dev = |
---|
88 | rtems_filesystem_make_dev_t( IMFS_DEVICE_MAJOR_NUMBER, fs_info->instance ); |
---|
89 | |
---|
90 | buf->st_mode = the_jnode->st_mode; |
---|
91 | buf->st_nlink = the_jnode->st_nlink; |
---|
92 | buf->st_ino = the_jnode->st_ino; |
---|
93 | buf->st_uid = the_jnode->st_uid; |
---|
94 | buf->st_gid = the_jnode->st_gid; |
---|
95 | |
---|
96 | buf->st_atime = the_jnode->stat_atime; |
---|
97 | buf->st_mtime = the_jnode->stat_mtime; |
---|
98 | buf->st_ctime = the_jnode->stat_ctime; |
---|
99 | |
---|
100 | if ( !IMFS_is_directory( the_jnode ) ) { |
---|
101 | buf->st_blksize = imfs_rq_memfile_bytes_per_block; |
---|
102 | } |
---|
103 | |
---|
104 | return 0; |
---|
105 | } |
---|