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/buffer_head.h>
20 * check if the filename is correct. For some obscure reason, qnx writes a
21 * new file twice in the directory entry, first with all possible options at 0
22 * and for a second time the way it is, they want us not to access the qnx
23 * filesystem when whe are using linux.
25 static int qnx4_match(int len, const char *name,
26 struct buffer_head *bh, unsigned long *offset)
28 struct qnx4_inode_entry *de;
32 printk(KERN_WARNING "qnx4: matching unassigned buffer !\n");
35 de = (struct qnx4_inode_entry *) (bh->b_data + *offset);
36 *offset += QNX4_DIR_ENTRY_SIZE;
37 if ((de->di_status & QNX4_FILE_LINK) != 0) {
38 namelen = QNX4_NAME_MAX;
40 namelen = QNX4_SHORT_NAME_MAX;
42 thislen = strlen( de->di_fname );
43 if ( thislen > namelen )
48 if (strncmp(name, de->di_fname, len) == 0) {
49 if ((de->di_status & (QNX4_FILE_USED|QNX4_FILE_LINK)) != 0) {
56 static struct buffer_head *qnx4_find_entry(int len, struct inode *dir,
57 const char *name, struct qnx4_inode_entry **res_dir, int *ino)
59 unsigned long block, offset, blkofs;
60 struct buffer_head *bh;
64 block = offset = blkofs = 0;
65 while (blkofs * QNX4_BLOCK_SIZE + offset < dir->i_size) {
67 block = qnx4_block_map(dir, blkofs);
69 bh = sb_bread(dir->i_sb, block);
75 *res_dir = (struct qnx4_inode_entry *) (bh->b_data + offset);
76 if (qnx4_match(len, name, bh, &offset)) {
77 *ino = block * QNX4_INODES_PER_BLOCK +
78 (offset / QNX4_DIR_ENTRY_SIZE) - 1;
81 if (offset < bh->b_size) {
94 struct dentry * qnx4_lookup(struct inode *dir, struct dentry *dentry, unsigned int flags)
97 struct qnx4_inode_entry *de;
98 struct qnx4_link_info *lnk;
99 struct buffer_head *bh;
100 const char *name = dentry->d_name.name;
101 int len = dentry->d_name.len;
102 struct inode *foundinode = NULL;
104 if (!(bh = qnx4_find_entry(len, dir, name, &de, &ino)))
106 /* The entry is linked, let's get the real info */
107 if ((de->di_status & QNX4_FILE_LINK) == QNX4_FILE_LINK) {
108 lnk = (struct qnx4_link_info *) de;
109 ino = (le32_to_cpu(lnk->dl_inode_blk) - 1) *
110 QNX4_INODES_PER_BLOCK +
115 foundinode = qnx4_iget(dir->i_sb, ino);
116 if (IS_ERR(foundinode)) {
117 QNX4DEBUG((KERN_ERR "qnx4: lookup->iget -> error %ld\n",
118 PTR_ERR(foundinode)));
119 return ERR_CAST(foundinode);
122 d_add(dentry, foundinode);