2 * QNX4 file system, Linux implementation.
6 * Using parts of the xiafs filesystem.
10 * 01-06-1998 by Richard Frowijn : first release.
11 * 21-06-1998 by Frank Denis : dcache support, fixed error codes.
12 * 04-07-1998 by Frank Denis : first step for rmdir/unlink.
15 #include <linux/smp_lock.h>
16 #include <linux/buffer_head.h>
21 * check if the filename is correct. For some obscure reason, qnx writes a
22 * new file twice in the directory entry, first with all possible options at 0
23 * and for a second time the way it is, they want us not to access the qnx
24 * filesystem when whe are using linux.
26 static int qnx4_match(int len
, const char *name
,
27 struct buffer_head
*bh
, unsigned long *offset
)
29 struct qnx4_inode_entry
*de
;
33 printk("qnx4: matching unassigned buffer !\n");
36 de
= (struct qnx4_inode_entry
*) (bh
->b_data
+ *offset
);
37 *offset
+= QNX4_DIR_ENTRY_SIZE
;
38 if ((de
->di_status
& QNX4_FILE_LINK
) != 0) {
39 namelen
= QNX4_NAME_MAX
;
41 namelen
= QNX4_SHORT_NAME_MAX
;
43 /* "" means "." ---> so paths like "/usr/lib//libc.a" work */
44 if (!len
&& (de
->di_fname
[0] == '.') && (de
->di_fname
[1] == '\0')) {
47 thislen
= strlen( de
->di_fname
);
48 if ( thislen
> namelen
)
53 if (strncmp(name
, de
->di_fname
, len
) == 0) {
54 if ((de
->di_status
& (QNX4_FILE_USED
|QNX4_FILE_LINK
)) != 0) {
61 static struct buffer_head
*qnx4_find_entry(int len
, struct inode
*dir
,
62 const char *name
, struct qnx4_inode_entry
**res_dir
, int *ino
)
64 unsigned long block
, offset
, blkofs
;
65 struct buffer_head
*bh
;
69 printk("qnx4: no superblock on dir.\n");
73 block
= offset
= blkofs
= 0;
74 while (blkofs
* QNX4_BLOCK_SIZE
+ offset
< dir
->i_size
) {
76 bh
= qnx4_bread(dir
, blkofs
, 0);
82 *res_dir
= (struct qnx4_inode_entry
*) (bh
->b_data
+ offset
);
83 if (qnx4_match(len
, name
, bh
, &offset
)) {
84 block
= qnx4_block_map( dir
, blkofs
);
85 *ino
= block
* QNX4_INODES_PER_BLOCK
+
86 (offset
/ QNX4_DIR_ENTRY_SIZE
) - 1;
89 if (offset
< bh
->b_size
) {
102 struct dentry
* qnx4_lookup(struct inode
*dir
, struct dentry
*dentry
, struct nameidata
*nd
)
105 struct qnx4_inode_entry
*de
;
106 struct qnx4_link_info
*lnk
;
107 struct buffer_head
*bh
;
108 const char *name
= dentry
->d_name
.name
;
109 int len
= dentry
->d_name
.len
;
110 struct inode
*foundinode
= NULL
;
113 if (!(bh
= qnx4_find_entry(len
, dir
, name
, &de
, &ino
)))
115 /* The entry is linked, let's get the real info */
116 if ((de
->di_status
& QNX4_FILE_LINK
) == QNX4_FILE_LINK
) {
117 lnk
= (struct qnx4_link_info
*) de
;
118 ino
= (le32_to_cpu(lnk
->dl_inode_blk
) - 1) *
119 QNX4_INODES_PER_BLOCK
+
124 foundinode
= qnx4_iget(dir
->i_sb
, ino
);
125 if (IS_ERR(foundinode
)) {
127 QNX4DEBUG(("qnx4: lookup->iget -> error %ld\n",
128 PTR_ERR(foundinode
)));
129 return ERR_CAST(foundinode
);
133 d_add(dentry
, foundinode
);
138 #ifdef CONFIG_QNX4FS_RW
139 int qnx4_create(struct inode
*dir
, struct dentry
*dentry
, int mode
,
140 struct nameidata
*nd
)
142 QNX4DEBUG(("qnx4: qnx4_create\n"));
149 int qnx4_rmdir(struct inode
*dir
, struct dentry
*dentry
)
151 struct buffer_head
*bh
;
152 struct qnx4_inode_entry
*de
;
157 QNX4DEBUG(("qnx4: qnx4_rmdir [%s]\n", dentry
->d_name
.name
));
159 bh
= qnx4_find_entry(dentry
->d_name
.len
, dir
, dentry
->d_name
.name
,
165 inode
= dentry
->d_inode
;
166 if (inode
->i_ino
!= ino
) {
171 if (!empty_dir(inode
)) {
176 if (inode
->i_nlink
!= 2) {
177 QNX4DEBUG(("empty directory has nlink!=2 (%d)\n", inode
->i_nlink
));
179 QNX4DEBUG(("qnx4: deleting directory\n"));
181 memset(de
->di_fname
, 0, sizeof de
->di_fname
);
183 mark_buffer_dirty_inode(bh
, dir
);
185 mark_inode_dirty(inode
);
186 inode
->i_ctime
= dir
->i_ctime
= dir
->i_mtime
= CURRENT_TIME_SEC
;
187 inode_dec_link_count(dir
);
197 int qnx4_unlink(struct inode
*dir
, struct dentry
*dentry
)
199 struct buffer_head
*bh
;
200 struct qnx4_inode_entry
*de
;
205 QNX4DEBUG(("qnx4: qnx4_unlink [%s]\n", dentry
->d_name
.name
));
207 bh
= qnx4_find_entry(dentry
->d_name
.len
, dir
, dentry
->d_name
.name
,
213 inode
= dentry
->d_inode
;
214 if (inode
->i_ino
!= ino
) {
219 if (!inode
->i_nlink
) {
220 QNX4DEBUG(("Deleting nonexistent file (%s:%lu), %d\n",
222 inode
->i_ino
, inode
->i_nlink
));
226 memset(de
->di_fname
, 0, sizeof de
->di_fname
);
228 mark_buffer_dirty_inode(bh
, dir
);
229 dir
->i_ctime
= dir
->i_mtime
= CURRENT_TIME_SEC
;
230 mark_inode_dirty(dir
);
231 inode
->i_ctime
= dir
->i_ctime
;
232 inode_dec_link_count(inode
);