fs.h 63 KB

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