This source file includes following definitions.
- sv_sb_fic_inode
- sysv_free_inode
- sysv_new_inode
- sysv_count_free_inodes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 #ifdef MODULE
23 #include <linux/module.h>
24 #endif
25
26 #include <linux/sched.h>
27 #include <linux/kernel.h>
28 #include <linux/fs.h>
29 #include <linux/sysv_fs.h>
30 #include <linux/stddef.h>
31 #include <linux/stat.h>
32 #include <linux/string.h>
33 #include <linux/locks.h>
34
35
36
37
38
39
40
41
42 static inline sysv_ino_t * sv_sb_fic_inode (struct super_block * sb, unsigned int i)
43 {
44 if (sb->sv_bh1 == sb->sv_bh2)
45 return &sb->sv_sb_fic_inodes[i];
46 else {
47
48 unsigned int offset = offsetof(struct xenix_super_block, s_inode[i]);
49 if (offset < 512)
50 return (sysv_ino_t*)(sb->sv_sbd1 + offset);
51 else
52 return (sysv_ino_t*)(sb->sv_sbd2 + offset);
53 }
54 }
55
56 void sysv_free_inode(struct inode * inode)
57 {
58 struct super_block * sb;
59 unsigned int ino;
60 struct buffer_head * bh;
61 struct sysv_inode * raw_inode;
62
63 if (!inode)
64 return;
65 if (!inode->i_dev) {
66 printk("sysv_free_inode: inode has no device\n");
67 return;
68 }
69 if (inode->i_count != 1) {
70 printk("sysv_free_inode: inode has count=%d\n", inode->i_count);
71 return;
72 }
73 if (inode->i_nlink) {
74 printk("sysv_free_inode: inode has nlink=%d\n", inode->i_nlink);
75 return;
76 }
77 if (!(sb = inode->i_sb)) {
78 printk("sysv_free_inode: inode on nonexistent device\n");
79 return;
80 }
81 ino = inode->i_ino;
82 if (ino <= SYSV_ROOT_INO || ino > sb->sv_ninodes) {
83 printk("sysv_free_inode: inode 0,1,2 or nonexistent inode\n");
84 return;
85 }
86 if (!(bh = sv_bread(sb, inode->i_dev, sb->sv_firstinodezone + ((ino-1) >> sb->sv_inodes_per_block_bits)))) {
87 printk("sysv_free_inode: unable to read inode block on device "
88 "%s\n", kdevname(inode->i_dev));
89 clear_inode(inode);
90 return;
91 }
92 raw_inode = (struct sysv_inode *) bh->b_data + ((ino-1) & sb->sv_inodes_per_block_1);
93 lock_super(sb);
94 if (*sb->sv_sb_fic_count < sb->sv_fic_size)
95 *sv_sb_fic_inode(sb,(*sb->sv_sb_fic_count)++) = ino;
96 (*sb->sv_sb_total_free_inodes)++;
97 mark_buffer_dirty(sb->sv_bh1, 1);
98 if (sb->sv_bh1 != sb->sv_bh2) mark_buffer_dirty(sb->sv_bh2, 1);
99 sb->s_dirt = 1;
100 memset(raw_inode, 0, sizeof(struct sysv_inode));
101 mark_buffer_dirty(bh, 1);
102 unlock_super(sb);
103 brelse(bh);
104 clear_inode(inode);
105 }
106
107 struct inode * sysv_new_inode(const struct inode * dir)
108 {
109 struct inode * inode;
110 struct super_block * sb;
111 struct buffer_head * bh;
112 struct sysv_inode * raw_inode;
113 int i,j,ino,block;
114
115 if (!dir || !(inode = get_empty_inode()))
116 return NULL;
117 sb = dir->i_sb;
118 inode->i_sb = sb;
119 inode->i_flags = inode->i_sb->s_flags;
120 lock_super(sb);
121 if ((*sb->sv_sb_fic_count == 0)
122 || (*sv_sb_fic_inode(sb,(*sb->sv_sb_fic_count)-1) == 0)
123 ) {
124
125
126
127
128
129
130
131 for (i = 0, ino = SYSV_ROOT_INO+1, block = sb->sv_firstinodezone, j = SYSV_ROOT_INO ; i < sb->sv_fic_size && block < sb->sv_firstdatazone ; block++, j = 0) {
132 if (!(bh = sv_bread(sb, sb->s_dev, block))) {
133 printk("sysv_new_inode: unable to read inode table\n");
134 break;
135
136 }
137 raw_inode = (struct sysv_inode *) bh->b_data + j;
138 for (; j < sb->sv_inodes_per_block && i < sb->sv_fic_size; ino++, j++, raw_inode++) {
139 if (raw_inode->i_mode == 0 && raw_inode->i_nlink == 0)
140 *sv_sb_fic_inode(sb,i++) = ino;
141 }
142 brelse(bh);
143 }
144 if (i == 0) {
145 iput(inode);
146 unlock_super(sb);
147 return NULL;
148 }
149 *sb->sv_sb_fic_count = i;
150 }
151
152 ino = *sv_sb_fic_inode(sb,--(*sb->sv_sb_fic_count));
153 mark_buffer_dirty(sb->sv_bh1, 1);
154 if (sb->sv_bh1 != sb->sv_bh2) mark_buffer_dirty(sb->sv_bh2, 1);
155 sb->s_dirt = 1;
156 inode->i_count = 1;
157 inode->i_nlink = 1;
158 inode->i_dev = sb->s_dev;
159 inode->i_uid = current->fsuid;
160 inode->i_gid = (dir->i_mode & S_ISGID) ? dir->i_gid : current->fsgid;
161 inode->i_dirt = 1;
162 inode->i_ino = ino;
163 inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
164 inode->i_op = NULL;
165 inode->i_blocks = inode->i_blksize = 0;
166 insert_inode_hash(inode);
167
168 inode->i_mode = 0;
169 inode->i_size = 0;
170 sysv_write_inode(inode);
171
172 inode->i_dirt = 1;
173
174 (*sb->sv_sb_total_free_inodes)--;
175 mark_buffer_dirty(sb->sv_bh2, 1);
176 sb->s_dirt = 1;
177 unlock_super(sb);
178 return inode;
179 }
180
181 unsigned long sysv_count_free_inodes(struct super_block * sb)
182 {
183 #if 1
184 struct buffer_head * bh;
185 struct sysv_inode * raw_inode;
186 int j,block,count;
187
188
189 count = 0;
190 lock_super(sb);
191
192
193
194
195
196
197 for (block = sb->sv_firstinodezone, j = SYSV_ROOT_INO ; block < sb->sv_firstdatazone ; block++, j = 0) {
198 if (!(bh = sv_bread(sb, sb->s_dev, block))) {
199 printk("sysv_count_free_inodes: unable to read inode table\n");
200 break;
201
202 }
203 raw_inode = (struct sysv_inode *) bh->b_data + j;
204 for (; j < sb->sv_inodes_per_block ; j++, raw_inode++)
205 if (raw_inode->i_mode == 0 && raw_inode->i_nlink == 0)
206 count++;
207 brelse(bh);
208 }
209 if (count != *sb->sv_sb_total_free_inodes) {
210 printk("sysv_count_free_inodes: free inode count was %d, correcting to %d\n",(short)(*sb->sv_sb_total_free_inodes),count);
211 if (!(sb->s_flags & MS_RDONLY)) {
212 *sb->sv_sb_total_free_inodes = count;
213 mark_buffer_dirty(sb->sv_bh2, 1);
214 sb->s_dirt = 1;
215 }
216 }
217 unlock_super(sb);
218 return count;
219 #else
220 return *sb->sv_sb_total_free_inodes;
221 #endif
222 }
223