summaryrefslogtreecommitdiff
path: root/filesys/miniFilter/change/context.h
blob: 33bc0aa88df6363cc20817c3accea71b70f80823 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*++

Copyright (c) Microsoft Corporation.  All Rights Reserved

Module Name:

    context.h

Abstract:

    Header file which contains context-related data 
	structures, type definitions, constants, 
	global variables and function prototypes.

Environment:

    Kernel mode

--*/

#ifndef __CONTEXT_H__
#define __CONTEXT_H__

#define CG_FILE_CONTEXT_TAG                'cFcG'
#define CG_TRANSACTION_CONTEXT_TAG           'cTcG'

//
//  Defines the transaction context structure
//

typedef struct _CG_TRANSACTION_CONTEXT {

    //
    //  Transaction object pointer
    //
    
    PKTRANSACTION Transaction;
    
    //
    //  A flag that tracks if it has ben enlisted in transaction
    //
    
    BOOLEAN Enlisted;
    
    //
    //  A flag that indicates if the fc list is drained
    //
    
    BOOLEAN ListDrained;
    
    //
    //  List head for file context list.
    //  The list is grown only when transacted writers are part of the 
    //  transaction, i.e. this list contains all file contexts likely 
    //  to be modified in a transaction.
    //
    
    LIST_ENTRY   ScListHead;
    
    //
    //  Lock used to protect the list.
    //

    PFAST_MUTEX    Mutex;
    
} CG_TRANSACTION_CONTEXT, *PCG_TRANSACTION_CONTEXT;

#define CG_TRANSACTION_CONTEXT_SIZE         sizeof( CG_TRANSACTION_CONTEXT )

//
//  This is to deal with ReFS' 128-bit file IDs & NTFS' 64-bit FileIDs.
//

typedef union _CG_FILE_REFERENCE {

    //
    //  For 64-bit fileIDs the upper 64-bits are always zeroes.
    //

    struct {
        ULONGLONG   Value;
        ULONGLONG   UpperZeroes;
    } FileId64;

    FILE_ID_128 FileId128;

} CG_FILE_REFERENCE, *PCG_FILE_REFERENCE;

//
//  File context data structure
//

typedef struct _CG_FILE_CONTEXT {

    //
    //  File ID, obtained from querying the file system for
    //  FileInternalInformation or FileIdInformation.
    //
    
    CG_FILE_REFERENCE    FileID;
    
    //
    //  The flag that we use to record if the file is dirty 
    //  if we have seen it before.
    //
    
    BOOLEAN     Dirty;
    
    //
    //  TxDirty is to record if the file is dirty in a 
    //  transaction
    //
    
    BOOLEAN     TxDirty;
    
    //
    //  A pointer to the transaction context, so we can jump to list in the transaction.
    //
    
    PCG_TRANSACTION_CONTEXT  TxContext;
    
    //
    //  This list entry is exactly the embedded entry to 
    //  form a doubly linked list inside transaction context.
    //
    
    LIST_ENTRY  ListInTransaction;
    
} CG_FILE_CONTEXT, *PCG_FILE_CONTEXT;

#define CG_FILE_CONTEXT_SIZE         sizeof( CG_FILE_CONTEXT )




NTSTATUS
CgFindOrCreateFileContext (
    _In_ PFLT_CALLBACK_DATA Cbd,
    _Outptr_ PCG_FILE_CONTEXT *FileContext
    );

    
NTSTATUS
CgFindOrCreateTransactionContext(
    _In_ PCFLT_RELATED_OBJECTS FltObjects,
    _Outptr_ PCG_TRANSACTION_CONTEXT *TransactionContext
    );


#endif