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/time.h>
17 #include <linux/qnx4_fs.h>
18 #include <linux/kernel.h>
19 #include <linux/string.h>
20 #include <linux/stat.h>
21 #include <linux/fcntl.h>
22 #include <linux/errno.h>
23 #include <linux/smp_lock.h>
24 #include <linux/buffer_head.h>
28 * check if the filename is correct. For some obscure reason, qnx writes a
29 * new file twice in the directory entry, first with all possible options at 0
30 * and for a second time the way it is, they want us not to access the qnx
31 * filesystem when whe are using linux.
33 static int qnx4_match(int len, const char *name,
34 struct buffer_head *bh, unsigned long *offset)
36 struct qnx4_inode_entry *de;
40 printk("qnx4: matching unassigned buffer !\n");
43 de = (struct qnx4_inode_entry *) (bh->b_data + *offset);
44 *offset += QNX4_DIR_ENTRY_SIZE;
45 if ((de->di_status & QNX4_FILE_LINK) != 0) {
46 namelen = QNX4_NAME_MAX;
48 namelen = QNX4_SHORT_NAME_MAX;
50 /* "" means "." ---> so paths like "/usr/lib//libc.a" work */
51 if (!len && (de->di_fname[0] == '.') && (de->di_fname[1] == '\0')) {
54 thislen = strlen( de->di_fname );
55 if ( thislen > namelen )
60 if (strncmp(name, de->di_fname, len) == 0) {
61 if ((de->di_status & (QNX4_FILE_USED|QNX4_FILE_LINK)) != 0) {
68 static struct buffer_head *qnx4_find_entry(int len, struct inode *dir,
69 const char *name, struct qnx4_inode_entry **res_dir, int *ino)
71 unsigned long block, offset, blkofs;
72 struct buffer_head *bh;
76 printk("qnx4: no superblock on dir.\n");
80 block = offset = blkofs = 0;
81 while (blkofs * QNX4_BLOCK_SIZE + offset < dir->i_size) {
83 bh = qnx4_bread(dir, blkofs, 0);
89 *res_dir = (struct qnx4_inode_entry *) (bh->b_data + offset);
90 if (qnx4_match(len, name, bh, &offset)) {
91 block = qnx4_block_map( dir, blkofs );
92 *ino = block * QNX4_INODES_PER_BLOCK +
93 (offset / QNX4_DIR_ENTRY_SIZE) - 1;
96 if (offset < bh->b_size) {
109 struct dentry * qnx4_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd)
112 struct qnx4_inode_entry *de;
113 struct qnx4_link_info *lnk;
114 struct buffer_head *bh;
115 const char *name = dentry->d_name.name;
116 int len = dentry->d_name.len;
117 struct inode *foundinode = NULL;
120 if (!(bh = qnx4_find_entry(len, dir, name, &de, &ino)))
122 /* The entry is linked, let's get the real info */
123 if ((de->di_status & QNX4_FILE_LINK) == QNX4_FILE_LINK) {
124 lnk = (struct qnx4_link_info *) de;
125 ino = (le32_to_cpu(lnk->dl_inode_blk) - 1) *
126 QNX4_INODES_PER_BLOCK +
131 foundinode = qnx4_iget(dir->i_sb, ino);
132 if (IS_ERR(foundinode)) {
134 QNX4DEBUG(("qnx4: lookup->iget -> error %ld\n",
135 PTR_ERR(foundinode)));
136 return ERR_CAST(foundinode);
140 d_add(dentry, foundinode);
145 #ifdef CONFIG_QNX4FS_RW
146 int qnx4_create(struct inode *dir, struct dentry *dentry, int mode,
147 struct nameidata *nd)
149 QNX4DEBUG(("qnx4: qnx4_create\n"));
156 int qnx4_rmdir(struct inode *dir, struct dentry *dentry)
158 struct buffer_head *bh;
159 struct qnx4_inode_entry *de;
164 QNX4DEBUG(("qnx4: qnx4_rmdir [%s]\n", dentry->d_name.name));
166 bh = qnx4_find_entry(dentry->d_name.len, dir, dentry->d_name.name,
172 inode = dentry->d_inode;
173 if (inode->i_ino != ino) {
178 if (!empty_dir(inode)) {
183 if (inode->i_nlink != 2) {
184 QNX4DEBUG(("empty directory has nlink!=2 (%d)\n", inode->i_nlink));
186 QNX4DEBUG(("qnx4: deleting directory\n"));
188 memset(de->di_fname, 0, sizeof de->di_fname);
190 mark_buffer_dirty(bh);
192 mark_inode_dirty(inode);
193 inode->i_ctime = dir->i_ctime = dir->i_mtime = CURRENT_TIME_SEC;
194 inode_dec_link_count(dir);
204 int qnx4_unlink(struct inode *dir, struct dentry *dentry)
206 struct buffer_head *bh;
207 struct qnx4_inode_entry *de;
212 QNX4DEBUG(("qnx4: qnx4_unlink [%s]\n", dentry->d_name.name));
214 bh = qnx4_find_entry(dentry->d_name.len, dir, dentry->d_name.name,
220 inode = dentry->d_inode;
221 if (inode->i_ino != ino) {
226 if (!inode->i_nlink) {
227 QNX4DEBUG(("Deleting nonexistent file (%s:%lu), %d\n",
229 inode->i_ino, inode->i_nlink));
233 memset(de->di_fname, 0, sizeof de->di_fname);
235 mark_buffer_dirty(bh);
236 dir->i_ctime = dir->i_mtime = CURRENT_TIME_SEC;
237 mark_inode_dirty(dir);
238 inode->i_ctime = dir->i_ctime;
239 inode_dec_link_count(inode);