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
);