fs.h 63 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783
  1. #ifndef _LINUX_FS_H
  2. #define _LINUX_FS_H
  3. /*
  4. * This file has definitions for some important file table
  5. * structures etc.
  6. */
  7. #include <linux/config.h>
  8. #include <linux/limits.h>
  9. #include <linux/ioctl.h>
  10. #include <linux/rcuref.h>
  11. /*
  12. * It's silly to have NR_OPEN bigger than NR_FILE, but you can change
  13. * the file limit at runtime and only root can increase the per-process
  14. * nr_file rlimit, so it's safe to set up a ridiculously high absolute
  15. * upper limit on files-per-process.
  16. *
  17. * Some programs (notably those using select()) may have to be
  18. * recompiled to take full advantage of the new limits..
  19. */
  20. /* Fixed constants first: */
  21. #undef NR_OPEN
  22. #define NR_OPEN (1024*1024) /* Absolute upper limit on fd num */
  23. #define INR_OPEN 1024 /* Initial setting for nfile rlimits */
  24. #define BLOCK_SIZE_BITS 10
  25. #define BLOCK_SIZE (1<<BLOCK_SIZE_BITS)
  26. /* And dynamically-tunable limits and defaults: */
  27. struct files_stat_struct {
  28. int nr_files; /* read only */
  29. int nr_free_files; /* read only */
  30. int max_files; /* tunable */
  31. };
  32. extern struct files_stat_struct files_stat;
  33. struct inodes_stat_t {
  34. int nr_inodes;
  35. int nr_unused;
  36. int dummy[5];
  37. };
  38. extern struct inodes_stat_t inodes_stat;
  39. extern int leases_enable, lease_break_time;
  40. #ifdef CONFIG_DNOTIFY
  41. extern int dir_notify_enable;
  42. #endif
  43. #define NR_FILE 8192 /* this can well be larger on a larger system */
  44. #define MAY_EXEC 1
  45. #define MAY_WRITE 2
  46. #define MAY_READ 4
  47. #define MAY_APPEND 8
  48. #define FMODE_READ 1
  49. #define FMODE_WRITE 2
  50. /* Internal kernel extensions */
  51. #define FMODE_LSEEK 4
  52. #define FMODE_PREAD 8
  53. #define FMODE_PWRITE FMODE_PREAD /* These go hand in hand */
  54. #define RW_MASK 1
  55. #define RWA_MASK 2
  56. #define READ 0
  57. #define WRITE 1
  58. #define READA 2 /* read-ahead - don't block if no resources */
  59. #define SWRITE 3 /* for ll_rw_block() - wait for buffer lock */
  60. #define SPECIAL 4 /* For non-blockdevice requests in request queue */
  61. #define READ_SYNC (READ | (1 << BIO_RW_SYNC))
  62. #define WRITE_SYNC (WRITE | (1 << BIO_RW_SYNC))
  63. #define WRITE_BARRIER ((1 << BIO_RW) | (1 << BIO_RW_BARRIER))
  64. #define SEL_IN 1
  65. #define SEL_OUT 2
  66. #define SEL_EX 4
  67. /* public flags for file_system_type */
  68. #define FS_REQUIRES_DEV 1
  69. #define FS_BINARY_MOUNTDATA 2
  70. #define FS_REVAL_DOT 16384 /* Check the paths ".", ".." for staleness */
  71. #define FS_ODD_RENAME 32768 /* Temporary stuff; will go away as soon
  72. * as nfs_rename() will be cleaned up
  73. */
  74. /*
  75. * These are the fs-independent mount-flags: up to 32 flags are supported
  76. */
  77. #define MS_RDONLY 1 /* Mount read-only */
  78. #define MS_NOSUID 2 /* Ignore suid and sgid bits */
  79. #define MS_NODEV 4 /* Disallow access to device special files */
  80. #define MS_NOEXEC 8 /* Disallow program execution */
  81. #define MS_SYNCHRONOUS 16 /* Writes are synced at once */
  82. #define MS_REMOUNT 32 /* Alter flags of a mounted FS */
  83. #define MS_MANDLOCK 64 /* Allow mandatory locks on an FS */
  84. #define MS_DIRSYNC 128 /* Directory modifications are synchronous */
  85. #define MS_NOATIME 1024 /* Do not update access times. */
  86. #define MS_NODIRATIME 2048 /* Do not update directory access times */
  87. #define MS_BIND 4096
  88. #define MS_MOVE 8192
  89. #define MS_REC 16384
  90. #define MS_VERBOSE 32768
  91. #define MS_POSIXACL (1<<16) /* VFS does not apply the umask */
  92. #define MS_ACTIVE (1<<30)
  93. #define MS_NOUSER (1<<31)
  94. /*
  95. * Superblock flags that can be altered by MS_REMOUNT
  96. */
  97. #define MS_RMT_MASK (MS_RDONLY|MS_SYNCHRONOUS|MS_MANDLOCK|MS_NOATIME|\
  98. MS_NODIRATIME)
  99. /*
  100. * Old magic mount flag and mask
  101. */
  102. #define MS_MGC_VAL 0xC0ED0000
  103. #define MS_MGC_MSK 0xffff0000
  104. /* Inode flags - they have nothing to superblock flags now */
  105. #define S_SYNC 1 /* Writes are synced at once */
  106. #define S_NOATIME 2 /* Do not update access times */
  107. #define S_APPEND 4 /* Append-only file */
  108. #define S_IMMUTABLE 8 /* Immutable file */
  109. #define S_DEAD 16 /* removed, but still open directory */
  110. #define S_NOQUOTA 32 /* Inode is not counted to quota */
  111. #define S_DIRSYNC 64 /* Directory modifications are synchronous */
  112. #define S_NOCMTIME 128 /* Do not update file c/mtime */
  113. #define S_SWAPFILE 256 /* Do not truncate: swapon got its bmaps */
  114. #define S_PRIVATE 512 /* Inode is fs-internal */
  115. /*
  116. * Note that nosuid etc flags are inode-specific: setting some file-system
  117. * flags just means all the inodes inherit those flags by default. It might be
  118. * possible to override it selectively if you really wanted to with some
  119. * ioctl() that is not currently implemented.
  120. *
  121. * Exception: MS_RDONLY is always applied to the entire file system.
  122. *
  123. * Unfortunately, it is possible to change a filesystems flags with it mounted
  124. * with files in use. This means that all of the inodes will not have their
  125. * i_flags updated. Hence, i_flags no longer inherit the superblock mount
  126. * flags, so these have to be checked separately. -- rmk@arm.uk.linux.org
  127. */
  128. #define __IS_FLG(inode,flg) ((inode)->i_sb->s_flags & (flg))
  129. #define IS_RDONLY(inode) ((inode)->i_sb->s_flags & MS_RDONLY)
  130. #define IS_SYNC(inode) (__IS_FLG(inode, MS_SYNCHRONOUS) || \
  131. ((inode)->i_flags & S_SYNC))
  132. #define IS_DIRSYNC(inode) (__IS_FLG(inode, MS_SYNCHRONOUS|MS_DIRSYNC) || \
  133. ((inode)->i_flags & (S_SYNC|S_DIRSYNC)))
  134. #define IS_MANDLOCK(inode) __IS_FLG(inode, MS_MANDLOCK)
  135. #define IS_NOQUOTA(inode) ((inode)->i_flags & S_NOQUOTA)
  136. #define IS_APPEND(inode) ((inode)->i_flags & S_APPEND)
  137. #define IS_IMMUTABLE(inode) ((inode)->i_flags & S_IMMUTABLE)
  138. #define IS_NOATIME(inode) (__IS_FLG(inode, MS_NOATIME) || ((inode)->i_flags & S_NOATIME))
  139. #define IS_NODIRATIME(inode) __IS_FLG(inode, MS_NODIRATIME)
  140. #define IS_POSIXACL(inode) __IS_FLG(inode, MS_POSIXACL)
  141. #define IS_DEADDIR(inode) ((inode)->i_flags & S_DEAD)
  142. #define IS_NOCMTIME(inode) ((inode)->i_flags & S_NOCMTIME)
  143. #define IS_SWAPFILE(inode) ((inode)->i_flags & S_SWAPFILE)
  144. #define IS_PRIVATE(inode) ((inode)->i_flags & S_PRIVATE)
  145. /* the read-only stuff doesn't really belong here, but any other place is
  146. probably as bad and I don't want to create yet another include file. */
  147. #define BLKROSET _IO(0x12,93) /* set device read-only (0 = read-write) */
  148. #define BLKROGET _IO(0x12,94) /* get read-only status (0 = read_write) */
  149. #define BLKRRPART _IO(0x12,95) /* re-read partition table */
  150. #define BLKGETSIZE _IO(0x12,96) /* return device size /512 (long *arg) */
  151. #define BLKFLSBUF _IO(0x12,97) /* flush buffer cache */
  152. #define BLKRASET _IO(0x12,98) /* set read ahead for block device */
  153. #define BLKRAGET _IO(0x12,99) /* get current read ahead setting */
  154. #define BLKFRASET _IO(0x12,100)/* set filesystem (mm/filemap.c) read-ahead */
  155. #define BLKFRAGET _IO(0x12,101)/* get filesystem (mm/filemap.c) read-ahead */
  156. #define BLKSECTSET _IO(0x12,102)/* set max sectors per request (ll_rw_blk.c) */
  157. #define BLKSECTGET _IO(0x12,103)/* get max sectors per request (ll_rw_blk.c) */
  158. #define BLKSSZGET _IO(0x12,104)/* get block device sector size */
  159. #if 0
  160. #define BLKPG _IO(0x12,105)/* See blkpg.h */
  161. /* Some people are morons. Do not use sizeof! */
  162. #define BLKELVGET _IOR(0x12,106,size_t)/* elevator get */
  163. #define BLKELVSET _IOW(0x12,107,size_t)/* elevator set */
  164. /* This was here just to show that the number is taken -
  165. probably all these _IO(0x12,*) ioctls should be moved to blkpg.h. */
  166. #endif
  167. /* A jump here: 108-111 have been used for various private purposes. */
  168. #define BLKBSZGET _IOR(0x12,112,size_t)
  169. #define BLKBSZSET _IOW(0x12,113,size_t)
  170. #define BLKGETSIZE64 _IOR(0x12,114,size_t) /* return device size in bytes (u64 *arg) */
  171. #define BMAP_IOCTL 1 /* obsolete - kept for compatibility */
  172. #define FIBMAP _IO(0x00,1) /* bmap access */
  173. #define FIGETBSZ _IO(0x00,2) /* get the block size used for bmap */
  174. #ifdef __KERNEL__
  175. #include <linux/linkage.h>
  176. #include <linux/wait.h>
  177. #include <linux/types.h>
  178. #include <linux/kdev_t.h>
  179. #include <linux/dcache.h>
  180. #include <linux/stat.h>
  181. #include <linux/cache.h>
  182. #include <linux/kobject.h>
  183. #include <linux/list.h>
  184. #include <linux/radix-tree.h>
  185. #include <linux/prio_tree.h>
  186. #include <linux/init.h>
  187. #include <linux/sched.h>
  188. #include <asm/atomic.h>
  189. #include <asm/semaphore.h>
  190. #include <asm/byteorder.h>
  191. struct iovec;
  192. struct nameidata;
  193. struct kiocb;
  194. struct pipe_inode_info;
  195. struct poll_table_struct;
  196. struct kstatfs;
  197. struct vm_area_struct;
  198. struct vfsmount;
  199. /* Used to be a macro which just called the function, now just a function */
  200. extern void update_atime (struct inode *);
  201. extern void __init inode_init(unsigned long);
  202. extern void __init inode_init_early(void);
  203. extern void __init mnt_init(unsigned long);
  204. extern void __init files_init(unsigned long);
  205. struct buffer_head;
  206. typedef int (get_block_t)(struct inode *inode, sector_t iblock,
  207. struct buffer_head *bh_result, int create);
  208. typedef int (get_blocks_t)(struct inode *inode, sector_t iblock,
  209. unsigned long max_blocks,
  210. struct buffer_head *bh_result, int create);
  211. typedef void (dio_iodone_t)(struct kiocb *iocb, loff_t offset,
  212. ssize_t bytes, void *private);
  213. /*
  214. * Attribute flags. These should be or-ed together to figure out what
  215. * has been changed!
  216. */
  217. #define ATTR_MODE 1
  218. #define ATTR_UID 2
  219. #define ATTR_GID 4
  220. #define ATTR_SIZE 8
  221. #define ATTR_ATIME 16
  222. #define ATTR_MTIME 32
  223. #define ATTR_CTIME 64
  224. #define ATTR_ATIME_SET 128
  225. #define ATTR_MTIME_SET 256
  226. #define ATTR_FORCE 512 /* Not a change, but a change it */
  227. #define ATTR_ATTR_FLAG 1024
  228. #define ATTR_KILL_SUID 2048
  229. #define ATTR_KILL_SGID 4096
  230. #define ATTR_FILE 8192
  231. /*
  232. * This is the Inode Attributes structure, used for notify_change(). It
  233. * uses the above definitions as flags, to know which values have changed.
  234. * Also, in this manner, a Filesystem can look at only the values it cares
  235. * about. Basically, these are the attributes that the VFS layer can
  236. * request to change from the FS layer.
  237. *
  238. * Derek Atkins <warlord@MIT.EDU> 94-10-20
  239. */
  240. struct iattr {
  241. unsigned int ia_valid;
  242. umode_t ia_mode;
  243. uid_t ia_uid;
  244. gid_t ia_gid;
  245. loff_t ia_size;
  246. struct timespec ia_atime;
  247. struct timespec ia_mtime;
  248. struct timespec ia_ctime;
  249. /*
  250. * Not an attribute, but an auxilary info for filesystems wanting to
  251. * implement an ftruncate() like method. NOTE: filesystem should
  252. * check for (ia_valid & ATTR_FILE), and not for (ia_file != NULL).
  253. */
  254. struct file *ia_file;
  255. };
  256. /*
  257. * Includes for diskquotas.
  258. */
  259. #include <linux/quota.h>
  260. /*
  261. * oh the beauties of C type declarations.
  262. */
  263. struct page;
  264. struct address_space;
  265. struct writeback_control;
  266. struct address_space_operations {
  267. int (*writepage)(struct page *page, struct writeback_control *wbc);
  268. int (*readpage)(struct file *, struct page *);
  269. int (*sync_page)(struct page *);
  270. /* Write back some dirty pages from this mapping. */
  271. int (*writepages)(struct address_space *, struct writeback_control *);
  272. /* Set a page dirty */
  273. int (*set_page_dirty)(struct page *page);
  274. int (*readpages)(struct file *filp, struct address_space *mapping,
  275. struct list_head *pages, unsigned nr_pages);
  276. /*
  277. * ext3 requires that a successful prepare_write() call be followed
  278. * by a commit_write() call - they must be balanced
  279. */
  280. int (*prepare_write)(struct file *, struct page *, unsigned, unsigned);
  281. int (*commit_write)(struct file *, struct page *, unsigned, unsigned);
  282. /* Unfortunately this kludge is needed for FIBMAP. Don't use it */
  283. sector_t (*bmap)(struct address_space *, sector_t);
  284. int (*invalidatepage) (struct page *, unsigned long);
  285. int (*releasepage) (struct page *, gfp_t);
  286. ssize_t (*direct_IO)(int, struct kiocb *, const struct iovec *iov,
  287. loff_t offset, unsigned long nr_segs);
  288. struct page* (*get_xip_page)(struct address_space *, sector_t,
  289. int);
  290. };
  291. struct backing_dev_info;
  292. struct address_space {
  293. struct inode *host; /* owner: inode, block_device */
  294. struct radix_tree_root page_tree; /* radix tree of all pages */
  295. rwlock_t tree_lock; /* and rwlock protecting it */
  296. unsigned int i_mmap_writable;/* count VM_SHARED mappings */
  297. struct prio_tree_root i_mmap; /* tree of private and shared mappings */
  298. struct list_head i_mmap_nonlinear;/*list VM_NONLINEAR mappings */
  299. spinlock_t i_mmap_lock; /* protect tree, count, list */
  300. unsigned int truncate_count; /* Cover race condition with truncate */
  301. unsigned long nrpages; /* number of total pages */
  302. pgoff_t writeback_index;/* writeback starts here */
  303. struct address_space_operations *a_ops; /* methods */
  304. unsigned long flags; /* error bits/gfp mask */
  305. struct backing_dev_info *backing_dev_info; /* device readahead, etc */
  306. spinlock_t private_lock; /* for use by the address_space */
  307. struct list_head private_list; /* ditto */
  308. struct address_space *assoc_mapping; /* ditto */
  309. } __attribute__((aligned(sizeof(long))));
  310. /*
  311. * On most architectures that alignment is already the case; but
  312. * must be enforced here for CRIS, to let the least signficant bit
  313. * of struct page's "mapping" pointer be used for PAGE_MAPPING_ANON.
  314. */
  315. struct block_device {
  316. dev_t bd_dev; /* not a kdev_t - it's a search key */
  317. struct inode * bd_inode; /* will die */
  318. int bd_openers;
  319. struct semaphore bd_sem; /* open/close mutex */
  320. struct semaphore bd_mount_sem; /* mount mutex */
  321. struct list_head bd_inodes;
  322. void * bd_holder;
  323. int bd_holders;
  324. struct block_device * bd_contains;
  325. unsigned bd_block_size;
  326. struct hd_struct * bd_part;
  327. /* number of times partitions within this device have been opened. */
  328. unsigned bd_part_count;
  329. int bd_invalidated;
  330. struct gendisk * bd_disk;
  331. struct list_head bd_list;
  332. struct backing_dev_info *bd_inode_backing_dev_info;
  333. /*
  334. * Private data. You must have bd_claim'ed the block_device
  335. * to use this. NOTE: bd_claim allows an owner to claim
  336. * the same device multiple times, the owner must take special
  337. * care to not mess up bd_private for that case.
  338. */
  339. unsigned long bd_private;
  340. };
  341. /*
  342. * Radix-tree tags, for tagging dirty and writeback pages within the pagecache
  343. * radix trees
  344. */
  345. #define PAGECACHE_TAG_DIRTY 0
  346. #define PAGECACHE_TAG_WRITEBACK 1
  347. int mapping_tagged(struct address_space *mapping, int tag);
  348. /*
  349. * Might pages of this file be mapped into userspace?
  350. */
  351. static inline int mapping_mapped(struct address_space *mapping)
  352. {
  353. return !prio_tree_empty(&mapping->i_mmap) ||
  354. !list_empty(&mapping->i_mmap_nonlinear);
  355. }
  356. /*
  357. * Might pages of this file have been modified in userspace?
  358. * Note that i_mmap_writable counts all VM_SHARED vmas: do_mmap_pgoff
  359. * marks vma as VM_SHARED if it is shared, and the file was opened for
  360. * writing i.e. vma may be mprotected writable even if now readonly.
  361. */
  362. static inline int mapping_writably_mapped(struct address_space *mapping)
  363. {
  364. return mapping->i_mmap_writable != 0;
  365. }
  366. /*
  367. * Use sequence counter to get consistent i_size on 32-bit processors.
  368. */
  369. #if BITS_PER_LONG==32 && defined(CONFIG_SMP)
  370. #include <linux/seqlock.h>
  371. #define __NEED_I_SIZE_ORDERED
  372. #define i_size_ordered_init(inode) seqcount_init(&inode->i_size_seqcount)
  373. #else
  374. #define i_size_ordered_init(inode) do { } while (0)
  375. #endif
  376. struct inode {
  377. struct hlist_node i_hash;
  378. struct list_head i_list;
  379. struct list_head i_sb_list;
  380. struct list_head i_dentry;
  381. unsigned long i_ino;
  382. atomic_t i_count;
  383. umode_t i_mode;
  384. unsigned int i_nlink;
  385. uid_t i_uid;
  386. gid_t i_gid;
  387. dev_t i_rdev;
  388. loff_t i_size;
  389. struct timespec i_atime;
  390. struct timespec i_mtime;
  391. struct timespec i_ctime;
  392. unsigned int i_blkbits;
  393. unsigned long i_blksize;
  394. unsigned long i_version;
  395. unsigned long i_blocks;
  396. unsigned short i_bytes;
  397. spinlock_t i_lock; /* i_blocks, i_bytes, maybe i_size */
  398. struct semaphore i_sem;
  399. struct rw_semaphore i_alloc_sem;
  400. struct inode_operations *i_op;
  401. struct file_operations *i_fop; /* former ->i_op->default_file_ops */
  402. struct super_block *i_sb;
  403. struct file_lock *i_flock;
  404. struct address_space *i_mapping;
  405. struct address_space i_data;
  406. #ifdef CONFIG_QUOTA
  407. struct dquot *i_dquot[MAXQUOTAS];
  408. #endif
  409. /* These three should probably be a union */
  410. struct list_head i_devices;
  411. struct pipe_inode_info *i_pipe;
  412. struct block_device *i_bdev;
  413. struct cdev *i_cdev;
  414. int i_cindex;
  415. __u32 i_generation;
  416. #ifdef CONFIG_DNOTIFY
  417. unsigned long i_dnotify_mask; /* Directory notify events */
  418. struct dnotify_struct *i_dnotify; /* for directory notifications */
  419. #endif
  420. #ifdef CONFIG_INOTIFY
  421. struct list_head inotify_watches; /* watches on this inode */
  422. struct semaphore inotify_sem; /* protects the watches list */
  423. #endif
  424. unsigned long i_state;
  425. unsigned long dirtied_when; /* jiffies of first dirtying */
  426. unsigned int i_flags;
  427. atomic_t i_writecount;
  428. void *i_security;
  429. union {
  430. void *generic_ip;
  431. } u;
  432. #ifdef __NEED_I_SIZE_ORDERED
  433. seqcount_t i_size_seqcount;
  434. #endif
  435. };
  436. /*
  437. * NOTE: in a 32bit arch with a preemptable kernel and
  438. * an UP compile the i_size_read/write must be atomic
  439. * with respect to the local cpu (unlike with preempt disabled),
  440. * but they don't need to be atomic with respect to other cpus like in
  441. * true SMP (so they need either to either locally disable irq around
  442. * the read or for example on x86 they can be still implemented as a
  443. * cmpxchg8b without the need of the lock prefix). For SMP compiles
  444. * and 64bit archs it makes no difference if preempt is enabled or not.
  445. */
  446. static inline loff_t i_size_read(struct inode *inode)
  447. {
  448. #if BITS_PER_LONG==32 && defined(CONFIG_SMP)
  449. loff_t i_size;
  450. unsigned int seq;
  451. do {
  452. seq = read_seqcount_begin(&inode->i_size_seqcount);
  453. i_size = inode->i_size;
  454. } while (read_seqcount_retry(&inode->i_size_seqcount, seq));
  455. return i_size;
  456. #elif BITS_PER_LONG==32 && defined(CONFIG_PREEMPT)
  457. loff_t i_size;
  458. preempt_disable();
  459. i_size = inode->i_size;
  460. preempt_enable();
  461. return i_size;
  462. #else
  463. return inode->i_size;
  464. #endif
  465. }
  466. static inline void i_size_write(struct inode *inode, loff_t i_size)
  467. {
  468. #if BITS_PER_LONG==32 && defined(CONFIG_SMP)
  469. write_seqcount_begin(&inode->i_size_seqcount);
  470. inode->i_size = i_size;
  471. write_seqcount_end(&inode->i_size_seqcount);
  472. #elif BITS_PER_LONG==32 && defined(CONFIG_PREEMPT)
  473. preempt_disable();
  474. inode->i_size = i_size;
  475. preempt_enable();
  476. #else
  477. inode->i_size = i_size;
  478. #endif
  479. }
  480. static inline unsigned iminor(struct inode *inode)
  481. {
  482. return MINOR(inode->i_rdev);
  483. }
  484. static inline unsigned imajor(struct inode *inode)
  485. {
  486. return MAJOR(inode->i_rdev);
  487. }
  488. extern struct block_device *I_BDEV(struct inode *inode);
  489. struct fown_struct {
  490. rwlock_t lock; /* protects pid, uid, euid fields */
  491. int pid; /* pid or -pgrp where SIGIO should be sent */
  492. uid_t uid, euid; /* uid/euid of process setting the owner */
  493. void *security;
  494. int signum; /* posix.1b rt signal to be delivered on IO */
  495. };
  496. /*
  497. * Track a single file's readahead state
  498. */
  499. struct file_ra_state {
  500. unsigned long start; /* Current window */
  501. unsigned long size;
  502. unsigned long flags; /* ra flags RA_FLAG_xxx*/
  503. unsigned long cache_hit; /* cache hit count*/
  504. unsigned long prev_page; /* Cache last read() position */
  505. unsigned long ahead_start; /* Ahead window */
  506. unsigned long ahead_size;
  507. unsigned long ra_pages; /* Maximum readahead window */
  508. unsigned long mmap_hit; /* Cache hit stat for mmap accesses */
  509. unsigned long mmap_miss; /* Cache miss stat for mmap accesses */
  510. };
  511. #define RA_FLAG_MISS 0x01 /* a cache miss occured against this file */
  512. #define RA_FLAG_INCACHE 0x02 /* file is already in cache */
  513. struct file {
  514. /*
  515. * fu_list becomes invalid after file_free is called and queued via
  516. * fu_rcuhead for RCU freeing
  517. */
  518. union {
  519. struct list_head fu_list;
  520. struct rcu_head fu_rcuhead;
  521. } f_u;
  522. struct dentry *f_dentry;
  523. struct vfsmount *f_vfsmnt;
  524. struct file_operations *f_op;
  525. atomic_t f_count;
  526. unsigned int f_flags;
  527. mode_t f_mode;
  528. loff_t f_pos;
  529. struct fown_struct f_owner;
  530. unsigned int f_uid, f_gid;
  531. struct file_ra_state f_ra;
  532. unsigned long f_version;
  533. void *f_security;
  534. /* needed for tty driver, and maybe others */
  535. void *private_data;
  536. #ifdef CONFIG_EPOLL
  537. /* Used by fs/eventpoll.c to link all the hooks to this file */
  538. struct list_head f_ep_links;
  539. spinlock_t f_ep_lock;
  540. #endif /* #ifdef CONFIG_EPOLL */
  541. struct address_space *f_mapping;
  542. };
  543. extern spinlock_t files_lock;
  544. #define file_list_lock() spin_lock(&files_lock);
  545. #define file_list_unlock() spin_unlock(&files_lock);
  546. #define get_file(x) rcuref_inc(&(x)->f_count)
  547. #define file_count(x) atomic_read(&(x)->f_count)
  548. #define MAX_NON_LFS ((1UL<<31) - 1)
  549. /* Page cache limit. The filesystems should put that into their s_maxbytes
  550. limits, otherwise bad things can happen in VM. */
  551. #if BITS_PER_LONG==32
  552. #define MAX_LFS_FILESIZE (((u64)PAGE_CACHE_SIZE << (BITS_PER_LONG-1))-1)
  553. #elif BITS_PER_LONG==64
  554. #define MAX_LFS_FILESIZE 0x7fffffffffffffffUL
  555. #endif
  556. #define FL_POSIX 1
  557. #define FL_FLOCK 2
  558. #define FL_ACCESS 8 /* not trying to lock, just looking */
  559. #define FL_LOCKD 16 /* lock held by rpc.lockd */
  560. #define FL_LEASE 32 /* lease held on this file */
  561. #define FL_SLEEP 128 /* A blocking lock */
  562. /*
  563. * The POSIX file lock owner is determined by
  564. * the "struct files_struct" in the thread group
  565. * (or NULL for no owner - BSD locks).
  566. *
  567. * Lockd stuffs a "host" pointer into this.
  568. */
  569. typedef struct files_struct *fl_owner_t;
  570. struct file_lock_operations {
  571. void (*fl_insert)(struct file_lock *); /* lock insertion callback */
  572. void (*fl_remove)(struct file_lock *); /* lock removal callback */
  573. void (*fl_copy_lock)(struct file_lock *, struct file_lock *);
  574. void (*fl_release_private)(struct file_lock *);
  575. };
  576. struct lock_manager_operations {
  577. int (*fl_compare_owner)(struct file_lock *, struct file_lock *);
  578. void (*fl_notify)(struct file_lock *); /* unblock callback */
  579. void (*fl_copy_lock)(struct file_lock *, struct file_lock *);
  580. void (*fl_release_private)(struct file_lock *);
  581. void (*fl_break)(struct file_lock *);
  582. int (*fl_mylease)(struct file_lock *, struct file_lock *);
  583. int (*fl_change)(struct file_lock **, int);
  584. };
  585. /* that will die - we need it for nfs_lock_info */
  586. #include <linux/nfs_fs_i.h>
  587. struct file_lock {
  588. struct file_lock *fl_next; /* singly linked list for this inode */
  589. struct list_head fl_link; /* doubly linked list of all locks */
  590. struct list_head fl_block; /* circular list of blocked processes */
  591. fl_owner_t fl_owner;
  592. unsigned int fl_pid;
  593. wait_queue_head_t fl_wait;
  594. struct file *fl_file;
  595. unsigned char fl_flags;
  596. unsigned char fl_type;
  597. loff_t fl_start;
  598. loff_t fl_end;
  599. struct fasync_struct * fl_fasync; /* for lease break notifications */
  600. unsigned long fl_break_time; /* for nonblocking lease breaks */
  601. struct file_lock_operations *fl_ops; /* Callbacks for filesystems */
  602. struct lock_manager_operations *fl_lmops; /* Callbacks for lockmanagers */
  603. union {
  604. struct nfs_lock_info nfs_fl;
  605. struct nfs4_lock_info nfs4_fl;
  606. } fl_u;
  607. };
  608. /* The following constant reflects the upper bound of the file/locking space */
  609. #ifndef OFFSET_MAX
  610. #define INT_LIMIT(x) (~((x)1 << (sizeof(x)*8 - 1)))
  611. #define OFFSET_MAX INT_LIMIT(loff_t)
  612. #define OFFT_OFFSET_MAX INT_LIMIT(off_t)
  613. #endif
  614. extern struct list_head file_lock_list;
  615. #include <linux/fcntl.h>
  616. extern int fcntl_getlk(struct file *, struct flock __user *);
  617. extern int fcntl_setlk(unsigned int, struct file *, unsigned int,
  618. struct flock __user *);
  619. #if BITS_PER_LONG == 32
  620. extern int fcntl_getlk64(struct file *, struct flock64 __user *);
  621. extern int fcntl_setlk64(unsigned int, struct file *, unsigned int,
  622. struct flock64 __user *);
  623. #endif
  624. extern void send_sigio(struct fown_struct *fown, int fd, int band);
  625. extern int fcntl_setlease(unsigned int fd, struct file *filp, long arg);
  626. extern int fcntl_getlease(struct file *filp);
  627. /* fs/locks.c */
  628. extern void locks_init_lock(struct file_lock *);
  629. extern void locks_copy_lock(struct file_lock *, struct file_lock *);
  630. extern void locks_remove_posix(struct file *, fl_owner_t);
  631. extern void locks_remove_flock(struct file *);
  632. extern struct file_lock *posix_test_lock(struct file *, struct file_lock *);
  633. extern int posix_lock_file(struct file *, struct file_lock *);
  634. extern int posix_lock_file_wait(struct file *, struct file_lock *);
  635. extern void posix_block_lock(struct file_lock *, struct file_lock *);
  636. extern void posix_unblock_lock(struct file *, struct file_lock *);
  637. extern int posix_locks_deadlock(struct file_lock *, struct file_lock *);
  638. extern int flock_lock_file_wait(struct file *filp, struct file_lock *fl);
  639. extern int __break_lease(struct inode *inode, unsigned int flags);
  640. extern void lease_get_mtime(struct inode *, struct timespec *time);
  641. extern int setlease(struct file *, long, struct file_lock **);
  642. extern int lease_modify(struct file_lock **, int);
  643. extern int lock_may_read(struct inode *, loff_t start, unsigned long count);
  644. extern int lock_may_write(struct inode *, loff_t start, unsigned long count);
  645. extern void steal_locks(fl_owner_t from);
  646. struct fasync_struct {
  647. int magic;
  648. int fa_fd;
  649. struct fasync_struct *fa_next; /* singly linked list */
  650. struct file *fa_file;
  651. };
  652. #define FASYNC_MAGIC 0x4601
  653. /* SMP safe fasync helpers: */
  654. extern int fasync_helper(int, struct file *, int, struct fasync_struct **);
  655. /* can be called from interrupts */
  656. extern void kill_fasync(struct fasync_struct **, int, int);
  657. /* only for net: no internal synchronization */
  658. extern void __kill_fasync(struct fasync_struct *, int, int);
  659. extern int f_setown(struct file *filp, unsigned long arg, int force);
  660. extern void f_delown(struct file *filp);
  661. extern int send_sigurg(struct fown_struct *fown);
  662. /*
  663. * Umount options
  664. */
  665. #define MNT_FORCE 0x00000001 /* Attempt to forcibily umount */
  666. #define MNT_DETACH 0x00000002 /* Just detach from the tree */
  667. #define MNT_EXPIRE 0x00000004 /* Mark for expiry */
  668. extern struct list_head super_blocks;
  669. extern spinlock_t sb_lock;
  670. #define sb_entry(list) list_entry((list), struct super_block, s_list)
  671. #define S_BIAS (1<<30)
  672. struct super_block {
  673. struct list_head s_list; /* Keep this first */
  674. dev_t s_dev; /* search index; _not_ kdev_t */
  675. unsigned long s_blocksize;
  676. unsigned long s_old_blocksize;
  677. unsigned char s_blocksize_bits;
  678. unsigned char s_dirt;
  679. unsigned long long s_maxbytes; /* Max file size */
  680. struct file_system_type *s_type;
  681. struct super_operations *s_op;
  682. struct dquot_operations *dq_op;
  683. struct quotactl_ops *s_qcop;
  684. struct export_operations *s_export_op;
  685. unsigned long s_flags;
  686. unsigned long s_magic;
  687. struct dentry *s_root;
  688. struct rw_semaphore s_umount;
  689. struct semaphore s_lock;
  690. int s_count;
  691. int s_syncing;
  692. int s_need_sync_fs;
  693. atomic_t s_active;
  694. void *s_security;
  695. struct xattr_handler **s_xattr;
  696. struct list_head s_inodes; /* all inodes */
  697. struct list_head s_dirty; /* dirty inodes */
  698. struct list_head s_io; /* parked for writeback */
  699. struct hlist_head s_anon; /* anonymous dentries for (nfs) exporting */
  700. struct list_head s_files;
  701. struct block_device *s_bdev;
  702. struct list_head s_instances;
  703. struct quota_info s_dquot; /* Diskquota specific options */
  704. int s_frozen;
  705. wait_queue_head_t s_wait_unfrozen;
  706. char s_id[32]; /* Informational name */
  707. void *s_fs_info; /* Filesystem private info */
  708. /*
  709. * The next field is for VFS *only*. No filesystems have any business
  710. * even looking at it. You had been warned.
  711. */
  712. struct semaphore s_vfs_rename_sem; /* Kludge */
  713. /* Granuality of c/m/atime in ns.
  714. Cannot be worse than a second */
  715. u32 s_time_gran;
  716. };
  717. extern struct timespec current_fs_time(struct super_block *sb);
  718. /*
  719. * Snapshotting support.
  720. */
  721. enum {
  722. SB_UNFROZEN = 0,
  723. SB_FREEZE_WRITE = 1,
  724. SB_FREEZE_TRANS = 2,
  725. };
  726. #define vfs_check_frozen(sb, level) \
  727. wait_event((sb)->s_wait_unfrozen, ((sb)->s_frozen < (level)))
  728. static inline void get_fs_excl(void)
  729. {
  730. atomic_inc(&current->fs_excl);
  731. }
  732. static inline void put_fs_excl(void)
  733. {
  734. atomic_dec(&current->fs_excl);
  735. }
  736. static inline int has_fs_excl(void)
  737. {
  738. return atomic_read(&current->fs_excl);
  739. }
  740. /*
  741. * Superblock locking.
  742. */
  743. static inline void lock_super(struct super_block * sb)
  744. {
  745. get_fs_excl();
  746. down(&sb->s_lock);
  747. }
  748. static inline void unlock_super(struct super_block * sb)
  749. {
  750. put_fs_excl();
  751. up(&sb->s_lock);
  752. }
  753. /*
  754. * VFS helper functions..
  755. */
  756. extern int vfs_create(struct inode *, struct dentry *, int, struct nameidata *);
  757. extern int vfs_mkdir(struct inode *, struct dentry *, int);
  758. extern int vfs_mknod(struct inode *, struct dentry *, int, dev_t);
  759. extern int vfs_symlink(struct inode *, struct dentry *, const char *, int);
  760. extern int vfs_link(struct dentry *, struct inode *, struct dentry *);
  761. extern int vfs_rmdir(struct inode *, struct dentry *);
  762. extern int vfs_unlink(struct inode *, struct dentry *);
  763. extern int vfs_rename(struct inode *, struct dentry *, struct inode *, struct dentry *);
  764. /*
  765. * VFS dentry helper functions.
  766. */
  767. extern void dentry_unhash(struct dentry *dentry);
  768. /*
  769. * File types
  770. *
  771. * NOTE! These match bits 12..15 of stat.st_mode
  772. * (ie "(i_mode >> 12) & 15").
  773. */
  774. #define DT_UNKNOWN 0
  775. #define DT_FIFO 1
  776. #define DT_CHR 2
  777. #define DT_DIR 4
  778. #define DT_BLK 6
  779. #define DT_REG 8
  780. #define DT_LNK 10
  781. #define DT_SOCK 12
  782. #define DT_WHT 14
  783. #define OSYNC_METADATA (1<<0)
  784. #define OSYNC_DATA (1<<1)
  785. #define OSYNC_INODE (1<<2)
  786. int generic_osync_inode(struct inode *, struct address_space *, int);
  787. /*
  788. * This is the "filldir" function type, used by readdir() to let
  789. * the kernel specify what kind of dirent layout it wants to have.
  790. * This allows the kernel to read directories into kernel space or
  791. * to have different dirent layouts depending on the binary type.
  792. */
  793. typedef int (*filldir_t)(void *, const char *, int, loff_t, ino_t, unsigned);
  794. struct block_device_operations {
  795. int (*open) (struct inode *, struct file *);
  796. int (*release) (struct inode *, struct file *);
  797. int (*ioctl) (struct inode *, struct file *, unsigned, unsigned long);
  798. long (*unlocked_ioctl) (struct file *, unsigned, unsigned long);
  799. long (*compat_ioctl) (struct file *, unsigned, unsigned long);
  800. int (*direct_access) (struct block_device *, sector_t, unsigned long *);
  801. int (*media_changed) (struct gendisk *);
  802. int (*revalidate_disk) (struct gendisk *);
  803. struct module *owner;
  804. };
  805. /*
  806. * "descriptor" for what we're up to with a read for sendfile().
  807. * This allows us to use the same read code yet
  808. * have multiple different users of the data that
  809. * we read from a file.
  810. *
  811. * The simplest case just copies the data to user
  812. * mode.
  813. */
  814. typedef struct {
  815. size_t written;
  816. size_t count;
  817. union {
  818. char __user * buf;
  819. void *data;
  820. } arg;
  821. int error;
  822. } read_descriptor_t;
  823. typedef int (*read_actor_t)(read_descriptor_t *, struct page *, unsigned long, unsigned long);
  824. /* These macros are for out of kernel modules to test that
  825. * the kernel supports the unlocked_ioctl and compat_ioctl
  826. * fields in struct file_operations. */
  827. #define HAVE_COMPAT_IOCTL 1
  828. #define HAVE_UNLOCKED_IOCTL 1
  829. /*
  830. * NOTE:
  831. * read, write, poll, fsync, readv, writev, unlocked_ioctl and compat_ioctl
  832. * can be called without the big kernel lock held in all filesystems.
  833. */
  834. struct file_operations {
  835. struct module *owner;
  836. loff_t (*llseek) (struct file *, loff_t, int);
  837. ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
  838. ssize_t (*aio_read) (struct kiocb *, char __user *, size_t, loff_t);
  839. ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);
  840. ssize_t (*aio_write) (struct kiocb *, const char __user *, size_t, loff_t);
  841. int (*readdir) (struct file *, void *, filldir_t);
  842. unsigned int (*poll) (struct file *, struct poll_table_struct *);
  843. int (*ioctl) (struct inode *, struct file *, unsigned int, unsigned long);
  844. long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long);
  845. long (*compat_ioctl) (struct file *, unsigned int, unsigned long);
  846. int (*mmap) (struct file *, struct vm_area_struct *);
  847. int (*open) (struct inode *, struct file *);
  848. int (*flush) (struct file *);
  849. int (*release) (struct inode *, struct file *);
  850. int (*fsync) (struct file *, struct dentry *, int datasync);
  851. int (*aio_fsync) (struct kiocb *, int datasync);
  852. int (*fasync) (int, struct file *, int);
  853. int (*lock) (struct file *, int, struct file_lock *);
  854. ssize_t (*readv) (struct file *, const struct iovec *, unsigned long, loff_t *);
  855. ssize_t (*writev) (struct file *, const struct iovec *, unsigned long, loff_t *);
  856. ssize_t (*sendfile) (struct file *, loff_t *, size_t, read_actor_t, void *);
  857. ssize_t (*sendpage) (struct file *, struct page *, int, size_t, loff_t *, int);
  858. unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
  859. int (*check_flags)(int);
  860. int (*dir_notify)(struct file *filp, unsigned long arg);
  861. int (*flock) (struct file *, int, struct file_lock *);
  862. };
  863. struct inode_operations {
  864. int (*create) (struct inode *,struct dentry *,int, struct nameidata *);
  865. struct dentry * (*lookup) (struct inode *,struct dentry *, struct nameidata *);
  866. int (*link) (struct dentry *,struct inode *,struct dentry *);
  867. int (*unlink) (struct inode *,struct dentry *);
  868. int (*symlink) (struct inode *,struct dentry *,const char *);
  869. int (*mkdir) (struct inode *,struct dentry *,int);
  870. int (*rmdir) (struct inode *,struct dentry *);
  871. int (*mknod) (struct inode *,struct dentry *,int,dev_t);
  872. int (*rename) (struct inode *, struct dentry *,
  873. struct inode *, struct dentry *);
  874. int (*readlink) (struct dentry *, char __user *,int);
  875. void * (*follow_link) (struct dentry *, struct nameidata *);
  876. void (*put_link) (struct dentry *, struct nameidata *, void *);
  877. void (*truncate) (struct inode *);
  878. int (*permission) (struct inode *, int, struct nameidata *);
  879. int (*setattr) (struct dentry *, struct iattr *);
  880. int (*getattr) (struct vfsmount *mnt, struct dentry *, struct kstat *);
  881. int (*setxattr) (struct dentry *, const char *,const void *,size_t,int);
  882. ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
  883. ssize_t (*listxattr) (struct dentry *, char *, size_t);
  884. int (*removexattr) (struct dentry *, const char *);
  885. };
  886. struct seq_file;
  887. extern ssize_t vfs_read(struct file *, char __user *, size_t, loff_t *);
  888. extern ssize_t vfs_write(struct file *, const char __user *, size_t, loff_t *);
  889. extern ssize_t vfs_readv(struct file *, const struct iovec __user *,
  890. unsigned long, loff_t *);
  891. extern ssize_t vfs_writev(struct file *, const struct iovec __user *,
  892. unsigned long, loff_t *);
  893. /*
  894. * NOTE: write_inode, delete_inode, clear_inode, put_inode can be called
  895. * without the big kernel lock held in all filesystems.
  896. */
  897. struct super_operations {
  898. struct inode *(*alloc_inode)(struct super_block *sb);
  899. void (*destroy_inode)(struct inode *);
  900. void (*read_inode) (struct inode *);
  901. void (*dirty_inode) (struct inode *);
  902. int (*write_inode) (struct inode *, int);
  903. void (*put_inode) (struct inode *);
  904. void (*drop_inode) (struct inode *);
  905. void (*delete_inode) (struct inode *);
  906. void (*put_super) (struct super_block *);
  907. void (*write_super) (struct super_block *);
  908. int (*sync_fs)(struct super_block *sb, int wait);
  909. void (*write_super_lockfs) (struct super_block *);
  910. void (*unlockfs) (struct super_block *);
  911. int (*statfs) (struct super_block *, struct kstatfs *);
  912. int (*remount_fs) (struct super_block *, int *, char *);
  913. void (*clear_inode) (struct inode *);
  914. void (*umount_begin) (struct super_block *);
  915. int (*show_options)(struct seq_file *, struct vfsmount *);
  916. ssize_t (*quota_read)(struct super_block *, int, char *, size_t, loff_t);
  917. ssize_t (*quota_write)(struct super_block *, int, const char *, size_t, loff_t);
  918. };
  919. /* Inode state bits. Protected by inode_lock. */
  920. #define I_DIRTY_SYNC 1 /* Not dirty enough for O_DATASYNC */
  921. #define I_DIRTY_DATASYNC 2 /* Data-related inode changes pending */
  922. #define I_DIRTY_PAGES 4 /* Data-related inode changes pending */
  923. #define __I_LOCK 3
  924. #define I_LOCK (1 << __I_LOCK)
  925. #define I_FREEING 16
  926. #define I_CLEAR 32
  927. #define I_NEW 64
  928. #define I_WILL_FREE 128
  929. #define I_DIRTY (I_DIRTY_SYNC | I_DIRTY_DATASYNC | I_DIRTY_PAGES)
  930. extern void __mark_inode_dirty(struct inode *, int);
  931. static inline void mark_inode_dirty(struct inode *inode)
  932. {
  933. __mark_inode_dirty(inode, I_DIRTY);
  934. }
  935. static inline void mark_inode_dirty_sync(struct inode *inode)
  936. {
  937. __mark_inode_dirty(inode, I_DIRTY_SYNC);
  938. }
  939. static inline void touch_atime(struct vfsmount *mnt, struct dentry *dentry)
  940. {
  941. /* per-mountpoint checks will go here */
  942. update_atime(dentry->d_inode);
  943. }
  944. static inline void file_accessed(struct file *file)
  945. {
  946. if (!(file->f_flags & O_NOATIME))
  947. touch_atime(file->f_vfsmnt, file->f_dentry);
  948. }
  949. int sync_inode(struct inode *inode, struct writeback_control *wbc);
  950. /**
  951. * struct export_operations - for nfsd to communicate with file systems
  952. * @decode_fh: decode a file handle fragment and return a &struct dentry
  953. * @encode_fh: encode a file handle fragment from a dentry
  954. * @get_name: find the name for a given inode in a given directory
  955. * @get_parent: find the parent of a given directory
  956. * @get_dentry: find a dentry for the inode given a file handle sub-fragment
  957. *
  958. * Description:
  959. * The export_operations structure provides a means for nfsd to communicate
  960. * with a particular exported file system - particularly enabling nfsd and
  961. * the filesystem to co-operate when dealing with file handles.
  962. *
  963. * export_operations contains two basic operation for dealing with file
  964. * handles, decode_fh() and encode_fh(), and allows for some other
  965. * operations to be defined which standard helper routines use to get
  966. * specific information from the filesystem.
  967. *
  968. * nfsd encodes information use to determine which filesystem a filehandle
  969. * applies to in the initial part of the file handle. The remainder, termed
  970. * a file handle fragment, is controlled completely by the filesystem. The
  971. * standard helper routines assume that this fragment will contain one or
  972. * two sub-fragments, one which identifies the file, and one which may be
  973. * used to identify the (a) directory containing the file.
  974. *
  975. * In some situations, nfsd needs to get a dentry which is connected into a
  976. * specific part of the file tree. To allow for this, it passes the
  977. * function acceptable() together with a @context which can be used to see
  978. * if the dentry is acceptable. As there can be multiple dentrys for a
  979. * given file, the filesystem should check each one for acceptability before
  980. * looking for the next. As soon as an acceptable one is found, it should
  981. * be returned.
  982. *
  983. * decode_fh:
  984. * @decode_fh is given a &struct super_block (@sb), a file handle fragment
  985. * (@fh, @fh_len) and an acceptability testing function (@acceptable,
  986. * @context). It should return a &struct dentry which refers to the same
  987. * file that the file handle fragment refers to, and which passes the
  988. * acceptability test. If it cannot, it should return a %NULL pointer if
  989. * the file was found but no acceptable &dentries were available, or a
  990. * %ERR_PTR error code indicating why it couldn't be found (e.g. %ENOENT or
  991. * %ENOMEM).
  992. *
  993. * encode_fh:
  994. * @encode_fh should store in the file handle fragment @fh (using at most
  995. * @max_len bytes) information that can be used by @decode_fh to recover the
  996. * file refered to by the &struct dentry @de. If the @connectable flag is
  997. * set, the encode_fh() should store sufficient information so that a good
  998. * attempt can be made to find not only the file but also it's place in the
  999. * filesystem. This typically means storing a reference to de->d_parent in
  1000. * the filehandle fragment. encode_fh() should return the number of bytes
  1001. * stored or a negative error code such as %-ENOSPC
  1002. *
  1003. * get_name:
  1004. * @get_name should find a name for the given @child in the given @parent
  1005. * directory. The name should be stored in the @name (with the
  1006. * understanding that it is already pointing to a a %NAME_MAX+1 sized
  1007. * buffer. get_name() should return %0 on success, a negative error code
  1008. * or error. @get_name will be called without @parent->i_sem held.
  1009. *
  1010. * get_parent:
  1011. * @get_parent should find the parent directory for the given @child which
  1012. * is also a directory. In the event that it cannot be found, or storage
  1013. * space cannot be allocated, a %ERR_PTR should be returned.
  1014. *
  1015. * get_dentry:
  1016. * Given a &super_block (@sb) and a pointer to a file-system specific inode
  1017. * identifier, possibly an inode number, (@inump) get_dentry() should find
  1018. * the identified inode and return a dentry for that inode. Any suitable
  1019. * dentry can be returned including, if necessary, a new dentry created with
  1020. * d_alloc_root. The caller can then find any other extant dentrys by
  1021. * following the d_alias links. If a new dentry was created using
  1022. * d_alloc_root, DCACHE_NFSD_DISCONNECTED should be set, and the dentry
  1023. * should be d_rehash()ed.
  1024. *
  1025. * If the inode cannot be found, either a %NULL pointer or an %ERR_PTR code
  1026. * can be returned. The @inump will be whatever was passed to
  1027. * nfsd_find_fh_dentry() in either the @obj or @parent parameters.
  1028. *
  1029. * Locking rules:
  1030. * get_parent is called with child->d_inode->i_sem down
  1031. * get_name is not (which is possibly inconsistent)
  1032. */
  1033. struct export_operations {
  1034. struct dentry *(*decode_fh)(struct super_block *sb, __u32 *fh, int fh_len, int fh_type,
  1035. int (*acceptable)(void *context, struct dentry *de),
  1036. void *context);
  1037. int (*encode_fh)(struct dentry *de, __u32 *fh, int *max_len,
  1038. int connectable);
  1039. /* the following are only called from the filesystem itself */
  1040. int (*get_name)(struct dentry *parent, char *name,
  1041. struct dentry *child);
  1042. struct dentry * (*get_parent)(struct dentry *child);
  1043. struct dentry * (*get_dentry)(struct super_block *sb, void *inump);
  1044. /* This is set by the exporting module to a standard helper */
  1045. struct dentry * (*find_exported_dentry)(
  1046. struct super_block *sb, void *obj, void *parent,
  1047. int (*acceptable)(void *context, struct dentry *de),
  1048. void *context);
  1049. };
  1050. extern struct dentry *
  1051. find_exported_dentry(struct super_block *sb, void *obj, void *parent,
  1052. int (*acceptable)(void *context, struct dentry *de),
  1053. void *context);
  1054. struct file_system_type {
  1055. const char *name;
  1056. int fs_flags;
  1057. struct super_block *(*get_sb) (struct file_system_type *, int,
  1058. const char *, void *);
  1059. void (*kill_sb) (struct super_block *);
  1060. struct module *owner;
  1061. struct file_system_type * next;
  1062. struct list_head fs_supers;
  1063. };
  1064. struct super_block *get_sb_bdev(struct file_system_type *fs_type,
  1065. int flags, const char *dev_name, void *data,
  1066. int (*fill_super)(struct super_block *, void *, int));
  1067. struct super_block *get_sb_single(struct file_system_type *fs_type,
  1068. int flags, void *data,
  1069. int (*fill_super)(struct super_block *, void *, int));
  1070. struct super_block *get_sb_nodev(struct file_system_type *fs_type,
  1071. int flags, void *data,
  1072. int (*fill_super)(struct super_block *, void *, int));
  1073. void generic_shutdown_super(struct super_block *sb);
  1074. void kill_block_super(struct super_block *sb);
  1075. void kill_anon_super(struct super_block *sb);
  1076. void kill_litter_super(struct super_block *sb);
  1077. void deactivate_super(struct super_block *sb);
  1078. int set_anon_super(struct super_block *s, void *data);
  1079. struct super_block *sget(struct file_system_type *type,
  1080. int (*test)(struct super_block *,void *),
  1081. int (*set)(struct super_block *,void *),
  1082. void *data);
  1083. struct super_block *get_sb_pseudo(struct file_system_type *, char *,
  1084. struct super_operations *ops, unsigned long);
  1085. int __put_super(struct super_block *sb);
  1086. int __put_super_and_need_restart(struct super_block *sb);
  1087. void unnamed_dev_init(void);
  1088. /* Alas, no aliases. Too much hassle with bringing module.h everywhere */
  1089. #define fops_get(fops) \
  1090. (((fops) && try_module_get((fops)->owner) ? (fops) : NULL))
  1091. #define fops_put(fops) \
  1092. do { if (fops) module_put((fops)->owner); } while(0)
  1093. extern int register_filesystem(struct file_system_type *);
  1094. extern int unregister_filesystem(struct file_system_type *);
  1095. extern struct vfsmount *kern_mount(struct file_system_type *);
  1096. extern int may_umount_tree(struct vfsmount *);
  1097. extern int may_umount(struct vfsmount *);
  1098. extern long do_mount(char *, char *, char *, unsigned long, void *);
  1099. extern int vfs_statfs(struct super_block *, struct kstatfs *);
  1100. #define FLOCK_VERIFY_READ 1
  1101. #define FLOCK_VERIFY_WRITE 2
  1102. extern int locks_mandatory_locked(struct inode *);
  1103. extern int locks_mandatory_area(int, struct inode *, struct file *, loff_t, size_t);
  1104. /*
  1105. * Candidates for mandatory locking have the setgid bit set
  1106. * but no group execute bit - an otherwise meaningless combination.
  1107. */
  1108. #define MANDATORY_LOCK(inode) \
  1109. (IS_MANDLOCK(inode) && ((inode)->i_mode & (S_ISGID | S_IXGRP)) == S_ISGID)
  1110. static inline int locks_verify_locked(struct inode *inode)
  1111. {
  1112. if (MANDATORY_LOCK(inode))
  1113. return locks_mandatory_locked(inode);
  1114. return 0;
  1115. }
  1116. extern int rw_verify_area(int, struct file *, loff_t *, size_t);
  1117. static inline int locks_verify_truncate(struct inode *inode,
  1118. struct file *filp,
  1119. loff_t size)
  1120. {
  1121. if (inode->i_flock && MANDATORY_LOCK(inode))
  1122. return locks_mandatory_area(
  1123. FLOCK_VERIFY_WRITE, inode, filp,
  1124. size < inode->i_size ? size : inode->i_size,
  1125. (size < inode->i_size ? inode->i_size - size
  1126. : size - inode->i_size)
  1127. );
  1128. return 0;
  1129. }
  1130. static inline int break_lease(struct inode *inode, unsigned int mode)
  1131. {
  1132. if (inode->i_flock)
  1133. return __break_lease(inode, mode);
  1134. return 0;
  1135. }
  1136. /* fs/open.c */
  1137. extern int do_truncate(struct dentry *, loff_t start, struct file *filp);
  1138. extern long do_sys_open(const char __user *filename, int flags, int mode);
  1139. extern struct file *filp_open(const char *, int, int);
  1140. extern struct file * dentry_open(struct dentry *, struct vfsmount *, int);
  1141. extern int filp_close(struct file *, fl_owner_t id);
  1142. extern char * getname(const char __user *);
  1143. /* fs/dcache.c */
  1144. extern void __init vfs_caches_init_early(void);
  1145. extern void __init vfs_caches_init(unsigned long);
  1146. #define __getname() kmem_cache_alloc(names_cachep, SLAB_KERNEL)
  1147. #define __putname(name) kmem_cache_free(names_cachep, (void *)(name))
  1148. #ifndef CONFIG_AUDITSYSCALL
  1149. #define putname(name) __putname(name)
  1150. #else
  1151. extern void putname(const char *name);
  1152. #endif
  1153. extern int register_blkdev(unsigned int, const char *);
  1154. extern int unregister_blkdev(unsigned int, const char *);
  1155. extern struct block_device *bdget(dev_t);
  1156. extern void bd_set_size(struct block_device *, loff_t size);
  1157. extern void bd_forget(struct inode *inode);
  1158. extern void bdput(struct block_device *);
  1159. extern struct block_device *open_by_devnum(dev_t, unsigned);
  1160. extern struct file_operations def_blk_fops;
  1161. extern struct address_space_operations def_blk_aops;
  1162. extern struct file_operations def_chr_fops;
  1163. extern struct file_operations bad_sock_fops;
  1164. extern struct file_operations def_fifo_fops;
  1165. extern int ioctl_by_bdev(struct block_device *, unsigned, unsigned long);
  1166. extern int blkdev_ioctl(struct inode *, struct file *, unsigned, unsigned long);
  1167. extern long compat_blkdev_ioctl(struct file *, unsigned, unsigned long);
  1168. extern int blkdev_get(struct block_device *, mode_t, unsigned);
  1169. extern int blkdev_put(struct block_device *);
  1170. extern int bd_claim(struct block_device *, void *);
  1171. extern void bd_release(struct block_device *);
  1172. /* fs/char_dev.c */
  1173. extern int alloc_chrdev_region(dev_t *, unsigned, unsigned, const char *);
  1174. extern int register_chrdev_region(dev_t, unsigned, const char *);
  1175. extern int register_chrdev(unsigned int, const char *,
  1176. struct file_operations *);
  1177. extern int unregister_chrdev(unsigned int, const char *);
  1178. extern void unregister_chrdev_region(dev_t, unsigned);
  1179. extern int chrdev_open(struct inode *, struct file *);
  1180. /* fs/block_dev.c */
  1181. #define BDEVNAME_SIZE 32 /* Largest string for a blockdev identifier */
  1182. extern const char *__bdevname(dev_t, char *buffer);
  1183. extern const char *bdevname(struct block_device *bdev, char *buffer);
  1184. extern struct block_device *lookup_bdev(const char *);
  1185. extern struct block_device *open_bdev_excl(const char *, int, void *);
  1186. extern void close_bdev_excl(struct block_device *);
  1187. extern void init_special_inode(struct inode *, umode_t, dev_t);
  1188. /* Invalid inode operations -- fs/bad_inode.c */
  1189. extern void make_bad_inode(struct inode *);
  1190. extern int is_bad_inode(struct inode *);
  1191. extern struct file_operations read_fifo_fops;
  1192. extern struct file_operations write_fifo_fops;
  1193. extern struct file_operations rdwr_fifo_fops;
  1194. extern struct file_operations read_pipe_fops;
  1195. extern struct file_operations write_pipe_fops;
  1196. extern struct file_operations rdwr_pipe_fops;
  1197. extern int fs_may_remount_ro(struct super_block *);
  1198. /*
  1199. * return READ, READA, or WRITE
  1200. */
  1201. #define bio_rw(bio) ((bio)->bi_rw & (RW_MASK | RWA_MASK))
  1202. /*
  1203. * return data direction, READ or WRITE
  1204. */
  1205. #define bio_data_dir(bio) ((bio)->bi_rw & 1)
  1206. extern int check_disk_change(struct block_device *);
  1207. extern int invalidate_inodes(struct super_block *);
  1208. extern int __invalidate_device(struct block_device *);
  1209. extern int invalidate_partition(struct gendisk *, int);
  1210. unsigned long invalidate_mapping_pages(struct address_space *mapping,
  1211. pgoff_t start, pgoff_t end);
  1212. unsigned long invalidate_inode_pages(struct address_space *mapping);
  1213. static inline void invalidate_remote_inode(struct inode *inode)
  1214. {
  1215. if (S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
  1216. S_ISLNK(inode->i_mode))
  1217. invalidate_inode_pages(inode->i_mapping);
  1218. }
  1219. extern int invalidate_inode_pages2(struct address_space *mapping);
  1220. extern int invalidate_inode_pages2_range(struct address_space *mapping,
  1221. pgoff_t start, pgoff_t end);
  1222. extern int write_inode_now(struct inode *, int);
  1223. extern int filemap_fdatawrite(struct address_space *);
  1224. extern int filemap_flush(struct address_space *);
  1225. extern int filemap_fdatawait(struct address_space *);
  1226. extern int filemap_write_and_wait(struct address_space *mapping);
  1227. extern int filemap_write_and_wait_range(struct address_space *mapping,
  1228. loff_t lstart, loff_t lend);
  1229. extern void sync_supers(void);
  1230. extern void sync_filesystems(int wait);
  1231. extern void emergency_sync(void);
  1232. extern void emergency_remount(void);
  1233. extern int do_remount_sb(struct super_block *sb, int flags,
  1234. void *data, int force);
  1235. extern sector_t bmap(struct inode *, sector_t);
  1236. extern int notify_change(struct dentry *, struct iattr *);
  1237. extern int permission(struct inode *, int, struct nameidata *);
  1238. extern int generic_permission(struct inode *, int,
  1239. int (*check_acl)(struct inode *, int));
  1240. extern int get_write_access(struct inode *);
  1241. extern int deny_write_access(struct file *);
  1242. static inline void put_write_access(struct inode * inode)
  1243. {
  1244. atomic_dec(&inode->i_writecount);
  1245. }
  1246. static inline void allow_write_access(struct file *file)
  1247. {
  1248. if (file)
  1249. atomic_inc(&file->f_dentry->d_inode->i_writecount);
  1250. }
  1251. extern int do_pipe(int *);
  1252. extern int open_namei(const char *, int, int, struct nameidata *);
  1253. extern int may_open(struct nameidata *, int, int);
  1254. extern int kernel_read(struct file *, unsigned long, char *, unsigned long);
  1255. extern struct file * open_exec(const char *);
  1256. /* fs/dcache.c -- generic fs support functions */
  1257. extern int is_subdir(struct dentry *, struct dentry *);
  1258. extern ino_t find_inode_number(struct dentry *, struct qstr *);
  1259. #include <linux/err.h>
  1260. /* needed for stackable file system support */
  1261. extern loff_t default_llseek(struct file *file, loff_t offset, int origin);
  1262. extern loff_t vfs_llseek(struct file *file, loff_t offset, int origin);
  1263. extern void inode_init_once(struct inode *);
  1264. extern void iput(struct inode *);
  1265. extern struct inode * igrab(struct inode *);
  1266. extern ino_t iunique(struct super_block *, ino_t);
  1267. extern int inode_needs_sync(struct inode *inode);
  1268. extern void generic_delete_inode(struct inode *inode);
  1269. extern void generic_drop_inode(struct inode *inode);
  1270. extern struct inode *ilookup5_nowait(struct super_block *sb,
  1271. unsigned long hashval, int (*test)(struct inode *, void *),
  1272. void *data);
  1273. extern struct inode *ilookup5(struct super_block *sb, unsigned long hashval,
  1274. int (*test)(struct inode *, void *), void *data);
  1275. extern struct inode *ilookup(struct super_block *sb, unsigned long ino);
  1276. extern struct inode * iget5_locked(struct super_block *, unsigned long, int (*test)(struct inode *, void *), int (*set)(struct inode *, void *), void *);
  1277. extern struct inode * iget_locked(struct super_block *, unsigned long);
  1278. extern void unlock_new_inode(struct inode *);
  1279. static inline struct inode *iget(struct super_block *sb, unsigned long ino)
  1280. {
  1281. struct inode *inode = iget_locked(sb, ino);
  1282. if (inode && (inode->i_state & I_NEW)) {
  1283. sb->s_op->read_inode(inode);
  1284. unlock_new_inode(inode);
  1285. }
  1286. return inode;
  1287. }
  1288. extern void __iget(struct inode * inode);
  1289. extern void clear_inode(struct inode *);
  1290. extern void destroy_inode(struct inode *);
  1291. extern struct inode *new_inode(struct super_block *);
  1292. extern int remove_suid(struct dentry *);
  1293. extern void remove_dquot_ref(struct super_block *, int, struct list_head *);
  1294. extern struct semaphore iprune_sem;
  1295. extern void __insert_inode_hash(struct inode *, unsigned long hashval);
  1296. extern void remove_inode_hash(struct inode *);
  1297. static inline void insert_inode_hash(struct inode *inode) {
  1298. __insert_inode_hash(inode, inode->i_ino);
  1299. }
  1300. extern struct file * get_empty_filp(void);
  1301. extern void file_move(struct file *f, struct list_head *list);
  1302. extern void file_kill(struct file *f);
  1303. struct bio;
  1304. extern void submit_bio(int, struct bio *);
  1305. extern int bdev_read_only(struct block_device *);
  1306. extern int set_blocksize(struct block_device *, int);
  1307. extern int sb_set_blocksize(struct super_block *, int);
  1308. extern int sb_min_blocksize(struct super_block *, int);
  1309. extern int generic_file_mmap(struct file *, struct vm_area_struct *);
  1310. extern int generic_file_readonly_mmap(struct file *, struct vm_area_struct *);
  1311. extern int file_read_actor(read_descriptor_t * desc, struct page *page, unsigned long offset, unsigned long size);
  1312. extern int file_send_actor(read_descriptor_t * desc, struct page *page, unsigned long offset, unsigned long size);
  1313. extern ssize_t generic_file_read(struct file *, char __user *, size_t, loff_t *);
  1314. int generic_write_checks(struct file *file, loff_t *pos, size_t *count, int isblk);
  1315. extern ssize_t generic_file_write(struct file *, const char __user *, size_t, loff_t *);
  1316. extern ssize_t generic_file_aio_read(struct kiocb *, char __user *, size_t, loff_t);
  1317. extern ssize_t __generic_file_aio_read(struct kiocb *, const struct iovec *, unsigned long, loff_t *);
  1318. extern ssize_t generic_file_aio_write(struct kiocb *, const char __user *, size_t, loff_t);
  1319. extern ssize_t generic_file_aio_write_nolock(struct kiocb *, const struct iovec *,
  1320. unsigned long, loff_t *);
  1321. extern ssize_t generic_file_direct_write(struct kiocb *, const struct iovec *,
  1322. unsigned long *, loff_t, loff_t *, size_t, size_t);
  1323. extern ssize_t generic_file_buffered_write(struct kiocb *, const struct iovec *,
  1324. unsigned long, loff_t, loff_t *, size_t, ssize_t);
  1325. extern ssize_t do_sync_read(struct file *filp, char __user *buf, size_t len, loff_t *ppos);
  1326. extern ssize_t do_sync_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos);
  1327. ssize_t generic_file_write_nolock(struct file *file, const struct iovec *iov,
  1328. unsigned long nr_segs, loff_t *ppos);
  1329. extern ssize_t generic_file_sendfile(struct file *, loff_t *, size_t, read_actor_t, void *);
  1330. extern void do_generic_mapping_read(struct address_space *mapping,
  1331. struct file_ra_state *, struct file *,
  1332. loff_t *, read_descriptor_t *, read_actor_t);
  1333. extern void
  1334. file_ra_state_init(struct file_ra_state *ra, struct address_space *mapping);
  1335. extern ssize_t generic_file_readv(struct file *filp, const struct iovec *iov,
  1336. unsigned long nr_segs, loff_t *ppos);
  1337. ssize_t generic_file_writev(struct file *filp, const struct iovec *iov,
  1338. unsigned long nr_segs, loff_t *ppos);
  1339. extern loff_t no_llseek(struct file *file, loff_t offset, int origin);
  1340. extern loff_t generic_file_llseek(struct file *file, loff_t offset, int origin);
  1341. extern loff_t remote_llseek(struct file *file, loff_t offset, int origin);
  1342. extern int generic_file_open(struct inode * inode, struct file * filp);
  1343. extern int nonseekable_open(struct inode * inode, struct file * filp);
  1344. #ifdef CONFIG_FS_XIP
  1345. extern ssize_t xip_file_read(struct file *filp, char __user *buf, size_t len,
  1346. loff_t *ppos);
  1347. extern ssize_t xip_file_sendfile(struct file *in_file, loff_t *ppos,
  1348. size_t count, read_actor_t actor,
  1349. void *target);
  1350. extern int xip_file_mmap(struct file * file, struct vm_area_struct * vma);
  1351. extern ssize_t xip_file_write(struct file *filp, const char __user *buf,
  1352. size_t len, loff_t *ppos);
  1353. extern int xip_truncate_page(struct address_space *mapping, loff_t from);
  1354. #else
  1355. static inline int xip_truncate_page(struct address_space *mapping, loff_t from)
  1356. {
  1357. return 0;
  1358. }
  1359. #endif
  1360. static inline void do_generic_file_read(struct file * filp, loff_t *ppos,
  1361. read_descriptor_t * desc,
  1362. read_actor_t actor)
  1363. {
  1364. do_generic_mapping_read(filp->f_mapping,
  1365. &filp->f_ra,
  1366. filp,
  1367. ppos,
  1368. desc,
  1369. actor);
  1370. }
  1371. ssize_t __blockdev_direct_IO(int rw, struct kiocb *iocb, struct inode *inode,
  1372. struct block_device *bdev, const struct iovec *iov, loff_t offset,
  1373. unsigned long nr_segs, get_blocks_t get_blocks, dio_iodone_t end_io,
  1374. int lock_type);
  1375. enum {
  1376. DIO_LOCKING = 1, /* need locking between buffered and direct access */
  1377. DIO_NO_LOCKING, /* bdev; no locking at all between buffered/direct */
  1378. DIO_OWN_LOCKING, /* filesystem locks buffered and direct internally */
  1379. };
  1380. static inline ssize_t blockdev_direct_IO(int rw, struct kiocb *iocb,
  1381. struct inode *inode, struct block_device *bdev, const struct iovec *iov,
  1382. loff_t offset, unsigned long nr_segs, get_blocks_t get_blocks,
  1383. dio_iodone_t end_io)
  1384. {
  1385. return __blockdev_direct_IO(rw, iocb, inode, bdev, iov, offset,
  1386. nr_segs, get_blocks, end_io, DIO_LOCKING);
  1387. }
  1388. static inline ssize_t blockdev_direct_IO_no_locking(int rw, struct kiocb *iocb,
  1389. struct inode *inode, struct block_device *bdev, const struct iovec *iov,
  1390. loff_t offset, unsigned long nr_segs, get_blocks_t get_blocks,
  1391. dio_iodone_t end_io)
  1392. {
  1393. return __blockdev_direct_IO(rw, iocb, inode, bdev, iov, offset,
  1394. nr_segs, get_blocks, end_io, DIO_NO_LOCKING);
  1395. }
  1396. static inline ssize_t blockdev_direct_IO_own_locking(int rw, struct kiocb *iocb,
  1397. struct inode *inode, struct block_device *bdev, const struct iovec *iov,
  1398. loff_t offset, unsigned long nr_segs, get_blocks_t get_blocks,
  1399. dio_iodone_t end_io)
  1400. {
  1401. return __blockdev_direct_IO(rw, iocb, inode, bdev, iov, offset,
  1402. nr_segs, get_blocks, end_io, DIO_OWN_LOCKING);
  1403. }
  1404. extern struct file_operations generic_ro_fops;
  1405. #define special_file(m) (S_ISCHR(m)||S_ISBLK(m)||S_ISFIFO(m)||S_ISSOCK(m))
  1406. extern int vfs_readlink(struct dentry *, char __user *, int, const char *);
  1407. extern int vfs_follow_link(struct nameidata *, const char *);
  1408. extern int page_readlink(struct dentry *, char __user *, int);
  1409. extern void *page_follow_link_light(struct dentry *, struct nameidata *);
  1410. extern void page_put_link(struct dentry *, struct nameidata *, void *);
  1411. extern int page_symlink(struct inode *inode, const char *symname, int len);
  1412. extern struct inode_operations page_symlink_inode_operations;
  1413. extern int generic_readlink(struct dentry *, char __user *, int);
  1414. extern void generic_fillattr(struct inode *, struct kstat *);
  1415. extern int vfs_getattr(struct vfsmount *, struct dentry *, struct kstat *);
  1416. void inode_add_bytes(struct inode *inode, loff_t bytes);
  1417. void inode_sub_bytes(struct inode *inode, loff_t bytes);
  1418. loff_t inode_get_bytes(struct inode *inode);
  1419. void inode_set_bytes(struct inode *inode, loff_t bytes);
  1420. extern int vfs_readdir(struct file *, filldir_t, void *);
  1421. extern int vfs_stat(char __user *, struct kstat *);
  1422. extern int vfs_lstat(char __user *, struct kstat *);
  1423. extern int vfs_fstat(unsigned int, struct kstat *);
  1424. extern int vfs_ioctl(struct file *, unsigned int, unsigned int, unsigned long);
  1425. extern struct file_system_type *get_fs_type(const char *name);
  1426. extern struct super_block *get_super(struct block_device *);
  1427. extern struct super_block *user_get_super(dev_t);
  1428. extern void drop_super(struct super_block *sb);
  1429. extern int dcache_dir_open(struct inode *, struct file *);
  1430. extern int dcache_dir_close(struct inode *, struct file *);
  1431. extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
  1432. extern int dcache_readdir(struct file *, void *, filldir_t);
  1433. extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
  1434. extern int simple_statfs(struct super_block *, struct kstatfs *);
  1435. extern int simple_link(struct dentry *, struct inode *, struct dentry *);
  1436. extern int simple_unlink(struct inode *, struct dentry *);
  1437. extern int simple_rmdir(struct inode *, struct dentry *);
  1438. extern int simple_rename(struct inode *, struct dentry *, struct inode *, struct dentry *);
  1439. extern int simple_sync_file(struct file *, struct dentry *, int);
  1440. extern int simple_empty(struct dentry *);
  1441. extern int simple_readpage(struct file *file, struct page *page);
  1442. extern int simple_prepare_write(struct file *file, struct page *page,
  1443. unsigned offset, unsigned to);
  1444. extern int simple_commit_write(struct file *file, struct page *page,
  1445. unsigned offset, unsigned to);
  1446. extern struct dentry *simple_lookup(struct inode *, struct dentry *, struct nameidata *);
  1447. extern ssize_t generic_read_dir(struct file *, char __user *, size_t, loff_t *);
  1448. extern struct file_operations simple_dir_operations;
  1449. extern struct inode_operations simple_dir_inode_operations;
  1450. struct tree_descr { char *name; struct file_operations *ops; int mode; };
  1451. struct dentry *d_alloc_name(struct dentry *, const char *);
  1452. extern int simple_fill_super(struct super_block *, int, struct tree_descr *);
  1453. extern int simple_pin_fs(char *name, struct vfsmount **mount, int *count);
  1454. extern void simple_release_fs(struct vfsmount **mount, int *count);
  1455. extern ssize_t simple_read_from_buffer(void __user *, size_t, loff_t *, const void *, size_t);
  1456. extern int inode_change_ok(struct inode *, struct iattr *);
  1457. extern int __must_check inode_setattr(struct inode *, struct iattr *);
  1458. extern void inode_update_time(struct inode *inode, int ctime_too);
  1459. static inline ino_t parent_ino(struct dentry *dentry)
  1460. {
  1461. ino_t res;
  1462. spin_lock(&dentry->d_lock);
  1463. res = dentry->d_parent->d_inode->i_ino;
  1464. spin_unlock(&dentry->d_lock);
  1465. return res;
  1466. }
  1467. /* kernel/fork.c */
  1468. extern int unshare_files(void);
  1469. /* Transaction based IO helpers */
  1470. /*
  1471. * An argresp is stored in an allocated page and holds the
  1472. * size of the argument or response, along with its content
  1473. */
  1474. struct simple_transaction_argresp {
  1475. ssize_t size;
  1476. char data[0];
  1477. };
  1478. #define SIMPLE_TRANSACTION_LIMIT (PAGE_SIZE - sizeof(struct simple_transaction_argresp))
  1479. char *simple_transaction_get(struct file *file, const char __user *buf,
  1480. size_t size);
  1481. ssize_t simple_transaction_read(struct file *file, char __user *buf,
  1482. size_t size, loff_t *pos);
  1483. int simple_transaction_release(struct inode *inode, struct file *file);
  1484. static inline void simple_transaction_set(struct file *file, size_t n)
  1485. {
  1486. struct simple_transaction_argresp *ar = file->private_data;
  1487. BUG_ON(n > SIMPLE_TRANSACTION_LIMIT);
  1488. /*
  1489. * The barrier ensures that ar->size will really remain zero until
  1490. * ar->data is ready for reading.
  1491. */
  1492. smp_mb();
  1493. ar->size = n;
  1494. }
  1495. /*
  1496. * simple attribute files
  1497. *
  1498. * These attributes behave similar to those in sysfs:
  1499. *
  1500. * Writing to an attribute immediately sets a value, an open file can be
  1501. * written to multiple times.
  1502. *
  1503. * Reading from an attribute creates a buffer from the value that might get
  1504. * read with multiple read calls. When the attribute has been read
  1505. * completely, no further read calls are possible until the file is opened
  1506. * again.
  1507. *
  1508. * All attributes contain a text representation of a numeric value
  1509. * that are accessed with the get() and set() functions.
  1510. */
  1511. #define DEFINE_SIMPLE_ATTRIBUTE(__fops, __get, __set, __fmt) \
  1512. static int __fops ## _open(struct inode *inode, struct file *file) \
  1513. { \
  1514. __simple_attr_check_format(__fmt, 0ull); \
  1515. return simple_attr_open(inode, file, __get, __set, __fmt); \
  1516. } \
  1517. static struct file_operations __fops = { \
  1518. .owner = THIS_MODULE, \
  1519. .open = __fops ## _open, \
  1520. .release = simple_attr_close, \
  1521. .read = simple_attr_read, \
  1522. .write = simple_attr_write, \
  1523. };
  1524. static inline void __attribute__((format(printf, 1, 2)))
  1525. __simple_attr_check_format(const char *fmt, ...)
  1526. {
  1527. /* don't do anything, just let the compiler check the arguments; */
  1528. }
  1529. int simple_attr_open(struct inode *inode, struct file *file,
  1530. u64 (*get)(void *), void (*set)(void *, u64),
  1531. const char *fmt);
  1532. int simple_attr_close(struct inode *inode, struct file *file);
  1533. ssize_t simple_attr_read(struct file *file, char __user *buf,
  1534. size_t len, loff_t *ppos);
  1535. ssize_t simple_attr_write(struct file *file, const char __user *buf,
  1536. size_t len, loff_t *ppos);
  1537. #ifdef CONFIG_SECURITY
  1538. static inline char *alloc_secdata(void)
  1539. {
  1540. return (char *)get_zeroed_page(GFP_KERNEL);
  1541. }
  1542. static inline void free_secdata(void *secdata)
  1543. {
  1544. free_page((unsigned long)secdata);
  1545. }
  1546. #else
  1547. static inline char *alloc_secdata(void)
  1548. {
  1549. return (char *)1;
  1550. }
  1551. static inline void free_secdata(void *secdata)
  1552. { }
  1553. #endif /* CONFIG_SECURITY */
  1554. #endif /* __KERNEL__ */
  1555. #endif /* _LINUX_FS_H */