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