1/*
2 * ntfs_dir.h - Defines for directory handling in the NTFS kernel driver.
3 *
4 * Copyright (c) 2006-2008 Anton Altaparmakov.  All Rights Reserved.
5 * Portions Copyright (c) 2006-2008 Apple Inc.  All Rights Reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright notice,
11 *    this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright notice,
13 *    this list of conditions and the following disclaimer in the documentation
14 *    and/or other materials provided with the distribution.
15 * 3. Neither the name of Apple Inc. ("Apple") nor the names of its
16 *    contributors may be used to endorse or promote products derived from this
17 *    software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
20 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 *
30 * ALTERNATIVELY, provided that this notice and licensing terms are retained in
31 * full, this file may be redistributed and/or modified under the terms of the
32 * GNU General Public License (GPL) Version 2, in which case the provisions of
33 * that version of the GPL will apply to you instead of the license terms
34 * above.  You can obtain a copy of the GPL Version 2 at
35 * http://developer.apple.com/opensource/licenses/gpl-2.txt.
36 */
37
38#ifndef _OSX_NTFS_DIR_H
39#define _OSX_NTFS_DIR_H
40
41#include <sys/errno.h>
42#include <sys/uio.h>
43
44#include "ntfs.h"
45#include "ntfs_inode.h"
46#include "ntfs_layout.h"
47#include "ntfs_types.h"
48
49/*
50 * ntfs_name is used to return the actual found filename to the caller of
51 * ntfs_lookup_inode_by_name() in order for the caller
52 * (ntfs_vnops.c::ntfs_vnop_lookup()) to be able to deal with the case
53 * sensitive name cache effectively.
54 */
55typedef struct {
56	MFT_REF mref;
57	FILENAME_TYPE_FLAGS type;
58	u8 len;
59	ntfschar name[NTFS_MAX_NAME_LEN];
60} ntfs_dir_lookup_name;
61
62/* The little endian Unicode string $I30 as a global constant. */
63__private_extern__ ntfschar I30[5];
64
65__private_extern__ errno_t ntfs_lookup_inode_by_name(ntfs_inode *dir_ni,
66		const ntfschar *uname, const signed uname_len,
67		MFT_REF *res_mref, ntfs_dir_lookup_name **res_name);
68
69__private_extern__ errno_t ntfs_readdir(ntfs_inode *dir_ni, uio_t uio,
70		int *eofflag, int *numdirent);
71
72__private_extern__ errno_t ntfs_dir_is_empty(ntfs_inode *dir_ni);
73
74__private_extern__ errno_t ntfs_dir_entry_delete(ntfs_inode *dir_ni,
75		ntfs_inode *ni, const FILENAME_ATTR *fn, const u32 fn_len);
76
77__private_extern__ errno_t ntfs_dir_entry_add(ntfs_inode *dir_ni,
78		const FILENAME_ATTR *fn, const u32 fn_len,
79		const leMFT_REF mref);
80
81/**
82 * struct _ntfs_dirhint - directory hint structure
83 *
84 * This is used to store state across directory enumerations, i.e. across calls
85 * to ntfs_readdir().
86 */
87struct _ntfs_dirhint {
88	TAILQ_ENTRY(_ntfs_dirhint) link;
89	unsigned ofs;
90	unsigned time;
91	unsigned fn_size;
92	FILENAME_ATTR *fn;
93};
94typedef struct _ntfs_dirhint ntfs_dirhint;
95
96/*
97 * NTFS_MAX_DIRHINTS cannot be larger than 63 without reducing
98 * NTFS_DIR_POS_MASK, because given the 6-bit tag, at most 63 different tags
99 * can exist.  When NTFS_MAX_DIRHINTS is larger than 63, the same list may
100 * contain dirhints of the same tag, and a staled dirhint may be returned.
101 */
102#define NTFS_MAX_DIRHINTS 32
103#define NTFS_DIRHINT_TTL 45
104#define NTFS_DIR_POS_MASK 0x03ffffff
105#define NTFS_DIR_TAG_MASK 0xfc000000
106#define NTFS_DIR_TAG_SHIFT 26
107
108__private_extern__ void ntfs_dirhints_put(ntfs_inode *ni, BOOL stale_only);
109
110#endif /* !_OSX_NTFS_DIR_H */
111