xref: /freebsd/sys/fs/msdosfs/denode.h (revision a176f73d19b9762975fc410fc715d0e12e57ad7f)
1a176f73dSBruce Evans /*	$Id: denode.h,v 1.2 1994/12/12 12:35:40 bde Exp $ */
227a0bc89SDoug Rabson /*	$NetBSD: denode.h,v 1.8 1994/08/21 18:43:49 ws Exp $	*/
327a0bc89SDoug Rabson 
427a0bc89SDoug Rabson /*-
527a0bc89SDoug Rabson  * Copyright (C) 1994 Wolfgang Solfrank.
627a0bc89SDoug Rabson  * Copyright (C) 1994 TooLs GmbH.
727a0bc89SDoug Rabson  * All rights reserved.
827a0bc89SDoug Rabson  * Original code by Paul Popelka (paulp@uts.amdahl.com) (see below).
927a0bc89SDoug Rabson  *
1027a0bc89SDoug Rabson  * Redistribution and use in source and binary forms, with or without
1127a0bc89SDoug Rabson  * modification, are permitted provided that the following conditions
1227a0bc89SDoug Rabson  * are met:
1327a0bc89SDoug Rabson  * 1. Redistributions of source code must retain the above copyright
1427a0bc89SDoug Rabson  *    notice, this list of conditions and the following disclaimer.
1527a0bc89SDoug Rabson  * 2. Redistributions in binary form must reproduce the above copyright
1627a0bc89SDoug Rabson  *    notice, this list of conditions and the following disclaimer in the
1727a0bc89SDoug Rabson  *    documentation and/or other materials provided with the distribution.
1827a0bc89SDoug Rabson  * 3. All advertising materials mentioning features or use of this software
1927a0bc89SDoug Rabson  *    must display the following acknowledgement:
2027a0bc89SDoug Rabson  *	This product includes software developed by TooLs GmbH.
2127a0bc89SDoug Rabson  * 4. The name of TooLs GmbH may not be used to endorse or promote products
2227a0bc89SDoug Rabson  *    derived from this software without specific prior written permission.
2327a0bc89SDoug Rabson  *
2427a0bc89SDoug Rabson  * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
2527a0bc89SDoug Rabson  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
2627a0bc89SDoug Rabson  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2727a0bc89SDoug Rabson  * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2827a0bc89SDoug Rabson  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
2927a0bc89SDoug Rabson  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
3027a0bc89SDoug Rabson  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
3127a0bc89SDoug Rabson  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
3227a0bc89SDoug Rabson  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
3327a0bc89SDoug Rabson  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3427a0bc89SDoug Rabson  */
3527a0bc89SDoug Rabson /*
3627a0bc89SDoug Rabson  * Written by Paul Popelka (paulp@uts.amdahl.com)
3727a0bc89SDoug Rabson  *
3827a0bc89SDoug Rabson  * You can do anything you want with this software, just don't say you wrote
3927a0bc89SDoug Rabson  * it, and don't remove this notice.
4027a0bc89SDoug Rabson  *
4127a0bc89SDoug Rabson  * This software is provided "as is".
4227a0bc89SDoug Rabson  *
4327a0bc89SDoug Rabson  * The author supplies this software to be publicly redistributed on the
4427a0bc89SDoug Rabson  * understanding that the author is not responsible for the correct
4527a0bc89SDoug Rabson  * functioning of this software in any circumstances and is not liable for
4627a0bc89SDoug Rabson  * any damages caused by this software.
4727a0bc89SDoug Rabson  *
4827a0bc89SDoug Rabson  * October 1992
4927a0bc89SDoug Rabson  */
5027a0bc89SDoug Rabson 
5127a0bc89SDoug Rabson /*
5227a0bc89SDoug Rabson  * This is the pc filesystem specific portion of the vnode structure.
5327a0bc89SDoug Rabson  *
5427a0bc89SDoug Rabson  * To describe a file uniquely the de_dirclust, de_diroffset, and
5527a0bc89SDoug Rabson  * de_StartCluster fields are used.
5627a0bc89SDoug Rabson  *
5727a0bc89SDoug Rabson  * de_dirclust contains the cluster number of the directory cluster
5827a0bc89SDoug Rabson  *	containing the entry for a file or directory.
5927a0bc89SDoug Rabson  * de_diroffset is the index into the cluster for the entry describing
6027a0bc89SDoug Rabson  *	a file or directory.
6127a0bc89SDoug Rabson  * de_StartCluster is the number of the first cluster of the file or directory.
6227a0bc89SDoug Rabson  *
6327a0bc89SDoug Rabson  * Now to describe the quirks of the pc filesystem.
6427a0bc89SDoug Rabson  * - Clusters 0 and 1 are reserved.
6527a0bc89SDoug Rabson  * - The first allocatable cluster is 2.
6627a0bc89SDoug Rabson  * - The root directory is of fixed size and all blocks that make it up
6727a0bc89SDoug Rabson  *   are contiguous.
6827a0bc89SDoug Rabson  * - Cluster 0 refers to the root directory when it is found in the
6927a0bc89SDoug Rabson  *   startcluster field of a directory entry that points to another directory.
7027a0bc89SDoug Rabson  * - Cluster 0 implies a 0 length file when found in the start cluster field
7127a0bc89SDoug Rabson  *   of a directory entry that points to a file.
7227a0bc89SDoug Rabson  * - You can't use the cluster number 0 to derive the address of the root
7327a0bc89SDoug Rabson  *   directory.
7427a0bc89SDoug Rabson  * - Multiple directory entries can point to a directory. The entry in the
7527a0bc89SDoug Rabson  *   parent directory points to a child directory.  Any directories in the
7627a0bc89SDoug Rabson  *   child directory contain a ".." entry that points back to the parent.
7727a0bc89SDoug Rabson  *   The child directory itself contains a "." entry that points to itself.
7827a0bc89SDoug Rabson  * - The root directory does not contain a "." or ".." entry.
7927a0bc89SDoug Rabson  * - Directory entries for directories are never changed once they are created
8027a0bc89SDoug Rabson  *   (except when removed).  The size stays 0, and the last modification time
8127a0bc89SDoug Rabson  *   is never changed.  This is because so many directory entries can point to
8227a0bc89SDoug Rabson  *   the physical clusters that make up a directory.  It would lead to an
8327a0bc89SDoug Rabson  *   update nightmare.
8427a0bc89SDoug Rabson  * - The length field in a directory entry pointing to a directory contains 0
8527a0bc89SDoug Rabson  *   (always).  The only way to find the end of a directory is to follow the
8627a0bc89SDoug Rabson  *   cluster chain until the "last cluster" marker is found.
8727a0bc89SDoug Rabson  *
8827a0bc89SDoug Rabson  * My extensions to make this house of cards work.  These apply only to the in
8927a0bc89SDoug Rabson  * memory copy of the directory entry.
9027a0bc89SDoug Rabson  * - A reference count for each denode will be kept since dos doesn't keep such
9127a0bc89SDoug Rabson  *   things.
9227a0bc89SDoug Rabson  */
9327a0bc89SDoug Rabson 
9427a0bc89SDoug Rabson /*
9527a0bc89SDoug Rabson  * Internal pseudo-offset for (nonexistent) directory entry for the root
9627a0bc89SDoug Rabson  * dir in the root dir
9727a0bc89SDoug Rabson  */
9827a0bc89SDoug Rabson #define	MSDOSFSROOT_OFS	0x1fffffff
9927a0bc89SDoug Rabson 
10027a0bc89SDoug Rabson /*
10127a0bc89SDoug Rabson  * The fat cache structure. fc_fsrcn is the filesystem relative cluster
10227a0bc89SDoug Rabson  * number that corresponds to the file relative cluster number in this
10327a0bc89SDoug Rabson  * structure (fc_frcn).
10427a0bc89SDoug Rabson  */
10527a0bc89SDoug Rabson struct fatcache {
10627a0bc89SDoug Rabson 	u_short fc_frcn;	/* file relative cluster number */
10727a0bc89SDoug Rabson 	u_short fc_fsrcn;	/* filesystem relative cluster number */
10827a0bc89SDoug Rabson };
10927a0bc89SDoug Rabson 
11027a0bc89SDoug Rabson /*
11127a0bc89SDoug Rabson  * The fat entry cache as it stands helps make extending files a "quick"
11227a0bc89SDoug Rabson  * operation by avoiding having to scan the fat to discover the last
11327a0bc89SDoug Rabson  * cluster of the file. The cache also helps sequential reads by
11427a0bc89SDoug Rabson  * remembering the last cluster read from the file.  This also prevents us
11527a0bc89SDoug Rabson  * from having to rescan the fat to find the next cluster to read.  This
11627a0bc89SDoug Rabson  * cache is probably pretty worthless if a file is opened by multiple
11727a0bc89SDoug Rabson  * processes.
11827a0bc89SDoug Rabson  */
11927a0bc89SDoug Rabson #define	FC_SIZE		2	/* number of entries in the cache */
12027a0bc89SDoug Rabson #define	FC_LASTMAP	0	/* entry the last call to pcbmap() resolved
12127a0bc89SDoug Rabson 				 * to */
12227a0bc89SDoug Rabson #define	FC_LASTFC	1	/* entry for the last cluster in the file */
12327a0bc89SDoug Rabson 
12427a0bc89SDoug Rabson #define	FCE_EMPTY	0xffff	/* doesn't represent an actual cluster # */
12527a0bc89SDoug Rabson 
12627a0bc89SDoug Rabson /*
12727a0bc89SDoug Rabson  * Set a slot in the fat cache.
12827a0bc89SDoug Rabson  */
12927a0bc89SDoug Rabson #define	fc_setcache(dep, slot, frcn, fsrcn) \
13027a0bc89SDoug Rabson 	(dep)->de_fc[slot].fc_frcn = frcn; \
13127a0bc89SDoug Rabson 	(dep)->de_fc[slot].fc_fsrcn = fsrcn;
13227a0bc89SDoug Rabson 
13327a0bc89SDoug Rabson /*
13427a0bc89SDoug Rabson  * This is the in memory variant of a dos directory entry.  It is usually
13527a0bc89SDoug Rabson  * contained within a vnode.
13627a0bc89SDoug Rabson  */
13727a0bc89SDoug Rabson struct denode {
13827a0bc89SDoug Rabson 	struct denode *de_next;	/* Hash chain forward */
13927a0bc89SDoug Rabson 	struct denode **de_prev; /* Hash chain back */
14027a0bc89SDoug Rabson 	struct vnode *de_vnode;	/* addr of vnode we are part of */
14127a0bc89SDoug Rabson 	struct vnode *de_devvp;	/* vnode of blk dev we live on */
14227a0bc89SDoug Rabson 	u_long de_flag;		/* flag bits */
14327a0bc89SDoug Rabson 	dev_t de_dev;		/* device where direntry lives */
14427a0bc89SDoug Rabson 	u_long de_dirclust;	/* cluster of the directory file containing this entry */
14527a0bc89SDoug Rabson 	u_long de_diroffset;	/* ordinal of this entry in the directory */
14627a0bc89SDoug Rabson 	u_long de_fndclust;	/* cluster of found dir entry */
14727a0bc89SDoug Rabson 	u_long de_fndoffset;	/* offset of found dir entry */
14827a0bc89SDoug Rabson 	long de_refcnt;		/* reference count */
14927a0bc89SDoug Rabson 	struct msdosfsmount *de_pmp;	/* addr of our mount struct */
15027a0bc89SDoug Rabson 	struct lockf *de_lockf;	/* byte level lock list */
15127a0bc89SDoug Rabson 	pid_t de_lockholder;	/* current lock holder */
15227a0bc89SDoug Rabson 	pid_t de_lockwaiter;	/* lock wanter */
15327a0bc89SDoug Rabson 	/* the next two fields must be contiguous in memory... */
15427a0bc89SDoug Rabson 	u_char de_Name[8];	/* name, from directory entry */
15527a0bc89SDoug Rabson 	u_char de_Extension[3];	/* extension, from directory entry */
15627a0bc89SDoug Rabson 	u_char de_Attributes;	/* attributes, from directory entry */
15727a0bc89SDoug Rabson 	u_short de_Time;	/* creation time */
15827a0bc89SDoug Rabson 	u_short de_Date;	/* creation date */
15927a0bc89SDoug Rabson 	u_short de_StartCluster; /* starting cluster of file */
16027a0bc89SDoug Rabson 	u_long de_FileSize;	/* size of file in bytes */
16127a0bc89SDoug Rabson 	struct fatcache de_fc[FC_SIZE];	/* fat cache */
16227a0bc89SDoug Rabson };
16327a0bc89SDoug Rabson 
16427a0bc89SDoug Rabson /*
16527a0bc89SDoug Rabson  * Values for the de_flag field of the denode.
16627a0bc89SDoug Rabson  */
16727a0bc89SDoug Rabson #define	DE_LOCKED	0x0001	/* directory entry is locked */
16827a0bc89SDoug Rabson #define	DE_WANTED	0x0002	/* someone wants this de */
16963e4f22aSBruce Evans #define	DE_UPDATE	0x0004	/* modification time update request */
17063e4f22aSBruce Evans #define	DE_MODIFIED	0x0080	/* denode has been modified, but DE_UPDATE
17163e4f22aSBruce Evans 				 * isn't set */
17227a0bc89SDoug Rabson 
17327a0bc89SDoug Rabson /*
17427a0bc89SDoug Rabson  * Transfer directory entries between internal and external form.
17527a0bc89SDoug Rabson  * dep is a struct denode * (internal form),
17627a0bc89SDoug Rabson  * dp is a struct direntry * (external form).
17727a0bc89SDoug Rabson  */
17827a0bc89SDoug Rabson #define DE_INTERNALIZE(dep, dp)			\
17927a0bc89SDoug Rabson 	(bcopy((dp)->deName, (dep)->de_Name, 11),	\
18027a0bc89SDoug Rabson 	 (dep)->de_Attributes = (dp)->deAttributes,	\
18127a0bc89SDoug Rabson 	 (dep)->de_Time = getushort((dp)->deTime),	\
18227a0bc89SDoug Rabson 	 (dep)->de_Date = getushort((dp)->deDate),	\
18327a0bc89SDoug Rabson 	 (dep)->de_StartCluster = getushort((dp)->deStartCluster), \
18427a0bc89SDoug Rabson 	 (dep)->de_FileSize = getulong((dp)->deFileSize))
18527a0bc89SDoug Rabson 
18627a0bc89SDoug Rabson #define DE_EXTERNALIZE(dp, dep)				\
18727a0bc89SDoug Rabson 	(bcopy((dep)->de_Name, (dp)->deName, 11),	\
18827a0bc89SDoug Rabson 	 (dp)->deAttributes = (dep)->de_Attributes,	\
18927a0bc89SDoug Rabson 	 putushort((dp)->deTime, (dep)->de_Time),	\
19027a0bc89SDoug Rabson 	 putushort((dp)->deDate, (dep)->de_Date),	\
19127a0bc89SDoug Rabson 	 putushort((dp)->deStartCluster, (dep)->de_StartCluster), \
19227a0bc89SDoug Rabson 	 putulong((dp)->deFileSize, (dep)->de_FileSize))
19327a0bc89SDoug Rabson 
19427a0bc89SDoug Rabson #define	de_forw		de_chain[0]
19527a0bc89SDoug Rabson #define	de_back		de_chain[1]
19627a0bc89SDoug Rabson 
19727a0bc89SDoug Rabson #ifdef KERNEL
19827a0bc89SDoug Rabson 
19927a0bc89SDoug Rabson #define	VTODE(vp)	((struct denode *)(vp)->v_data)
20027a0bc89SDoug Rabson #define	DETOV(de)	((de)->de_vnode)
20127a0bc89SDoug Rabson 
20227a0bc89SDoug Rabson #define	DE_TIMES(dep, t) \
20363e4f22aSBruce Evans 	if ((dep)->de_flag & DE_UPDATE) { \
204a176f73dSBruce Evans 		if (!((dep)->de_Attributes & ATTR_DIRECTORY)) { \
20563e4f22aSBruce Evans 			struct timespec DE_TIMES_ts; \
20627a0bc89SDoug Rabson 			(dep)->de_flag |= DE_MODIFIED; \
20763e4f22aSBruce Evans 			TIMEVAL_TO_TIMESPEC((t), &DE_TIMES_ts); \
208a176f73dSBruce Evans 			unix2dostime(&DE_TIMES_ts, &(dep)->de_Date, \
209a176f73dSBruce Evans 				     &(dep)->de_Time); \
210a176f73dSBruce Evans 			(dep)->de_Attributes |= ATTR_ARCHIVE; \
211a176f73dSBruce Evans 		} \
21227a0bc89SDoug Rabson 		(dep)->de_flag &= ~DE_UPDATE; \
21327a0bc89SDoug Rabson 	}
21427a0bc89SDoug Rabson 
21527a0bc89SDoug Rabson /*
21663e4f22aSBruce Evans  * This overlays the fid structure (see mount.h)
21727a0bc89SDoug Rabson  */
21827a0bc89SDoug Rabson struct defid {
21927a0bc89SDoug Rabson 	u_short defid_len;	/* length of structure */
22027a0bc89SDoug Rabson 	u_short defid_pad;	/* force long alignment */
22127a0bc89SDoug Rabson 
22227a0bc89SDoug Rabson 	u_long defid_dirclust;	/* cluster this dir entry came from */
22327a0bc89SDoug Rabson 	u_long defid_dirofs;	/* index of entry within the cluster */
22427a0bc89SDoug Rabson 
22527a0bc89SDoug Rabson 	/* u_long	defid_gen;	 generation number */
22627a0bc89SDoug Rabson };
22727a0bc89SDoug Rabson 
22827a0bc89SDoug Rabson /*
22927a0bc89SDoug Rabson  * Prototypes for MSDOSFS vnode operations
23027a0bc89SDoug Rabson  */
23127a0bc89SDoug Rabson int msdosfs_lookup __P((struct vop_lookup_args *));
23227a0bc89SDoug Rabson int msdosfs_create __P((struct vop_create_args *));
23327a0bc89SDoug Rabson int msdosfs_mknod __P((struct vop_mknod_args *));
23427a0bc89SDoug Rabson int msdosfs_open __P((struct vop_open_args *));
23527a0bc89SDoug Rabson int msdosfs_close __P((struct vop_close_args *));
23627a0bc89SDoug Rabson int msdosfs_access __P((struct vop_access_args *));
23727a0bc89SDoug Rabson int msdosfs_getattr __P((struct vop_getattr_args *));
23827a0bc89SDoug Rabson int msdosfs_setattr __P((struct vop_setattr_args *));
23927a0bc89SDoug Rabson int msdosfs_read __P((struct vop_read_args *));
24027a0bc89SDoug Rabson int msdosfs_write __P((struct vop_write_args *));
24127a0bc89SDoug Rabson int msdosfs_ioctl __P((struct vop_ioctl_args *));
24227a0bc89SDoug Rabson int msdosfs_select __P((struct vop_select_args *));
24327a0bc89SDoug Rabson int msdosfs_mmap __P((struct vop_mmap_args *));
24427a0bc89SDoug Rabson int msdosfs_fsync __P((struct vop_fsync_args *));
24527a0bc89SDoug Rabson int msdosfs_seek __P((struct vop_seek_args *));
24627a0bc89SDoug Rabson int msdosfs_remove __P((struct vop_remove_args *));
24727a0bc89SDoug Rabson int msdosfs_link __P((struct vop_link_args *));
24827a0bc89SDoug Rabson int msdosfs_rename __P((struct vop_rename_args *));
24927a0bc89SDoug Rabson int msdosfs_mkdir __P((struct vop_mkdir_args *));
25027a0bc89SDoug Rabson int msdosfs_rmdir __P((struct vop_rmdir_args *));
25127a0bc89SDoug Rabson int msdosfs_symlink __P((struct vop_symlink_args *));
25227a0bc89SDoug Rabson int msdosfs_readdir __P((struct vop_readdir_args *));
25327a0bc89SDoug Rabson int msdosfs_readlink __P((struct vop_readlink_args *));
25427a0bc89SDoug Rabson int msdosfs_abortop __P((struct vop_abortop_args *));
25527a0bc89SDoug Rabson int msdosfs_inactive __P((struct vop_inactive_args *));
25627a0bc89SDoug Rabson int msdosfs_reclaim __P((struct vop_reclaim_args *));
25727a0bc89SDoug Rabson int msdosfs_lock __P((struct vop_lock_args *));
25827a0bc89SDoug Rabson int msdosfs_unlock __P((struct vop_unlock_args *));
25927a0bc89SDoug Rabson int msdosfs_bmap __P((struct vop_bmap_args *));
26027a0bc89SDoug Rabson int msdosfs_strategy __P((struct vop_strategy_args *));
26127a0bc89SDoug Rabson int msdosfs_print __P((struct vop_print_args *));
26227a0bc89SDoug Rabson int msdosfs_islocked __P((struct vop_islocked_args *));
26327a0bc89SDoug Rabson int msdosfs_advlock __P((struct vop_advlock_args *));
26427a0bc89SDoug Rabson int msdosfs_reallocblks __P((struct vop_reallocblks_args *));
26527a0bc89SDoug Rabson 
26627a0bc89SDoug Rabson /*
26727a0bc89SDoug Rabson  * Internal service routine prototypes.
26827a0bc89SDoug Rabson  */
26927a0bc89SDoug Rabson int deget __P((struct msdosfsmount * pmp, u_long dirclust, u_long diroffset, struct direntry * direntptr, struct denode ** depp));
27027a0bc89SDoug Rabson #endif	/* KERNEL */
271