Rev 2365 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2365 | Rev 2435 | ||
---|---|---|---|
- | 1 | /* |
|
- | 2 | * Copyright (c) 1987,1997, Prentice Hall |
|
- | 3 | * All rights reserved. |
|
- | 4 | * |
|
- | 5 | * Redistribution and use of the MINIX operating system in source and |
|
- | 6 | * binary forms, with or without modification, are permitted provided |
|
- | 7 | * that the following conditions are met: |
|
- | 8 | ||
1 | /* This file contains the procedures for support directory operations. */ |
9 | * - Redistributions of source code must retain the above copyright |
- | 10 | * notice, this list of conditions and the following disclaimer. |
|
2 | 11 | ||
- | 12 | * - Redistributions in binary form must reproduce the above |
|
- | 13 | * copyright notice, this list of conditions and the following |
|
- | 14 | * disclaimer in the documentation and/or other materials provided |
|
3 | /* Methods: |
15 | * with the distribution. |
- | 16 | ||
- | 17 | * - Neither the name of Prentice Hall nor the names of the software |
|
4 | * do_sum: return total number of directory entries |
18 | * authors or contributors may be used to endorse or promote |
- | 19 | * products derived from this software without specific prior |
|
- | 20 | * written permission. |
|
- | 21 | ||
- | 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS, AUTHORS, AND |
|
- | 23 | * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, |
|
- | 24 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
|
- | 25 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
|
- | 26 | * IN NO EVENT SHALL PRENTICE HALL OR ANY AUTHORS OR CONTRIBUTORS BE |
|
- | 27 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|
- | 28 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
- | 29 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
|
- | 30 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
|
- | 31 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
|
- | 32 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |
|
- | 33 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
- | 34 | */ |
|
- | 35 | ||
- | 36 | /** @addtogroup FileSystemImpl |
|
- | 37 | * @{ |
|
- | 38 | */ |
|
- | 39 | ||
- | 40 | /** |
|
- | 41 | * @file dir.c |
|
5 | * do_readentry: fill in the user buffer with directory entry specified by number |
42 | * @brief This file contains the procedures for support directory operations. |
6 | */ |
43 | */ |
7 | - | ||
8 | 44 | ||
9 | #include <stdio.h> |
45 | #include <stdio.h> |
10 | #include "fs.h" |
46 | #include "fs.h" |
11 | #include "dir.h" |
47 | #include "dir.h" |
12 | #include "block.h" |
48 | #include "block.h" |
13 | #include "inode.h" |
49 | #include "inode.h" |
14 | #include "param.h" |
50 | #include "param.h" |
15 | 51 | ||
16 | 52 | /** |
|
- | 53 | * Return total number of directory entries |
|
- | 54 | */ |
|
17 | int do_sum() |
55 | int do_sum() |
18 | { |
56 | { |
19 | 57 | ||
20 | /* Perform dsum system call. */ |
58 | /* Perform dsum system call. */ |
21 | 59 | ||
22 | inode_t *rip; |
60 | inode_t *rip; |
23 | int dir_count; |
61 | int dir_count; |
24 | offset_t dir_size; |
62 | offset_t dir_size; |
25 | 63 | ||
26 | rip = fp->fp_workdir; |
64 | rip = fp->fp_workdir; |
27 | dir_size = rip->i_size; |
65 | dir_size = rip->i_size; |
28 | 66 | ||
29 | /* We must calculate with both versions of directory entry sizes. */ |
67 | /* We must calculate with both versions of directory entry sizes. */ |
30 | if (rip->i_sp->s_extend) { |
68 | if (rip->i_sp->s_extend) { |
31 | dir_count = dir_size/DIR_ENTRY_SIZE; |
69 | dir_count = dir_size/DIR_ENTRY_SIZE; |
32 | } |
70 | } |
33 | else { |
71 | else { |
34 | dir_count = dir_size/DIR_ENTRY_SIZE_EX; |
72 | dir_count = dir_size/DIR_ENTRY_SIZE_EX; |
35 | } |
73 | } |
36 | if (dir_size % DIR_ENTRY_SIZE_EX != 0) { |
74 | if (dir_size % DIR_ENTRY_SIZE_EX != 0) { |
37 | print_console("dir_size % DIR_ENTRY_SIZE_EX != 0\n"); |
75 | print_console("dir_size % DIR_ENTRY_SIZE_EX != 0\n"); |
38 | } |
76 | } |
39 | 77 | ||
40 | return dir_count; |
78 | return dir_count; |
41 | } |
79 | } |
42 | 80 | ||
43 | 81 | /** |
|
- | 82 | * Fill in the user buffer with directory entry specified by number |
|
- | 83 | */ |
|
44 | int do_readentry() |
84 | int do_readentry() |
45 | { |
85 | { |
46 | 86 | ||
47 | /* Perform readentry(numb, buffer) system call. */ |
87 | /* Perform readentry(numb, buffer) system call. */ |
48 | 88 | ||
49 | int actual_sum, extend; |
89 | int actual_sum, extend; |
50 | offset_t pos; |
90 | offset_t pos; |
51 | inode_t *rip; |
91 | inode_t *rip; |
52 | block_num_t b; |
92 | block_num_t b; |
53 | block_t *bp; |
93 | block_t *bp; |
54 | register int r; |
94 | register int r; |
55 | direct_t *dir; |
95 | direct_t *dir; |
56 | directex_t *direx; |
96 | directex_t *direx; |
57 | 97 | ||
58 | /* Get actual number of directory entries within the block. */ |
98 | /* Get actual number of directory entries within the block. */ |
59 | actual_sum = do_sum(); |
99 | actual_sum = do_sum(); |
60 | if (entry_number < 0 || actual_sum <= entry_number) |
100 | if (entry_number < 0 || actual_sum <= entry_number) |
61 | return FS_EINVAL; |
101 | return FS_EINVAL; |
62 | 102 | ||
63 | rip = fp->fp_workdir; |
103 | rip = fp->fp_workdir; |
64 | extend = rip->i_sp->s_extend; |
104 | extend = rip->i_sp->s_extend; |
65 | 105 | ||
66 | if (extend) { |
106 | if (extend) { |
67 | pos = entry_number * DIR_ENTRY_SIZE_EX; |
107 | pos = entry_number * DIR_ENTRY_SIZE_EX; |
68 | } |
108 | } |
69 | else { |
109 | else { |
70 | pos = entry_number * DIR_ENTRY_SIZE; |
110 | pos = entry_number * DIR_ENTRY_SIZE; |
71 | } |
111 | } |
72 | 112 | ||
73 | /* Get number of block within the entry is. */ |
113 | /* Get number of block within the entry is. */ |
74 | b = read_map(rip, pos); |
114 | b = read_map(rip, pos); |
75 | if (b == NO_BLOCK) |
115 | if (b == NO_BLOCK) |
76 | return 0; |
116 | return 0; |
77 | 117 | ||
78 | bp = get_block(b); |
118 | bp = get_block(b); |
79 | 119 | ||
80 | /* Copy the entry data into address space of actual consument. */ |
120 | /* Copy the entry data into address space of actual consument. */ |
81 | if (extend) { |
121 | if (extend) { |
82 | direx = &bp->b.b__direx[entry_number]; |
122 | direx = &bp->b.b__direx[entry_number]; |
83 | memcpy(fp->buffer, (void*)direx, DIR_ENTRY_SIZE_EX); |
123 | memcpy(fp->buffer, (void*)direx, DIR_ENTRY_SIZE_EX); |
84 | } |
124 | } |
85 | else { |
125 | else { |
86 | dir = &bp->b.b__dir[entry_number]; |
126 | dir = &bp->b.b__dir[entry_number]; |
87 | memcpy(fp->buffer, (void*)dir, DIR_ENTRY_SIZE); |
127 | memcpy(fp->buffer, (void*)dir, DIR_ENTRY_SIZE); |
88 | } |
128 | } |
89 | 129 | ||
90 | r = (extend ? DIR_ENTRY_SIZE_EX : DIR_ENTRY_SIZE); |
130 | r = (extend ? DIR_ENTRY_SIZE_EX : DIR_ENTRY_SIZE); |
91 | 131 | ||
92 | return r; |
132 | return r; |
93 | } |
133 | } |
94 | 134 | ||
95 | 135 | ||
- | 136 | /** |
|
- | 137 | * } |
|
- | 138 | */ |
|
- | 139 | ||
96 | 140 |