2
* Copyright (C) 2005-2008 Junjiro Okajima
4
* This program, aufs is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22
* $Id: file.h,v 1.2 2008/04/21 01:35:14 sfjro Exp $
25
#ifndef __AUFS_FILE_H__
26
#define __AUFS_FILE_H__
30
#include <linux/file.h>
33
#include <linux/aufs_type.h>
38
/* ---------------------------------------------------------------------- */
43
struct au_branch *hf_br;
48
atomic_t fi_generation;
50
struct au_rwsem fi_rwsem;
51
struct au_hfile *fi_hfile;
52
aufs_bindex_t fi_bstart, fi_bend;
55
struct vm_operations_struct *fi_h_vm_ops;
56
struct au_vdir *fi_vdir_cache;
60
/* ---------------------------------------------------------------------- */
63
extern struct address_space_operations aufs_aop;
64
unsigned int au_file_roflags(unsigned int flags);
65
struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
67
int au_do_open(struct inode *inode, struct file *file,
68
int (*open)(struct file *file, int flags));
69
int au_reopen_nondir(struct file *file);
70
int au_ready_to_write(struct file *file, loff_t len);
71
int au_reval_and_lock_finfo(struct file *file, int (*reopen)(struct file *file),
72
int wlock, int locked);
75
extern struct file_operations aufs_file_fop;
76
int aufs_flush(struct file *file, fl_owner_t id);
79
struct au_finfo *au_fi(struct file *file);
80
struct au_branch *au_fbr(struct file *file, aufs_bindex_t bindex);
81
struct file *au_h_fptr(struct file *file, aufs_bindex_t bindex);
83
void au_hfput(struct au_hfile *hf);
84
void au_set_h_fptr(struct file *file, aufs_bindex_t bindex,
87
void au_finfo_fin(struct file *file);
88
int au_finfo_init(struct file *file);
90
#ifdef CONFIG_AUFS_ROBR
92
struct file *au_robr_safe_file(struct vm_area_struct *vma);
93
void au_robr_reset_file(struct vm_area_struct *vma, struct file *file);
95
static inline struct file *au_robr_safe_file(struct vm_area_struct *vma)
100
if (file->private_data && au_test_aufs(file->f_dentry->d_sb))
106
void au_robr_reset_file(struct vm_area_struct *vma, struct file *file)
109
smp_mb(); /* flush vm_file */
111
#endif /* CONFIG_AUFS_ROBR */
113
/* ---------------------------------------------------------------------- */
115
//todo: memory barrier?
116
static inline au_gen_t au_figen(struct file *f)
118
return atomic_read(&au_fi(f)->fi_generation);
121
static inline int au_test_mmapped(struct file *f)
123
return !!(au_fi(f)->fi_h_vm_ops);
126
static inline int au_test_aufs_file(struct file *f)
128
return !(f->f_dentry->d_inode->i_mode
129
& (S_IFCHR | S_IFBLK | S_IFIFO | S_IFSOCK));
132
/* ---------------------------------------------------------------------- */
134
#if !defined(CONFIG_AUFS_MODULE) || defined(CONFIG_AUFS_DENY_WRITE_ACCESS_PATCH)
135
int au_store_fmode_exec(struct nameidata *nd, struct inode *inode);
137
static inline int au_deny_write_access(struct file *h_file)
139
LKTRTrace("%.*s\n", AuDLNPair(h_file->f_dentry));
140
return deny_write_access(h_file);
143
static inline void au_allow_write_access(struct file *h_file)
145
allow_write_access(h_file);
150
static inline int au_store_fmode_exec(struct nameidata *nd, struct inode *inode)
156
static inline int au_deny_write_access(struct file *h_file)
162
static inline void au_allow_write_access(struct file *h_file)
166
#endif /* CONFIG_AUFS_DENY_WRITE_ACCESS_PATCH */
168
/* ---------------------------------------------------------------------- */
171
* fi_read_lock, fi_write_lock,
172
* fi_read_unlock, fi_write_unlock, fi_downgrade_lock
174
AuSimpleRwsemFuncs(fi, struct file *f, au_fi(f)->fi_rwsem);
176
/* to debug easier, do not make them inlined functions */
177
#define FiMustReadLock(f) do { \
178
SiMustAnyLock((f)->f_dentry->d_sb); \
179
AuRwMustReadLock(&au_fi(f)->fi_rwsem); \
182
#define FiMustWriteLock(f) do { \
183
SiMustAnyLock((f)->f_dentry->d_sb); \
184
AuRwMustWriteLock(&au_fi(f)->fi_rwsem); \
187
#define FiMustAnyLock(f) do { \
188
SiMustAnyLock((f)->f_dentry->d_sb); \
189
AuRwMustAnyLock(&au_fi(f)->fi_rwsem); \
192
#define FiMustNoWaiters(f) AuRwMustNoWaiters(&au_fi(f)->fi_rwsem)
194
/* ---------------------------------------------------------------------- */
197
static inline aufs_bindex_t au_fbstart(struct file *file)
200
return au_fi(file)->fi_bstart;
203
static inline aufs_bindex_t au_fbend(struct file *file)
206
return au_fi(file)->fi_bend;
209
static inline struct au_vdir *au_fvdir_cache(struct file *file)
212
return au_fi(file)->fi_vdir_cache;
215
static inline void au_set_fbstart(struct file *file, aufs_bindex_t bindex)
217
FiMustWriteLock(file);
218
AuDebugOn(au_sbend(file->f_dentry->d_sb) < bindex);
219
au_fi(file)->fi_bstart = bindex;
222
static inline void au_set_fbend(struct file *file, aufs_bindex_t bindex)
224
FiMustWriteLock(file);
225
AuDebugOn(au_sbend(file->f_dentry->d_sb) < bindex
226
|| bindex < au_fbstart(file));
227
au_fi(file)->fi_bend = bindex;
230
static inline void au_set_fvdir_cache(struct file *file,
231
struct au_vdir *vdir_cache)
233
FiMustWriteLock(file);
234
AuDebugOn(!S_ISDIR(file->f_dentry->d_inode->i_mode)
235
|| (au_fi(file)->fi_vdir_cache && vdir_cache));
236
au_fi(file)->fi_vdir_cache = vdir_cache;
239
static inline void au_update_figen(struct file *file)
241
atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_dentry));
242
//smp_mb(); /* atomic_set */
245
#endif /* __KERNEL__ */
246
#endif /* __AUFS_FILE_H__ */