~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Linux/fs/hpfs/inode.c

Version: ~ [ 2.4.0 ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  *  linux/fs/hpfs/inode.c
  3  *
  4  *  Mikulas Patocka (mikulas@artax.karlin.mff.cuni.cz), 1998-1999
  5  *
  6  *  inode VFS functions
  7  */
  8 
  9 #include <linux/sched.h>
 10 #include <linux/smp_lock.h>
 11 #include "hpfs_fn.h"
 12 
 13 static struct file_operations hpfs_file_ops =
 14 {
 15         read:           generic_file_read,
 16         write:          hpfs_file_write,
 17         mmap:           generic_file_mmap,
 18         open:           hpfs_open,
 19         release:        hpfs_file_release,
 20         fsync:          hpfs_file_fsync,
 21 };
 22 
 23 static struct inode_operations hpfs_file_iops =
 24 {
 25         truncate:       hpfs_truncate,
 26         setattr:        hpfs_notify_change,
 27 };
 28 
 29 static struct file_operations hpfs_dir_ops =
 30 {
 31         llseek:         hpfs_dir_lseek,
 32         read:           generic_read_dir,
 33         readdir:        hpfs_readdir,
 34         open:           hpfs_open,
 35         release:        hpfs_dir_release,
 36         fsync:          hpfs_file_fsync,
 37 };
 38 
 39 static struct inode_operations hpfs_dir_iops =
 40 {
 41         create:         hpfs_create,
 42         lookup:         hpfs_lookup,
 43         unlink:         hpfs_unlink,
 44         symlink:        hpfs_symlink,
 45         mkdir:          hpfs_mkdir,
 46         rmdir:          hpfs_rmdir,
 47         mknod:          hpfs_mknod,
 48         rename:         hpfs_rename,
 49         setattr:        hpfs_notify_change,
 50 };
 51 
 52 struct address_space_operations hpfs_symlink_aops = {
 53         readpage:       hpfs_symlink_readpage
 54 };
 55 
 56 void hpfs_read_inode(struct inode *i)
 57 {
 58         struct buffer_head *bh;
 59         struct fnode *fnode;
 60         struct super_block *sb = i->i_sb;
 61         unsigned char *ea;
 62         int ea_size;
 63         init_MUTEX(&i->i_hpfs_sem);
 64         i->i_uid = sb->s_hpfs_uid;
 65         i->i_gid = sb->s_hpfs_gid;
 66         i->i_mode = sb->s_hpfs_mode;
 67         i->i_hpfs_conv = sb->s_hpfs_conv;
 68         i->i_blksize = 512;
 69         i->i_size = -1;
 70         i->i_blocks = -1;
 71         
 72         i->i_hpfs_dno = 0;
 73         i->i_hpfs_n_secs = 0;
 74         i->i_hpfs_file_sec = 0;
 75         i->i_hpfs_disk_sec = 0;
 76         i->i_hpfs_dpos = 0;
 77         i->i_hpfs_dsubdno = 0;
 78         i->i_hpfs_ea_mode = 0;
 79         i->i_hpfs_ea_uid = 0;
 80         i->i_hpfs_ea_gid = 0;
 81         i->i_hpfs_ea_size = 0;
 82         i->i_version = ++event;
 83 
 84         i->i_hpfs_rddir_off = NULL;
 85         i->i_hpfs_dirty = 0;
 86 
 87         i->i_atime = 0;
 88         i->i_mtime = 0;
 89         i->i_ctime = 0;
 90 
 91         if (!i->i_sb->s_hpfs_rd_inode)
 92                 hpfs_error(i->i_sb, "read_inode: s_hpfs_rd_inode == 0");
 93         if (i->i_sb->s_hpfs_rd_inode == 2) {
 94                 i->i_mode |= S_IFREG;
 95                 i->i_mode &= ~0111;
 96                 i->i_op = &hpfs_file_iops;
 97                 i->i_fop = &hpfs_file_ops;
 98                 i->i_nlink = 1;
 99                 return;
100         }
101         if (!(fnode = hpfs_map_fnode(sb, i->i_ino, &bh))) {
102                 /*i->i_mode |= S_IFREG;
103                 i->i_mode &= ~0111;
104                 i->i_op = &hpfs_file_iops;
105                 i->i_fop = &hpfs_file_ops;
106                 i->i_nlink = 0;*/
107                 make_bad_inode(i);
108                 return;
109         }
110         if (i->i_sb->s_hpfs_eas) {
111                 if ((ea = hpfs_get_ea(i->i_sb, fnode, "UID", &ea_size))) {
112                         if (ea_size == 2) {
113                                 i->i_uid = ea[0] + (ea[1] << 8);
114                                 i->i_hpfs_ea_uid = 1;
115                         }
116                         kfree(ea);
117                 }
118                 if ((ea = hpfs_get_ea(i->i_sb, fnode, "GID", &ea_size))) {
119                         if (ea_size == 2) {
120                                 i->i_gid = ea[0] + (ea[1] << 8);
121                                 i->i_hpfs_ea_gid = 1;
122                         }
123                         kfree(ea);
124                 }
125                 if ((ea = hpfs_get_ea(i->i_sb, fnode, "SYMLINK", &ea_size))) {
126                         kfree(ea);
127                         i->i_mode = S_IFLNK | 0777;
128                         i->i_op = &page_symlink_inode_operations;
129                         i->i_data.a_ops = &hpfs_symlink_aops;
130                         i->i_nlink = 1;
131                         i->i_size = ea_size;
132                         i->i_blocks = 1;
133                         brelse(bh);
134                         return;
135                 }
136                 if ((ea = hpfs_get_ea(i->i_sb, fnode, "MODE", &ea_size))) {
137                         int rdev = 0;
138                         umode_t mode = sb->s_hpfs_mode;
139                         if (ea_size == 2) {
140                                 mode = ea[0] + (ea[1] << 8);
141                                 i->i_hpfs_ea_mode = 1;
142                         }
143                         kfree(ea);
144                         i->i_mode = mode;
145                         if (S_ISBLK(mode) || S_ISCHR(mode)) {
146                                 if ((ea = hpfs_get_ea(i->i_sb, fnode, "DEV", &ea_size))) {
147                                         if (ea_size == 4)
148                                                 rdev = ea[0] + (ea[1] << 8) + (ea[2] << 16) + (ea[3] << 24);
149                                         kfree(ea);
150                                 }
151                         }
152                         if (S_ISBLK(mode) || S_ISCHR(mode) || S_ISFIFO(mode) || S_ISSOCK(mode)) {
153                                 brelse(bh);
154                                 i->i_nlink = 1;
155                                 i->i_size = 0;
156                                 i->i_blocks = 1;
157                                 init_special_inode(i, mode, rdev);
158                                 return;
159                         }
160                 }
161         }
162         if (fnode->dirflag) {
163                 unsigned n_dnodes, n_subdirs;
164                 i->i_mode |= S_IFDIR;
165                 i->i_op = &hpfs_dir_iops;
166                 i->i_fop = &hpfs_dir_ops;
167                 i->i_hpfs_parent_dir = fnode->up;
168                 i->i_hpfs_dno = fnode->u.external[0].disk_secno;
169                 if (sb->s_hpfs_chk >= 2) {
170                         struct buffer_head *bh0;
171                         if (hpfs_map_fnode(sb, i->i_hpfs_parent_dir, &bh0)) brelse(bh0);
172                 }
173                 n_dnodes = 0; n_subdirs = 0;
174                 hpfs_count_dnodes(i->i_sb, i->i_hpfs_dno, &n_dnodes, &n_subdirs, NULL);
175                 i->i_blocks = 4 * n_dnodes;
176                 i->i_size = 2048 * n_dnodes;
177                 i->i_nlink = 2 + n_subdirs;
178         } else {
179                 i->i_mode |= S_IFREG;
180                 if (!i->i_hpfs_ea_mode) i->i_mode &= ~0111;
181                 i->i_op = &hpfs_file_iops;
182                 i->i_fop = &hpfs_file_ops;
183                 i->i_nlink = 1;
184                 i->i_size = fnode->file_size;
185                 i->i_blocks = ((i->i_size + 511) >> 9) + 1;
186                 i->i_data.a_ops = &hpfs_aops;
187                 i->u.hpfs_i.mmu_private = i->i_size;
188         }
189         brelse(bh);
190 }
191 
192 void hpfs_write_inode_ea(struct inode *i, struct fnode *fnode)
193 {
194         if (fnode->acl_size_l || fnode->acl_size_s) {
195                 /* Some unknown structures like ACL may be in fnode,
196                    we'd better not overwrite them */
197                 hpfs_error(i->i_sb, "fnode %08x has some unknown HPFS386 stuctures", i->i_ino);
198         } else if (i->i_sb->s_hpfs_eas >= 2) {
199                 unsigned char ea[4];
200                 if ((i->i_uid != i->i_sb->s_hpfs_uid) || i->i_hpfs_ea_uid) {
201                         ea[0] = i->i_uid & 0xff;
202                         ea[1] = i->i_uid >> 8;
203                         hpfs_set_ea(i, fnode, "UID", ea, 2);
204                         i->i_hpfs_ea_uid = 1;
205                 }
206                 if ((i->i_gid != i->i_sb->s_hpfs_gid) || i->i_hpfs_ea_gid) {
207                         ea[0] = i->i_gid & 0xff;
208                         ea[1] = i->i_gid >> 8;
209                         hpfs_set_ea(i, fnode, "GID", ea, 2);
210                         i->i_hpfs_ea_gid = 1;
211                 }
212                 if (!S_ISLNK(i->i_mode))
213                         if ((i->i_mode != ((i->i_sb->s_hpfs_mode & ~(S_ISDIR(i->i_mode) ? 0 : 0111))
214                           | (S_ISDIR(i->i_mode) ? S_IFDIR : S_IFREG))
215                           && i->i_mode != ((i->i_sb->s_hpfs_mode & ~(S_ISDIR(i->i_mode) ? 0222 : 0333))
216                           | (S_ISDIR(i->i_mode) ? S_IFDIR : S_IFREG))) || i->i_hpfs_ea_mode) {
217                                 ea[0] = i->i_mode & 0xff;
218                                 ea[1] = i->i_mode >> 8;
219                                 hpfs_set_ea(i, fnode, "MODE", ea, 2);
220                                 i->i_hpfs_ea_mode = 1;
221                         }
222                 if (S_ISBLK(i->i_mode) || S_ISCHR(i->i_mode)) {
223                         int d = kdev_t_to_nr(i->i_rdev);
224                         ea[0] = d & 0xff;
225                         ea[1] = (d >> 8) & 0xff;
226                         ea[2] = (d >> 16) & 0xff;
227                         ea[3] = d >> 24;
228                         hpfs_set_ea(i, fnode, "DEV", ea, 4);
229                 }
230         }
231 }
232 
233 void hpfs_write_inode(struct inode *i)
234 {
235         struct inode *parent;
236         if (!i->i_nlink) return;
237         if (i->i_ino == i->i_sb->s_hpfs_root) return;
238         if (i->i_hpfs_rddir_off && !atomic_read(&i->i_count)) {
239                 if (*i->i_hpfs_rddir_off) printk("HPFS: write_inode: some position still there\n");
240                 kfree(i->i_hpfs_rddir_off);
241                 i->i_hpfs_rddir_off = NULL;
242         }
243         i->i_hpfs_dirty = 0;
244         hpfs_lock_iget(i->i_sb, 1);
245         parent = iget(i->i_sb, i->i_hpfs_parent_dir);
246         hpfs_unlock_iget(i->i_sb);
247         hpfs_lock_inode(parent);
248         hpfs_write_inode_nolock(i);
249         hpfs_unlock_inode(parent);
250         iput(parent);
251 }
252 
253 void hpfs_write_inode_nolock(struct inode *i)
254 {
255         struct buffer_head *bh;
256         struct fnode *fnode;
257         struct quad_buffer_head qbh;
258         struct hpfs_dirent *de;
259         if (i->i_ino == i->i_sb->s_hpfs_root) return;
260         if (!(fnode = hpfs_map_fnode(i->i_sb, i->i_ino, &bh))) return;
261         if (i->i_ino != i->i_sb->s_hpfs_root) {
262                 if (!(de = map_fnode_dirent(i->i_sb, i->i_ino, fnode, &qbh))) {
263                         brelse(bh);
264                         return;
265                 }
266         } else de = NULL;
267         if (S_ISREG(i->i_mode)) {
268                 fnode->file_size = de->file_size = i->i_size;
269         } else if (S_ISDIR(i->i_mode)) {
270                 fnode->file_size = de->file_size = 0;
271         }
272         hpfs_write_inode_ea(i, fnode);
273         if (de) {
274                 de->write_date = gmt_to_local(i->i_sb, i->i_mtime);
275                 de->read_date = gmt_to_local(i->i_sb, i->i_atime);
276                 de->creation_date = gmt_to_local(i->i_sb, i->i_ctime);
277                 de->read_only = !(i->i_mode & 0222);
278                 de->ea_size = i->i_hpfs_ea_size;
279                 hpfs_mark_4buffers_dirty(&qbh);
280                 hpfs_brelse4(&qbh);
281         }
282         if (S_ISDIR(i->i_mode)) {
283                 if ((de = map_dirent(i, i->i_hpfs_dno, "\001\001", 2, NULL, &qbh))) {
284                         de->write_date = gmt_to_local(i->i_sb, i->i_mtime);
285                         de->read_date = gmt_to_local(i->i_sb, i->i_atime);
286                         de->creation_date = gmt_to_local(i->i_sb, i->i_ctime);
287                         de->read_only = !(i->i_mode & 0222);
288                         de->ea_size = /*i->i_hpfs_ea_size*/0;
289                         de->file_size = 0;
290                         hpfs_mark_4buffers_dirty(&qbh);
291                         hpfs_brelse4(&qbh);
292                 } else hpfs_error(i->i_sb, "directory %08x doesn't have '.' entry", i->i_ino);
293         }
294         mark_buffer_dirty(bh);
295         brelse(bh);
296 }
297 
298 int hpfs_notify_change(struct dentry *dentry, struct iattr *attr)
299 {
300         struct inode *inode = dentry->d_inode;
301         int error;
302         if (inode->i_sb->s_hpfs_root == inode->i_ino) return -EINVAL;
303         if ((error = inode_change_ok(inode, attr))) return error;
304         inode_setattr(inode, attr);
305         hpfs_write_inode(inode);
306         return 0;
307 }
308 
309 void hpfs_write_if_changed(struct inode *inode)
310 {
311         if (inode->i_hpfs_dirty) {
312                 hpfs_write_inode(inode);
313         }
314 }
315 
316 void hpfs_delete_inode(struct inode *inode)
317 {
318         lock_kernel();
319         hpfs_remove_fnode(inode->i_sb, inode->i_ino);
320         unlock_kernel();
321         clear_inode(inode);
322 }
323 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.