fs.h 76 KB

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