xref: /dflybsd-src/sys/vfs/hpfs/hpfs_lookup.c (revision 86d7f5d305c6adaa56ff4582ece9859d73106103)
186d7f5d3SJohn Marino /*-
286d7f5d3SJohn Marino  * Copyright (c) 1998, 1999 Semen Ustimenko (semenu@FreeBSD.org)
386d7f5d3SJohn Marino  * All rights reserved.
486d7f5d3SJohn Marino  *
586d7f5d3SJohn Marino  * Redistribution and use in source and binary forms, with or without
686d7f5d3SJohn Marino  * modification, are permitted provided that the following conditions
786d7f5d3SJohn Marino  * are met:
886d7f5d3SJohn Marino  * 1. Redistributions of source code must retain the above copyright
986d7f5d3SJohn Marino  *    notice, this list of conditions and the following disclaimer.
1086d7f5d3SJohn Marino  * 2. Redistributions in binary form must reproduce the above copyright
1186d7f5d3SJohn Marino  *    notice, this list of conditions and the following disclaimer in the
1286d7f5d3SJohn Marino  *    documentation and/or other materials provided with the distribution.
1386d7f5d3SJohn Marino  *
1486d7f5d3SJohn Marino  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1586d7f5d3SJohn Marino  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1686d7f5d3SJohn Marino  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1786d7f5d3SJohn Marino  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1886d7f5d3SJohn Marino  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1986d7f5d3SJohn Marino  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2086d7f5d3SJohn Marino  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2186d7f5d3SJohn Marino  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2286d7f5d3SJohn Marino  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2386d7f5d3SJohn Marino  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2486d7f5d3SJohn Marino  * SUCH DAMAGE.
2586d7f5d3SJohn Marino  *
2686d7f5d3SJohn Marino  * $FreeBSD: src/sys/fs/hpfs/hpfs_lookup.c,v 1.1 1999/12/09 19:09:59 semenu Exp $
2786d7f5d3SJohn Marino  * $DragonFly: src/sys/vfs/hpfs/hpfs_lookup.c,v 1.4 2003/08/07 21:17:41 dillon Exp $
2886d7f5d3SJohn Marino  */
2986d7f5d3SJohn Marino 
3086d7f5d3SJohn Marino #include <sys/param.h>
3186d7f5d3SJohn Marino #include <sys/systm.h>
3286d7f5d3SJohn Marino #include <sys/kernel.h>
3386d7f5d3SJohn Marino #include <sys/proc.h>
3486d7f5d3SJohn Marino #include <sys/time.h>
3586d7f5d3SJohn Marino #include <sys/types.h>
3686d7f5d3SJohn Marino #include <sys/stat.h>
3786d7f5d3SJohn Marino #include <sys/vnode.h>
3886d7f5d3SJohn Marino #include <sys/mount.h>
3986d7f5d3SJohn Marino #include <sys/namei.h>
4086d7f5d3SJohn Marino #include <sys/malloc.h>
4186d7f5d3SJohn Marino #include <sys/buf.h>
4286d7f5d3SJohn Marino 
4386d7f5d3SJohn Marino #include "hpfs.h"
4486d7f5d3SJohn Marino #include "hpfsmount.h"
4586d7f5d3SJohn Marino #include "hpfs_subr.h"
4686d7f5d3SJohn Marino 
4786d7f5d3SJohn Marino int	hpfs_removedirent (struct hpfsmount *, lsn_t, char *, int, int *);
4886d7f5d3SJohn Marino 
4986d7f5d3SJohn Marino /*
5086d7f5d3SJohn Marino  * This routine traverse the b+ tree representing directory
5186d7f5d3SJohn Marino  * looking for file named 'name'. Returns buf struct and hpfsdirent
5286d7f5d3SJohn Marino  * pointer. Calling routine is supposed to brelse buffer.
5386d7f5d3SJohn Marino  * name is supposed in Unix encodeing.
5486d7f5d3SJohn Marino  */
5586d7f5d3SJohn Marino int
hpfs_genlookupbyname(struct hpfsnode * dhp,char * name,int namelen,struct buf ** bpp,struct hpfsdirent ** depp)5686d7f5d3SJohn Marino hpfs_genlookupbyname (
5786d7f5d3SJohn Marino 	struct hpfsnode *dhp,
5886d7f5d3SJohn Marino 	char *name,
5986d7f5d3SJohn Marino 	int namelen,
6086d7f5d3SJohn Marino 	struct buf **bpp,
6186d7f5d3SJohn Marino 	struct hpfsdirent **depp)
6286d7f5d3SJohn Marino {
6386d7f5d3SJohn Marino 	struct hpfsmount *hpmp = dhp->h_hpmp;
6486d7f5d3SJohn Marino 	struct buf *bp;
6586d7f5d3SJohn Marino 	struct dirblk *dp;
6686d7f5d3SJohn Marino 	struct hpfsdirent *dep;
6786d7f5d3SJohn Marino 	lsn_t lsn;
6886d7f5d3SJohn Marino 	int error, res;
6986d7f5d3SJohn Marino 
7086d7f5d3SJohn Marino 	dprintf(("hpfs_genlookupbyname(0x%x, %s (%d)): \n",
7186d7f5d3SJohn Marino 		dhp->h_no, name, namelen));
7286d7f5d3SJohn Marino 
7386d7f5d3SJohn Marino 	lsn = ((alleaf_t *)dhp->h_fn.fn_abd)->al_lsn;
7486d7f5d3SJohn Marino dive:
7586d7f5d3SJohn Marino 	error = hpfs_breaddirblk (hpmp, lsn, &bp);
7686d7f5d3SJohn Marino 	if (error)
7786d7f5d3SJohn Marino 		return (error);
7886d7f5d3SJohn Marino 
7986d7f5d3SJohn Marino 	dp = (struct dirblk *) bp->b_data;
8086d7f5d3SJohn Marino 	dep = D_DIRENT(dp);
8186d7f5d3SJohn Marino 
8286d7f5d3SJohn Marino 	while(!(dep->de_flag & DE_END)) {
8386d7f5d3SJohn Marino 		dprintf(("no: 0x%x, size: %d, name: %2d:%.*s, flag: 0x%x\n",
8486d7f5d3SJohn Marino 			dep->de_fnode, dep->de_size, dep->de_namelen,
8586d7f5d3SJohn Marino 			dep->de_namelen, dep->de_name, dep->de_flag));
8686d7f5d3SJohn Marino 
8786d7f5d3SJohn Marino 		res = hpfs_cmpfname(hpmp, name, namelen,
8886d7f5d3SJohn Marino 				dep->de_name, dep->de_namelen, dep->de_cpid);
8986d7f5d3SJohn Marino 		if (res == 0) {
9086d7f5d3SJohn Marino 			*bpp = bp;
9186d7f5d3SJohn Marino 			*depp = dep;
9286d7f5d3SJohn Marino 			return (0);
9386d7f5d3SJohn Marino 		} else if (res < 0)
9486d7f5d3SJohn Marino 			break;
9586d7f5d3SJohn Marino 
9686d7f5d3SJohn Marino 		dep = (hpfsdirent_t *)(((caddr_t)dep) + dep->de_reclen);
9786d7f5d3SJohn Marino 	}
9886d7f5d3SJohn Marino 
9986d7f5d3SJohn Marino 	if (dep->de_flag & DE_DOWN) {
10086d7f5d3SJohn Marino 		lsn = DE_DOWNLSN(dep);
10186d7f5d3SJohn Marino 		brelse(bp);
10286d7f5d3SJohn Marino 		goto dive;
10386d7f5d3SJohn Marino 	}
10486d7f5d3SJohn Marino 
10586d7f5d3SJohn Marino 	brelse(bp);
10686d7f5d3SJohn Marino 
10786d7f5d3SJohn Marino 	return (ENOENT);
10886d7f5d3SJohn Marino }
10986d7f5d3SJohn Marino 
11086d7f5d3SJohn Marino int
hpfs_makefnode(struct vnode * dvp,struct vnode ** vpp,struct componentname * cnp,struct vattr * vap)11186d7f5d3SJohn Marino hpfs_makefnode (
11286d7f5d3SJohn Marino 	struct vnode * dvp,
11386d7f5d3SJohn Marino 	struct vnode ** vpp,
11486d7f5d3SJohn Marino 	struct componentname *cnp,
11586d7f5d3SJohn Marino 	struct vattr *vap)
11686d7f5d3SJohn Marino {
11786d7f5d3SJohn Marino #ifdef HPFS_DEBUG
11886d7f5d3SJohn Marino 	struct hpfsnode *dhp = VTOHP(dvp);
11986d7f5d3SJohn Marino 	dprintf(("hpfs_makefnode(0x%x, %s, %ld): \n",
12086d7f5d3SJohn Marino 		dhp->h_no, cnp->cn_nameptr, cnp->cn_namelen));
12186d7f5d3SJohn Marino #endif
12286d7f5d3SJohn Marino 
12386d7f5d3SJohn Marino 	return (EOPNOTSUPP);
12486d7f5d3SJohn Marino }
12586d7f5d3SJohn Marino 
12686d7f5d3SJohn Marino int
hpfs_removedirent(struct hpfsmount * hpmp,lsn_t lsn,char * name,int namelen,int * retp)12786d7f5d3SJohn Marino hpfs_removedirent (
12886d7f5d3SJohn Marino 	struct hpfsmount *hpmp,
12986d7f5d3SJohn Marino 	lsn_t lsn,
13086d7f5d3SJohn Marino 	char *name,
13186d7f5d3SJohn Marino 	int namelen,
13286d7f5d3SJohn Marino 	int *retp)
13386d7f5d3SJohn Marino {
13486d7f5d3SJohn Marino #if 0
13586d7f5d3SJohn Marino 	struct buf *bp;
13686d7f5d3SJohn Marino 	dirblk_t *dbp;
13786d7f5d3SJohn Marino 	struct hpfsdirent *dep;
13886d7f5d3SJohn Marino 	int deoff;
13986d7f5d3SJohn Marino 	int error, ret;
14086d7f5d3SJohn Marino 
14186d7f5d3SJohn Marino 	dprintf(("hpfs_removedirent(0x%x, %.*s, %d): \n",
14286d7f5d3SJohn Marino 		 lsn, namelen, name, namelen));
14386d7f5d3SJohn Marino 
14486d7f5d3SJohn Marino 	error = hpfs_breaddirblk (hpmp, lsn, &bp);
14586d7f5d3SJohn Marino 	if (error)
14686d7f5d3SJohn Marino 		return (error);
14786d7f5d3SJohn Marino 
14886d7f5d3SJohn Marino 	dbp = (dirblk_t *) bp->b_data;
14986d7f5d3SJohn Marino 	deoff = sizeof(dirblk_t);
15086d7f5d3SJohn Marino 	dep = DB_DIRENT(dbp);
15186d7f5d3SJohn Marino 
15286d7f5d3SJohn Marino 	while(!(dep->de_flag & DE_END)) {
15386d7f5d3SJohn Marino 		dprintf(("no: 0x%x, size: %d, name: %2d:%.*s, flag: 0x%x\n",
15486d7f5d3SJohn Marino 			dep->de_fnode, dep->de_size, dep->de_namelen,
15586d7f5d3SJohn Marino 			dep->de_namelen, dep->de_name, dep->de_flag));
15686d7f5d3SJohn Marino 
15786d7f5d3SJohn Marino 		res = hpfs_cmpfname(hpmp, name, namelen,
15886d7f5d3SJohn Marino 				dep->de_name, dep->de_namelen, dep->de_cpid);
15986d7f5d3SJohn Marino 		if (res == 0) {
16086d7f5d3SJohn Marino 			if (dep->de_flag & DE_DOWN) {
16186d7f5d3SJohn Marino 				/*XXXXXX*/
16286d7f5d3SJohn Marino 			} else {
16386d7f5d3SJohn Marino 				/* XXX we can copy less */
16486d7f5d3SJohn Marino 				bcopy (DE_NEXTDE(dep), dep, DB_BSIZE - deoff - dep->de_reclen);
16586d7f5d3SJohn Marino 				dbp->d_freeoff -= dep->de_reclen;
16686d7f5d3SJohn Marino 				*retp = 0;
16786d7f5d3SJohn Marino 			}
16886d7f5d3SJohn Marino 			bdwrite (bp);
16986d7f5d3SJohn Marino 			return (0);
17086d7f5d3SJohn Marino 		} else if (res < 0)
17186d7f5d3SJohn Marino 			break;
17286d7f5d3SJohn Marino 
17386d7f5d3SJohn Marino 		deoff += dep->de_reclen;
17486d7f5d3SJohn Marino 		dep = DB_NEXTDE(dep);
17586d7f5d3SJohn Marino 	}
17686d7f5d3SJohn Marino 
17786d7f5d3SJohn Marino 	if (dep->de_flag & DE_DOWN) {
17886d7f5d3SJohn Marino 		error = hpfs_removede (hpmp, DE_DOWNLSN(dep), name, namelen, &ret);
17986d7f5d3SJohn Marino 		if (error) {
18086d7f5d3SJohn Marino 			brelse (bp);
18186d7f5d3SJohn Marino 			return (error);
18286d7f5d3SJohn Marino 		}
18386d7f5d3SJohn Marino 		if (ret == 0) {
18486d7f5d3SJohn Marino 			if (deoff > sizeof (dirblk_t)) {
18586d7f5d3SJohn Marino 			} else if (deoff + dep->de_reclen < dbp->db_freeoff) {
18686d7f5d3SJohn Marino 			}
18786d7f5d3SJohn Marino 		}
18886d7f5d3SJohn Marino 	} else {
18986d7f5d3SJohn Marino 		error = ENOENT;
19086d7f5d3SJohn Marino 	}
19186d7f5d3SJohn Marino 
19286d7f5d3SJohn Marino 	brelse (bp);
19386d7f5d3SJohn Marino 	return (error);
19486d7f5d3SJohn Marino #endif
19586d7f5d3SJohn Marino 	return (EOPNOTSUPP);
19686d7f5d3SJohn Marino }
19786d7f5d3SJohn Marino 
19886d7f5d3SJohn Marino int
hpfs_removefnode(struct vnode * dvp,struct vnode * vp,struct componentname * cnp)19986d7f5d3SJohn Marino hpfs_removefnode (
20086d7f5d3SJohn Marino 	struct vnode * dvp,
20186d7f5d3SJohn Marino 	struct vnode * vp,
20286d7f5d3SJohn Marino 	struct componentname *cnp)
20386d7f5d3SJohn Marino {
20486d7f5d3SJohn Marino #ifdef HPFS_DEBUG
20586d7f5d3SJohn Marino 	struct hpfsnode *dhp = VTOHP(dvp);
20686d7f5d3SJohn Marino 	struct hpfsnode *hp = VTOHP(vp);
20786d7f5d3SJohn Marino 	dprintf(("hpfs_removefnode(0x%x, 0x%x, %s, %ld): \n",
20886d7f5d3SJohn Marino 		dhp->h_no, hp->h_no, cnp->cn_nameptr, cnp->cn_namelen));
20986d7f5d3SJohn Marino #endif
21086d7f5d3SJohn Marino 
21186d7f5d3SJohn Marino 
21286d7f5d3SJohn Marino 	return (EOPNOTSUPP);
21386d7f5d3SJohn Marino }
214