fs.h 66 KB

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