fs.h 75 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175
  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/limits.h>
  8. #include <linux/ioctl.h>
  9. /*
  10. * It's silly to have NR_OPEN bigger than NR_FILE, but you can change
  11. * the file limit at runtime and only root can increase the per-process
  12. * nr_file rlimit, so it's safe to set up a ridiculously high absolute
  13. * upper limit on files-per-process.
  14. *
  15. * Some programs (notably those using select()) may have to be
  16. * recompiled to take full advantage of the new limits..
  17. */
  18. /* Fixed constants first: */
  19. #undef NR_OPEN
  20. extern int sysctl_nr_open;
  21. #define INR_OPEN 1024 /* Initial setting for nfile rlimits */
  22. #define BLOCK_SIZE_BITS 10
  23. #define BLOCK_SIZE (1<<BLOCK_SIZE_BITS)
  24. #define SEEK_SET 0 /* seek relative to beginning of file */
  25. #define SEEK_CUR 1 /* seek relative to current file position */
  26. #define SEEK_END 2 /* seek relative to end of file */
  27. #define SEEK_MAX SEEK_END
  28. /* And dynamically-tunable limits and defaults: */
  29. struct files_stat_struct {
  30. int nr_files; /* read only */
  31. int nr_free_files; /* read only */
  32. int max_files; /* tunable */
  33. };
  34. extern struct files_stat_struct files_stat;
  35. extern int get_max_files(void);
  36. struct inodes_stat_t {
  37. int nr_inodes;
  38. int nr_unused;
  39. int dummy[5]; /* padding for sysctl ABI compatibility */
  40. };
  41. extern struct inodes_stat_t inodes_stat;
  42. extern int leases_enable, lease_break_time;
  43. #ifdef CONFIG_DNOTIFY
  44. extern int dir_notify_enable;
  45. #endif
  46. #define NR_FILE 8192 /* this can well be larger on a larger system */
  47. #define MAY_EXEC 1
  48. #define MAY_WRITE 2
  49. #define MAY_READ 4
  50. #define MAY_APPEND 8
  51. #define MAY_ACCESS 16
  52. #define MAY_OPEN 32
  53. #define FMODE_READ 1
  54. #define FMODE_WRITE 2
  55. /* Internal kernel extensions */
  56. #define FMODE_LSEEK 4
  57. #define FMODE_PREAD 8
  58. #define FMODE_PWRITE FMODE_PREAD /* These go hand in hand */
  59. /* File is being opened for execution. Primary users of this flag are
  60. distributed filesystems that can use it to achieve correct ETXTBUSY
  61. behavior for cross-node execution/opening_for_writing of files */
  62. #define FMODE_EXEC 16
  63. #define RW_MASK 1
  64. #define RWA_MASK 2
  65. #define READ 0
  66. #define WRITE 1
  67. #define READA 2 /* read-ahead - don't block if no resources */
  68. #define SWRITE 3 /* for ll_rw_block() - wait for buffer lock */
  69. #define READ_SYNC (READ | (1 << BIO_RW_SYNC))
  70. #define READ_META (READ | (1 << BIO_RW_META))
  71. #define WRITE_SYNC (WRITE | (1 << BIO_RW_SYNC))
  72. #define SWRITE_SYNC (SWRITE | (1 << BIO_RW_SYNC))
  73. #define WRITE_BARRIER ((1 << BIO_RW) | (1 << BIO_RW_BARRIER))
  74. #define SEL_IN 1
  75. #define SEL_OUT 2
  76. #define SEL_EX 4
  77. /* public flags for file_system_type */
  78. #define FS_REQUIRES_DEV 1
  79. #define FS_BINARY_MOUNTDATA 2
  80. #define FS_HAS_SUBTYPE 4
  81. #define FS_REVAL_DOT 16384 /* Check the paths ".", ".." for staleness */
  82. #define FS_RENAME_DOES_D_MOVE 32768 /* FS will handle d_move()
  83. * during rename() internally.
  84. */
  85. /*
  86. * These are the fs-independent mount-flags: up to 32 flags are supported
  87. */
  88. #define MS_RDONLY 1 /* Mount read-only */
  89. #define MS_NOSUID 2 /* Ignore suid and sgid bits */
  90. #define MS_NODEV 4 /* Disallow access to device special files */
  91. #define MS_NOEXEC 8 /* Disallow program execution */
  92. #define MS_SYNCHRONOUS 16 /* Writes are synced at once */
  93. #define MS_REMOUNT 32 /* Alter flags of a mounted FS */
  94. #define MS_MANDLOCK 64 /* Allow mandatory locks on an FS */
  95. #define MS_DIRSYNC 128 /* Directory modifications are synchronous */
  96. #define MS_NOATIME 1024 /* Do not update access times. */
  97. #define MS_NODIRATIME 2048 /* Do not update directory access times */
  98. #define MS_BIND 4096
  99. #define MS_MOVE 8192
  100. #define MS_REC 16384
  101. #define MS_VERBOSE 32768 /* War is peace. Verbosity is silence.
  102. MS_VERBOSE is deprecated. */
  103. #define MS_SILENT 32768
  104. #define MS_POSIXACL (1<<16) /* VFS does not apply the umask */
  105. #define MS_UNBINDABLE (1<<17) /* change to unbindable */
  106. #define MS_PRIVATE (1<<18) /* change to private */
  107. #define MS_SLAVE (1<<19) /* change to slave */
  108. #define MS_SHARED (1<<20) /* change to shared */
  109. #define MS_RELATIME (1<<21) /* Update atime relative to mtime/ctime. */
  110. #define MS_KERNMOUNT (1<<22) /* this is a kern_mount call */
  111. #define MS_I_VERSION (1<<23) /* Update inode I_version field */
  112. #define MS_ACTIVE (1<<30)
  113. #define MS_NOUSER (1<<31)
  114. /*
  115. * Superblock flags that can be altered by MS_REMOUNT
  116. */
  117. #define MS_RMT_MASK (MS_RDONLY|MS_SYNCHRONOUS|MS_MANDLOCK)
  118. /*
  119. * Old magic mount flag and mask
  120. */
  121. #define MS_MGC_VAL 0xC0ED0000
  122. #define MS_MGC_MSK 0xffff0000
  123. /* Inode flags - they have nothing to superblock flags now */
  124. #define S_SYNC 1 /* Writes are synced at once */
  125. #define S_NOATIME 2 /* Do not update access times */
  126. #define S_APPEND 4 /* Append-only file */
  127. #define S_IMMUTABLE 8 /* Immutable file */
  128. #define S_DEAD 16 /* removed, but still open directory */
  129. #define S_NOQUOTA 32 /* Inode is not counted to quota */
  130. #define S_DIRSYNC 64 /* Directory modifications are synchronous */
  131. #define S_NOCMTIME 128 /* Do not update file c/mtime */
  132. #define S_SWAPFILE 256 /* Do not truncate: swapon got its bmaps */
  133. #define S_PRIVATE 512 /* Inode is fs-internal */
  134. /*
  135. * Note that nosuid etc flags are inode-specific: setting some file-system
  136. * flags just means all the inodes inherit those flags by default. It might be
  137. * possible to override it selectively if you really wanted to with some
  138. * ioctl() that is not currently implemented.
  139. *
  140. * Exception: MS_RDONLY is always applied to the entire file system.
  141. *
  142. * Unfortunately, it is possible to change a filesystems flags with it mounted
  143. * with files in use. This means that all of the inodes will not have their
  144. * i_flags updated. Hence, i_flags no longer inherit the superblock mount
  145. * flags, so these have to be checked separately. -- rmk@arm.uk.linux.org
  146. */
  147. #define __IS_FLG(inode,flg) ((inode)->i_sb->s_flags & (flg))
  148. #define IS_RDONLY(inode) ((inode)->i_sb->s_flags & MS_RDONLY)
  149. #define IS_SYNC(inode) (__IS_FLG(inode, MS_SYNCHRONOUS) || \
  150. ((inode)->i_flags & S_SYNC))
  151. #define IS_DIRSYNC(inode) (__IS_FLG(inode, MS_SYNCHRONOUS|MS_DIRSYNC) || \
  152. ((inode)->i_flags & (S_SYNC|S_DIRSYNC)))
  153. #define IS_MANDLOCK(inode) __IS_FLG(inode, MS_MANDLOCK)
  154. #define IS_NOATIME(inode) __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
  155. #define IS_I_VERSION(inode) __IS_FLG(inode, MS_I_VERSION)
  156. #define IS_NOQUOTA(inode) ((inode)->i_flags & S_NOQUOTA)
  157. #define IS_APPEND(inode) ((inode)->i_flags & S_APPEND)
  158. #define IS_IMMUTABLE(inode) ((inode)->i_flags & S_IMMUTABLE)
  159. #define IS_POSIXACL(inode) __IS_FLG(inode, MS_POSIXACL)
  160. #define IS_DEADDIR(inode) ((inode)->i_flags & S_DEAD)
  161. #define IS_NOCMTIME(inode) ((inode)->i_flags & S_NOCMTIME)
  162. #define IS_SWAPFILE(inode) ((inode)->i_flags & S_SWAPFILE)
  163. #define IS_PRIVATE(inode) ((inode)->i_flags & S_PRIVATE)
  164. /* the read-only stuff doesn't really belong here, but any other place is
  165. probably as bad and I don't want to create yet another include file. */
  166. #define BLKROSET _IO(0x12,93) /* set device read-only (0 = read-write) */
  167. #define BLKROGET _IO(0x12,94) /* get read-only status (0 = read_write) */
  168. #define BLKRRPART _IO(0x12,95) /* re-read partition table */
  169. #define BLKGETSIZE _IO(0x12,96) /* return device size /512 (long *arg) */
  170. #define BLKFLSBUF _IO(0x12,97) /* flush buffer cache */
  171. #define BLKRASET _IO(0x12,98) /* set read ahead for block device */
  172. #define BLKRAGET _IO(0x12,99) /* get current read ahead setting */
  173. #define BLKFRASET _IO(0x12,100)/* set filesystem (mm/filemap.c) read-ahead */
  174. #define BLKFRAGET _IO(0x12,101)/* get filesystem (mm/filemap.c) read-ahead */
  175. #define BLKSECTSET _IO(0x12,102)/* set max sectors per request (ll_rw_blk.c) */
  176. #define BLKSECTGET _IO(0x12,103)/* get max sectors per request (ll_rw_blk.c) */
  177. #define BLKSSZGET _IO(0x12,104)/* get block device sector size */
  178. #if 0
  179. #define BLKPG _IO(0x12,105)/* See blkpg.h */
  180. /* Some people are morons. Do not use sizeof! */
  181. #define BLKELVGET _IOR(0x12,106,size_t)/* elevator get */
  182. #define BLKELVSET _IOW(0x12,107,size_t)/* elevator set */
  183. /* This was here just to show that the number is taken -
  184. probably all these _IO(0x12,*) ioctls should be moved to blkpg.h. */
  185. #endif
  186. /* A jump here: 108-111 have been used for various private purposes. */
  187. #define BLKBSZGET _IOR(0x12,112,size_t)
  188. #define BLKBSZSET _IOW(0x12,113,size_t)
  189. #define BLKGETSIZE64 _IOR(0x12,114,size_t) /* return device size in bytes (u64 *arg) */
  190. #define BLKTRACESETUP _IOWR(0x12,115,struct blk_user_trace_setup)
  191. #define BLKTRACESTART _IO(0x12,116)
  192. #define BLKTRACESTOP _IO(0x12,117)
  193. #define BLKTRACETEARDOWN _IO(0x12,118)
  194. #define BMAP_IOCTL 1 /* obsolete - kept for compatibility */
  195. #define FIBMAP _IO(0x00,1) /* bmap access */
  196. #define FIGETBSZ _IO(0x00,2) /* get the block size used for bmap */
  197. #define FS_IOC_GETFLAGS _IOR('f', 1, long)
  198. #define FS_IOC_SETFLAGS _IOW('f', 2, long)
  199. #define FS_IOC_GETVERSION _IOR('v', 1, long)
  200. #define FS_IOC_SETVERSION _IOW('v', 2, long)
  201. #define FS_IOC_FIEMAP _IOWR('f', 11, struct fiemap)
  202. #define FS_IOC32_GETFLAGS _IOR('f', 1, int)
  203. #define FS_IOC32_SETFLAGS _IOW('f', 2, int)
  204. #define FS_IOC32_GETVERSION _IOR('v', 1, int)
  205. #define FS_IOC32_SETVERSION _IOW('v', 2, int)
  206. /*
  207. * Inode flags (FS_IOC_GETFLAGS / FS_IOC_SETFLAGS)
  208. */
  209. #define FS_SECRM_FL 0x00000001 /* Secure deletion */
  210. #define FS_UNRM_FL 0x00000002 /* Undelete */
  211. #define FS_COMPR_FL 0x00000004 /* Compress file */
  212. #define FS_SYNC_FL 0x00000008 /* Synchronous updates */
  213. #define FS_IMMUTABLE_FL 0x00000010 /* Immutable file */
  214. #define FS_APPEND_FL 0x00000020 /* writes to file may only append */
  215. #define FS_NODUMP_FL 0x00000040 /* do not dump file */
  216. #define FS_NOATIME_FL 0x00000080 /* do not update atime */
  217. /* Reserved for compression usage... */
  218. #define FS_DIRTY_FL 0x00000100
  219. #define FS_COMPRBLK_FL 0x00000200 /* One or more compressed clusters */
  220. #define FS_NOCOMP_FL 0x00000400 /* Don't compress */
  221. #define FS_ECOMPR_FL 0x00000800 /* Compression error */
  222. /* End compression flags --- maybe not all used */
  223. #define FS_BTREE_FL 0x00001000 /* btree format dir */
  224. #define FS_INDEX_FL 0x00001000 /* hash-indexed directory */
  225. #define FS_IMAGIC_FL 0x00002000 /* AFS directory */
  226. #define FS_JOURNAL_DATA_FL 0x00004000 /* Reserved for ext3 */
  227. #define FS_NOTAIL_FL 0x00008000 /* file tail should not be merged */
  228. #define FS_DIRSYNC_FL 0x00010000 /* dirsync behaviour (directories only) */
  229. #define FS_TOPDIR_FL 0x00020000 /* Top of directory hierarchies*/
  230. #define FS_EXTENT_FL 0x00080000 /* Extents */
  231. #define FS_DIRECTIO_FL 0x00100000 /* Use direct i/o */
  232. #define FS_RESERVED_FL 0x80000000 /* reserved for ext2 lib */
  233. #define FS_FL_USER_VISIBLE 0x0003DFFF /* User visible flags */
  234. #define FS_FL_USER_MODIFIABLE 0x000380FF /* User modifiable flags */
  235. #define SYNC_FILE_RANGE_WAIT_BEFORE 1
  236. #define SYNC_FILE_RANGE_WRITE 2
  237. #define SYNC_FILE_RANGE_WAIT_AFTER 4
  238. #ifdef __KERNEL__
  239. #include <linux/linkage.h>
  240. #include <linux/wait.h>
  241. #include <linux/types.h>
  242. #include <linux/kdev_t.h>
  243. #include <linux/dcache.h>
  244. #include <linux/path.h>
  245. #include <linux/stat.h>
  246. #include <linux/cache.h>
  247. #include <linux/kobject.h>
  248. #include <linux/list.h>
  249. #include <linux/radix-tree.h>
  250. #include <linux/prio_tree.h>
  251. #include <linux/init.h>
  252. #include <linux/pid.h>
  253. #include <linux/mutex.h>
  254. #include <linux/capability.h>
  255. #include <linux/semaphore.h>
  256. #include <linux/fiemap.h>
  257. #include <asm/atomic.h>
  258. #include <asm/byteorder.h>
  259. struct export_operations;
  260. struct hd_geometry;
  261. struct iovec;
  262. struct nameidata;
  263. struct kiocb;
  264. struct pipe_inode_info;
  265. struct poll_table_struct;
  266. struct kstatfs;
  267. struct vm_area_struct;
  268. struct vfsmount;
  269. extern void __init inode_init(void);
  270. extern void __init inode_init_early(void);
  271. extern void __init files_init(unsigned long);
  272. struct buffer_head;
  273. typedef int (get_block_t)(struct inode *inode, sector_t iblock,
  274. struct buffer_head *bh_result, int create);
  275. typedef void (dio_iodone_t)(struct kiocb *iocb, loff_t offset,
  276. ssize_t bytes, void *private);
  277. /*
  278. * Attribute flags. These should be or-ed together to figure out what
  279. * has been changed!
  280. */
  281. #define ATTR_MODE (1 << 0)
  282. #define ATTR_UID (1 << 1)
  283. #define ATTR_GID (1 << 2)
  284. #define ATTR_SIZE (1 << 3)
  285. #define ATTR_ATIME (1 << 4)
  286. #define ATTR_MTIME (1 << 5)
  287. #define ATTR_CTIME (1 << 6)
  288. #define ATTR_ATIME_SET (1 << 7)
  289. #define ATTR_MTIME_SET (1 << 8)
  290. #define ATTR_FORCE (1 << 9) /* Not a change, but a change it */
  291. #define ATTR_ATTR_FLAG (1 << 10)
  292. #define ATTR_KILL_SUID (1 << 11)
  293. #define ATTR_KILL_SGID (1 << 12)
  294. #define ATTR_FILE (1 << 13)
  295. #define ATTR_KILL_PRIV (1 << 14)
  296. #define ATTR_OPEN (1 << 15) /* Truncating from open(O_TRUNC) */
  297. #define ATTR_TIMES_SET (1 << 16)
  298. /*
  299. * This is the Inode Attributes structure, used for notify_change(). It
  300. * uses the above definitions as flags, to know which values have changed.
  301. * Also, in this manner, a Filesystem can look at only the values it cares
  302. * about. Basically, these are the attributes that the VFS layer can
  303. * request to change from the FS layer.
  304. *
  305. * Derek Atkins <warlord@MIT.EDU> 94-10-20
  306. */
  307. struct iattr {
  308. unsigned int ia_valid;
  309. umode_t ia_mode;
  310. uid_t ia_uid;
  311. gid_t ia_gid;
  312. loff_t ia_size;
  313. struct timespec ia_atime;
  314. struct timespec ia_mtime;
  315. struct timespec ia_ctime;
  316. /*
  317. * Not an attribute, but an auxilary info for filesystems wanting to
  318. * implement an ftruncate() like method. NOTE: filesystem should
  319. * check for (ia_valid & ATTR_FILE), and not for (ia_file != NULL).
  320. */
  321. struct file *ia_file;
  322. };
  323. /*
  324. * Includes for diskquotas.
  325. */
  326. #include <linux/quota.h>
  327. /**
  328. * enum positive_aop_returns - aop return codes with specific semantics
  329. *
  330. * @AOP_WRITEPAGE_ACTIVATE: Informs the caller that page writeback has
  331. * completed, that the page is still locked, and
  332. * should be considered active. The VM uses this hint
  333. * to return the page to the active list -- it won't
  334. * be a candidate for writeback again in the near
  335. * future. Other callers must be careful to unlock
  336. * the page if they get this return. Returned by
  337. * writepage();
  338. *
  339. * @AOP_TRUNCATED_PAGE: The AOP method that was handed a locked page has
  340. * unlocked it and the page might have been truncated.
  341. * The caller should back up to acquiring a new page and
  342. * trying again. The aop will be taking reasonable
  343. * precautions not to livelock. If the caller held a page
  344. * reference, it should drop it before retrying. Returned
  345. * by readpage().
  346. *
  347. * address_space_operation functions return these large constants to indicate
  348. * special semantics to the caller. These are much larger than the bytes in a
  349. * page to allow for functions that return the number of bytes operated on in a
  350. * given page.
  351. */
  352. enum positive_aop_returns {
  353. AOP_WRITEPAGE_ACTIVATE = 0x80000,
  354. AOP_TRUNCATED_PAGE = 0x80001,
  355. };
  356. #define AOP_FLAG_UNINTERRUPTIBLE 0x0001 /* will not do a short write */
  357. #define AOP_FLAG_CONT_EXPAND 0x0002 /* called from cont_expand */
  358. /*
  359. * oh the beauties of C type declarations.
  360. */
  361. struct page;
  362. struct address_space;
  363. struct writeback_control;
  364. struct iov_iter {
  365. const struct iovec *iov;
  366. unsigned long nr_segs;
  367. size_t iov_offset;
  368. size_t count;
  369. };
  370. size_t iov_iter_copy_from_user_atomic(struct page *page,
  371. struct iov_iter *i, unsigned long offset, size_t bytes);
  372. size_t iov_iter_copy_from_user(struct page *page,
  373. struct iov_iter *i, unsigned long offset, size_t bytes);
  374. void iov_iter_advance(struct iov_iter *i, size_t bytes);
  375. int iov_iter_fault_in_readable(struct iov_iter *i, size_t bytes);
  376. size_t iov_iter_single_seg_count(struct iov_iter *i);
  377. static inline void iov_iter_init(struct iov_iter *i,
  378. const struct iovec *iov, unsigned long nr_segs,
  379. size_t count, size_t written)
  380. {
  381. i->iov = iov;
  382. i->nr_segs = nr_segs;
  383. i->iov_offset = 0;
  384. i->count = count + written;
  385. iov_iter_advance(i, written);
  386. }
  387. static inline size_t iov_iter_count(struct iov_iter *i)
  388. {
  389. return i->count;
  390. }
  391. /*
  392. * "descriptor" for what we're up to with a read.
  393. * This allows us to use the same read code yet
  394. * have multiple different users of the data that
  395. * we read from a file.
  396. *
  397. * The simplest case just copies the data to user
  398. * mode.
  399. */
  400. typedef struct {
  401. size_t written;
  402. size_t count;
  403. union {
  404. char __user *buf;
  405. void *data;
  406. } arg;
  407. int error;
  408. } read_descriptor_t;
  409. typedef int (*read_actor_t)(read_descriptor_t *, struct page *,
  410. unsigned long, unsigned long);
  411. struct address_space_operations {
  412. int (*writepage)(struct page *page, struct writeback_control *wbc);
  413. int (*readpage)(struct file *, struct page *);
  414. void (*sync_page)(struct page *);
  415. /* Write back some dirty pages from this mapping. */
  416. int (*writepages)(struct address_space *, struct writeback_control *);
  417. /* Set a page dirty. Return true if this dirtied it */
  418. int (*set_page_dirty)(struct page *page);
  419. int (*readpages)(struct file *filp, struct address_space *mapping,
  420. struct list_head *pages, unsigned nr_pages);
  421. /*
  422. * ext3 requires that a successful prepare_write() call be followed
  423. * by a commit_write() call - they must be balanced
  424. */
  425. int (*prepare_write)(struct file *, struct page *, unsigned, unsigned);
  426. int (*commit_write)(struct file *, struct page *, unsigned, unsigned);
  427. int (*write_begin)(struct file *, struct address_space *mapping,
  428. loff_t pos, unsigned len, unsigned flags,
  429. struct page **pagep, void **fsdata);
  430. int (*write_end)(struct file *, struct address_space *mapping,
  431. loff_t pos, unsigned len, unsigned copied,
  432. struct page *page, void *fsdata);
  433. /* Unfortunately this kludge is needed for FIBMAP. Don't use it */
  434. sector_t (*bmap)(struct address_space *, sector_t);
  435. void (*invalidatepage) (struct page *, unsigned long);
  436. int (*releasepage) (struct page *, gfp_t);
  437. ssize_t (*direct_IO)(int, struct kiocb *, const struct iovec *iov,
  438. loff_t offset, unsigned long nr_segs);
  439. int (*get_xip_mem)(struct address_space *, pgoff_t, int,
  440. void **, unsigned long *);
  441. /* migrate the contents of a page to the specified target */
  442. int (*migratepage) (struct address_space *,
  443. struct page *, struct page *);
  444. int (*launder_page) (struct page *);
  445. int (*is_partially_uptodate) (struct page *, read_descriptor_t *,
  446. unsigned long);
  447. };
  448. /*
  449. * pagecache_write_begin/pagecache_write_end must be used by general code
  450. * to write into the pagecache.
  451. */
  452. int pagecache_write_begin(struct file *, struct address_space *mapping,
  453. loff_t pos, unsigned len, unsigned flags,
  454. struct page **pagep, void **fsdata);
  455. int pagecache_write_end(struct file *, struct address_space *mapping,
  456. loff_t pos, unsigned len, unsigned copied,
  457. struct page *page, void *fsdata);
  458. struct backing_dev_info;
  459. struct address_space {
  460. struct inode *host; /* owner: inode, block_device */
  461. struct radix_tree_root page_tree; /* radix tree of all pages */
  462. spinlock_t tree_lock; /* and lock protecting it */
  463. unsigned int i_mmap_writable;/* count VM_SHARED mappings */
  464. struct prio_tree_root i_mmap; /* tree of private and shared mappings */
  465. struct list_head i_mmap_nonlinear;/*list VM_NONLINEAR mappings */
  466. spinlock_t i_mmap_lock; /* protect tree, count, list */
  467. unsigned int truncate_count; /* Cover race condition with truncate */
  468. unsigned long nrpages; /* number of total pages */
  469. pgoff_t writeback_index;/* writeback starts here */
  470. const struct address_space_operations *a_ops; /* methods */
  471. unsigned long flags; /* error bits/gfp mask */
  472. struct backing_dev_info *backing_dev_info; /* device readahead, etc */
  473. spinlock_t private_lock; /* for use by the address_space */
  474. struct list_head private_list; /* ditto */
  475. struct address_space *assoc_mapping; /* ditto */
  476. } __attribute__((aligned(sizeof(long))));
  477. /*
  478. * On most architectures that alignment is already the case; but
  479. * must be enforced here for CRIS, to let the least signficant bit
  480. * of struct page's "mapping" pointer be used for PAGE_MAPPING_ANON.
  481. */
  482. struct block_device {
  483. dev_t bd_dev; /* not a kdev_t - it's a search key */
  484. struct inode * bd_inode; /* will die */
  485. int bd_openers;
  486. struct mutex bd_mutex; /* open/close mutex */
  487. struct semaphore bd_mount_sem;
  488. struct list_head bd_inodes;
  489. void * bd_holder;
  490. int bd_holders;
  491. #ifdef CONFIG_SYSFS
  492. struct list_head bd_holder_list;
  493. #endif
  494. struct block_device * bd_contains;
  495. unsigned bd_block_size;
  496. struct hd_struct * bd_part;
  497. /* number of times partitions within this device have been opened. */
  498. unsigned bd_part_count;
  499. int bd_invalidated;
  500. struct gendisk * bd_disk;
  501. struct list_head bd_list;
  502. struct backing_dev_info *bd_inode_backing_dev_info;
  503. /*
  504. * Private data. You must have bd_claim'ed the block_device
  505. * to use this. NOTE: bd_claim allows an owner to claim
  506. * the same device multiple times, the owner must take special
  507. * care to not mess up bd_private for that case.
  508. */
  509. unsigned long bd_private;
  510. };
  511. /*
  512. * Radix-tree tags, for tagging dirty and writeback pages within the pagecache
  513. * radix trees
  514. */
  515. #define PAGECACHE_TAG_DIRTY 0
  516. #define PAGECACHE_TAG_WRITEBACK 1
  517. int mapping_tagged(struct address_space *mapping, int tag);
  518. /*
  519. * Might pages of this file be mapped into userspace?
  520. */
  521. static inline int mapping_mapped(struct address_space *mapping)
  522. {
  523. return !prio_tree_empty(&mapping->i_mmap) ||
  524. !list_empty(&mapping->i_mmap_nonlinear);
  525. }
  526. /*
  527. * Might pages of this file have been modified in userspace?
  528. * Note that i_mmap_writable counts all VM_SHARED vmas: do_mmap_pgoff
  529. * marks vma as VM_SHARED if it is shared, and the file was opened for
  530. * writing i.e. vma may be mprotected writable even if now readonly.
  531. */
  532. static inline int mapping_writably_mapped(struct address_space *mapping)
  533. {
  534. return mapping->i_mmap_writable != 0;
  535. }
  536. /*
  537. * Use sequence counter to get consistent i_size on 32-bit processors.
  538. */
  539. #if BITS_PER_LONG==32 && defined(CONFIG_SMP)
  540. #include <linux/seqlock.h>
  541. #define __NEED_I_SIZE_ORDERED
  542. #define i_size_ordered_init(inode) seqcount_init(&inode->i_size_seqcount)
  543. #else
  544. #define i_size_ordered_init(inode) do { } while (0)
  545. #endif
  546. struct inode {
  547. struct hlist_node i_hash;
  548. struct list_head i_list;
  549. struct list_head i_sb_list;
  550. struct list_head i_dentry;
  551. unsigned long i_ino;
  552. atomic_t i_count;
  553. unsigned int i_nlink;
  554. uid_t i_uid;
  555. gid_t i_gid;
  556. dev_t i_rdev;
  557. u64 i_version;
  558. loff_t i_size;
  559. #ifdef __NEED_I_SIZE_ORDERED
  560. seqcount_t i_size_seqcount;
  561. #endif
  562. struct timespec i_atime;
  563. struct timespec i_mtime;
  564. struct timespec i_ctime;
  565. unsigned int i_blkbits;
  566. blkcnt_t i_blocks;
  567. unsigned short i_bytes;
  568. umode_t i_mode;
  569. spinlock_t i_lock; /* i_blocks, i_bytes, maybe i_size */
  570. struct mutex i_mutex;
  571. struct rw_semaphore i_alloc_sem;
  572. const struct inode_operations *i_op;
  573. const struct file_operations *i_fop; /* former ->i_op->default_file_ops */
  574. struct super_block *i_sb;
  575. struct file_lock *i_flock;
  576. struct address_space *i_mapping;
  577. struct address_space i_data;
  578. #ifdef CONFIG_QUOTA
  579. struct dquot *i_dquot[MAXQUOTAS];
  580. #endif
  581. struct list_head i_devices;
  582. union {
  583. struct pipe_inode_info *i_pipe;
  584. struct block_device *i_bdev;
  585. struct cdev *i_cdev;
  586. };
  587. int i_cindex;
  588. __u32 i_generation;
  589. #ifdef CONFIG_DNOTIFY
  590. unsigned long i_dnotify_mask; /* Directory notify events */
  591. struct dnotify_struct *i_dnotify; /* for directory notifications */
  592. #endif
  593. #ifdef CONFIG_INOTIFY
  594. struct list_head inotify_watches; /* watches on this inode */
  595. struct mutex inotify_mutex; /* protects the watches list */
  596. #endif
  597. unsigned long i_state;
  598. unsigned long dirtied_when; /* jiffies of first dirtying */
  599. unsigned int i_flags;
  600. atomic_t i_writecount;
  601. #ifdef CONFIG_SECURITY
  602. void *i_security;
  603. #endif
  604. void *i_private; /* fs or device private pointer */
  605. };
  606. /*
  607. * inode->i_mutex nesting subclasses for the lock validator:
  608. *
  609. * 0: the object of the current VFS operation
  610. * 1: parent
  611. * 2: child/target
  612. * 3: quota file
  613. *
  614. * The locking order between these classes is
  615. * parent -> child -> normal -> xattr -> quota
  616. */
  617. enum inode_i_mutex_lock_class
  618. {
  619. I_MUTEX_NORMAL,
  620. I_MUTEX_PARENT,
  621. I_MUTEX_CHILD,
  622. I_MUTEX_XATTR,
  623. I_MUTEX_QUOTA
  624. };
  625. extern void inode_double_lock(struct inode *inode1, struct inode *inode2);
  626. extern void inode_double_unlock(struct inode *inode1, struct inode *inode2);
  627. /*
  628. * NOTE: in a 32bit arch with a preemptable kernel and
  629. * an UP compile the i_size_read/write must be atomic
  630. * with respect to the local cpu (unlike with preempt disabled),
  631. * but they don't need to be atomic with respect to other cpus like in
  632. * true SMP (so they need either to either locally disable irq around
  633. * the read or for example on x86 they can be still implemented as a
  634. * cmpxchg8b without the need of the lock prefix). For SMP compiles
  635. * and 64bit archs it makes no difference if preempt is enabled or not.
  636. */
  637. static inline loff_t i_size_read(const struct inode *inode)
  638. {
  639. #if BITS_PER_LONG==32 && defined(CONFIG_SMP)
  640. loff_t i_size;
  641. unsigned int seq;
  642. do {
  643. seq = read_seqcount_begin(&inode->i_size_seqcount);
  644. i_size = inode->i_size;
  645. } while (read_seqcount_retry(&inode->i_size_seqcount, seq));
  646. return i_size;
  647. #elif BITS_PER_LONG==32 && defined(CONFIG_PREEMPT)
  648. loff_t i_size;
  649. preempt_disable();
  650. i_size = inode->i_size;
  651. preempt_enable();
  652. return i_size;
  653. #else
  654. return inode->i_size;
  655. #endif
  656. }
  657. /*
  658. * NOTE: unlike i_size_read(), i_size_write() does need locking around it
  659. * (normally i_mutex), otherwise on 32bit/SMP an update of i_size_seqcount
  660. * can be lost, resulting in subsequent i_size_read() calls spinning forever.
  661. */
  662. static inline void i_size_write(struct inode *inode, loff_t i_size)
  663. {
  664. #if BITS_PER_LONG==32 && defined(CONFIG_SMP)
  665. write_seqcount_begin(&inode->i_size_seqcount);
  666. inode->i_size = i_size;
  667. write_seqcount_end(&inode->i_size_seqcount);
  668. #elif BITS_PER_LONG==32 && defined(CONFIG_PREEMPT)
  669. preempt_disable();
  670. inode->i_size = i_size;
  671. preempt_enable();
  672. #else
  673. inode->i_size = i_size;
  674. #endif
  675. }
  676. static inline unsigned iminor(const struct inode *inode)
  677. {
  678. return MINOR(inode->i_rdev);
  679. }
  680. static inline unsigned imajor(const struct inode *inode)
  681. {
  682. return MAJOR(inode->i_rdev);
  683. }
  684. extern struct block_device *I_BDEV(struct inode *inode);
  685. struct fown_struct {
  686. rwlock_t lock; /* protects pid, uid, euid fields */
  687. struct pid *pid; /* pid or -pgrp where SIGIO should be sent */
  688. enum pid_type pid_type; /* Kind of process group SIGIO should be sent to */
  689. uid_t uid, euid; /* uid/euid of process setting the owner */
  690. int signum; /* posix.1b rt signal to be delivered on IO */
  691. };
  692. /*
  693. * Track a single file's readahead state
  694. */
  695. struct file_ra_state {
  696. pgoff_t start; /* where readahead started */
  697. unsigned int size; /* # of readahead pages */
  698. unsigned int async_size; /* do asynchronous readahead when
  699. there are only # of pages ahead */
  700. unsigned int ra_pages; /* Maximum readahead window */
  701. int mmap_miss; /* Cache miss stat for mmap accesses */
  702. loff_t prev_pos; /* Cache last read() position */
  703. };
  704. /*
  705. * Check if @index falls in the readahead windows.
  706. */
  707. static inline int ra_has_index(struct file_ra_state *ra, pgoff_t index)
  708. {
  709. return (index >= ra->start &&
  710. index < ra->start + ra->size);
  711. }
  712. #define FILE_MNT_WRITE_TAKEN 1
  713. #define FILE_MNT_WRITE_RELEASED 2
  714. struct file {
  715. /*
  716. * fu_list becomes invalid after file_free is called and queued via
  717. * fu_rcuhead for RCU freeing
  718. */
  719. union {
  720. struct list_head fu_list;
  721. struct rcu_head fu_rcuhead;
  722. } f_u;
  723. struct path f_path;
  724. #define f_dentry f_path.dentry
  725. #define f_vfsmnt f_path.mnt
  726. const struct file_operations *f_op;
  727. atomic_long_t f_count;
  728. unsigned int f_flags;
  729. mode_t f_mode;
  730. loff_t f_pos;
  731. struct fown_struct f_owner;
  732. unsigned int f_uid, f_gid;
  733. struct file_ra_state f_ra;
  734. u64 f_version;
  735. #ifdef CONFIG_SECURITY
  736. void *f_security;
  737. #endif
  738. /* needed for tty driver, and maybe others */
  739. void *private_data;
  740. #ifdef CONFIG_EPOLL
  741. /* Used by fs/eventpoll.c to link all the hooks to this file */
  742. struct list_head f_ep_links;
  743. spinlock_t f_ep_lock;
  744. #endif /* #ifdef CONFIG_EPOLL */
  745. struct address_space *f_mapping;
  746. #ifdef CONFIG_DEBUG_WRITECOUNT
  747. unsigned long f_mnt_write_state;
  748. #endif
  749. };
  750. extern spinlock_t files_lock;
  751. #define file_list_lock() spin_lock(&files_lock);
  752. #define file_list_unlock() spin_unlock(&files_lock);
  753. #define get_file(x) atomic_long_inc(&(x)->f_count)
  754. #define file_count(x) atomic_long_read(&(x)->f_count)
  755. #ifdef CONFIG_DEBUG_WRITECOUNT
  756. static inline void file_take_write(struct file *f)
  757. {
  758. WARN_ON(f->f_mnt_write_state != 0);
  759. f->f_mnt_write_state = FILE_MNT_WRITE_TAKEN;
  760. }
  761. static inline void file_release_write(struct file *f)
  762. {
  763. f->f_mnt_write_state |= FILE_MNT_WRITE_RELEASED;
  764. }
  765. static inline void file_reset_write(struct file *f)
  766. {
  767. f->f_mnt_write_state = 0;
  768. }
  769. static inline void file_check_state(struct file *f)
  770. {
  771. /*
  772. * At this point, either both or neither of these bits
  773. * should be set.
  774. */
  775. WARN_ON(f->f_mnt_write_state == FILE_MNT_WRITE_TAKEN);
  776. WARN_ON(f->f_mnt_write_state == FILE_MNT_WRITE_RELEASED);
  777. }
  778. static inline int file_check_writeable(struct file *f)
  779. {
  780. if (f->f_mnt_write_state == FILE_MNT_WRITE_TAKEN)
  781. return 0;
  782. printk(KERN_WARNING "writeable file with no "
  783. "mnt_want_write()\n");
  784. WARN_ON(1);
  785. return -EINVAL;
  786. }
  787. #else /* !CONFIG_DEBUG_WRITECOUNT */
  788. static inline void file_take_write(struct file *filp) {}
  789. static inline void file_release_write(struct file *filp) {}
  790. static inline void file_reset_write(struct file *filp) {}
  791. static inline void file_check_state(struct file *filp) {}
  792. static inline int file_check_writeable(struct file *filp)
  793. {
  794. return 0;
  795. }
  796. #endif /* CONFIG_DEBUG_WRITECOUNT */
  797. #define MAX_NON_LFS ((1UL<<31) - 1)
  798. /* Page cache limit. The filesystems should put that into their s_maxbytes
  799. limits, otherwise bad things can happen in VM. */
  800. #if BITS_PER_LONG==32
  801. #define MAX_LFS_FILESIZE (((u64)PAGE_CACHE_SIZE << (BITS_PER_LONG-1))-1)
  802. #elif BITS_PER_LONG==64
  803. #define MAX_LFS_FILESIZE 0x7fffffffffffffffUL
  804. #endif
  805. #define FL_POSIX 1
  806. #define FL_FLOCK 2
  807. #define FL_ACCESS 8 /* not trying to lock, just looking */
  808. #define FL_EXISTS 16 /* when unlocking, test for existence */
  809. #define FL_LEASE 32 /* lease held on this file */
  810. #define FL_CLOSE 64 /* unlock on close */
  811. #define FL_SLEEP 128 /* A blocking lock */
  812. /*
  813. * Special return value from posix_lock_file() and vfs_lock_file() for
  814. * asynchronous locking.
  815. */
  816. #define FILE_LOCK_DEFERRED 1
  817. /*
  818. * The POSIX file lock owner is determined by
  819. * the "struct files_struct" in the thread group
  820. * (or NULL for no owner - BSD locks).
  821. *
  822. * Lockd stuffs a "host" pointer into this.
  823. */
  824. typedef struct files_struct *fl_owner_t;
  825. struct file_lock_operations {
  826. void (*fl_copy_lock)(struct file_lock *, struct file_lock *);
  827. void (*fl_release_private)(struct file_lock *);
  828. };
  829. struct lock_manager_operations {
  830. int (*fl_compare_owner)(struct file_lock *, struct file_lock *);
  831. void (*fl_notify)(struct file_lock *); /* unblock callback */
  832. int (*fl_grant)(struct file_lock *, struct file_lock *, int);
  833. void (*fl_copy_lock)(struct file_lock *, struct file_lock *);
  834. void (*fl_release_private)(struct file_lock *);
  835. void (*fl_break)(struct file_lock *);
  836. int (*fl_mylease)(struct file_lock *, struct file_lock *);
  837. int (*fl_change)(struct file_lock **, int);
  838. };
  839. /* that will die - we need it for nfs_lock_info */
  840. #include <linux/nfs_fs_i.h>
  841. struct file_lock {
  842. struct file_lock *fl_next; /* singly linked list for this inode */
  843. struct list_head fl_link; /* doubly linked list of all locks */
  844. struct list_head fl_block; /* circular list of blocked processes */
  845. fl_owner_t fl_owner;
  846. unsigned char fl_flags;
  847. unsigned char fl_type;
  848. unsigned int fl_pid;
  849. struct pid *fl_nspid;
  850. wait_queue_head_t fl_wait;
  851. struct file *fl_file;
  852. loff_t fl_start;
  853. loff_t fl_end;
  854. struct fasync_struct * fl_fasync; /* for lease break notifications */
  855. unsigned long fl_break_time; /* for nonblocking lease breaks */
  856. struct file_lock_operations *fl_ops; /* Callbacks for filesystems */
  857. struct lock_manager_operations *fl_lmops; /* Callbacks for lockmanagers */
  858. union {
  859. struct nfs_lock_info nfs_fl;
  860. struct nfs4_lock_info nfs4_fl;
  861. struct {
  862. struct list_head link; /* link in AFS vnode's pending_locks list */
  863. int state; /* state of grant or error if -ve */
  864. } afs;
  865. } fl_u;
  866. };
  867. /* The following constant reflects the upper bound of the file/locking space */
  868. #ifndef OFFSET_MAX
  869. #define INT_LIMIT(x) (~((x)1 << (sizeof(x)*8 - 1)))
  870. #define OFFSET_MAX INT_LIMIT(loff_t)
  871. #define OFFT_OFFSET_MAX INT_LIMIT(off_t)
  872. #endif
  873. #include <linux/fcntl.h>
  874. extern int fcntl_getlk(struct file *, struct flock __user *);
  875. extern int fcntl_setlk(unsigned int, struct file *, unsigned int,
  876. struct flock __user *);
  877. #if BITS_PER_LONG == 32
  878. extern int fcntl_getlk64(struct file *, struct flock64 __user *);
  879. extern int fcntl_setlk64(unsigned int, struct file *, unsigned int,
  880. struct flock64 __user *);
  881. #endif
  882. extern void send_sigio(struct fown_struct *fown, int fd, int band);
  883. extern int fcntl_setlease(unsigned int fd, struct file *filp, long arg);
  884. extern int fcntl_getlease(struct file *filp);
  885. /* fs/sync.c */
  886. extern int do_sync_mapping_range(struct address_space *mapping, loff_t offset,
  887. loff_t endbyte, unsigned int flags);
  888. /* fs/locks.c */
  889. extern void locks_init_lock(struct file_lock *);
  890. extern void locks_copy_lock(struct file_lock *, struct file_lock *);
  891. extern void __locks_copy_lock(struct file_lock *, const struct file_lock *);
  892. extern void locks_remove_posix(struct file *, fl_owner_t);
  893. extern void locks_remove_flock(struct file *);
  894. extern void posix_test_lock(struct file *, struct file_lock *);
  895. extern int posix_lock_file(struct file *, struct file_lock *, struct file_lock *);
  896. extern int posix_lock_file_wait(struct file *, struct file_lock *);
  897. extern int posix_unblock_lock(struct file *, struct file_lock *);
  898. extern int vfs_test_lock(struct file *, struct file_lock *);
  899. extern int vfs_lock_file(struct file *, unsigned int, struct file_lock *, struct file_lock *);
  900. extern int vfs_cancel_lock(struct file *filp, struct file_lock *fl);
  901. extern int flock_lock_file_wait(struct file *filp, struct file_lock *fl);
  902. extern int __break_lease(struct inode *inode, unsigned int flags);
  903. extern void lease_get_mtime(struct inode *, struct timespec *time);
  904. extern int generic_setlease(struct file *, long, struct file_lock **);
  905. extern int vfs_setlease(struct file *, long, struct file_lock **);
  906. extern int lease_modify(struct file_lock **, int);
  907. extern int lock_may_read(struct inode *, loff_t start, unsigned long count);
  908. extern int lock_may_write(struct inode *, loff_t start, unsigned long count);
  909. extern struct seq_operations locks_seq_operations;
  910. struct fasync_struct {
  911. int magic;
  912. int fa_fd;
  913. struct fasync_struct *fa_next; /* singly linked list */
  914. struct file *fa_file;
  915. };
  916. #define FASYNC_MAGIC 0x4601
  917. /* SMP safe fasync helpers: */
  918. extern int fasync_helper(int, struct file *, int, struct fasync_struct **);
  919. /* can be called from interrupts */
  920. extern void kill_fasync(struct fasync_struct **, int, int);
  921. /* only for net: no internal synchronization */
  922. extern void __kill_fasync(struct fasync_struct *, int, int);
  923. extern int __f_setown(struct file *filp, struct pid *, enum pid_type, int force);
  924. extern int f_setown(struct file *filp, unsigned long arg, int force);
  925. extern void f_delown(struct file *filp);
  926. extern pid_t f_getown(struct file *filp);
  927. extern int send_sigurg(struct fown_struct *fown);
  928. /*
  929. * Umount options
  930. */
  931. #define MNT_FORCE 0x00000001 /* Attempt to forcibily umount */
  932. #define MNT_DETACH 0x00000002 /* Just detach from the tree */
  933. #define MNT_EXPIRE 0x00000004 /* Mark for expiry */
  934. extern struct list_head super_blocks;
  935. extern spinlock_t sb_lock;
  936. #define sb_entry(list) list_entry((list), struct super_block, s_list)
  937. #define S_BIAS (1<<30)
  938. struct super_block {
  939. struct list_head s_list; /* Keep this first */
  940. dev_t s_dev; /* search index; _not_ kdev_t */
  941. unsigned long s_blocksize;
  942. unsigned char s_blocksize_bits;
  943. unsigned char s_dirt;
  944. unsigned long long s_maxbytes; /* Max file size */
  945. struct file_system_type *s_type;
  946. const struct super_operations *s_op;
  947. struct dquot_operations *dq_op;
  948. struct quotactl_ops *s_qcop;
  949. const struct export_operations *s_export_op;
  950. unsigned long s_flags;
  951. unsigned long s_magic;
  952. struct dentry *s_root;
  953. struct rw_semaphore s_umount;
  954. struct mutex s_lock;
  955. int s_count;
  956. int s_syncing;
  957. int s_need_sync_fs;
  958. atomic_t s_active;
  959. #ifdef CONFIG_SECURITY
  960. void *s_security;
  961. #endif
  962. struct xattr_handler **s_xattr;
  963. struct list_head s_inodes; /* all inodes */
  964. struct list_head s_dirty; /* dirty inodes */
  965. struct list_head s_io; /* parked for writeback */
  966. struct list_head s_more_io; /* parked for more writeback */
  967. struct hlist_head s_anon; /* anonymous dentries for (nfs) exporting */
  968. struct list_head s_files;
  969. /* s_dentry_lru and s_nr_dentry_unused are protected by dcache_lock */
  970. struct list_head s_dentry_lru; /* unused dentry lru */
  971. int s_nr_dentry_unused; /* # of dentry on lru */
  972. struct block_device *s_bdev;
  973. struct mtd_info *s_mtd;
  974. struct list_head s_instances;
  975. struct quota_info s_dquot; /* Diskquota specific options */
  976. int s_frozen;
  977. wait_queue_head_t s_wait_unfrozen;
  978. char s_id[32]; /* Informational name */
  979. void *s_fs_info; /* Filesystem private info */
  980. /*
  981. * The next field is for VFS *only*. No filesystems have any business
  982. * even looking at it. You had been warned.
  983. */
  984. struct mutex s_vfs_rename_mutex; /* Kludge */
  985. /* Granularity of c/m/atime in ns.
  986. Cannot be worse than a second */
  987. u32 s_time_gran;
  988. /*
  989. * Filesystem subtype. If non-empty the filesystem type field
  990. * in /proc/mounts will be "type.subtype"
  991. */
  992. char *s_subtype;
  993. /*
  994. * Saved mount options for lazy filesystems using
  995. * generic_show_options()
  996. */
  997. char *s_options;
  998. };
  999. extern struct timespec current_fs_time(struct super_block *sb);
  1000. /*
  1001. * Snapshotting support.
  1002. */
  1003. enum {
  1004. SB_UNFROZEN = 0,
  1005. SB_FREEZE_WRITE = 1,
  1006. SB_FREEZE_TRANS = 2,
  1007. };
  1008. #define vfs_check_frozen(sb, level) \
  1009. wait_event((sb)->s_wait_unfrozen, ((sb)->s_frozen < (level)))
  1010. #define get_fs_excl() atomic_inc(&current->fs_excl)
  1011. #define put_fs_excl() atomic_dec(&current->fs_excl)
  1012. #define has_fs_excl() atomic_read(&current->fs_excl)
  1013. #define is_owner_or_cap(inode) \
  1014. ((current->fsuid == (inode)->i_uid) || capable(CAP_FOWNER))
  1015. /* not quite ready to be deprecated, but... */
  1016. extern void lock_super(struct super_block *);
  1017. extern void unlock_super(struct super_block *);
  1018. /*
  1019. * VFS helper functions..
  1020. */
  1021. extern int vfs_permission(struct nameidata *, int);
  1022. extern int vfs_create(struct inode *, struct dentry *, int, struct nameidata *);
  1023. extern int vfs_mkdir(struct inode *, struct dentry *, int);
  1024. extern int vfs_mknod(struct inode *, struct dentry *, int, dev_t);
  1025. extern int vfs_symlink(struct inode *, struct dentry *, const char *);
  1026. extern int vfs_link(struct dentry *, struct inode *, struct dentry *);
  1027. extern int vfs_rmdir(struct inode *, struct dentry *);
  1028. extern int vfs_unlink(struct inode *, struct dentry *);
  1029. extern int vfs_rename(struct inode *, struct dentry *, struct inode *, struct dentry *);
  1030. /*
  1031. * VFS dentry helper functions.
  1032. */
  1033. extern void dentry_unhash(struct dentry *dentry);
  1034. /*
  1035. * VFS file helper functions.
  1036. */
  1037. extern int file_permission(struct file *, int);
  1038. /*
  1039. * VFS FS_IOC_FIEMAP helper definitions.
  1040. */
  1041. struct fiemap_extent_info {
  1042. unsigned int fi_flags; /* Flags as passed from user */
  1043. unsigned int fi_extents_mapped; /* Number of mapped extents */
  1044. unsigned int fi_extents_max; /* Size of fiemap_extent array */
  1045. struct fiemap_extent *fi_extents_start; /* Start of fiemap_extent
  1046. * array */
  1047. };
  1048. int fiemap_fill_next_extent(struct fiemap_extent_info *info, u64 logical,
  1049. u64 phys, u64 len, u32 flags);
  1050. int fiemap_check_flags(struct fiemap_extent_info *fieinfo, u32 fs_flags);
  1051. /*
  1052. * File types
  1053. *
  1054. * NOTE! These match bits 12..15 of stat.st_mode
  1055. * (ie "(i_mode >> 12) & 15").
  1056. */
  1057. #define DT_UNKNOWN 0
  1058. #define DT_FIFO 1
  1059. #define DT_CHR 2
  1060. #define DT_DIR 4
  1061. #define DT_BLK 6
  1062. #define DT_REG 8
  1063. #define DT_LNK 10
  1064. #define DT_SOCK 12
  1065. #define DT_WHT 14
  1066. #define OSYNC_METADATA (1<<0)
  1067. #define OSYNC_DATA (1<<1)
  1068. #define OSYNC_INODE (1<<2)
  1069. int generic_osync_inode(struct inode *, struct address_space *, int);
  1070. /*
  1071. * This is the "filldir" function type, used by readdir() to let
  1072. * the kernel specify what kind of dirent layout it wants to have.
  1073. * This allows the kernel to read directories into kernel space or
  1074. * to have different dirent layouts depending on the binary type.
  1075. */
  1076. typedef int (*filldir_t)(void *, const char *, int, loff_t, u64, unsigned);
  1077. struct block_device_operations {
  1078. int (*open) (struct inode *, struct file *);
  1079. int (*release) (struct inode *, struct file *);
  1080. int (*ioctl) (struct inode *, struct file *, unsigned, unsigned long);
  1081. long (*unlocked_ioctl) (struct file *, unsigned, unsigned long);
  1082. long (*compat_ioctl) (struct file *, unsigned, unsigned long);
  1083. int (*direct_access) (struct block_device *, sector_t,
  1084. void **, unsigned long *);
  1085. int (*media_changed) (struct gendisk *);
  1086. int (*revalidate_disk) (struct gendisk *);
  1087. int (*getgeo)(struct block_device *, struct hd_geometry *);
  1088. struct module *owner;
  1089. };
  1090. /* These macros are for out of kernel modules to test that
  1091. * the kernel supports the unlocked_ioctl and compat_ioctl
  1092. * fields in struct file_operations. */
  1093. #define HAVE_COMPAT_IOCTL 1
  1094. #define HAVE_UNLOCKED_IOCTL 1
  1095. /*
  1096. * NOTE:
  1097. * read, write, poll, fsync, readv, writev, unlocked_ioctl and compat_ioctl
  1098. * can be called without the big kernel lock held in all filesystems.
  1099. */
  1100. struct file_operations {
  1101. struct module *owner;
  1102. loff_t (*llseek) (struct file *, loff_t, int);
  1103. ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
  1104. ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);
  1105. ssize_t (*aio_read) (struct kiocb *, const struct iovec *, unsigned long, loff_t);
  1106. ssize_t (*aio_write) (struct kiocb *, const struct iovec *, unsigned long, loff_t);
  1107. int (*readdir) (struct file *, void *, filldir_t);
  1108. unsigned int (*poll) (struct file *, struct poll_table_struct *);
  1109. int (*ioctl) (struct inode *, struct file *, unsigned int, unsigned long);
  1110. long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long);
  1111. long (*compat_ioctl) (struct file *, unsigned int, unsigned long);
  1112. int (*mmap) (struct file *, struct vm_area_struct *);
  1113. int (*open) (struct inode *, struct file *);
  1114. int (*flush) (struct file *, fl_owner_t id);
  1115. int (*release) (struct inode *, struct file *);
  1116. int (*fsync) (struct file *, struct dentry *, int datasync);
  1117. int (*aio_fsync) (struct kiocb *, int datasync);
  1118. int (*fasync) (int, struct file *, int);
  1119. int (*lock) (struct file *, int, struct file_lock *);
  1120. ssize_t (*sendpage) (struct file *, struct page *, int, size_t, loff_t *, int);
  1121. unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
  1122. int (*check_flags)(int);
  1123. int (*dir_notify)(struct file *filp, unsigned long arg);
  1124. int (*flock) (struct file *, int, struct file_lock *);
  1125. ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int);
  1126. ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int);
  1127. int (*setlease)(struct file *, long, struct file_lock **);
  1128. };
  1129. struct inode_operations {
  1130. int (*create) (struct inode *,struct dentry *,int, struct nameidata *);
  1131. struct dentry * (*lookup) (struct inode *,struct dentry *, struct nameidata *);
  1132. int (*link) (struct dentry *,struct inode *,struct dentry *);
  1133. int (*unlink) (struct inode *,struct dentry *);
  1134. int (*symlink) (struct inode *,struct dentry *,const char *);
  1135. int (*mkdir) (struct inode *,struct dentry *,int);
  1136. int (*rmdir) (struct inode *,struct dentry *);
  1137. int (*mknod) (struct inode *,struct dentry *,int,dev_t);
  1138. int (*rename) (struct inode *, struct dentry *,
  1139. struct inode *, struct dentry *);
  1140. int (*readlink) (struct dentry *, char __user *,int);
  1141. void * (*follow_link) (struct dentry *, struct nameidata *);
  1142. void (*put_link) (struct dentry *, struct nameidata *, void *);
  1143. void (*truncate) (struct inode *);
  1144. int (*permission) (struct inode *, int);
  1145. int (*setattr) (struct dentry *, struct iattr *);
  1146. int (*getattr) (struct vfsmount *mnt, struct dentry *, struct kstat *);
  1147. int (*setxattr) (struct dentry *, const char *,const void *,size_t,int);
  1148. ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
  1149. ssize_t (*listxattr) (struct dentry *, char *, size_t);
  1150. int (*removexattr) (struct dentry *, const char *);
  1151. void (*truncate_range)(struct inode *, loff_t, loff_t);
  1152. long (*fallocate)(struct inode *inode, int mode, loff_t offset,
  1153. loff_t len);
  1154. int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start,
  1155. u64 len);
  1156. };
  1157. struct seq_file;
  1158. ssize_t rw_copy_check_uvector(int type, const struct iovec __user * uvector,
  1159. unsigned long nr_segs, unsigned long fast_segs,
  1160. struct iovec *fast_pointer,
  1161. struct iovec **ret_pointer);
  1162. extern ssize_t vfs_read(struct file *, char __user *, size_t, loff_t *);
  1163. extern ssize_t vfs_write(struct file *, const char __user *, size_t, loff_t *);
  1164. extern ssize_t vfs_readv(struct file *, const struct iovec __user *,
  1165. unsigned long, loff_t *);
  1166. extern ssize_t vfs_writev(struct file *, const struct iovec __user *,
  1167. unsigned long, loff_t *);
  1168. struct super_operations {
  1169. struct inode *(*alloc_inode)(struct super_block *sb);
  1170. void (*destroy_inode)(struct inode *);
  1171. void (*dirty_inode) (struct inode *);
  1172. int (*write_inode) (struct inode *, int);
  1173. void (*drop_inode) (struct inode *);
  1174. void (*delete_inode) (struct inode *);
  1175. void (*put_super) (struct super_block *);
  1176. void (*write_super) (struct super_block *);
  1177. int (*sync_fs)(struct super_block *sb, int wait);
  1178. void (*write_super_lockfs) (struct super_block *);
  1179. void (*unlockfs) (struct super_block *);
  1180. int (*statfs) (struct dentry *, struct kstatfs *);
  1181. int (*remount_fs) (struct super_block *, int *, char *);
  1182. void (*clear_inode) (struct inode *);
  1183. void (*umount_begin) (struct super_block *);
  1184. int (*show_options)(struct seq_file *, struct vfsmount *);
  1185. int (*show_stats)(struct seq_file *, struct vfsmount *);
  1186. #ifdef CONFIG_QUOTA
  1187. ssize_t (*quota_read)(struct super_block *, int, char *, size_t, loff_t);
  1188. ssize_t (*quota_write)(struct super_block *, int, const char *, size_t, loff_t);
  1189. #endif
  1190. };
  1191. /*
  1192. * Inode state bits. Protected by inode_lock.
  1193. *
  1194. * Three bits determine the dirty state of the inode, I_DIRTY_SYNC,
  1195. * I_DIRTY_DATASYNC and I_DIRTY_PAGES.
  1196. *
  1197. * Four bits define the lifetime of an inode. Initially, inodes are I_NEW,
  1198. * until that flag is cleared. I_WILL_FREE, I_FREEING and I_CLEAR are set at
  1199. * various stages of removing an inode.
  1200. *
  1201. * Two bits are used for locking and completion notification, I_LOCK and I_SYNC.
  1202. *
  1203. * I_DIRTY_SYNC Inode is dirty, but doesn't have to be written on
  1204. * fdatasync(). i_atime is the usual cause.
  1205. * I_DIRTY_DATASYNC Data-related inode changes pending. We keep track of
  1206. * these changes separately from I_DIRTY_SYNC so that we
  1207. * don't have to write inode on fdatasync() when only
  1208. * mtime has changed in it.
  1209. * I_DIRTY_PAGES Inode has dirty pages. Inode itself may be clean.
  1210. * I_NEW get_new_inode() sets i_state to I_LOCK|I_NEW. Both
  1211. * are cleared by unlock_new_inode(), called from iget().
  1212. * I_WILL_FREE Must be set when calling write_inode_now() if i_count
  1213. * is zero. I_FREEING must be set when I_WILL_FREE is
  1214. * cleared.
  1215. * I_FREEING Set when inode is about to be freed but still has dirty
  1216. * pages or buffers attached or the inode itself is still
  1217. * dirty.
  1218. * I_CLEAR Set by clear_inode(). In this state the inode is clean
  1219. * and can be destroyed.
  1220. *
  1221. * Inodes that are I_WILL_FREE, I_FREEING or I_CLEAR are
  1222. * prohibited for many purposes. iget() must wait for
  1223. * the inode to be completely released, then create it
  1224. * anew. Other functions will just ignore such inodes,
  1225. * if appropriate. I_LOCK is used for waiting.
  1226. *
  1227. * I_LOCK Serves as both a mutex and completion notification.
  1228. * New inodes set I_LOCK. If two processes both create
  1229. * the same inode, one of them will release its inode and
  1230. * wait for I_LOCK to be released before returning.
  1231. * Inodes in I_WILL_FREE, I_FREEING or I_CLEAR state can
  1232. * also cause waiting on I_LOCK, without I_LOCK actually
  1233. * being set. find_inode() uses this to prevent returning
  1234. * nearly-dead inodes.
  1235. * I_SYNC Similar to I_LOCK, but limited in scope to writeback
  1236. * of inode dirty data. Having a separate lock for this
  1237. * purpose reduces latency and prevents some filesystem-
  1238. * specific deadlocks.
  1239. *
  1240. * Q: What is the difference between I_WILL_FREE and I_FREEING?
  1241. * Q: igrab() only checks on (I_FREEING|I_WILL_FREE). Should it also check on
  1242. * I_CLEAR? If not, why?
  1243. */
  1244. #define I_DIRTY_SYNC 1
  1245. #define I_DIRTY_DATASYNC 2
  1246. #define I_DIRTY_PAGES 4
  1247. #define I_NEW 8
  1248. #define I_WILL_FREE 16
  1249. #define I_FREEING 32
  1250. #define I_CLEAR 64
  1251. #define __I_LOCK 7
  1252. #define I_LOCK (1 << __I_LOCK)
  1253. #define __I_SYNC 8
  1254. #define I_SYNC (1 << __I_SYNC)
  1255. #define I_DIRTY (I_DIRTY_SYNC | I_DIRTY_DATASYNC | I_DIRTY_PAGES)
  1256. extern void __mark_inode_dirty(struct inode *, int);
  1257. static inline void mark_inode_dirty(struct inode *inode)
  1258. {
  1259. __mark_inode_dirty(inode, I_DIRTY);
  1260. }
  1261. static inline void mark_inode_dirty_sync(struct inode *inode)
  1262. {
  1263. __mark_inode_dirty(inode, I_DIRTY_SYNC);
  1264. }
  1265. /**
  1266. * inc_nlink - directly increment an inode's link count
  1267. * @inode: inode
  1268. *
  1269. * This is a low-level filesystem helper to replace any
  1270. * direct filesystem manipulation of i_nlink. Currently,
  1271. * it is only here for parity with dec_nlink().
  1272. */
  1273. static inline void inc_nlink(struct inode *inode)
  1274. {
  1275. inode->i_nlink++;
  1276. }
  1277. static inline void inode_inc_link_count(struct inode *inode)
  1278. {
  1279. inc_nlink(inode);
  1280. mark_inode_dirty(inode);
  1281. }
  1282. /**
  1283. * drop_nlink - directly drop an inode's link count
  1284. * @inode: inode
  1285. *
  1286. * This is a low-level filesystem helper to replace any
  1287. * direct filesystem manipulation of i_nlink. In cases
  1288. * where we are attempting to track writes to the
  1289. * filesystem, a decrement to zero means an imminent
  1290. * write when the file is truncated and actually unlinked
  1291. * on the filesystem.
  1292. */
  1293. static inline void drop_nlink(struct inode *inode)
  1294. {
  1295. inode->i_nlink--;
  1296. }
  1297. /**
  1298. * clear_nlink - directly zero an inode's link count
  1299. * @inode: inode
  1300. *
  1301. * This is a low-level filesystem helper to replace any
  1302. * direct filesystem manipulation of i_nlink. See
  1303. * drop_nlink() for why we care about i_nlink hitting zero.
  1304. */
  1305. static inline void clear_nlink(struct inode *inode)
  1306. {
  1307. inode->i_nlink = 0;
  1308. }
  1309. static inline void inode_dec_link_count(struct inode *inode)
  1310. {
  1311. drop_nlink(inode);
  1312. mark_inode_dirty(inode);
  1313. }
  1314. /**
  1315. * inode_inc_iversion - increments i_version
  1316. * @inode: inode that need to be updated
  1317. *
  1318. * Every time the inode is modified, the i_version field will be incremented.
  1319. * The filesystem has to be mounted with i_version flag
  1320. */
  1321. static inline void inode_inc_iversion(struct inode *inode)
  1322. {
  1323. spin_lock(&inode->i_lock);
  1324. inode->i_version++;
  1325. spin_unlock(&inode->i_lock);
  1326. }
  1327. extern void touch_atime(struct vfsmount *mnt, struct dentry *dentry);
  1328. static inline void file_accessed(struct file *file)
  1329. {
  1330. if (!(file->f_flags & O_NOATIME))
  1331. touch_atime(file->f_path.mnt, file->f_path.dentry);
  1332. }
  1333. int sync_inode(struct inode *inode, struct writeback_control *wbc);
  1334. struct file_system_type {
  1335. const char *name;
  1336. int fs_flags;
  1337. int (*get_sb) (struct file_system_type *, int,
  1338. const char *, void *, struct vfsmount *);
  1339. void (*kill_sb) (struct super_block *);
  1340. struct module *owner;
  1341. struct file_system_type * next;
  1342. struct list_head fs_supers;
  1343. struct lock_class_key s_lock_key;
  1344. struct lock_class_key s_umount_key;
  1345. struct lock_class_key i_lock_key;
  1346. struct lock_class_key i_mutex_key;
  1347. struct lock_class_key i_mutex_dir_key;
  1348. struct lock_class_key i_alloc_sem_key;
  1349. };
  1350. extern int get_sb_bdev(struct file_system_type *fs_type,
  1351. int flags, const char *dev_name, void *data,
  1352. int (*fill_super)(struct super_block *, void *, int),
  1353. struct vfsmount *mnt);
  1354. extern int get_sb_single(struct file_system_type *fs_type,
  1355. int flags, void *data,
  1356. int (*fill_super)(struct super_block *, void *, int),
  1357. struct vfsmount *mnt);
  1358. extern int get_sb_nodev(struct file_system_type *fs_type,
  1359. int flags, void *data,
  1360. int (*fill_super)(struct super_block *, void *, int),
  1361. struct vfsmount *mnt);
  1362. void generic_shutdown_super(struct super_block *sb);
  1363. void kill_block_super(struct super_block *sb);
  1364. void kill_anon_super(struct super_block *sb);
  1365. void kill_litter_super(struct super_block *sb);
  1366. void deactivate_super(struct super_block *sb);
  1367. int set_anon_super(struct super_block *s, void *data);
  1368. struct super_block *sget(struct file_system_type *type,
  1369. int (*test)(struct super_block *,void *),
  1370. int (*set)(struct super_block *,void *),
  1371. void *data);
  1372. extern int get_sb_pseudo(struct file_system_type *, char *,
  1373. const struct super_operations *ops, unsigned long,
  1374. struct vfsmount *mnt);
  1375. extern int simple_set_mnt(struct vfsmount *mnt, struct super_block *sb);
  1376. int __put_super_and_need_restart(struct super_block *sb);
  1377. void unnamed_dev_init(void);
  1378. /* Alas, no aliases. Too much hassle with bringing module.h everywhere */
  1379. #define fops_get(fops) \
  1380. (((fops) && try_module_get((fops)->owner) ? (fops) : NULL))
  1381. #define fops_put(fops) \
  1382. do { if (fops) module_put((fops)->owner); } while(0)
  1383. extern int register_filesystem(struct file_system_type *);
  1384. extern int unregister_filesystem(struct file_system_type *);
  1385. extern struct vfsmount *kern_mount_data(struct file_system_type *, void *data);
  1386. #define kern_mount(type) kern_mount_data(type, NULL)
  1387. extern int may_umount_tree(struct vfsmount *);
  1388. extern int may_umount(struct vfsmount *);
  1389. extern long do_mount(char *, char *, char *, unsigned long, void *);
  1390. extern struct vfsmount *collect_mounts(struct vfsmount *, struct dentry *);
  1391. extern void drop_collected_mounts(struct vfsmount *);
  1392. extern int vfs_statfs(struct dentry *, struct kstatfs *);
  1393. /* /sys/fs */
  1394. extern struct kobject *fs_kobj;
  1395. #define FLOCK_VERIFY_READ 1
  1396. #define FLOCK_VERIFY_WRITE 2
  1397. extern int locks_mandatory_locked(struct inode *);
  1398. extern int locks_mandatory_area(int, struct inode *, struct file *, loff_t, size_t);
  1399. /*
  1400. * Candidates for mandatory locking have the setgid bit set
  1401. * but no group execute bit - an otherwise meaningless combination.
  1402. */
  1403. static inline int __mandatory_lock(struct inode *ino)
  1404. {
  1405. return (ino->i_mode & (S_ISGID | S_IXGRP)) == S_ISGID;
  1406. }
  1407. /*
  1408. * ... and these candidates should be on MS_MANDLOCK mounted fs,
  1409. * otherwise these will be advisory locks
  1410. */
  1411. static inline int mandatory_lock(struct inode *ino)
  1412. {
  1413. return IS_MANDLOCK(ino) && __mandatory_lock(ino);
  1414. }
  1415. static inline int locks_verify_locked(struct inode *inode)
  1416. {
  1417. if (mandatory_lock(inode))
  1418. return locks_mandatory_locked(inode);
  1419. return 0;
  1420. }
  1421. extern int rw_verify_area(int, struct file *, loff_t *, size_t);
  1422. static inline int locks_verify_truncate(struct inode *inode,
  1423. struct file *filp,
  1424. loff_t size)
  1425. {
  1426. if (inode->i_flock && mandatory_lock(inode))
  1427. return locks_mandatory_area(
  1428. FLOCK_VERIFY_WRITE, inode, filp,
  1429. size < inode->i_size ? size : inode->i_size,
  1430. (size < inode->i_size ? inode->i_size - size
  1431. : size - inode->i_size)
  1432. );
  1433. return 0;
  1434. }
  1435. static inline int break_lease(struct inode *inode, unsigned int mode)
  1436. {
  1437. if (inode->i_flock)
  1438. return __break_lease(inode, mode);
  1439. return 0;
  1440. }
  1441. /* fs/open.c */
  1442. extern int do_truncate(struct dentry *, loff_t start, unsigned int time_attrs,
  1443. struct file *filp);
  1444. extern long do_sys_open(int dfd, const char __user *filename, int flags,
  1445. int mode);
  1446. extern struct file *filp_open(const char *, int, int);
  1447. extern struct file * dentry_open(struct dentry *, struct vfsmount *, int);
  1448. extern int filp_close(struct file *, fl_owner_t id);
  1449. extern char * getname(const char __user *);
  1450. /* fs/dcache.c */
  1451. extern void __init vfs_caches_init_early(void);
  1452. extern void __init vfs_caches_init(unsigned long);
  1453. extern struct kmem_cache *names_cachep;
  1454. #define __getname() kmem_cache_alloc(names_cachep, GFP_KERNEL)
  1455. #define __putname(name) kmem_cache_free(names_cachep, (void *)(name))
  1456. #ifndef CONFIG_AUDITSYSCALL
  1457. #define putname(name) __putname(name)
  1458. #else
  1459. extern void putname(const char *name);
  1460. #endif
  1461. #ifdef CONFIG_BLOCK
  1462. extern int register_blkdev(unsigned int, const char *);
  1463. extern void unregister_blkdev(unsigned int, const char *);
  1464. extern struct block_device *bdget(dev_t);
  1465. extern void bd_set_size(struct block_device *, loff_t size);
  1466. extern void bd_forget(struct inode *inode);
  1467. extern void bdput(struct block_device *);
  1468. extern struct block_device *open_by_devnum(dev_t, unsigned);
  1469. #else
  1470. static inline void bd_forget(struct inode *inode) {}
  1471. #endif
  1472. extern const struct file_operations def_blk_fops;
  1473. extern const struct file_operations def_chr_fops;
  1474. extern const struct file_operations bad_sock_fops;
  1475. extern const struct file_operations def_fifo_fops;
  1476. #ifdef CONFIG_BLOCK
  1477. extern int ioctl_by_bdev(struct block_device *, unsigned, unsigned long);
  1478. extern int blkdev_ioctl(struct inode *, struct file *, unsigned, unsigned long);
  1479. extern int blkdev_driver_ioctl(struct inode *inode, struct file *file,
  1480. struct gendisk *disk, unsigned cmd,
  1481. unsigned long arg);
  1482. extern long compat_blkdev_ioctl(struct file *, unsigned, unsigned long);
  1483. extern int blkdev_get(struct block_device *, mode_t, unsigned);
  1484. extern int blkdev_put(struct block_device *);
  1485. extern int bd_claim(struct block_device *, void *);
  1486. extern void bd_release(struct block_device *);
  1487. #ifdef CONFIG_SYSFS
  1488. extern int bd_claim_by_disk(struct block_device *, void *, struct gendisk *);
  1489. extern void bd_release_from_disk(struct block_device *, struct gendisk *);
  1490. #else
  1491. #define bd_claim_by_disk(bdev, holder, disk) bd_claim(bdev, holder)
  1492. #define bd_release_from_disk(bdev, disk) bd_release(bdev)
  1493. #endif
  1494. #endif
  1495. /* fs/char_dev.c */
  1496. #define CHRDEV_MAJOR_HASH_SIZE 255
  1497. extern int alloc_chrdev_region(dev_t *, unsigned, unsigned, const char *);
  1498. extern int register_chrdev_region(dev_t, unsigned, const char *);
  1499. extern int register_chrdev(unsigned int, const char *,
  1500. const struct file_operations *);
  1501. extern void unregister_chrdev(unsigned int, const char *);
  1502. extern void unregister_chrdev_region(dev_t, unsigned);
  1503. extern void chrdev_show(struct seq_file *,off_t);
  1504. /* fs/block_dev.c */
  1505. #define BDEVNAME_SIZE 32 /* Largest string for a blockdev identifier */
  1506. #ifdef CONFIG_BLOCK
  1507. #define BLKDEV_MAJOR_HASH_SIZE 255
  1508. extern const char *__bdevname(dev_t, char *buffer);
  1509. extern const char *bdevname(struct block_device *bdev, char *buffer);
  1510. extern struct block_device *lookup_bdev(const char *);
  1511. extern struct block_device *open_bdev_excl(const char *, int, void *);
  1512. extern void close_bdev_excl(struct block_device *);
  1513. extern void blkdev_show(struct seq_file *,off_t);
  1514. #else
  1515. #define BLKDEV_MAJOR_HASH_SIZE 0
  1516. #endif
  1517. extern void init_special_inode(struct inode *, umode_t, dev_t);
  1518. /* Invalid inode operations -- fs/bad_inode.c */
  1519. extern void make_bad_inode(struct inode *);
  1520. extern int is_bad_inode(struct inode *);
  1521. extern const struct file_operations read_pipefifo_fops;
  1522. extern const struct file_operations write_pipefifo_fops;
  1523. extern const struct file_operations rdwr_pipefifo_fops;
  1524. extern int fs_may_remount_ro(struct super_block *);
  1525. #ifdef CONFIG_BLOCK
  1526. /*
  1527. * return READ, READA, or WRITE
  1528. */
  1529. #define bio_rw(bio) ((bio)->bi_rw & (RW_MASK | RWA_MASK))
  1530. /*
  1531. * return data direction, READ or WRITE
  1532. */
  1533. #define bio_data_dir(bio) ((bio)->bi_rw & 1)
  1534. extern int check_disk_change(struct block_device *);
  1535. extern int __invalidate_device(struct block_device *);
  1536. extern int invalidate_partition(struct gendisk *, int);
  1537. #endif
  1538. extern int invalidate_inodes(struct super_block *);
  1539. unsigned long __invalidate_mapping_pages(struct address_space *mapping,
  1540. pgoff_t start, pgoff_t end,
  1541. bool be_atomic);
  1542. unsigned long invalidate_mapping_pages(struct address_space *mapping,
  1543. pgoff_t start, pgoff_t end);
  1544. static inline unsigned long __deprecated
  1545. invalidate_inode_pages(struct address_space *mapping)
  1546. {
  1547. return invalidate_mapping_pages(mapping, 0, ~0UL);
  1548. }
  1549. static inline void invalidate_remote_inode(struct inode *inode)
  1550. {
  1551. if (S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
  1552. S_ISLNK(inode->i_mode))
  1553. invalidate_mapping_pages(inode->i_mapping, 0, -1);
  1554. }
  1555. extern int invalidate_inode_pages2(struct address_space *mapping);
  1556. extern int invalidate_inode_pages2_range(struct address_space *mapping,
  1557. pgoff_t start, pgoff_t end);
  1558. extern void generic_sync_sb_inodes(struct super_block *sb,
  1559. struct writeback_control *wbc);
  1560. extern int write_inode_now(struct inode *, int);
  1561. extern int filemap_fdatawrite(struct address_space *);
  1562. extern int filemap_flush(struct address_space *);
  1563. extern int filemap_fdatawait(struct address_space *);
  1564. extern int filemap_write_and_wait(struct address_space *mapping);
  1565. extern int filemap_write_and_wait_range(struct address_space *mapping,
  1566. loff_t lstart, loff_t lend);
  1567. extern int wait_on_page_writeback_range(struct address_space *mapping,
  1568. pgoff_t start, pgoff_t end);
  1569. extern int __filemap_fdatawrite_range(struct address_space *mapping,
  1570. loff_t start, loff_t end, int sync_mode);
  1571. extern int filemap_fdatawrite_range(struct address_space *mapping,
  1572. loff_t start, loff_t end);
  1573. extern long do_fsync(struct file *file, int datasync);
  1574. extern void sync_supers(void);
  1575. extern void sync_filesystems(int wait);
  1576. extern void __fsync_super(struct super_block *sb);
  1577. extern void emergency_sync(void);
  1578. extern void emergency_remount(void);
  1579. extern int do_remount_sb(struct super_block *sb, int flags,
  1580. void *data, int force);
  1581. #ifdef CONFIG_BLOCK
  1582. extern sector_t bmap(struct inode *, sector_t);
  1583. #endif
  1584. extern int notify_change(struct dentry *, struct iattr *);
  1585. extern int inode_permission(struct inode *, int);
  1586. extern int generic_permission(struct inode *, int,
  1587. int (*check_acl)(struct inode *, int));
  1588. extern int get_write_access(struct inode *);
  1589. extern int deny_write_access(struct file *);
  1590. static inline void put_write_access(struct inode * inode)
  1591. {
  1592. atomic_dec(&inode->i_writecount);
  1593. }
  1594. static inline void allow_write_access(struct file *file)
  1595. {
  1596. if (file)
  1597. atomic_inc(&file->f_path.dentry->d_inode->i_writecount);
  1598. }
  1599. extern int do_pipe(int *);
  1600. extern int do_pipe_flags(int *, int);
  1601. extern struct file *create_read_pipe(struct file *f, int flags);
  1602. extern struct file *create_write_pipe(int flags);
  1603. extern void free_write_pipe(struct file *);
  1604. extern struct file *do_filp_open(int dfd, const char *pathname,
  1605. int open_flag, int mode);
  1606. extern int may_open(struct nameidata *, int, int);
  1607. extern int kernel_read(struct file *, unsigned long, char *, unsigned long);
  1608. extern struct file * open_exec(const char *);
  1609. /* fs/dcache.c -- generic fs support functions */
  1610. extern int is_subdir(struct dentry *, struct dentry *);
  1611. extern ino_t find_inode_number(struct dentry *, struct qstr *);
  1612. #include <linux/err.h>
  1613. /* needed for stackable file system support */
  1614. extern loff_t default_llseek(struct file *file, loff_t offset, int origin);
  1615. extern loff_t vfs_llseek(struct file *file, loff_t offset, int origin);
  1616. extern void inode_init_once(struct inode *);
  1617. extern void iput(struct inode *);
  1618. extern struct inode * igrab(struct inode *);
  1619. extern ino_t iunique(struct super_block *, ino_t);
  1620. extern int inode_needs_sync(struct inode *inode);
  1621. extern void generic_delete_inode(struct inode *inode);
  1622. extern void generic_drop_inode(struct inode *inode);
  1623. extern struct inode *ilookup5_nowait(struct super_block *sb,
  1624. unsigned long hashval, int (*test)(struct inode *, void *),
  1625. void *data);
  1626. extern struct inode *ilookup5(struct super_block *sb, unsigned long hashval,
  1627. int (*test)(struct inode *, void *), void *data);
  1628. extern struct inode *ilookup(struct super_block *sb, unsigned long ino);
  1629. extern struct inode * iget5_locked(struct super_block *, unsigned long, int (*test)(struct inode *, void *), int (*set)(struct inode *, void *), void *);
  1630. extern struct inode * iget_locked(struct super_block *, unsigned long);
  1631. extern void unlock_new_inode(struct inode *);
  1632. extern void __iget(struct inode * inode);
  1633. extern void iget_failed(struct inode *);
  1634. extern void clear_inode(struct inode *);
  1635. extern void destroy_inode(struct inode *);
  1636. extern struct inode *new_inode(struct super_block *);
  1637. extern int should_remove_suid(struct dentry *);
  1638. extern int file_remove_suid(struct file *);
  1639. extern void __insert_inode_hash(struct inode *, unsigned long hashval);
  1640. extern void remove_inode_hash(struct inode *);
  1641. static inline void insert_inode_hash(struct inode *inode) {
  1642. __insert_inode_hash(inode, inode->i_ino);
  1643. }
  1644. extern struct file * get_empty_filp(void);
  1645. extern void file_move(struct file *f, struct list_head *list);
  1646. extern void file_kill(struct file *f);
  1647. #ifdef CONFIG_BLOCK
  1648. struct bio;
  1649. extern void submit_bio(int, struct bio *);
  1650. extern int bdev_read_only(struct block_device *);
  1651. #endif
  1652. extern int set_blocksize(struct block_device *, int);
  1653. extern int sb_set_blocksize(struct super_block *, int);
  1654. extern int sb_min_blocksize(struct super_block *, int);
  1655. extern int sb_has_dirty_inodes(struct super_block *);
  1656. extern int generic_file_mmap(struct file *, struct vm_area_struct *);
  1657. extern int generic_file_readonly_mmap(struct file *, struct vm_area_struct *);
  1658. extern int file_read_actor(read_descriptor_t * desc, struct page *page, unsigned long offset, unsigned long size);
  1659. int generic_write_checks(struct file *file, loff_t *pos, size_t *count, int isblk);
  1660. extern ssize_t generic_file_aio_read(struct kiocb *, const struct iovec *, unsigned long, loff_t);
  1661. extern ssize_t generic_file_aio_write(struct kiocb *, const struct iovec *, unsigned long, loff_t);
  1662. extern ssize_t generic_file_aio_write_nolock(struct kiocb *, const struct iovec *,
  1663. unsigned long, loff_t);
  1664. extern ssize_t generic_file_direct_write(struct kiocb *, const struct iovec *,
  1665. unsigned long *, loff_t, loff_t *, size_t, size_t);
  1666. extern ssize_t generic_file_buffered_write(struct kiocb *, const struct iovec *,
  1667. unsigned long, loff_t, loff_t *, size_t, ssize_t);
  1668. extern ssize_t do_sync_read(struct file *filp, char __user *buf, size_t len, loff_t *ppos);
  1669. extern ssize_t do_sync_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos);
  1670. extern int generic_segment_checks(const struct iovec *iov,
  1671. unsigned long *nr_segs, size_t *count, int access_flags);
  1672. /* fs/splice.c */
  1673. extern ssize_t generic_file_splice_read(struct file *, loff_t *,
  1674. struct pipe_inode_info *, size_t, unsigned int);
  1675. extern ssize_t generic_file_splice_write(struct pipe_inode_info *,
  1676. struct file *, loff_t *, size_t, unsigned int);
  1677. extern ssize_t generic_file_splice_write_nolock(struct pipe_inode_info *,
  1678. struct file *, loff_t *, size_t, unsigned int);
  1679. extern ssize_t generic_splice_sendpage(struct pipe_inode_info *pipe,
  1680. struct file *out, loff_t *, size_t len, unsigned int flags);
  1681. extern long do_splice_direct(struct file *in, loff_t *ppos, struct file *out,
  1682. size_t len, unsigned int flags);
  1683. extern void
  1684. file_ra_state_init(struct file_ra_state *ra, struct address_space *mapping);
  1685. extern loff_t no_llseek(struct file *file, loff_t offset, int origin);
  1686. extern loff_t generic_file_llseek(struct file *file, loff_t offset, int origin);
  1687. extern loff_t generic_file_llseek_unlocked(struct file *file, loff_t offset,
  1688. int origin);
  1689. extern int generic_file_open(struct inode * inode, struct file * filp);
  1690. extern int nonseekable_open(struct inode * inode, struct file * filp);
  1691. #ifdef CONFIG_FS_XIP
  1692. extern ssize_t xip_file_read(struct file *filp, char __user *buf, size_t len,
  1693. loff_t *ppos);
  1694. extern int xip_file_mmap(struct file * file, struct vm_area_struct * vma);
  1695. extern ssize_t xip_file_write(struct file *filp, const char __user *buf,
  1696. size_t len, loff_t *ppos);
  1697. extern int xip_truncate_page(struct address_space *mapping, loff_t from);
  1698. #else
  1699. static inline int xip_truncate_page(struct address_space *mapping, loff_t from)
  1700. {
  1701. return 0;
  1702. }
  1703. #endif
  1704. #ifdef CONFIG_BLOCK
  1705. ssize_t __blockdev_direct_IO(int rw, struct kiocb *iocb, struct inode *inode,
  1706. struct block_device *bdev, const struct iovec *iov, loff_t offset,
  1707. unsigned long nr_segs, get_block_t get_block, dio_iodone_t end_io,
  1708. int lock_type);
  1709. enum {
  1710. DIO_LOCKING = 1, /* need locking between buffered and direct access */
  1711. DIO_NO_LOCKING, /* bdev; no locking at all between buffered/direct */
  1712. DIO_OWN_LOCKING, /* filesystem locks buffered and direct internally */
  1713. };
  1714. static inline ssize_t blockdev_direct_IO(int rw, struct kiocb *iocb,
  1715. struct inode *inode, struct block_device *bdev, const struct iovec *iov,
  1716. loff_t offset, unsigned long nr_segs, get_block_t get_block,
  1717. dio_iodone_t end_io)
  1718. {
  1719. return __blockdev_direct_IO(rw, iocb, inode, bdev, iov, offset,
  1720. nr_segs, get_block, end_io, DIO_LOCKING);
  1721. }
  1722. static inline ssize_t blockdev_direct_IO_no_locking(int rw, struct kiocb *iocb,
  1723. struct inode *inode, struct block_device *bdev, const struct iovec *iov,
  1724. loff_t offset, unsigned long nr_segs, get_block_t get_block,
  1725. dio_iodone_t end_io)
  1726. {
  1727. return __blockdev_direct_IO(rw, iocb, inode, bdev, iov, offset,
  1728. nr_segs, get_block, end_io, DIO_NO_LOCKING);
  1729. }
  1730. static inline ssize_t blockdev_direct_IO_own_locking(int rw, struct kiocb *iocb,
  1731. struct inode *inode, struct block_device *bdev, const struct iovec *iov,
  1732. loff_t offset, unsigned long nr_segs, get_block_t get_block,
  1733. dio_iodone_t end_io)
  1734. {
  1735. return __blockdev_direct_IO(rw, iocb, inode, bdev, iov, offset,
  1736. nr_segs, get_block, end_io, DIO_OWN_LOCKING);
  1737. }
  1738. #endif
  1739. extern const struct file_operations generic_ro_fops;
  1740. #define special_file(m) (S_ISCHR(m)||S_ISBLK(m)||S_ISFIFO(m)||S_ISSOCK(m))
  1741. extern int vfs_readlink(struct dentry *, char __user *, int, const char *);
  1742. extern int vfs_follow_link(struct nameidata *, const char *);
  1743. extern int page_readlink(struct dentry *, char __user *, int);
  1744. extern void *page_follow_link_light(struct dentry *, struct nameidata *);
  1745. extern void page_put_link(struct dentry *, struct nameidata *, void *);
  1746. extern int __page_symlink(struct inode *inode, const char *symname, int len,
  1747. gfp_t gfp_mask);
  1748. extern int page_symlink(struct inode *inode, const char *symname, int len);
  1749. extern const struct inode_operations page_symlink_inode_operations;
  1750. extern int generic_readlink(struct dentry *, char __user *, int);
  1751. extern void generic_fillattr(struct inode *, struct kstat *);
  1752. extern int vfs_getattr(struct vfsmount *, struct dentry *, struct kstat *);
  1753. void inode_add_bytes(struct inode *inode, loff_t bytes);
  1754. void inode_sub_bytes(struct inode *inode, loff_t bytes);
  1755. loff_t inode_get_bytes(struct inode *inode);
  1756. void inode_set_bytes(struct inode *inode, loff_t bytes);
  1757. extern int vfs_readdir(struct file *, filldir_t, void *);
  1758. extern int vfs_stat(char __user *, struct kstat *);
  1759. extern int vfs_lstat(char __user *, struct kstat *);
  1760. extern int vfs_stat_fd(int dfd, char __user *, struct kstat *);
  1761. extern int vfs_lstat_fd(int dfd, char __user *, struct kstat *);
  1762. extern int vfs_fstat(unsigned int, struct kstat *);
  1763. extern int do_vfs_ioctl(struct file *filp, unsigned int fd, unsigned int cmd,
  1764. unsigned long arg);
  1765. extern void get_filesystem(struct file_system_type *fs);
  1766. extern void put_filesystem(struct file_system_type *fs);
  1767. extern struct file_system_type *get_fs_type(const char *name);
  1768. extern struct super_block *get_super(struct block_device *);
  1769. extern struct super_block *user_get_super(dev_t);
  1770. extern void drop_super(struct super_block *sb);
  1771. extern int dcache_dir_open(struct inode *, struct file *);
  1772. extern int dcache_dir_close(struct inode *, struct file *);
  1773. extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
  1774. extern int dcache_readdir(struct file *, void *, filldir_t);
  1775. extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
  1776. extern int simple_statfs(struct dentry *, struct kstatfs *);
  1777. extern int simple_link(struct dentry *, struct inode *, struct dentry *);
  1778. extern int simple_unlink(struct inode *, struct dentry *);
  1779. extern int simple_rmdir(struct inode *, struct dentry *);
  1780. extern int simple_rename(struct inode *, struct dentry *, struct inode *, struct dentry *);
  1781. extern int simple_sync_file(struct file *, struct dentry *, int);
  1782. extern int simple_empty(struct dentry *);
  1783. extern int simple_readpage(struct file *file, struct page *page);
  1784. extern int simple_prepare_write(struct file *file, struct page *page,
  1785. unsigned offset, unsigned to);
  1786. extern int simple_write_begin(struct file *file, struct address_space *mapping,
  1787. loff_t pos, unsigned len, unsigned flags,
  1788. struct page **pagep, void **fsdata);
  1789. extern int simple_write_end(struct file *file, struct address_space *mapping,
  1790. loff_t pos, unsigned len, unsigned copied,
  1791. struct page *page, void *fsdata);
  1792. extern struct dentry *simple_lookup(struct inode *, struct dentry *, struct nameidata *);
  1793. extern ssize_t generic_read_dir(struct file *, char __user *, size_t, loff_t *);
  1794. extern const struct file_operations simple_dir_operations;
  1795. extern const struct inode_operations simple_dir_inode_operations;
  1796. struct tree_descr { char *name; const struct file_operations *ops; int mode; };
  1797. struct dentry *d_alloc_name(struct dentry *, const char *);
  1798. extern int simple_fill_super(struct super_block *, int, struct tree_descr *);
  1799. extern int simple_pin_fs(struct file_system_type *, struct vfsmount **mount, int *count);
  1800. extern void simple_release_fs(struct vfsmount **mount, int *count);
  1801. extern ssize_t simple_read_from_buffer(void __user *to, size_t count,
  1802. loff_t *ppos, const void *from, size_t available);
  1803. #ifdef CONFIG_MIGRATION
  1804. extern int buffer_migrate_page(struct address_space *,
  1805. struct page *, struct page *);
  1806. #else
  1807. #define buffer_migrate_page NULL
  1808. #endif
  1809. extern int inode_change_ok(struct inode *, struct iattr *);
  1810. extern int __must_check inode_setattr(struct inode *, struct iattr *);
  1811. extern void file_update_time(struct file *file);
  1812. extern int generic_show_options(struct seq_file *m, struct vfsmount *mnt);
  1813. extern void save_mount_options(struct super_block *sb, char *options);
  1814. static inline ino_t parent_ino(struct dentry *dentry)
  1815. {
  1816. ino_t res;
  1817. spin_lock(&dentry->d_lock);
  1818. res = dentry->d_parent->d_inode->i_ino;
  1819. spin_unlock(&dentry->d_lock);
  1820. return res;
  1821. }
  1822. /* Transaction based IO helpers */
  1823. /*
  1824. * An argresp is stored in an allocated page and holds the
  1825. * size of the argument or response, along with its content
  1826. */
  1827. struct simple_transaction_argresp {
  1828. ssize_t size;
  1829. char data[0];
  1830. };
  1831. #define SIMPLE_TRANSACTION_LIMIT (PAGE_SIZE - sizeof(struct simple_transaction_argresp))
  1832. char *simple_transaction_get(struct file *file, const char __user *buf,
  1833. size_t size);
  1834. ssize_t simple_transaction_read(struct file *file, char __user *buf,
  1835. size_t size, loff_t *pos);
  1836. int simple_transaction_release(struct inode *inode, struct file *file);
  1837. static inline void simple_transaction_set(struct file *file, size_t n)
  1838. {
  1839. struct simple_transaction_argresp *ar = file->private_data;
  1840. BUG_ON(n > SIMPLE_TRANSACTION_LIMIT);
  1841. /*
  1842. * The barrier ensures that ar->size will really remain zero until
  1843. * ar->data is ready for reading.
  1844. */
  1845. smp_mb();
  1846. ar->size = n;
  1847. }
  1848. /*
  1849. * simple attribute files
  1850. *
  1851. * These attributes behave similar to those in sysfs:
  1852. *
  1853. * Writing to an attribute immediately sets a value, an open file can be
  1854. * written to multiple times.
  1855. *
  1856. * Reading from an attribute creates a buffer from the value that might get
  1857. * read with multiple read calls. When the attribute has been read
  1858. * completely, no further read calls are possible until the file is opened
  1859. * again.
  1860. *
  1861. * All attributes contain a text representation of a numeric value
  1862. * that are accessed with the get() and set() functions.
  1863. */
  1864. #define DEFINE_SIMPLE_ATTRIBUTE(__fops, __get, __set, __fmt) \
  1865. static int __fops ## _open(struct inode *inode, struct file *file) \
  1866. { \
  1867. __simple_attr_check_format(__fmt, 0ull); \
  1868. return simple_attr_open(inode, file, __get, __set, __fmt); \
  1869. } \
  1870. static struct file_operations __fops = { \
  1871. .owner = THIS_MODULE, \
  1872. .open = __fops ## _open, \
  1873. .release = simple_attr_release, \
  1874. .read = simple_attr_read, \
  1875. .write = simple_attr_write, \
  1876. };
  1877. static inline void __attribute__((format(printf, 1, 2)))
  1878. __simple_attr_check_format(const char *fmt, ...)
  1879. {
  1880. /* don't do anything, just let the compiler check the arguments; */
  1881. }
  1882. int simple_attr_open(struct inode *inode, struct file *file,
  1883. int (*get)(void *, u64 *), int (*set)(void *, u64),
  1884. const char *fmt);
  1885. int simple_attr_release(struct inode *inode, struct file *file);
  1886. ssize_t simple_attr_read(struct file *file, char __user *buf,
  1887. size_t len, loff_t *ppos);
  1888. ssize_t simple_attr_write(struct file *file, const char __user *buf,
  1889. size_t len, loff_t *ppos);
  1890. #ifdef CONFIG_SECURITY
  1891. static inline char *alloc_secdata(void)
  1892. {
  1893. return (char *)get_zeroed_page(GFP_KERNEL);
  1894. }
  1895. static inline void free_secdata(void *secdata)
  1896. {
  1897. free_page((unsigned long)secdata);
  1898. }
  1899. #else
  1900. static inline char *alloc_secdata(void)
  1901. {
  1902. return (char *)1;
  1903. }
  1904. static inline void free_secdata(void *secdata)
  1905. { }
  1906. #endif /* CONFIG_SECURITY */
  1907. struct ctl_table;
  1908. int proc_nr_files(struct ctl_table *table, int write, struct file *filp,
  1909. void __user *buffer, size_t *lenp, loff_t *ppos);
  1910. int get_filesystem_list(char * buf);
  1911. #endif /* __KERNEL__ */
  1912. #endif /* _LINUX_FS_H */