2 * linux/fs/hpfs/inode.c
4 * Mikulas Patocka (mikulas@artax.karlin.mff.cuni.cz), 1998-1999
11 void hpfs_init_inode(struct inode *i)
13 struct super_block *sb = i->i_sb;
14 struct hpfs_inode_info *hpfs_inode = hpfs_i(i);
16 i->i_uid = hpfs_sb(sb)->sb_uid;
17 i->i_gid = hpfs_sb(sb)->sb_gid;
18 i->i_mode = hpfs_sb(sb)->sb_mode;
19 hpfs_inode->i_conv = hpfs_sb(sb)->sb_conv;
23 hpfs_inode->i_dno = 0;
24 hpfs_inode->i_n_secs = 0;
25 hpfs_inode->i_file_sec = 0;
26 hpfs_inode->i_disk_sec = 0;
27 hpfs_inode->i_dpos = 0;
28 hpfs_inode->i_dsubdno = 0;
29 hpfs_inode->i_ea_mode = 0;
30 hpfs_inode->i_ea_uid = 0;
31 hpfs_inode->i_ea_gid = 0;
32 hpfs_inode->i_ea_size = 0;
34 hpfs_inode->i_rddir_off = NULL;
35 hpfs_inode->i_dirty = 0;
37 i->i_ctime.tv_sec = i->i_ctime.tv_nsec = 0;
38 i->i_mtime.tv_sec = i->i_mtime.tv_nsec = 0;
39 i->i_atime.tv_sec = i->i_atime.tv_nsec = 0;
42 void hpfs_read_inode(struct inode *i)
44 struct buffer_head *bh;
46 struct super_block *sb = i->i_sb;
47 struct hpfs_inode_info *hpfs_inode = hpfs_i(i);
51 if (!(fnode = hpfs_map_fnode(sb, i->i_ino, &bh))) {
52 /*i->i_mode |= S_IFREG;
54 i->i_op = &hpfs_file_iops;
55 i->i_fop = &hpfs_file_ops;
60 if (hpfs_sb(i->i_sb)->sb_eas) {
61 if ((ea = hpfs_get_ea(i->i_sb, fnode, "UID", &ea_size))) {
63 i->i_uid = le16_to_cpu(*(u16*)ea);
64 hpfs_inode->i_ea_uid = 1;
68 if ((ea = hpfs_get_ea(i->i_sb, fnode, "GID", &ea_size))) {
70 i->i_gid = le16_to_cpu(*(u16*)ea);
71 hpfs_inode->i_ea_gid = 1;
75 if ((ea = hpfs_get_ea(i->i_sb, fnode, "SYMLINK", &ea_size))) {
77 i->i_mode = S_IFLNK | 0777;
78 i->i_op = &page_symlink_inode_operations;
79 i->i_data.a_ops = &hpfs_symlink_aops;
86 if ((ea = hpfs_get_ea(i->i_sb, fnode, "MODE", &ea_size))) {
88 umode_t mode = hpfs_sb(sb)->sb_mode;
90 mode = le16_to_cpu(*(u16*)ea);
91 hpfs_inode->i_ea_mode = 1;
95 if (S_ISBLK(mode) || S_ISCHR(mode)) {
96 if ((ea = hpfs_get_ea(i->i_sb, fnode, "DEV", &ea_size))) {
98 rdev = le32_to_cpu(*(u32*)ea);
102 if (S_ISBLK(mode) || S_ISCHR(mode) || S_ISFIFO(mode) || S_ISSOCK(mode)) {
107 init_special_inode(i, mode,
108 new_decode_dev(rdev));
113 if (fnode->dirflag) {
114 unsigned n_dnodes, n_subdirs;
115 i->i_mode |= S_IFDIR;
116 i->i_op = &hpfs_dir_iops;
117 i->i_fop = &hpfs_dir_ops;
118 hpfs_inode->i_parent_dir = fnode->up;
119 hpfs_inode->i_dno = fnode->u.external[0].disk_secno;
120 if (hpfs_sb(sb)->sb_chk >= 2) {
121 struct buffer_head *bh0;
122 if (hpfs_map_fnode(sb, hpfs_inode->i_parent_dir, &bh0)) brelse(bh0);
124 n_dnodes = 0; n_subdirs = 0;
125 hpfs_count_dnodes(i->i_sb, hpfs_inode->i_dno, &n_dnodes, &n_subdirs, NULL);
126 i->i_blocks = 4 * n_dnodes;
127 i->i_size = 2048 * n_dnodes;
128 i->i_nlink = 2 + n_subdirs;
130 i->i_mode |= S_IFREG;
131 if (!hpfs_inode->i_ea_mode) i->i_mode &= ~0111;
132 i->i_op = &hpfs_file_iops;
133 i->i_fop = &hpfs_file_ops;
135 i->i_size = fnode->file_size;
136 i->i_blocks = ((i->i_size + 511) >> 9) + 1;
137 i->i_data.a_ops = &hpfs_aops;
138 hpfs_i(i)->mmu_private = i->i_size;
143 static void hpfs_write_inode_ea(struct inode *i, struct fnode *fnode)
145 struct hpfs_inode_info *hpfs_inode = hpfs_i(i);
146 /*if (fnode->acl_size_l || fnode->acl_size_s) {
147 Some unknown structures like ACL may be in fnode,
148 we'd better not overwrite them
149 hpfs_error(i->i_sb, "fnode %08x has some unknown HPFS386 stuctures", i->i_ino);
150 } else*/ if (hpfs_sb(i->i_sb)->sb_eas >= 2) {
152 if ((i->i_uid != hpfs_sb(i->i_sb)->sb_uid) || hpfs_inode->i_ea_uid) {
153 ea = cpu_to_le32(i->i_uid);
154 hpfs_set_ea(i, fnode, "UID", (char*)&ea, 2);
155 hpfs_inode->i_ea_uid = 1;
157 if ((i->i_gid != hpfs_sb(i->i_sb)->sb_gid) || hpfs_inode->i_ea_gid) {
158 ea = cpu_to_le32(i->i_gid);
159 hpfs_set_ea(i, fnode, "GID", (char *)&ea, 2);
160 hpfs_inode->i_ea_gid = 1;
162 if (!S_ISLNK(i->i_mode))
163 if ((i->i_mode != ((hpfs_sb(i->i_sb)->sb_mode & ~(S_ISDIR(i->i_mode) ? 0 : 0111))
164 | (S_ISDIR(i->i_mode) ? S_IFDIR : S_IFREG))
165 && i->i_mode != ((hpfs_sb(i->i_sb)->sb_mode & ~(S_ISDIR(i->i_mode) ? 0222 : 0333))
166 | (S_ISDIR(i->i_mode) ? S_IFDIR : S_IFREG))) || hpfs_inode->i_ea_mode) {
167 ea = cpu_to_le32(i->i_mode);
168 hpfs_set_ea(i, fnode, "MODE", (char *)&ea, 2);
169 hpfs_inode->i_ea_mode = 1;
171 if (S_ISBLK(i->i_mode) || S_ISCHR(i->i_mode)) {
172 ea = cpu_to_le32(new_encode_dev(i->i_rdev));
173 hpfs_set_ea(i, fnode, "DEV", (char *)&ea, 4);
178 void hpfs_write_inode(struct inode *i)
180 struct hpfs_inode_info *hpfs_inode = hpfs_i(i);
181 struct inode *parent;
182 if (i->i_ino == hpfs_sb(i->i_sb)->sb_root) return;
183 if (hpfs_inode->i_rddir_off && !atomic_read(&i->i_count)) {
184 if (*hpfs_inode->i_rddir_off) printk("HPFS: write_inode: some position still there\n");
185 kfree(hpfs_inode->i_rddir_off);
186 hpfs_inode->i_rddir_off = NULL;
188 mutex_lock(&hpfs_inode->i_parent_mutex);
190 mutex_unlock(&hpfs_inode->i_parent_mutex);
193 parent = iget_locked(i->i_sb, hpfs_inode->i_parent_dir);
195 hpfs_inode->i_dirty = 0;
196 if (parent->i_state & I_NEW) {
197 hpfs_init_inode(parent);
198 hpfs_read_inode(parent);
199 unlock_new_inode(parent);
201 mutex_lock(&hpfs_inode->i_mutex);
202 hpfs_write_inode_nolock(i);
203 mutex_unlock(&hpfs_inode->i_mutex);
208 mutex_unlock(&hpfs_inode->i_parent_mutex);
211 void hpfs_write_inode_nolock(struct inode *i)
213 struct hpfs_inode_info *hpfs_inode = hpfs_i(i);
214 struct buffer_head *bh;
216 struct quad_buffer_head qbh;
217 struct hpfs_dirent *de;
218 if (i->i_ino == hpfs_sb(i->i_sb)->sb_root) return;
219 if (!(fnode = hpfs_map_fnode(i->i_sb, i->i_ino, &bh))) return;
220 if (i->i_ino != hpfs_sb(i->i_sb)->sb_root && i->i_nlink) {
221 if (!(de = map_fnode_dirent(i->i_sb, i->i_ino, fnode, &qbh))) {
226 if (S_ISREG(i->i_mode)) {
227 fnode->file_size = i->i_size;
228 if (de) de->file_size = i->i_size;
229 } else if (S_ISDIR(i->i_mode)) {
230 fnode->file_size = 0;
231 if (de) de->file_size = 0;
233 hpfs_write_inode_ea(i, fnode);
235 de->write_date = gmt_to_local(i->i_sb, i->i_mtime.tv_sec);
236 de->read_date = gmt_to_local(i->i_sb, i->i_atime.tv_sec);
237 de->creation_date = gmt_to_local(i->i_sb, i->i_ctime.tv_sec);
238 de->read_only = !(i->i_mode & 0222);
239 de->ea_size = hpfs_inode->i_ea_size;
240 hpfs_mark_4buffers_dirty(&qbh);
243 if (S_ISDIR(i->i_mode)) {
244 if ((de = map_dirent(i, hpfs_inode->i_dno, "\001\001", 2, NULL, &qbh))) {
245 de->write_date = gmt_to_local(i->i_sb, i->i_mtime.tv_sec);
246 de->read_date = gmt_to_local(i->i_sb, i->i_atime.tv_sec);
247 de->creation_date = gmt_to_local(i->i_sb, i->i_ctime.tv_sec);
248 de->read_only = !(i->i_mode & 0222);
249 de->ea_size = /*hpfs_inode->i_ea_size*/0;
251 hpfs_mark_4buffers_dirty(&qbh);
253 } else hpfs_error(i->i_sb, "directory %08x doesn't have '.' entry", i->i_ino);
255 mark_buffer_dirty(bh);
259 int hpfs_notify_change(struct dentry *dentry, struct iattr *attr)
261 struct inode *inode = dentry->d_inode;
264 if ( ((attr->ia_valid & ATTR_SIZE) && attr->ia_size > inode->i_size) ||
265 (hpfs_sb(inode->i_sb)->sb_root == inode->i_ino) ) {
267 } else if ((error = inode_change_ok(inode, attr))) {
268 } else if ((error = inode_setattr(inode, attr))) {
270 hpfs_write_inode(inode);
276 void hpfs_write_if_changed(struct inode *inode)
278 struct hpfs_inode_info *hpfs_inode = hpfs_i(inode);
280 if (hpfs_inode->i_dirty)
281 hpfs_write_inode(inode);
284 void hpfs_delete_inode(struct inode *inode)
286 truncate_inode_pages(&inode->i_data, 0);
288 hpfs_remove_fnode(inode->i_sb, inode->i_ino);