fs.h 91 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743
  1. #ifndef _LINUX_FS_H
  2. #define _LINUX_FS_H
  3. #include <linux/linkage.h>
  4. #include <linux/wait.h>
  5. #include <linux/kdev_t.h>
  6. #include <linux/dcache.h>
  7. #include <linux/path.h>
  8. #include <linux/stat.h>
  9. #include <linux/cache.h>
  10. #include <linux/list.h>
  11. #include <linux/llist.h>
  12. #include <linux/radix-tree.h>
  13. #include <linux/rbtree.h>
  14. #include <linux/init.h>
  15. #include <linux/pid.h>
  16. #include <linux/bug.h>
  17. #include <linux/mutex.h>
  18. #include <linux/capability.h>
  19. #include <linux/semaphore.h>
  20. #include <linux/fiemap.h>
  21. #include <linux/rculist_bl.h>
  22. #include <linux/atomic.h>
  23. #include <linux/shrinker.h>
  24. #include <linux/migrate_mode.h>
  25. #include <linux/uidgid.h>
  26. #include <linux/lockdep.h>
  27. #include <linux/percpu-rwsem.h>
  28. #include <linux/blk_types.h>
  29. #include <asm/byteorder.h>
  30. #include <uapi/linux/fs.h>
  31. struct export_operations;
  32. struct hd_geometry;
  33. struct iovec;
  34. struct nameidata;
  35. struct kiocb;
  36. struct kobject;
  37. struct pipe_inode_info;
  38. struct poll_table_struct;
  39. struct kstatfs;
  40. struct vm_area_struct;
  41. struct vfsmount;
  42. struct cred;
  43. struct swap_info_struct;
  44. struct seq_file;
  45. extern void __init inode_init(void);
  46. extern void __init inode_init_early(void);
  47. extern void __init files_init(unsigned long);
  48. extern struct files_stat_struct files_stat;
  49. extern unsigned long get_max_files(void);
  50. extern int sysctl_nr_open;
  51. extern struct inodes_stat_t inodes_stat;
  52. extern int leases_enable, lease_break_time;
  53. extern int sysctl_protected_symlinks;
  54. extern int sysctl_protected_hardlinks;
  55. struct buffer_head;
  56. typedef int (get_block_t)(struct inode *inode, sector_t iblock,
  57. struct buffer_head *bh_result, int create);
  58. typedef void (dio_iodone_t)(struct kiocb *iocb, loff_t offset,
  59. ssize_t bytes, void *private, int ret,
  60. bool is_async);
  61. #define MAY_EXEC 0x00000001
  62. #define MAY_WRITE 0x00000002
  63. #define MAY_READ 0x00000004
  64. #define MAY_APPEND 0x00000008
  65. #define MAY_ACCESS 0x00000010
  66. #define MAY_OPEN 0x00000020
  67. #define MAY_CHDIR 0x00000040
  68. /* called from RCU mode, don't block */
  69. #define MAY_NOT_BLOCK 0x00000080
  70. /*
  71. * flags in file.f_mode. Note that FMODE_READ and FMODE_WRITE must correspond
  72. * to O_WRONLY and O_RDWR via the strange trick in __dentry_open()
  73. */
  74. /* file is open for reading */
  75. #define FMODE_READ ((__force fmode_t)0x1)
  76. /* file is open for writing */
  77. #define FMODE_WRITE ((__force fmode_t)0x2)
  78. /* file is seekable */
  79. #define FMODE_LSEEK ((__force fmode_t)0x4)
  80. /* file can be accessed using pread */
  81. #define FMODE_PREAD ((__force fmode_t)0x8)
  82. /* file can be accessed using pwrite */
  83. #define FMODE_PWRITE ((__force fmode_t)0x10)
  84. /* File is opened for execution with sys_execve / sys_uselib */
  85. #define FMODE_EXEC ((__force fmode_t)0x20)
  86. /* File is opened with O_NDELAY (only set for block devices) */
  87. #define FMODE_NDELAY ((__force fmode_t)0x40)
  88. /* File is opened with O_EXCL (only set for block devices) */
  89. #define FMODE_EXCL ((__force fmode_t)0x80)
  90. /* File is opened using open(.., 3, ..) and is writeable only for ioctls
  91. (specialy hack for floppy.c) */
  92. #define FMODE_WRITE_IOCTL ((__force fmode_t)0x100)
  93. /* 32bit hashes as llseek() offset (for directories) */
  94. #define FMODE_32BITHASH ((__force fmode_t)0x200)
  95. /* 64bit hashes as llseek() offset (for directories) */
  96. #define FMODE_64BITHASH ((__force fmode_t)0x400)
  97. /*
  98. * Don't update ctime and mtime.
  99. *
  100. * Currently a special hack for the XFS open_by_handle ioctl, but we'll
  101. * hopefully graduate it to a proper O_CMTIME flag supported by open(2) soon.
  102. */
  103. #define FMODE_NOCMTIME ((__force fmode_t)0x800)
  104. /* Expect random access pattern */
  105. #define FMODE_RANDOM ((__force fmode_t)0x1000)
  106. /* File is huge (eg. /dev/kmem): treat loff_t as unsigned */
  107. #define FMODE_UNSIGNED_OFFSET ((__force fmode_t)0x2000)
  108. /* File is opened with O_PATH; almost nothing can be done with it */
  109. #define FMODE_PATH ((__force fmode_t)0x4000)
  110. /* File was opened by fanotify and shouldn't generate fanotify events */
  111. #define FMODE_NONOTIFY ((__force fmode_t)0x1000000)
  112. /*
  113. * Flag for rw_copy_check_uvector and compat_rw_copy_check_uvector
  114. * that indicates that they should check the contents of the iovec are
  115. * valid, but not check the memory that the iovec elements
  116. * points too.
  117. */
  118. #define CHECK_IOVEC_ONLY -1
  119. /*
  120. * The below are the various read and write types that we support. Some of
  121. * them include behavioral modifiers that send information down to the
  122. * block layer and IO scheduler. Terminology:
  123. *
  124. * The block layer uses device plugging to defer IO a little bit, in
  125. * the hope that we will see more IO very shortly. This increases
  126. * coalescing of adjacent IO and thus reduces the number of IOs we
  127. * have to send to the device. It also allows for better queuing,
  128. * if the IO isn't mergeable. If the caller is going to be waiting
  129. * for the IO, then he must ensure that the device is unplugged so
  130. * that the IO is dispatched to the driver.
  131. *
  132. * All IO is handled async in Linux. This is fine for background
  133. * writes, but for reads or writes that someone waits for completion
  134. * on, we want to notify the block layer and IO scheduler so that they
  135. * know about it. That allows them to make better scheduling
  136. * decisions. So when the below references 'sync' and 'async', it
  137. * is referencing this priority hint.
  138. *
  139. * With that in mind, the available types are:
  140. *
  141. * READ A normal read operation. Device will be plugged.
  142. * READ_SYNC A synchronous read. Device is not plugged, caller can
  143. * immediately wait on this read without caring about
  144. * unplugging.
  145. * READA Used for read-ahead operations. Lower priority, and the
  146. * block layer could (in theory) choose to ignore this
  147. * request if it runs into resource problems.
  148. * WRITE A normal async write. Device will be plugged.
  149. * WRITE_SYNC Synchronous write. Identical to WRITE, but passes down
  150. * the hint that someone will be waiting on this IO
  151. * shortly. The write equivalent of READ_SYNC.
  152. * WRITE_ODIRECT Special case write for O_DIRECT only.
  153. * WRITE_FLUSH Like WRITE_SYNC but with preceding cache flush.
  154. * WRITE_FUA Like WRITE_SYNC but data is guaranteed to be on
  155. * non-volatile media on completion.
  156. * WRITE_FLUSH_FUA Combination of WRITE_FLUSH and FUA. The IO is preceded
  157. * by a cache flush and data is guaranteed to be on
  158. * non-volatile media on completion.
  159. *
  160. */
  161. #define RW_MASK REQ_WRITE
  162. #define RWA_MASK REQ_RAHEAD
  163. #define READ 0
  164. #define WRITE RW_MASK
  165. #define READA RWA_MASK
  166. #define KERNEL_READ (READ|REQ_KERNEL)
  167. #define KERNEL_WRITE (WRITE|REQ_KERNEL)
  168. #define READ_SYNC (READ | REQ_SYNC)
  169. #define WRITE_SYNC (WRITE | REQ_SYNC | REQ_NOIDLE)
  170. #define WRITE_ODIRECT (WRITE | REQ_SYNC)
  171. #define WRITE_FLUSH (WRITE | REQ_SYNC | REQ_NOIDLE | REQ_FLUSH)
  172. #define WRITE_FUA (WRITE | REQ_SYNC | REQ_NOIDLE | REQ_FUA)
  173. #define WRITE_FLUSH_FUA (WRITE | REQ_SYNC | REQ_NOIDLE | REQ_FLUSH | REQ_FUA)
  174. /*
  175. * Attribute flags. These should be or-ed together to figure out what
  176. * has been changed!
  177. */
  178. #define ATTR_MODE (1 << 0)
  179. #define ATTR_UID (1 << 1)
  180. #define ATTR_GID (1 << 2)
  181. #define ATTR_SIZE (1 << 3)
  182. #define ATTR_ATIME (1 << 4)
  183. #define ATTR_MTIME (1 << 5)
  184. #define ATTR_CTIME (1 << 6)
  185. #define ATTR_ATIME_SET (1 << 7)
  186. #define ATTR_MTIME_SET (1 << 8)
  187. #define ATTR_FORCE (1 << 9) /* Not a change, but a change it */
  188. #define ATTR_ATTR_FLAG (1 << 10)
  189. #define ATTR_KILL_SUID (1 << 11)
  190. #define ATTR_KILL_SGID (1 << 12)
  191. #define ATTR_FILE (1 << 13)
  192. #define ATTR_KILL_PRIV (1 << 14)
  193. #define ATTR_OPEN (1 << 15) /* Truncating from open(O_TRUNC) */
  194. #define ATTR_TIMES_SET (1 << 16)
  195. /*
  196. * This is the Inode Attributes structure, used for notify_change(). It
  197. * uses the above definitions as flags, to know which values have changed.
  198. * Also, in this manner, a Filesystem can look at only the values it cares
  199. * about. Basically, these are the attributes that the VFS layer can
  200. * request to change from the FS layer.
  201. *
  202. * Derek Atkins <warlord@MIT.EDU> 94-10-20
  203. */
  204. struct iattr {
  205. unsigned int ia_valid;
  206. umode_t ia_mode;
  207. kuid_t ia_uid;
  208. kgid_t ia_gid;
  209. loff_t ia_size;
  210. struct timespec ia_atime;
  211. struct timespec ia_mtime;
  212. struct timespec ia_ctime;
  213. /*
  214. * Not an attribute, but an auxiliary info for filesystems wanting to
  215. * implement an ftruncate() like method. NOTE: filesystem should
  216. * check for (ia_valid & ATTR_FILE), and not for (ia_file != NULL).
  217. */
  218. struct file *ia_file;
  219. };
  220. /*
  221. * Includes for diskquotas.
  222. */
  223. #include <linux/quota.h>
  224. /**
  225. * enum positive_aop_returns - aop return codes with specific semantics
  226. *
  227. * @AOP_WRITEPAGE_ACTIVATE: Informs the caller that page writeback has
  228. * completed, that the page is still locked, and
  229. * should be considered active. The VM uses this hint
  230. * to return the page to the active list -- it won't
  231. * be a candidate for writeback again in the near
  232. * future. Other callers must be careful to unlock
  233. * the page if they get this return. Returned by
  234. * writepage();
  235. *
  236. * @AOP_TRUNCATED_PAGE: The AOP method that was handed a locked page has
  237. * unlocked it and the page might have been truncated.
  238. * The caller should back up to acquiring a new page and
  239. * trying again. The aop will be taking reasonable
  240. * precautions not to livelock. If the caller held a page
  241. * reference, it should drop it before retrying. Returned
  242. * by readpage().
  243. *
  244. * address_space_operation functions return these large constants to indicate
  245. * special semantics to the caller. These are much larger than the bytes in a
  246. * page to allow for functions that return the number of bytes operated on in a
  247. * given page.
  248. */
  249. enum positive_aop_returns {
  250. AOP_WRITEPAGE_ACTIVATE = 0x80000,
  251. AOP_TRUNCATED_PAGE = 0x80001,
  252. };
  253. #define AOP_FLAG_UNINTERRUPTIBLE 0x0001 /* will not do a short write */
  254. #define AOP_FLAG_CONT_EXPAND 0x0002 /* called from cont_expand */
  255. #define AOP_FLAG_NOFS 0x0004 /* used by filesystem to direct
  256. * helper code (eg buffer layer)
  257. * to clear GFP_FS from alloc */
  258. /*
  259. * oh the beauties of C type declarations.
  260. */
  261. struct page;
  262. struct address_space;
  263. struct writeback_control;
  264. struct iov_iter {
  265. const struct iovec *iov;
  266. unsigned long nr_segs;
  267. size_t iov_offset;
  268. size_t count;
  269. };
  270. size_t iov_iter_copy_from_user_atomic(struct page *page,
  271. struct iov_iter *i, unsigned long offset, size_t bytes);
  272. size_t iov_iter_copy_from_user(struct page *page,
  273. struct iov_iter *i, unsigned long offset, size_t bytes);
  274. void iov_iter_advance(struct iov_iter *i, size_t bytes);
  275. int iov_iter_fault_in_readable(struct iov_iter *i, size_t bytes);
  276. size_t iov_iter_single_seg_count(const struct iov_iter *i);
  277. static inline void iov_iter_init(struct iov_iter *i,
  278. const struct iovec *iov, unsigned long nr_segs,
  279. size_t count, size_t written)
  280. {
  281. i->iov = iov;
  282. i->nr_segs = nr_segs;
  283. i->iov_offset = 0;
  284. i->count = count + written;
  285. iov_iter_advance(i, written);
  286. }
  287. static inline size_t iov_iter_count(struct iov_iter *i)
  288. {
  289. return i->count;
  290. }
  291. /*
  292. * "descriptor" for what we're up to with a read.
  293. * This allows us to use the same read code yet
  294. * have multiple different users of the data that
  295. * we read from a file.
  296. *
  297. * The simplest case just copies the data to user
  298. * mode.
  299. */
  300. typedef struct {
  301. size_t written;
  302. size_t count;
  303. union {
  304. char __user *buf;
  305. void *data;
  306. } arg;
  307. int error;
  308. } read_descriptor_t;
  309. typedef int (*read_actor_t)(read_descriptor_t *, struct page *,
  310. unsigned long, unsigned long);
  311. struct address_space_operations {
  312. int (*writepage)(struct page *page, struct writeback_control *wbc);
  313. int (*readpage)(struct file *, struct page *);
  314. /* Write back some dirty pages from this mapping. */
  315. int (*writepages)(struct address_space *, struct writeback_control *);
  316. /* Set a page dirty. Return true if this dirtied it */
  317. int (*set_page_dirty)(struct page *page);
  318. int (*readpages)(struct file *filp, struct address_space *mapping,
  319. struct list_head *pages, unsigned nr_pages);
  320. int (*write_begin)(struct file *, struct address_space *mapping,
  321. loff_t pos, unsigned len, unsigned flags,
  322. struct page **pagep, void **fsdata);
  323. int (*write_end)(struct file *, struct address_space *mapping,
  324. loff_t pos, unsigned len, unsigned copied,
  325. struct page *page, void *fsdata);
  326. /* Unfortunately this kludge is needed for FIBMAP. Don't use it */
  327. sector_t (*bmap)(struct address_space *, sector_t);
  328. void (*invalidatepage) (struct page *, unsigned int, unsigned int);
  329. int (*releasepage) (struct page *, gfp_t);
  330. void (*freepage)(struct page *);
  331. ssize_t (*direct_IO)(int, struct kiocb *, const struct iovec *iov,
  332. loff_t offset, unsigned long nr_segs);
  333. int (*get_xip_mem)(struct address_space *, pgoff_t, int,
  334. void **, unsigned long *);
  335. /*
  336. * migrate the contents of a page to the specified target. If sync
  337. * is false, it must not block.
  338. */
  339. int (*migratepage) (struct address_space *,
  340. struct page *, struct page *, enum migrate_mode);
  341. int (*launder_page) (struct page *);
  342. int (*is_partially_uptodate) (struct page *, read_descriptor_t *,
  343. unsigned long);
  344. void (*is_dirty_writeback) (struct page *, bool *, bool *);
  345. int (*error_remove_page)(struct address_space *, struct page *);
  346. /* swapfile support */
  347. int (*swap_activate)(struct swap_info_struct *sis, struct file *file,
  348. sector_t *span);
  349. void (*swap_deactivate)(struct file *file);
  350. };
  351. extern const struct address_space_operations empty_aops;
  352. /*
  353. * pagecache_write_begin/pagecache_write_end must be used by general code
  354. * to write into the pagecache.
  355. */
  356. int pagecache_write_begin(struct file *, struct address_space *mapping,
  357. loff_t pos, unsigned len, unsigned flags,
  358. struct page **pagep, void **fsdata);
  359. int pagecache_write_end(struct file *, struct address_space *mapping,
  360. loff_t pos, unsigned len, unsigned copied,
  361. struct page *page, void *fsdata);
  362. struct backing_dev_info;
  363. struct address_space {
  364. struct inode *host; /* owner: inode, block_device */
  365. struct radix_tree_root page_tree; /* radix tree of all pages */
  366. spinlock_t tree_lock; /* and lock protecting it */
  367. unsigned int i_mmap_writable;/* count VM_SHARED mappings */
  368. struct rb_root i_mmap; /* tree of private and shared mappings */
  369. struct list_head i_mmap_nonlinear;/*list VM_NONLINEAR mappings */
  370. struct mutex i_mmap_mutex; /* protect tree, count, list */
  371. /* Protected by tree_lock together with the radix tree */
  372. unsigned long nrpages; /* number of total pages */
  373. pgoff_t writeback_index;/* writeback starts here */
  374. const struct address_space_operations *a_ops; /* methods */
  375. unsigned long flags; /* error bits/gfp mask */
  376. struct backing_dev_info *backing_dev_info; /* device readahead, etc */
  377. spinlock_t private_lock; /* for use by the address_space */
  378. struct list_head private_list; /* ditto */
  379. void *private_data; /* ditto */
  380. } __attribute__((aligned(sizeof(long))));
  381. /*
  382. * On most architectures that alignment is already the case; but
  383. * must be enforced here for CRIS, to let the least significant bit
  384. * of struct page's "mapping" pointer be used for PAGE_MAPPING_ANON.
  385. */
  386. struct request_queue;
  387. struct block_device {
  388. dev_t bd_dev; /* not a kdev_t - it's a search key */
  389. int bd_openers;
  390. struct inode * bd_inode; /* will die */
  391. struct super_block * bd_super;
  392. struct mutex bd_mutex; /* open/close mutex */
  393. struct list_head bd_inodes;
  394. void * bd_claiming;
  395. void * bd_holder;
  396. int bd_holders;
  397. bool bd_write_holder;
  398. #ifdef CONFIG_SYSFS
  399. struct list_head bd_holder_disks;
  400. #endif
  401. struct block_device * bd_contains;
  402. unsigned bd_block_size;
  403. struct hd_struct * bd_part;
  404. /* number of times partitions within this device have been opened. */
  405. unsigned bd_part_count;
  406. int bd_invalidated;
  407. struct gendisk * bd_disk;
  408. struct request_queue * bd_queue;
  409. struct list_head bd_list;
  410. /*
  411. * Private data. You must have bd_claim'ed the block_device
  412. * to use this. NOTE: bd_claim allows an owner to claim
  413. * the same device multiple times, the owner must take special
  414. * care to not mess up bd_private for that case.
  415. */
  416. unsigned long bd_private;
  417. /* The counter of freeze processes */
  418. int bd_fsfreeze_count;
  419. /* Mutex for freeze */
  420. struct mutex bd_fsfreeze_mutex;
  421. };
  422. /*
  423. * Radix-tree tags, for tagging dirty and writeback pages within the pagecache
  424. * radix trees
  425. */
  426. #define PAGECACHE_TAG_DIRTY 0
  427. #define PAGECACHE_TAG_WRITEBACK 1
  428. #define PAGECACHE_TAG_TOWRITE 2
  429. int mapping_tagged(struct address_space *mapping, int tag);
  430. /*
  431. * Might pages of this file be mapped into userspace?
  432. */
  433. static inline int mapping_mapped(struct address_space *mapping)
  434. {
  435. return !RB_EMPTY_ROOT(&mapping->i_mmap) ||
  436. !list_empty(&mapping->i_mmap_nonlinear);
  437. }
  438. /*
  439. * Might pages of this file have been modified in userspace?
  440. * Note that i_mmap_writable counts all VM_SHARED vmas: do_mmap_pgoff
  441. * marks vma as VM_SHARED if it is shared, and the file was opened for
  442. * writing i.e. vma may be mprotected writable even if now readonly.
  443. */
  444. static inline int mapping_writably_mapped(struct address_space *mapping)
  445. {
  446. return mapping->i_mmap_writable != 0;
  447. }
  448. /*
  449. * Use sequence counter to get consistent i_size on 32-bit processors.
  450. */
  451. #if BITS_PER_LONG==32 && defined(CONFIG_SMP)
  452. #include <linux/seqlock.h>
  453. #define __NEED_I_SIZE_ORDERED
  454. #define i_size_ordered_init(inode) seqcount_init(&inode->i_size_seqcount)
  455. #else
  456. #define i_size_ordered_init(inode) do { } while (0)
  457. #endif
  458. struct posix_acl;
  459. #define ACL_NOT_CACHED ((void *)(-1))
  460. #define IOP_FASTPERM 0x0001
  461. #define IOP_LOOKUP 0x0002
  462. #define IOP_NOFOLLOW 0x0004
  463. /*
  464. * Keep mostly read-only and often accessed (especially for
  465. * the RCU path lookup and 'stat' data) fields at the beginning
  466. * of the 'struct inode'
  467. */
  468. struct inode {
  469. umode_t i_mode;
  470. unsigned short i_opflags;
  471. kuid_t i_uid;
  472. kgid_t i_gid;
  473. unsigned int i_flags;
  474. #ifdef CONFIG_FS_POSIX_ACL
  475. struct posix_acl *i_acl;
  476. struct posix_acl *i_default_acl;
  477. #endif
  478. const struct inode_operations *i_op;
  479. struct super_block *i_sb;
  480. struct address_space *i_mapping;
  481. #ifdef CONFIG_SECURITY
  482. void *i_security;
  483. #endif
  484. /* Stat data, not accessed from path walking */
  485. unsigned long i_ino;
  486. /*
  487. * Filesystems may only read i_nlink directly. They shall use the
  488. * following functions for modification:
  489. *
  490. * (set|clear|inc|drop)_nlink
  491. * inode_(inc|dec)_link_count
  492. */
  493. union {
  494. const unsigned int i_nlink;
  495. unsigned int __i_nlink;
  496. };
  497. dev_t i_rdev;
  498. loff_t i_size;
  499. struct timespec i_atime;
  500. struct timespec i_mtime;
  501. struct timespec i_ctime;
  502. spinlock_t i_lock; /* i_blocks, i_bytes, maybe i_size */
  503. unsigned short i_bytes;
  504. unsigned int i_blkbits;
  505. blkcnt_t i_blocks;
  506. #ifdef __NEED_I_SIZE_ORDERED
  507. seqcount_t i_size_seqcount;
  508. #endif
  509. /* Misc */
  510. unsigned long i_state;
  511. struct mutex i_mutex;
  512. unsigned long dirtied_when; /* jiffies of first dirtying */
  513. struct hlist_node i_hash;
  514. struct list_head i_wb_list; /* backing dev IO list */
  515. struct list_head i_lru; /* inode LRU list */
  516. struct list_head i_sb_list;
  517. union {
  518. struct hlist_head i_dentry;
  519. struct rcu_head i_rcu;
  520. };
  521. u64 i_version;
  522. atomic_t i_count;
  523. atomic_t i_dio_count;
  524. atomic_t i_writecount;
  525. const struct file_operations *i_fop; /* former ->i_op->default_file_ops */
  526. struct file_lock *i_flock;
  527. struct address_space i_data;
  528. #ifdef CONFIG_QUOTA
  529. struct dquot *i_dquot[MAXQUOTAS];
  530. #endif
  531. struct list_head i_devices;
  532. union {
  533. struct pipe_inode_info *i_pipe;
  534. struct block_device *i_bdev;
  535. struct cdev *i_cdev;
  536. };
  537. __u32 i_generation;
  538. #ifdef CONFIG_FSNOTIFY
  539. __u32 i_fsnotify_mask; /* all events this inode cares about */
  540. struct hlist_head i_fsnotify_marks;
  541. #endif
  542. #ifdef CONFIG_IMA
  543. atomic_t i_readcount; /* struct files open RO */
  544. #endif
  545. void *i_private; /* fs or device private pointer */
  546. };
  547. static inline int inode_unhashed(struct inode *inode)
  548. {
  549. return hlist_unhashed(&inode->i_hash);
  550. }
  551. /*
  552. * inode->i_mutex nesting subclasses for the lock validator:
  553. *
  554. * 0: the object of the current VFS operation
  555. * 1: parent
  556. * 2: child/target
  557. * 3: quota file
  558. *
  559. * The locking order between these classes is
  560. * parent -> child -> normal -> xattr -> quota
  561. */
  562. enum inode_i_mutex_lock_class
  563. {
  564. I_MUTEX_NORMAL,
  565. I_MUTEX_PARENT,
  566. I_MUTEX_CHILD,
  567. I_MUTEX_XATTR,
  568. I_MUTEX_QUOTA
  569. };
  570. /*
  571. * NOTE: in a 32bit arch with a preemptable kernel and
  572. * an UP compile the i_size_read/write must be atomic
  573. * with respect to the local cpu (unlike with preempt disabled),
  574. * but they don't need to be atomic with respect to other cpus like in
  575. * true SMP (so they need either to either locally disable irq around
  576. * the read or for example on x86 they can be still implemented as a
  577. * cmpxchg8b without the need of the lock prefix). For SMP compiles
  578. * and 64bit archs it makes no difference if preempt is enabled or not.
  579. */
  580. static inline loff_t i_size_read(const struct inode *inode)
  581. {
  582. #if BITS_PER_LONG==32 && defined(CONFIG_SMP)
  583. loff_t i_size;
  584. unsigned int seq;
  585. do {
  586. seq = read_seqcount_begin(&inode->i_size_seqcount);
  587. i_size = inode->i_size;
  588. } while (read_seqcount_retry(&inode->i_size_seqcount, seq));
  589. return i_size;
  590. #elif BITS_PER_LONG==32 && defined(CONFIG_PREEMPT)
  591. loff_t i_size;
  592. preempt_disable();
  593. i_size = inode->i_size;
  594. preempt_enable();
  595. return i_size;
  596. #else
  597. return inode->i_size;
  598. #endif
  599. }
  600. /*
  601. * NOTE: unlike i_size_read(), i_size_write() does need locking around it
  602. * (normally i_mutex), otherwise on 32bit/SMP an update of i_size_seqcount
  603. * can be lost, resulting in subsequent i_size_read() calls spinning forever.
  604. */
  605. static inline void i_size_write(struct inode *inode, loff_t i_size)
  606. {
  607. #if BITS_PER_LONG==32 && defined(CONFIG_SMP)
  608. preempt_disable();
  609. write_seqcount_begin(&inode->i_size_seqcount);
  610. inode->i_size = i_size;
  611. write_seqcount_end(&inode->i_size_seqcount);
  612. preempt_enable();
  613. #elif BITS_PER_LONG==32 && defined(CONFIG_PREEMPT)
  614. preempt_disable();
  615. inode->i_size = i_size;
  616. preempt_enable();
  617. #else
  618. inode->i_size = i_size;
  619. #endif
  620. }
  621. /* Helper functions so that in most cases filesystems will
  622. * not need to deal directly with kuid_t and kgid_t and can
  623. * instead deal with the raw numeric values that are stored
  624. * in the filesystem.
  625. */
  626. static inline uid_t i_uid_read(const struct inode *inode)
  627. {
  628. return from_kuid(&init_user_ns, inode->i_uid);
  629. }
  630. static inline gid_t i_gid_read(const struct inode *inode)
  631. {
  632. return from_kgid(&init_user_ns, inode->i_gid);
  633. }
  634. static inline void i_uid_write(struct inode *inode, uid_t uid)
  635. {
  636. inode->i_uid = make_kuid(&init_user_ns, uid);
  637. }
  638. static inline void i_gid_write(struct inode *inode, gid_t gid)
  639. {
  640. inode->i_gid = make_kgid(&init_user_ns, gid);
  641. }
  642. static inline unsigned iminor(const struct inode *inode)
  643. {
  644. return MINOR(inode->i_rdev);
  645. }
  646. static inline unsigned imajor(const struct inode *inode)
  647. {
  648. return MAJOR(inode->i_rdev);
  649. }
  650. extern struct block_device *I_BDEV(struct inode *inode);
  651. struct fown_struct {
  652. rwlock_t lock; /* protects pid, uid, euid fields */
  653. struct pid *pid; /* pid or -pgrp where SIGIO should be sent */
  654. enum pid_type pid_type; /* Kind of process group SIGIO should be sent to */
  655. kuid_t uid, euid; /* uid/euid of process setting the owner */
  656. int signum; /* posix.1b rt signal to be delivered on IO */
  657. };
  658. /*
  659. * Track a single file's readahead state
  660. */
  661. struct file_ra_state {
  662. pgoff_t start; /* where readahead started */
  663. unsigned int size; /* # of readahead pages */
  664. unsigned int async_size; /* do asynchronous readahead when
  665. there are only # of pages ahead */
  666. unsigned int ra_pages; /* Maximum readahead window */
  667. unsigned int mmap_miss; /* Cache miss stat for mmap accesses */
  668. loff_t prev_pos; /* Cache last read() position */
  669. };
  670. /*
  671. * Check if @index falls in the readahead windows.
  672. */
  673. static inline int ra_has_index(struct file_ra_state *ra, pgoff_t index)
  674. {
  675. return (index >= ra->start &&
  676. index < ra->start + ra->size);
  677. }
  678. #define FILE_MNT_WRITE_TAKEN 1
  679. #define FILE_MNT_WRITE_RELEASED 2
  680. struct file {
  681. /*
  682. * fu_list becomes invalid after file_free is called and queued via
  683. * fu_rcuhead for RCU freeing
  684. */
  685. union {
  686. struct list_head fu_list;
  687. struct llist_node fu_llist;
  688. struct rcu_head fu_rcuhead;
  689. } f_u;
  690. struct path f_path;
  691. #define f_dentry f_path.dentry
  692. struct inode *f_inode; /* cached value */
  693. const struct file_operations *f_op;
  694. /*
  695. * Protects f_ep_links, f_flags, f_pos vs i_size in lseek SEEK_CUR.
  696. * Must not be taken from IRQ context.
  697. */
  698. spinlock_t f_lock;
  699. #ifdef CONFIG_SMP
  700. int f_sb_list_cpu;
  701. #endif
  702. atomic_long_t f_count;
  703. unsigned int f_flags;
  704. fmode_t f_mode;
  705. loff_t f_pos;
  706. struct fown_struct f_owner;
  707. const struct cred *f_cred;
  708. struct file_ra_state f_ra;
  709. u64 f_version;
  710. #ifdef CONFIG_SECURITY
  711. void *f_security;
  712. #endif
  713. /* needed for tty driver, and maybe others */
  714. void *private_data;
  715. #ifdef CONFIG_EPOLL
  716. /* Used by fs/eventpoll.c to link all the hooks to this file */
  717. struct list_head f_ep_links;
  718. struct list_head f_tfile_llink;
  719. #endif /* #ifdef CONFIG_EPOLL */
  720. struct address_space *f_mapping;
  721. #ifdef CONFIG_DEBUG_WRITECOUNT
  722. unsigned long f_mnt_write_state;
  723. #endif
  724. };
  725. struct file_handle {
  726. __u32 handle_bytes;
  727. int handle_type;
  728. /* file identifier */
  729. unsigned char f_handle[0];
  730. };
  731. static inline struct file *get_file(struct file *f)
  732. {
  733. atomic_long_inc(&f->f_count);
  734. return f;
  735. }
  736. #define fput_atomic(x) atomic_long_add_unless(&(x)->f_count, -1, 1)
  737. #define file_count(x) atomic_long_read(&(x)->f_count)
  738. #ifdef CONFIG_DEBUG_WRITECOUNT
  739. static inline void file_take_write(struct file *f)
  740. {
  741. WARN_ON(f->f_mnt_write_state != 0);
  742. f->f_mnt_write_state = FILE_MNT_WRITE_TAKEN;
  743. }
  744. static inline void file_release_write(struct file *f)
  745. {
  746. f->f_mnt_write_state |= FILE_MNT_WRITE_RELEASED;
  747. }
  748. static inline void file_reset_write(struct file *f)
  749. {
  750. f->f_mnt_write_state = 0;
  751. }
  752. static inline void file_check_state(struct file *f)
  753. {
  754. /*
  755. * At this point, either both or neither of these bits
  756. * should be set.
  757. */
  758. WARN_ON(f->f_mnt_write_state == FILE_MNT_WRITE_TAKEN);
  759. WARN_ON(f->f_mnt_write_state == FILE_MNT_WRITE_RELEASED);
  760. }
  761. static inline int file_check_writeable(struct file *f)
  762. {
  763. if (f->f_mnt_write_state == FILE_MNT_WRITE_TAKEN)
  764. return 0;
  765. printk(KERN_WARNING "writeable file with no "
  766. "mnt_want_write()\n");
  767. WARN_ON(1);
  768. return -EINVAL;
  769. }
  770. #else /* !CONFIG_DEBUG_WRITECOUNT */
  771. static inline void file_take_write(struct file *filp) {}
  772. static inline void file_release_write(struct file *filp) {}
  773. static inline void file_reset_write(struct file *filp) {}
  774. static inline void file_check_state(struct file *filp) {}
  775. static inline int file_check_writeable(struct file *filp)
  776. {
  777. return 0;
  778. }
  779. #endif /* CONFIG_DEBUG_WRITECOUNT */
  780. #define MAX_NON_LFS ((1UL<<31) - 1)
  781. /* Page cache limit. The filesystems should put that into their s_maxbytes
  782. limits, otherwise bad things can happen in VM. */
  783. #if BITS_PER_LONG==32
  784. #define MAX_LFS_FILESIZE (((loff_t)PAGE_CACHE_SIZE << (BITS_PER_LONG-1))-1)
  785. #elif BITS_PER_LONG==64
  786. #define MAX_LFS_FILESIZE ((loff_t)0x7fffffffffffffffLL)
  787. #endif
  788. #define FL_POSIX 1
  789. #define FL_FLOCK 2
  790. #define FL_ACCESS 8 /* not trying to lock, just looking */
  791. #define FL_EXISTS 16 /* when unlocking, test for existence */
  792. #define FL_LEASE 32 /* lease held on this file */
  793. #define FL_CLOSE 64 /* unlock on close */
  794. #define FL_SLEEP 128 /* A blocking lock */
  795. #define FL_DOWNGRADE_PENDING 256 /* Lease is being downgraded */
  796. #define FL_UNLOCK_PENDING 512 /* Lease is being broken */
  797. /*
  798. * Special return value from posix_lock_file() and vfs_lock_file() for
  799. * asynchronous locking.
  800. */
  801. #define FILE_LOCK_DEFERRED 1
  802. /*
  803. * The POSIX file lock owner is determined by
  804. * the "struct files_struct" in the thread group
  805. * (or NULL for no owner - BSD locks).
  806. *
  807. * Lockd stuffs a "host" pointer into this.
  808. */
  809. typedef struct files_struct *fl_owner_t;
  810. struct file_lock_operations {
  811. void (*fl_copy_lock)(struct file_lock *, struct file_lock *);
  812. void (*fl_release_private)(struct file_lock *);
  813. };
  814. struct lock_manager_operations {
  815. int (*lm_compare_owner)(struct file_lock *, struct file_lock *);
  816. unsigned long (*lm_owner_key)(struct file_lock *);
  817. void (*lm_notify)(struct file_lock *); /* unblock callback */
  818. int (*lm_grant)(struct file_lock *, struct file_lock *, int);
  819. void (*lm_break)(struct file_lock *);
  820. int (*lm_change)(struct file_lock **, int);
  821. };
  822. struct lock_manager {
  823. struct list_head list;
  824. };
  825. struct net;
  826. void locks_start_grace(struct net *, struct lock_manager *);
  827. void locks_end_grace(struct lock_manager *);
  828. int locks_in_grace(struct net *);
  829. /* that will die - we need it for nfs_lock_info */
  830. #include <linux/nfs_fs_i.h>
  831. /*
  832. * struct file_lock represents a generic "file lock". It's used to represent
  833. * POSIX byte range locks, BSD (flock) locks, and leases. It's important to
  834. * note that the same struct is used to represent both a request for a lock and
  835. * the lock itself, but the same object is never used for both.
  836. *
  837. * FIXME: should we create a separate "struct lock_request" to help distinguish
  838. * these two uses?
  839. *
  840. * The i_flock list is ordered by:
  841. *
  842. * 1) lock type -- FL_LEASEs first, then FL_FLOCK, and finally FL_POSIX
  843. * 2) lock owner
  844. * 3) lock range start
  845. * 4) lock range end
  846. *
  847. * Obviously, the last two criteria only matter for POSIX locks.
  848. */
  849. struct file_lock {
  850. struct file_lock *fl_next; /* singly linked list for this inode */
  851. struct hlist_node fl_link; /* node in global lists */
  852. struct list_head fl_block; /* circular list of blocked processes */
  853. fl_owner_t fl_owner;
  854. unsigned int fl_flags;
  855. unsigned char fl_type;
  856. unsigned int fl_pid;
  857. int fl_link_cpu; /* what cpu's list is this on? */
  858. struct pid *fl_nspid;
  859. wait_queue_head_t fl_wait;
  860. struct file *fl_file;
  861. loff_t fl_start;
  862. loff_t fl_end;
  863. struct fasync_struct * fl_fasync; /* for lease break notifications */
  864. /* for lease breaks: */
  865. unsigned long fl_break_time;
  866. unsigned long fl_downgrade_time;
  867. const struct file_lock_operations *fl_ops; /* Callbacks for filesystems */
  868. const struct lock_manager_operations *fl_lmops; /* Callbacks for lockmanagers */
  869. union {
  870. struct nfs_lock_info nfs_fl;
  871. struct nfs4_lock_info nfs4_fl;
  872. struct {
  873. struct list_head link; /* link in AFS vnode's pending_locks list */
  874. int state; /* state of grant or error if -ve */
  875. } afs;
  876. } fl_u;
  877. };
  878. /* The following constant reflects the upper bound of the file/locking space */
  879. #ifndef OFFSET_MAX
  880. #define INT_LIMIT(x) (~((x)1 << (sizeof(x)*8 - 1)))
  881. #define OFFSET_MAX INT_LIMIT(loff_t)
  882. #define OFFT_OFFSET_MAX INT_LIMIT(off_t)
  883. #endif
  884. #include <linux/fcntl.h>
  885. extern void send_sigio(struct fown_struct *fown, int fd, int band);
  886. #ifdef CONFIG_FILE_LOCKING
  887. extern int fcntl_getlk(struct file *, struct flock __user *);
  888. extern int fcntl_setlk(unsigned int, struct file *, unsigned int,
  889. struct flock __user *);
  890. #if BITS_PER_LONG == 32
  891. extern int fcntl_getlk64(struct file *, struct flock64 __user *);
  892. extern int fcntl_setlk64(unsigned int, struct file *, unsigned int,
  893. struct flock64 __user *);
  894. #endif
  895. extern int fcntl_setlease(unsigned int fd, struct file *filp, long arg);
  896. extern int fcntl_getlease(struct file *filp);
  897. /* fs/locks.c */
  898. void locks_free_lock(struct file_lock *fl);
  899. extern void locks_init_lock(struct file_lock *);
  900. extern struct file_lock * locks_alloc_lock(void);
  901. extern void locks_copy_lock(struct file_lock *, struct file_lock *);
  902. extern void __locks_copy_lock(struct file_lock *, const struct file_lock *);
  903. extern void locks_remove_posix(struct file *, fl_owner_t);
  904. extern void locks_remove_flock(struct file *);
  905. extern void locks_release_private(struct file_lock *);
  906. extern void posix_test_lock(struct file *, struct file_lock *);
  907. extern int posix_lock_file(struct file *, struct file_lock *, struct file_lock *);
  908. extern int posix_lock_file_wait(struct file *, struct file_lock *);
  909. extern int posix_unblock_lock(struct file_lock *);
  910. extern int vfs_test_lock(struct file *, struct file_lock *);
  911. extern int vfs_lock_file(struct file *, unsigned int, struct file_lock *, struct file_lock *);
  912. extern int vfs_cancel_lock(struct file *filp, struct file_lock *fl);
  913. extern int flock_lock_file_wait(struct file *filp, struct file_lock *fl);
  914. extern int __break_lease(struct inode *inode, unsigned int flags);
  915. extern void lease_get_mtime(struct inode *, struct timespec *time);
  916. extern int generic_setlease(struct file *, long, struct file_lock **);
  917. extern int vfs_setlease(struct file *, long, struct file_lock **);
  918. extern int lease_modify(struct file_lock **, int);
  919. extern int lock_may_read(struct inode *, loff_t start, unsigned long count);
  920. extern int lock_may_write(struct inode *, loff_t start, unsigned long count);
  921. #else /* !CONFIG_FILE_LOCKING */
  922. static inline int fcntl_getlk(struct file *file, struct flock __user *user)
  923. {
  924. return -EINVAL;
  925. }
  926. static inline int fcntl_setlk(unsigned int fd, struct file *file,
  927. unsigned int cmd, struct flock __user *user)
  928. {
  929. return -EACCES;
  930. }
  931. #if BITS_PER_LONG == 32
  932. static inline int fcntl_getlk64(struct file *file, struct flock64 __user *user)
  933. {
  934. return -EINVAL;
  935. }
  936. static inline int fcntl_setlk64(unsigned int fd, struct file *file,
  937. unsigned int cmd, struct flock64 __user *user)
  938. {
  939. return -EACCES;
  940. }
  941. #endif
  942. static inline int fcntl_setlease(unsigned int fd, struct file *filp, long arg)
  943. {
  944. return 0;
  945. }
  946. static inline int fcntl_getlease(struct file *filp)
  947. {
  948. return 0;
  949. }
  950. static inline void locks_init_lock(struct file_lock *fl)
  951. {
  952. return;
  953. }
  954. static inline void __locks_copy_lock(struct file_lock *new, struct file_lock *fl)
  955. {
  956. return;
  957. }
  958. static inline void locks_copy_lock(struct file_lock *new, struct file_lock *fl)
  959. {
  960. return;
  961. }
  962. static inline void locks_remove_posix(struct file *filp, fl_owner_t owner)
  963. {
  964. return;
  965. }
  966. static inline void locks_remove_flock(struct file *filp)
  967. {
  968. return;
  969. }
  970. static inline void posix_test_lock(struct file *filp, struct file_lock *fl)
  971. {
  972. return;
  973. }
  974. static inline int posix_lock_file(struct file *filp, struct file_lock *fl,
  975. struct file_lock *conflock)
  976. {
  977. return -ENOLCK;
  978. }
  979. static inline int posix_lock_file_wait(struct file *filp, struct file_lock *fl)
  980. {
  981. return -ENOLCK;
  982. }
  983. static inline int posix_unblock_lock(struct file_lock *waiter)
  984. {
  985. return -ENOENT;
  986. }
  987. static inline int vfs_test_lock(struct file *filp, struct file_lock *fl)
  988. {
  989. return 0;
  990. }
  991. static inline int vfs_lock_file(struct file *filp, unsigned int cmd,
  992. struct file_lock *fl, struct file_lock *conf)
  993. {
  994. return -ENOLCK;
  995. }
  996. static inline int vfs_cancel_lock(struct file *filp, struct file_lock *fl)
  997. {
  998. return 0;
  999. }
  1000. static inline int flock_lock_file_wait(struct file *filp,
  1001. struct file_lock *request)
  1002. {
  1003. return -ENOLCK;
  1004. }
  1005. static inline int __break_lease(struct inode *inode, unsigned int mode)
  1006. {
  1007. return 0;
  1008. }
  1009. static inline void lease_get_mtime(struct inode *inode, struct timespec *time)
  1010. {
  1011. return;
  1012. }
  1013. static inline int generic_setlease(struct file *filp, long arg,
  1014. struct file_lock **flp)
  1015. {
  1016. return -EINVAL;
  1017. }
  1018. static inline int vfs_setlease(struct file *filp, long arg,
  1019. struct file_lock **lease)
  1020. {
  1021. return -EINVAL;
  1022. }
  1023. static inline int lease_modify(struct file_lock **before, int arg)
  1024. {
  1025. return -EINVAL;
  1026. }
  1027. static inline int lock_may_read(struct inode *inode, loff_t start,
  1028. unsigned long len)
  1029. {
  1030. return 1;
  1031. }
  1032. static inline int lock_may_write(struct inode *inode, loff_t start,
  1033. unsigned long len)
  1034. {
  1035. return 1;
  1036. }
  1037. #endif /* !CONFIG_FILE_LOCKING */
  1038. struct fasync_struct {
  1039. spinlock_t fa_lock;
  1040. int magic;
  1041. int fa_fd;
  1042. struct fasync_struct *fa_next; /* singly linked list */
  1043. struct file *fa_file;
  1044. struct rcu_head fa_rcu;
  1045. };
  1046. #define FASYNC_MAGIC 0x4601
  1047. /* SMP safe fasync helpers: */
  1048. extern int fasync_helper(int, struct file *, int, struct fasync_struct **);
  1049. extern struct fasync_struct *fasync_insert_entry(int, struct file *, struct fasync_struct **, struct fasync_struct *);
  1050. extern int fasync_remove_entry(struct file *, struct fasync_struct **);
  1051. extern struct fasync_struct *fasync_alloc(void);
  1052. extern void fasync_free(struct fasync_struct *);
  1053. /* can be called from interrupts */
  1054. extern void kill_fasync(struct fasync_struct **, int, int);
  1055. extern int __f_setown(struct file *filp, struct pid *, enum pid_type, int force);
  1056. extern int f_setown(struct file *filp, unsigned long arg, int force);
  1057. extern void f_delown(struct file *filp);
  1058. extern pid_t f_getown(struct file *filp);
  1059. extern int send_sigurg(struct fown_struct *fown);
  1060. struct mm_struct;
  1061. /*
  1062. * Umount options
  1063. */
  1064. #define MNT_FORCE 0x00000001 /* Attempt to forcibily umount */
  1065. #define MNT_DETACH 0x00000002 /* Just detach from the tree */
  1066. #define MNT_EXPIRE 0x00000004 /* Mark for expiry */
  1067. #define UMOUNT_NOFOLLOW 0x00000008 /* Don't follow symlink on umount */
  1068. #define UMOUNT_UNUSED 0x80000000 /* Flag guaranteed to be unused */
  1069. extern struct list_head super_blocks;
  1070. extern spinlock_t sb_lock;
  1071. /* Possible states of 'frozen' field */
  1072. enum {
  1073. SB_UNFROZEN = 0, /* FS is unfrozen */
  1074. SB_FREEZE_WRITE = 1, /* Writes, dir ops, ioctls frozen */
  1075. SB_FREEZE_PAGEFAULT = 2, /* Page faults stopped as well */
  1076. SB_FREEZE_FS = 3, /* For internal FS use (e.g. to stop
  1077. * internal threads if needed) */
  1078. SB_FREEZE_COMPLETE = 4, /* ->freeze_fs finished successfully */
  1079. };
  1080. #define SB_FREEZE_LEVELS (SB_FREEZE_COMPLETE - 1)
  1081. struct sb_writers {
  1082. /* Counters for counting writers at each level */
  1083. struct percpu_counter counter[SB_FREEZE_LEVELS];
  1084. wait_queue_head_t wait; /* queue for waiting for
  1085. writers / faults to finish */
  1086. int frozen; /* Is sb frozen? */
  1087. wait_queue_head_t wait_unfrozen; /* queue for waiting for
  1088. sb to be thawed */
  1089. #ifdef CONFIG_DEBUG_LOCK_ALLOC
  1090. struct lockdep_map lock_map[SB_FREEZE_LEVELS];
  1091. #endif
  1092. };
  1093. struct super_block {
  1094. struct list_head s_list; /* Keep this first */
  1095. dev_t s_dev; /* search index; _not_ kdev_t */
  1096. unsigned char s_blocksize_bits;
  1097. unsigned long s_blocksize;
  1098. loff_t s_maxbytes; /* Max file size */
  1099. struct file_system_type *s_type;
  1100. const struct super_operations *s_op;
  1101. const struct dquot_operations *dq_op;
  1102. const struct quotactl_ops *s_qcop;
  1103. const struct export_operations *s_export_op;
  1104. unsigned long s_flags;
  1105. unsigned long s_magic;
  1106. struct dentry *s_root;
  1107. struct rw_semaphore s_umount;
  1108. int s_count;
  1109. atomic_t s_active;
  1110. #ifdef CONFIG_SECURITY
  1111. void *s_security;
  1112. #endif
  1113. const struct xattr_handler **s_xattr;
  1114. struct list_head s_inodes; /* all inodes */
  1115. struct hlist_bl_head s_anon; /* anonymous dentries for (nfs) exporting */
  1116. #ifdef CONFIG_SMP
  1117. struct list_head __percpu *s_files;
  1118. #else
  1119. struct list_head s_files;
  1120. #endif
  1121. struct list_head s_mounts; /* list of mounts; _not_ for fs use */
  1122. /* s_dentry_lru, s_nr_dentry_unused protected by dcache.c lru locks */
  1123. struct list_head s_dentry_lru; /* unused dentry lru */
  1124. int s_nr_dentry_unused; /* # of dentry on lru */
  1125. /* s_inode_lru_lock protects s_inode_lru and s_nr_inodes_unused */
  1126. spinlock_t s_inode_lru_lock ____cacheline_aligned_in_smp;
  1127. struct list_head s_inode_lru; /* unused inode lru */
  1128. int s_nr_inodes_unused; /* # of inodes on lru */
  1129. struct block_device *s_bdev;
  1130. struct backing_dev_info *s_bdi;
  1131. struct mtd_info *s_mtd;
  1132. struct hlist_node s_instances;
  1133. struct quota_info s_dquot; /* Diskquota specific options */
  1134. struct sb_writers s_writers;
  1135. char s_id[32]; /* Informational name */
  1136. u8 s_uuid[16]; /* UUID */
  1137. void *s_fs_info; /* Filesystem private info */
  1138. unsigned int s_max_links;
  1139. fmode_t s_mode;
  1140. /* Granularity of c/m/atime in ns.
  1141. Cannot be worse than a second */
  1142. u32 s_time_gran;
  1143. /*
  1144. * The next field is for VFS *only*. No filesystems have any business
  1145. * even looking at it. You had been warned.
  1146. */
  1147. struct mutex s_vfs_rename_mutex; /* Kludge */
  1148. /*
  1149. * Filesystem subtype. If non-empty the filesystem type field
  1150. * in /proc/mounts will be "type.subtype"
  1151. */
  1152. char *s_subtype;
  1153. /*
  1154. * Saved mount options for lazy filesystems using
  1155. * generic_show_options()
  1156. */
  1157. char __rcu *s_options;
  1158. const struct dentry_operations *s_d_op; /* default d_op for dentries */
  1159. /*
  1160. * Saved pool identifier for cleancache (-1 means none)
  1161. */
  1162. int cleancache_poolid;
  1163. struct shrinker s_shrink; /* per-sb shrinker handle */
  1164. /* Number of inodes with nlink == 0 but still referenced */
  1165. atomic_long_t s_remove_count;
  1166. /* Being remounted read-only */
  1167. int s_readonly_remount;
  1168. };
  1169. /* superblock cache pruning functions */
  1170. extern void prune_icache_sb(struct super_block *sb, int nr_to_scan);
  1171. extern void prune_dcache_sb(struct super_block *sb, int nr_to_scan);
  1172. extern struct timespec current_fs_time(struct super_block *sb);
  1173. /*
  1174. * Snapshotting support.
  1175. */
  1176. void __sb_end_write(struct super_block *sb, int level);
  1177. int __sb_start_write(struct super_block *sb, int level, bool wait);
  1178. /**
  1179. * sb_end_write - drop write access to a superblock
  1180. * @sb: the super we wrote to
  1181. *
  1182. * Decrement number of writers to the filesystem. Wake up possible waiters
  1183. * wanting to freeze the filesystem.
  1184. */
  1185. static inline void sb_end_write(struct super_block *sb)
  1186. {
  1187. __sb_end_write(sb, SB_FREEZE_WRITE);
  1188. }
  1189. /**
  1190. * sb_end_pagefault - drop write access to a superblock from a page fault
  1191. * @sb: the super we wrote to
  1192. *
  1193. * Decrement number of processes handling write page fault to the filesystem.
  1194. * Wake up possible waiters wanting to freeze the filesystem.
  1195. */
  1196. static inline void sb_end_pagefault(struct super_block *sb)
  1197. {
  1198. __sb_end_write(sb, SB_FREEZE_PAGEFAULT);
  1199. }
  1200. /**
  1201. * sb_end_intwrite - drop write access to a superblock for internal fs purposes
  1202. * @sb: the super we wrote to
  1203. *
  1204. * Decrement fs-internal number of writers to the filesystem. Wake up possible
  1205. * waiters wanting to freeze the filesystem.
  1206. */
  1207. static inline void sb_end_intwrite(struct super_block *sb)
  1208. {
  1209. __sb_end_write(sb, SB_FREEZE_FS);
  1210. }
  1211. /**
  1212. * sb_start_write - get write access to a superblock
  1213. * @sb: the super we write to
  1214. *
  1215. * When a process wants to write data or metadata to a file system (i.e. dirty
  1216. * a page or an inode), it should embed the operation in a sb_start_write() -
  1217. * sb_end_write() pair to get exclusion against file system freezing. This
  1218. * function increments number of writers preventing freezing. If the file
  1219. * system is already frozen, the function waits until the file system is
  1220. * thawed.
  1221. *
  1222. * Since freeze protection behaves as a lock, users have to preserve
  1223. * ordering of freeze protection and other filesystem locks. Generally,
  1224. * freeze protection should be the outermost lock. In particular, we have:
  1225. *
  1226. * sb_start_write
  1227. * -> i_mutex (write path, truncate, directory ops, ...)
  1228. * -> s_umount (freeze_super, thaw_super)
  1229. */
  1230. static inline void sb_start_write(struct super_block *sb)
  1231. {
  1232. __sb_start_write(sb, SB_FREEZE_WRITE, true);
  1233. }
  1234. static inline int sb_start_write_trylock(struct super_block *sb)
  1235. {
  1236. return __sb_start_write(sb, SB_FREEZE_WRITE, false);
  1237. }
  1238. /**
  1239. * sb_start_pagefault - get write access to a superblock from a page fault
  1240. * @sb: the super we write to
  1241. *
  1242. * When a process starts handling write page fault, it should embed the
  1243. * operation into sb_start_pagefault() - sb_end_pagefault() pair to get
  1244. * exclusion against file system freezing. This is needed since the page fault
  1245. * is going to dirty a page. This function increments number of running page
  1246. * faults preventing freezing. If the file system is already frozen, the
  1247. * function waits until the file system is thawed.
  1248. *
  1249. * Since page fault freeze protection behaves as a lock, users have to preserve
  1250. * ordering of freeze protection and other filesystem locks. It is advised to
  1251. * put sb_start_pagefault() close to mmap_sem in lock ordering. Page fault
  1252. * handling code implies lock dependency:
  1253. *
  1254. * mmap_sem
  1255. * -> sb_start_pagefault
  1256. */
  1257. static inline void sb_start_pagefault(struct super_block *sb)
  1258. {
  1259. __sb_start_write(sb, SB_FREEZE_PAGEFAULT, true);
  1260. }
  1261. /*
  1262. * sb_start_intwrite - get write access to a superblock for internal fs purposes
  1263. * @sb: the super we write to
  1264. *
  1265. * This is the third level of protection against filesystem freezing. It is
  1266. * free for use by a filesystem. The only requirement is that it must rank
  1267. * below sb_start_pagefault.
  1268. *
  1269. * For example filesystem can call sb_start_intwrite() when starting a
  1270. * transaction which somewhat eases handling of freezing for internal sources
  1271. * of filesystem changes (internal fs threads, discarding preallocation on file
  1272. * close, etc.).
  1273. */
  1274. static inline void sb_start_intwrite(struct super_block *sb)
  1275. {
  1276. __sb_start_write(sb, SB_FREEZE_FS, true);
  1277. }
  1278. extern bool inode_owner_or_capable(const struct inode *inode);
  1279. /*
  1280. * VFS helper functions..
  1281. */
  1282. extern int vfs_create(struct inode *, struct dentry *, umode_t, bool);
  1283. extern int vfs_mkdir(struct inode *, struct dentry *, umode_t);
  1284. extern int vfs_mknod(struct inode *, struct dentry *, umode_t, dev_t);
  1285. extern int vfs_symlink(struct inode *, struct dentry *, const char *);
  1286. extern int vfs_link(struct dentry *, struct inode *, struct dentry *);
  1287. extern int vfs_rmdir(struct inode *, struct dentry *);
  1288. extern int vfs_unlink(struct inode *, struct dentry *);
  1289. extern int vfs_rename(struct inode *, struct dentry *, struct inode *, struct dentry *);
  1290. /*
  1291. * VFS dentry helper functions.
  1292. */
  1293. extern void dentry_unhash(struct dentry *dentry);
  1294. /*
  1295. * VFS file helper functions.
  1296. */
  1297. extern void inode_init_owner(struct inode *inode, const struct inode *dir,
  1298. umode_t mode);
  1299. /*
  1300. * VFS FS_IOC_FIEMAP helper definitions.
  1301. */
  1302. struct fiemap_extent_info {
  1303. unsigned int fi_flags; /* Flags as passed from user */
  1304. unsigned int fi_extents_mapped; /* Number of mapped extents */
  1305. unsigned int fi_extents_max; /* Size of fiemap_extent array */
  1306. struct fiemap_extent __user *fi_extents_start; /* Start of
  1307. fiemap_extent array */
  1308. };
  1309. int fiemap_fill_next_extent(struct fiemap_extent_info *info, u64 logical,
  1310. u64 phys, u64 len, u32 flags);
  1311. int fiemap_check_flags(struct fiemap_extent_info *fieinfo, u32 fs_flags);
  1312. /*
  1313. * File types
  1314. *
  1315. * NOTE! These match bits 12..15 of stat.st_mode
  1316. * (ie "(i_mode >> 12) & 15").
  1317. */
  1318. #define DT_UNKNOWN 0
  1319. #define DT_FIFO 1
  1320. #define DT_CHR 2
  1321. #define DT_DIR 4
  1322. #define DT_BLK 6
  1323. #define DT_REG 8
  1324. #define DT_LNK 10
  1325. #define DT_SOCK 12
  1326. #define DT_WHT 14
  1327. /*
  1328. * This is the "filldir" function type, used by readdir() to let
  1329. * the kernel specify what kind of dirent layout it wants to have.
  1330. * This allows the kernel to read directories into kernel space or
  1331. * to have different dirent layouts depending on the binary type.
  1332. */
  1333. typedef int (*filldir_t)(void *, const char *, int, loff_t, u64, unsigned);
  1334. struct dir_context {
  1335. const filldir_t actor;
  1336. loff_t pos;
  1337. };
  1338. struct block_device_operations;
  1339. /* These macros are for out of kernel modules to test that
  1340. * the kernel supports the unlocked_ioctl and compat_ioctl
  1341. * fields in struct file_operations. */
  1342. #define HAVE_COMPAT_IOCTL 1
  1343. #define HAVE_UNLOCKED_IOCTL 1
  1344. struct file_operations {
  1345. struct module *owner;
  1346. loff_t (*llseek) (struct file *, loff_t, int);
  1347. ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
  1348. ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);
  1349. ssize_t (*aio_read) (struct kiocb *, const struct iovec *, unsigned long, loff_t);
  1350. ssize_t (*aio_write) (struct kiocb *, const struct iovec *, unsigned long, loff_t);
  1351. int (*iterate) (struct file *, struct dir_context *);
  1352. unsigned int (*poll) (struct file *, struct poll_table_struct *);
  1353. long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long);
  1354. long (*compat_ioctl) (struct file *, unsigned int, unsigned long);
  1355. int (*mmap) (struct file *, struct vm_area_struct *);
  1356. int (*open) (struct inode *, struct file *);
  1357. int (*flush) (struct file *, fl_owner_t id);
  1358. int (*release) (struct inode *, struct file *);
  1359. int (*fsync) (struct file *, loff_t, loff_t, int datasync);
  1360. int (*aio_fsync) (struct kiocb *, int datasync);
  1361. int (*fasync) (int, struct file *, int);
  1362. int (*lock) (struct file *, int, struct file_lock *);
  1363. ssize_t (*sendpage) (struct file *, struct page *, int, size_t, loff_t *, int);
  1364. unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
  1365. int (*check_flags)(int);
  1366. int (*flock) (struct file *, int, struct file_lock *);
  1367. ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int);
  1368. ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int);
  1369. int (*setlease)(struct file *, long, struct file_lock **);
  1370. long (*fallocate)(struct file *file, int mode, loff_t offset,
  1371. loff_t len);
  1372. int (*show_fdinfo)(struct seq_file *m, struct file *f);
  1373. };
  1374. struct inode_operations {
  1375. struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
  1376. void * (*follow_link) (struct dentry *, struct nameidata *);
  1377. int (*permission) (struct inode *, int);
  1378. struct posix_acl * (*get_acl)(struct inode *, int);
  1379. int (*readlink) (struct dentry *, char __user *,int);
  1380. void (*put_link) (struct dentry *, struct nameidata *, void *);
  1381. int (*create) (struct inode *,struct dentry *, umode_t, bool);
  1382. int (*link) (struct dentry *,struct inode *,struct dentry *);
  1383. int (*unlink) (struct inode *,struct dentry *);
  1384. int (*symlink) (struct inode *,struct dentry *,const char *);
  1385. int (*mkdir) (struct inode *,struct dentry *,umode_t);
  1386. int (*rmdir) (struct inode *,struct dentry *);
  1387. int (*mknod) (struct inode *,struct dentry *,umode_t,dev_t);
  1388. int (*rename) (struct inode *, struct dentry *,
  1389. struct inode *, struct dentry *);
  1390. int (*setattr) (struct dentry *, struct iattr *);
  1391. int (*getattr) (struct vfsmount *mnt, struct dentry *, struct kstat *);
  1392. int (*setxattr) (struct dentry *, const char *,const void *,size_t,int);
  1393. ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
  1394. ssize_t (*listxattr) (struct dentry *, char *, size_t);
  1395. int (*removexattr) (struct dentry *, const char *);
  1396. int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start,
  1397. u64 len);
  1398. int (*update_time)(struct inode *, struct timespec *, int);
  1399. int (*atomic_open)(struct inode *, struct dentry *,
  1400. struct file *, unsigned open_flag,
  1401. umode_t create_mode, int *opened);
  1402. int (*tmpfile) (struct inode *, struct dentry *, umode_t);
  1403. } ____cacheline_aligned;
  1404. ssize_t rw_copy_check_uvector(int type, const struct iovec __user * uvector,
  1405. unsigned long nr_segs, unsigned long fast_segs,
  1406. struct iovec *fast_pointer,
  1407. struct iovec **ret_pointer);
  1408. extern ssize_t vfs_read(struct file *, char __user *, size_t, loff_t *);
  1409. extern ssize_t vfs_write(struct file *, const char __user *, size_t, loff_t *);
  1410. extern ssize_t vfs_readv(struct file *, const struct iovec __user *,
  1411. unsigned long, loff_t *);
  1412. extern ssize_t vfs_writev(struct file *, const struct iovec __user *,
  1413. unsigned long, loff_t *);
  1414. struct super_operations {
  1415. struct inode *(*alloc_inode)(struct super_block *sb);
  1416. void (*destroy_inode)(struct inode *);
  1417. void (*dirty_inode) (struct inode *, int flags);
  1418. int (*write_inode) (struct inode *, struct writeback_control *wbc);
  1419. int (*drop_inode) (struct inode *);
  1420. void (*evict_inode) (struct inode *);
  1421. void (*put_super) (struct super_block *);
  1422. int (*sync_fs)(struct super_block *sb, int wait);
  1423. int (*freeze_fs) (struct super_block *);
  1424. int (*unfreeze_fs) (struct super_block *);
  1425. int (*statfs) (struct dentry *, struct kstatfs *);
  1426. int (*remount_fs) (struct super_block *, int *, char *);
  1427. void (*umount_begin) (struct super_block *);
  1428. int (*show_options)(struct seq_file *, struct dentry *);
  1429. int (*show_devname)(struct seq_file *, struct dentry *);
  1430. int (*show_path)(struct seq_file *, struct dentry *);
  1431. int (*show_stats)(struct seq_file *, struct dentry *);
  1432. #ifdef CONFIG_QUOTA
  1433. ssize_t (*quota_read)(struct super_block *, int, char *, size_t, loff_t);
  1434. ssize_t (*quota_write)(struct super_block *, int, const char *, size_t, loff_t);
  1435. #endif
  1436. int (*bdev_try_to_free_page)(struct super_block*, struct page*, gfp_t);
  1437. int (*nr_cached_objects)(struct super_block *);
  1438. void (*free_cached_objects)(struct super_block *, int);
  1439. };
  1440. /*
  1441. * Inode flags - they have no relation to superblock flags now
  1442. */
  1443. #define S_SYNC 1 /* Writes are synced at once */
  1444. #define S_NOATIME 2 /* Do not update access times */
  1445. #define S_APPEND 4 /* Append-only file */
  1446. #define S_IMMUTABLE 8 /* Immutable file */
  1447. #define S_DEAD 16 /* removed, but still open directory */
  1448. #define S_NOQUOTA 32 /* Inode is not counted to quota */
  1449. #define S_DIRSYNC 64 /* Directory modifications are synchronous */
  1450. #define S_NOCMTIME 128 /* Do not update file c/mtime */
  1451. #define S_SWAPFILE 256 /* Do not truncate: swapon got its bmaps */
  1452. #define S_PRIVATE 512 /* Inode is fs-internal */
  1453. #define S_IMA 1024 /* Inode has an associated IMA struct */
  1454. #define S_AUTOMOUNT 2048 /* Automount/referral quasi-directory */
  1455. #define S_NOSEC 4096 /* no suid or xattr security attributes */
  1456. /*
  1457. * Note that nosuid etc flags are inode-specific: setting some file-system
  1458. * flags just means all the inodes inherit those flags by default. It might be
  1459. * possible to override it selectively if you really wanted to with some
  1460. * ioctl() that is not currently implemented.
  1461. *
  1462. * Exception: MS_RDONLY is always applied to the entire file system.
  1463. *
  1464. * Unfortunately, it is possible to change a filesystems flags with it mounted
  1465. * with files in use. This means that all of the inodes will not have their
  1466. * i_flags updated. Hence, i_flags no longer inherit the superblock mount
  1467. * flags, so these have to be checked separately. -- rmk@arm.uk.linux.org
  1468. */
  1469. #define __IS_FLG(inode, flg) ((inode)->i_sb->s_flags & (flg))
  1470. #define IS_RDONLY(inode) ((inode)->i_sb->s_flags & MS_RDONLY)
  1471. #define IS_SYNC(inode) (__IS_FLG(inode, MS_SYNCHRONOUS) || \
  1472. ((inode)->i_flags & S_SYNC))
  1473. #define IS_DIRSYNC(inode) (__IS_FLG(inode, MS_SYNCHRONOUS|MS_DIRSYNC) || \
  1474. ((inode)->i_flags & (S_SYNC|S_DIRSYNC)))
  1475. #define IS_MANDLOCK(inode) __IS_FLG(inode, MS_MANDLOCK)
  1476. #define IS_NOATIME(inode) __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
  1477. #define IS_I_VERSION(inode) __IS_FLG(inode, MS_I_VERSION)
  1478. #define IS_NOQUOTA(inode) ((inode)->i_flags & S_NOQUOTA)
  1479. #define IS_APPEND(inode) ((inode)->i_flags & S_APPEND)
  1480. #define IS_IMMUTABLE(inode) ((inode)->i_flags & S_IMMUTABLE)
  1481. #define IS_POSIXACL(inode) __IS_FLG(inode, MS_POSIXACL)
  1482. #define IS_DEADDIR(inode) ((inode)->i_flags & S_DEAD)
  1483. #define IS_NOCMTIME(inode) ((inode)->i_flags & S_NOCMTIME)
  1484. #define IS_SWAPFILE(inode) ((inode)->i_flags & S_SWAPFILE)
  1485. #define IS_PRIVATE(inode) ((inode)->i_flags & S_PRIVATE)
  1486. #define IS_IMA(inode) ((inode)->i_flags & S_IMA)
  1487. #define IS_AUTOMOUNT(inode) ((inode)->i_flags & S_AUTOMOUNT)
  1488. #define IS_NOSEC(inode) ((inode)->i_flags & S_NOSEC)
  1489. /*
  1490. * Inode state bits. Protected by inode->i_lock
  1491. *
  1492. * Three bits determine the dirty state of the inode, I_DIRTY_SYNC,
  1493. * I_DIRTY_DATASYNC and I_DIRTY_PAGES.
  1494. *
  1495. * Four bits define the lifetime of an inode. Initially, inodes are I_NEW,
  1496. * until that flag is cleared. I_WILL_FREE, I_FREEING and I_CLEAR are set at
  1497. * various stages of removing an inode.
  1498. *
  1499. * Two bits are used for locking and completion notification, I_NEW and I_SYNC.
  1500. *
  1501. * I_DIRTY_SYNC Inode is dirty, but doesn't have to be written on
  1502. * fdatasync(). i_atime is the usual cause.
  1503. * I_DIRTY_DATASYNC Data-related inode changes pending. We keep track of
  1504. * these changes separately from I_DIRTY_SYNC so that we
  1505. * don't have to write inode on fdatasync() when only
  1506. * mtime has changed in it.
  1507. * I_DIRTY_PAGES Inode has dirty pages. Inode itself may be clean.
  1508. * I_NEW Serves as both a mutex and completion notification.
  1509. * New inodes set I_NEW. If two processes both create
  1510. * the same inode, one of them will release its inode and
  1511. * wait for I_NEW to be released before returning.
  1512. * Inodes in I_WILL_FREE, I_FREEING or I_CLEAR state can
  1513. * also cause waiting on I_NEW, without I_NEW actually
  1514. * being set. find_inode() uses this to prevent returning
  1515. * nearly-dead inodes.
  1516. * I_WILL_FREE Must be set when calling write_inode_now() if i_count
  1517. * is zero. I_FREEING must be set when I_WILL_FREE is
  1518. * cleared.
  1519. * I_FREEING Set when inode is about to be freed but still has dirty
  1520. * pages or buffers attached or the inode itself is still
  1521. * dirty.
  1522. * I_CLEAR Added by clear_inode(). In this state the inode is
  1523. * clean and can be destroyed. Inode keeps I_FREEING.
  1524. *
  1525. * Inodes that are I_WILL_FREE, I_FREEING or I_CLEAR are
  1526. * prohibited for many purposes. iget() must wait for
  1527. * the inode to be completely released, then create it
  1528. * anew. Other functions will just ignore such inodes,
  1529. * if appropriate. I_NEW is used for waiting.
  1530. *
  1531. * I_SYNC Writeback of inode is running. The bit is set during
  1532. * data writeback, and cleared with a wakeup on the bit
  1533. * address once it is done. The bit is also used to pin
  1534. * the inode in memory for flusher thread.
  1535. *
  1536. * I_REFERENCED Marks the inode as recently references on the LRU list.
  1537. *
  1538. * I_DIO_WAKEUP Never set. Only used as a key for wait_on_bit().
  1539. *
  1540. * Q: What is the difference between I_WILL_FREE and I_FREEING?
  1541. */
  1542. #define I_DIRTY_SYNC (1 << 0)
  1543. #define I_DIRTY_DATASYNC (1 << 1)
  1544. #define I_DIRTY_PAGES (1 << 2)
  1545. #define __I_NEW 3
  1546. #define I_NEW (1 << __I_NEW)
  1547. #define I_WILL_FREE (1 << 4)
  1548. #define I_FREEING (1 << 5)
  1549. #define I_CLEAR (1 << 6)
  1550. #define __I_SYNC 7
  1551. #define I_SYNC (1 << __I_SYNC)
  1552. #define I_REFERENCED (1 << 8)
  1553. #define __I_DIO_WAKEUP 9
  1554. #define I_DIO_WAKEUP (1 << I_DIO_WAKEUP)
  1555. #define I_LINKABLE (1 << 10)
  1556. #define I_DIRTY (I_DIRTY_SYNC | I_DIRTY_DATASYNC | I_DIRTY_PAGES)
  1557. extern void __mark_inode_dirty(struct inode *, int);
  1558. static inline void mark_inode_dirty(struct inode *inode)
  1559. {
  1560. __mark_inode_dirty(inode, I_DIRTY);
  1561. }
  1562. static inline void mark_inode_dirty_sync(struct inode *inode)
  1563. {
  1564. __mark_inode_dirty(inode, I_DIRTY_SYNC);
  1565. }
  1566. extern void inc_nlink(struct inode *inode);
  1567. extern void drop_nlink(struct inode *inode);
  1568. extern void clear_nlink(struct inode *inode);
  1569. extern void set_nlink(struct inode *inode, unsigned int nlink);
  1570. static inline void inode_inc_link_count(struct inode *inode)
  1571. {
  1572. inc_nlink(inode);
  1573. mark_inode_dirty(inode);
  1574. }
  1575. static inline void inode_dec_link_count(struct inode *inode)
  1576. {
  1577. drop_nlink(inode);
  1578. mark_inode_dirty(inode);
  1579. }
  1580. /**
  1581. * inode_inc_iversion - increments i_version
  1582. * @inode: inode that need to be updated
  1583. *
  1584. * Every time the inode is modified, the i_version field will be incremented.
  1585. * The filesystem has to be mounted with i_version flag
  1586. */
  1587. static inline void inode_inc_iversion(struct inode *inode)
  1588. {
  1589. spin_lock(&inode->i_lock);
  1590. inode->i_version++;
  1591. spin_unlock(&inode->i_lock);
  1592. }
  1593. enum file_time_flags {
  1594. S_ATIME = 1,
  1595. S_MTIME = 2,
  1596. S_CTIME = 4,
  1597. S_VERSION = 8,
  1598. };
  1599. extern void touch_atime(struct path *);
  1600. static inline void file_accessed(struct file *file)
  1601. {
  1602. if (!(file->f_flags & O_NOATIME))
  1603. touch_atime(&file->f_path);
  1604. }
  1605. int sync_inode(struct inode *inode, struct writeback_control *wbc);
  1606. int sync_inode_metadata(struct inode *inode, int wait);
  1607. struct file_system_type {
  1608. const char *name;
  1609. int fs_flags;
  1610. #define FS_REQUIRES_DEV 1
  1611. #define FS_BINARY_MOUNTDATA 2
  1612. #define FS_HAS_SUBTYPE 4
  1613. #define FS_USERNS_MOUNT 8 /* Can be mounted by userns root */
  1614. #define FS_USERNS_DEV_MOUNT 16 /* A userns mount does not imply MNT_NODEV */
  1615. #define FS_RENAME_DOES_D_MOVE 32768 /* FS will handle d_move() during rename() internally. */
  1616. struct dentry *(*mount) (struct file_system_type *, int,
  1617. const char *, void *);
  1618. void (*kill_sb) (struct super_block *);
  1619. struct module *owner;
  1620. struct file_system_type * next;
  1621. struct hlist_head fs_supers;
  1622. struct lock_class_key s_lock_key;
  1623. struct lock_class_key s_umount_key;
  1624. struct lock_class_key s_vfs_rename_key;
  1625. struct lock_class_key s_writers_key[SB_FREEZE_LEVELS];
  1626. struct lock_class_key i_lock_key;
  1627. struct lock_class_key i_mutex_key;
  1628. struct lock_class_key i_mutex_dir_key;
  1629. };
  1630. #define MODULE_ALIAS_FS(NAME) MODULE_ALIAS("fs-" NAME)
  1631. extern struct dentry *mount_ns(struct file_system_type *fs_type, int flags,
  1632. void *data, int (*fill_super)(struct super_block *, void *, int));
  1633. extern struct dentry *mount_bdev(struct file_system_type *fs_type,
  1634. int flags, const char *dev_name, void *data,
  1635. int (*fill_super)(struct super_block *, void *, int));
  1636. extern struct dentry *mount_single(struct file_system_type *fs_type,
  1637. int flags, void *data,
  1638. int (*fill_super)(struct super_block *, void *, int));
  1639. extern struct dentry *mount_nodev(struct file_system_type *fs_type,
  1640. int flags, void *data,
  1641. int (*fill_super)(struct super_block *, void *, int));
  1642. extern struct dentry *mount_subtree(struct vfsmount *mnt, const char *path);
  1643. void generic_shutdown_super(struct super_block *sb);
  1644. void kill_block_super(struct super_block *sb);
  1645. void kill_anon_super(struct super_block *sb);
  1646. void kill_litter_super(struct super_block *sb);
  1647. void deactivate_super(struct super_block *sb);
  1648. void deactivate_locked_super(struct super_block *sb);
  1649. int set_anon_super(struct super_block *s, void *data);
  1650. int get_anon_bdev(dev_t *);
  1651. void free_anon_bdev(dev_t);
  1652. struct super_block *sget(struct file_system_type *type,
  1653. int (*test)(struct super_block *,void *),
  1654. int (*set)(struct super_block *,void *),
  1655. int flags, void *data);
  1656. extern struct dentry *mount_pseudo(struct file_system_type *, char *,
  1657. const struct super_operations *ops,
  1658. const struct dentry_operations *dops,
  1659. unsigned long);
  1660. /* Alas, no aliases. Too much hassle with bringing module.h everywhere */
  1661. #define fops_get(fops) \
  1662. (((fops) && try_module_get((fops)->owner) ? (fops) : NULL))
  1663. #define fops_put(fops) \
  1664. do { if (fops) module_put((fops)->owner); } while(0)
  1665. extern int register_filesystem(struct file_system_type *);
  1666. extern int unregister_filesystem(struct file_system_type *);
  1667. extern struct vfsmount *kern_mount_data(struct file_system_type *, void *data);
  1668. #define kern_mount(type) kern_mount_data(type, NULL)
  1669. extern void kern_unmount(struct vfsmount *mnt);
  1670. extern int may_umount_tree(struct vfsmount *);
  1671. extern int may_umount(struct vfsmount *);
  1672. extern long do_mount(const char *, const char *, const char *, unsigned long, void *);
  1673. extern struct vfsmount *collect_mounts(struct path *);
  1674. extern void drop_collected_mounts(struct vfsmount *);
  1675. extern int iterate_mounts(int (*)(struct vfsmount *, void *), void *,
  1676. struct vfsmount *);
  1677. extern int vfs_statfs(struct path *, struct kstatfs *);
  1678. extern int user_statfs(const char __user *, struct kstatfs *);
  1679. extern int fd_statfs(int, struct kstatfs *);
  1680. extern int vfs_ustat(dev_t, struct kstatfs *);
  1681. extern int freeze_super(struct super_block *super);
  1682. extern int thaw_super(struct super_block *super);
  1683. extern bool our_mnt(struct vfsmount *mnt);
  1684. extern int current_umask(void);
  1685. /* /sys/fs */
  1686. extern struct kobject *fs_kobj;
  1687. #define MAX_RW_COUNT (INT_MAX & PAGE_CACHE_MASK)
  1688. #define FLOCK_VERIFY_READ 1
  1689. #define FLOCK_VERIFY_WRITE 2
  1690. #ifdef CONFIG_FILE_LOCKING
  1691. extern int locks_mandatory_locked(struct inode *);
  1692. extern int locks_mandatory_area(int, struct inode *, struct file *, loff_t, size_t);
  1693. /*
  1694. * Candidates for mandatory locking have the setgid bit set
  1695. * but no group execute bit - an otherwise meaningless combination.
  1696. */
  1697. static inline int __mandatory_lock(struct inode *ino)
  1698. {
  1699. return (ino->i_mode & (S_ISGID | S_IXGRP)) == S_ISGID;
  1700. }
  1701. /*
  1702. * ... and these candidates should be on MS_MANDLOCK mounted fs,
  1703. * otherwise these will be advisory locks
  1704. */
  1705. static inline int mandatory_lock(struct inode *ino)
  1706. {
  1707. return IS_MANDLOCK(ino) && __mandatory_lock(ino);
  1708. }
  1709. static inline int locks_verify_locked(struct inode *inode)
  1710. {
  1711. if (mandatory_lock(inode))
  1712. return locks_mandatory_locked(inode);
  1713. return 0;
  1714. }
  1715. static inline int locks_verify_truncate(struct inode *inode,
  1716. struct file *filp,
  1717. loff_t size)
  1718. {
  1719. if (inode->i_flock && mandatory_lock(inode))
  1720. return locks_mandatory_area(
  1721. FLOCK_VERIFY_WRITE, inode, filp,
  1722. size < inode->i_size ? size : inode->i_size,
  1723. (size < inode->i_size ? inode->i_size - size
  1724. : size - inode->i_size)
  1725. );
  1726. return 0;
  1727. }
  1728. static inline int break_lease(struct inode *inode, unsigned int mode)
  1729. {
  1730. if (inode->i_flock)
  1731. return __break_lease(inode, mode);
  1732. return 0;
  1733. }
  1734. #else /* !CONFIG_FILE_LOCKING */
  1735. static inline int locks_mandatory_locked(struct inode *inode)
  1736. {
  1737. return 0;
  1738. }
  1739. static inline int locks_mandatory_area(int rw, struct inode *inode,
  1740. struct file *filp, loff_t offset,
  1741. size_t count)
  1742. {
  1743. return 0;
  1744. }
  1745. static inline int __mandatory_lock(struct inode *inode)
  1746. {
  1747. return 0;
  1748. }
  1749. static inline int mandatory_lock(struct inode *inode)
  1750. {
  1751. return 0;
  1752. }
  1753. static inline int locks_verify_locked(struct inode *inode)
  1754. {
  1755. return 0;
  1756. }
  1757. static inline int locks_verify_truncate(struct inode *inode, struct file *filp,
  1758. size_t size)
  1759. {
  1760. return 0;
  1761. }
  1762. static inline int break_lease(struct inode *inode, unsigned int mode)
  1763. {
  1764. return 0;
  1765. }
  1766. #endif /* CONFIG_FILE_LOCKING */
  1767. /* fs/open.c */
  1768. struct audit_names;
  1769. struct filename {
  1770. const char *name; /* pointer to actual string */
  1771. const __user char *uptr; /* original userland pointer */
  1772. struct audit_names *aname;
  1773. bool separate; /* should "name" be freed? */
  1774. };
  1775. extern long vfs_truncate(struct path *, loff_t);
  1776. extern int do_truncate(struct dentry *, loff_t start, unsigned int time_attrs,
  1777. struct file *filp);
  1778. extern int do_fallocate(struct file *file, int mode, loff_t offset,
  1779. loff_t len);
  1780. extern long do_sys_open(int dfd, const char __user *filename, int flags,
  1781. umode_t mode);
  1782. extern struct file *file_open_name(struct filename *, int, umode_t);
  1783. extern struct file *filp_open(const char *, int, umode_t);
  1784. extern struct file *file_open_root(struct dentry *, struct vfsmount *,
  1785. const char *, int);
  1786. extern struct file * dentry_open(const struct path *, int, const struct cred *);
  1787. extern int filp_close(struct file *, fl_owner_t id);
  1788. extern struct filename *getname(const char __user *);
  1789. enum {
  1790. FILE_CREATED = 1,
  1791. FILE_OPENED = 2
  1792. };
  1793. extern int finish_open(struct file *file, struct dentry *dentry,
  1794. int (*open)(struct inode *, struct file *),
  1795. int *opened);
  1796. extern int finish_no_open(struct file *file, struct dentry *dentry);
  1797. /* fs/ioctl.c */
  1798. extern int ioctl_preallocate(struct file *filp, void __user *argp);
  1799. /* fs/dcache.c */
  1800. extern void __init vfs_caches_init_early(void);
  1801. extern void __init vfs_caches_init(unsigned long);
  1802. extern struct kmem_cache *names_cachep;
  1803. extern void final_putname(struct filename *name);
  1804. #define __getname() kmem_cache_alloc(names_cachep, GFP_KERNEL)
  1805. #define __putname(name) kmem_cache_free(names_cachep, (void *)(name))
  1806. #ifndef CONFIG_AUDITSYSCALL
  1807. #define putname(name) final_putname(name)
  1808. #else
  1809. extern void putname(struct filename *name);
  1810. #endif
  1811. #ifdef CONFIG_BLOCK
  1812. extern int register_blkdev(unsigned int, const char *);
  1813. extern void unregister_blkdev(unsigned int, const char *);
  1814. extern struct block_device *bdget(dev_t);
  1815. extern struct block_device *bdgrab(struct block_device *bdev);
  1816. extern void bd_set_size(struct block_device *, loff_t size);
  1817. extern void bd_forget(struct inode *inode);
  1818. extern void bdput(struct block_device *);
  1819. extern void invalidate_bdev(struct block_device *);
  1820. extern void iterate_bdevs(void (*)(struct block_device *, void *), void *);
  1821. extern int sync_blockdev(struct block_device *bdev);
  1822. extern void kill_bdev(struct block_device *);
  1823. extern struct super_block *freeze_bdev(struct block_device *);
  1824. extern void emergency_thaw_all(void);
  1825. extern int thaw_bdev(struct block_device *bdev, struct super_block *sb);
  1826. extern int fsync_bdev(struct block_device *);
  1827. #else
  1828. static inline void bd_forget(struct inode *inode) {}
  1829. static inline int sync_blockdev(struct block_device *bdev) { return 0; }
  1830. static inline void kill_bdev(struct block_device *bdev) {}
  1831. static inline void invalidate_bdev(struct block_device *bdev) {}
  1832. static inline struct super_block *freeze_bdev(struct block_device *sb)
  1833. {
  1834. return NULL;
  1835. }
  1836. static inline int thaw_bdev(struct block_device *bdev, struct super_block *sb)
  1837. {
  1838. return 0;
  1839. }
  1840. static inline void iterate_bdevs(void (*f)(struct block_device *, void *), void *arg)
  1841. {
  1842. }
  1843. #endif
  1844. extern int sync_filesystem(struct super_block *);
  1845. extern const struct file_operations def_blk_fops;
  1846. extern const struct file_operations def_chr_fops;
  1847. extern const struct file_operations bad_sock_fops;
  1848. #ifdef CONFIG_BLOCK
  1849. extern int ioctl_by_bdev(struct block_device *, unsigned, unsigned long);
  1850. extern int blkdev_ioctl(struct block_device *, fmode_t, unsigned, unsigned long);
  1851. extern long compat_blkdev_ioctl(struct file *, unsigned, unsigned long);
  1852. extern int blkdev_get(struct block_device *bdev, fmode_t mode, void *holder);
  1853. extern struct block_device *blkdev_get_by_path(const char *path, fmode_t mode,
  1854. void *holder);
  1855. extern struct block_device *blkdev_get_by_dev(dev_t dev, fmode_t mode,
  1856. void *holder);
  1857. extern void blkdev_put(struct block_device *bdev, fmode_t mode);
  1858. #ifdef CONFIG_SYSFS
  1859. extern int bd_link_disk_holder(struct block_device *bdev, struct gendisk *disk);
  1860. extern void bd_unlink_disk_holder(struct block_device *bdev,
  1861. struct gendisk *disk);
  1862. #else
  1863. static inline int bd_link_disk_holder(struct block_device *bdev,
  1864. struct gendisk *disk)
  1865. {
  1866. return 0;
  1867. }
  1868. static inline void bd_unlink_disk_holder(struct block_device *bdev,
  1869. struct gendisk *disk)
  1870. {
  1871. }
  1872. #endif
  1873. #endif
  1874. /* fs/char_dev.c */
  1875. #define CHRDEV_MAJOR_HASH_SIZE 255
  1876. extern int alloc_chrdev_region(dev_t *, unsigned, unsigned, const char *);
  1877. extern int register_chrdev_region(dev_t, unsigned, const char *);
  1878. extern int __register_chrdev(unsigned int major, unsigned int baseminor,
  1879. unsigned int count, const char *name,
  1880. const struct file_operations *fops);
  1881. extern void __unregister_chrdev(unsigned int major, unsigned int baseminor,
  1882. unsigned int count, const char *name);
  1883. extern void unregister_chrdev_region(dev_t, unsigned);
  1884. extern void chrdev_show(struct seq_file *,off_t);
  1885. static inline int register_chrdev(unsigned int major, const char *name,
  1886. const struct file_operations *fops)
  1887. {
  1888. return __register_chrdev(major, 0, 256, name, fops);
  1889. }
  1890. static inline void unregister_chrdev(unsigned int major, const char *name)
  1891. {
  1892. __unregister_chrdev(major, 0, 256, name);
  1893. }
  1894. /* fs/block_dev.c */
  1895. #define BDEVNAME_SIZE 32 /* Largest string for a blockdev identifier */
  1896. #define BDEVT_SIZE 10 /* Largest string for MAJ:MIN for blkdev */
  1897. #ifdef CONFIG_BLOCK
  1898. #define BLKDEV_MAJOR_HASH_SIZE 255
  1899. extern const char *__bdevname(dev_t, char *buffer);
  1900. extern const char *bdevname(struct block_device *bdev, char *buffer);
  1901. extern struct block_device *lookup_bdev(const char *);
  1902. extern void blkdev_show(struct seq_file *,off_t);
  1903. #else
  1904. #define BLKDEV_MAJOR_HASH_SIZE 0
  1905. #endif
  1906. extern void init_special_inode(struct inode *, umode_t, dev_t);
  1907. /* Invalid inode operations -- fs/bad_inode.c */
  1908. extern void make_bad_inode(struct inode *);
  1909. extern int is_bad_inode(struct inode *);
  1910. #ifdef CONFIG_BLOCK
  1911. /*
  1912. * return READ, READA, or WRITE
  1913. */
  1914. #define bio_rw(bio) ((bio)->bi_rw & (RW_MASK | RWA_MASK))
  1915. /*
  1916. * return data direction, READ or WRITE
  1917. */
  1918. #define bio_data_dir(bio) ((bio)->bi_rw & 1)
  1919. extern void check_disk_size_change(struct gendisk *disk,
  1920. struct block_device *bdev);
  1921. extern int revalidate_disk(struct gendisk *);
  1922. extern int check_disk_change(struct block_device *);
  1923. extern int __invalidate_device(struct block_device *, bool);
  1924. extern int invalidate_partition(struct gendisk *, int);
  1925. #endif
  1926. unsigned long invalidate_mapping_pages(struct address_space *mapping,
  1927. pgoff_t start, pgoff_t end);
  1928. static inline void invalidate_remote_inode(struct inode *inode)
  1929. {
  1930. if (S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
  1931. S_ISLNK(inode->i_mode))
  1932. invalidate_mapping_pages(inode->i_mapping, 0, -1);
  1933. }
  1934. extern int invalidate_inode_pages2(struct address_space *mapping);
  1935. extern int invalidate_inode_pages2_range(struct address_space *mapping,
  1936. pgoff_t start, pgoff_t end);
  1937. extern int write_inode_now(struct inode *, int);
  1938. extern int filemap_fdatawrite(struct address_space *);
  1939. extern int filemap_flush(struct address_space *);
  1940. extern int filemap_fdatawait(struct address_space *);
  1941. extern int filemap_fdatawait_range(struct address_space *, loff_t lstart,
  1942. loff_t lend);
  1943. extern int filemap_write_and_wait(struct address_space *mapping);
  1944. extern int filemap_write_and_wait_range(struct address_space *mapping,
  1945. loff_t lstart, loff_t lend);
  1946. extern int __filemap_fdatawrite_range(struct address_space *mapping,
  1947. loff_t start, loff_t end, int sync_mode);
  1948. extern int filemap_fdatawrite_range(struct address_space *mapping,
  1949. loff_t start, loff_t end);
  1950. extern int vfs_fsync_range(struct file *file, loff_t start, loff_t end,
  1951. int datasync);
  1952. extern int vfs_fsync(struct file *file, int datasync);
  1953. extern int generic_write_sync(struct file *file, loff_t pos, loff_t count);
  1954. extern void emergency_sync(void);
  1955. extern void emergency_remount(void);
  1956. #ifdef CONFIG_BLOCK
  1957. extern sector_t bmap(struct inode *, sector_t);
  1958. #endif
  1959. extern int notify_change(struct dentry *, struct iattr *);
  1960. extern int inode_permission(struct inode *, int);
  1961. extern int generic_permission(struct inode *, int);
  1962. static inline bool execute_ok(struct inode *inode)
  1963. {
  1964. return (inode->i_mode & S_IXUGO) || S_ISDIR(inode->i_mode);
  1965. }
  1966. static inline struct inode *file_inode(struct file *f)
  1967. {
  1968. return f->f_inode;
  1969. }
  1970. static inline void file_start_write(struct file *file)
  1971. {
  1972. if (!S_ISREG(file_inode(file)->i_mode))
  1973. return;
  1974. __sb_start_write(file_inode(file)->i_sb, SB_FREEZE_WRITE, true);
  1975. }
  1976. static inline bool file_start_write_trylock(struct file *file)
  1977. {
  1978. if (!S_ISREG(file_inode(file)->i_mode))
  1979. return true;
  1980. return __sb_start_write(file_inode(file)->i_sb, SB_FREEZE_WRITE, false);
  1981. }
  1982. static inline void file_end_write(struct file *file)
  1983. {
  1984. if (!S_ISREG(file_inode(file)->i_mode))
  1985. return;
  1986. __sb_end_write(file_inode(file)->i_sb, SB_FREEZE_WRITE);
  1987. }
  1988. /*
  1989. * get_write_access() gets write permission for a file.
  1990. * put_write_access() releases this write permission.
  1991. * This is used for regular files.
  1992. * We cannot support write (and maybe mmap read-write shared) accesses and
  1993. * MAP_DENYWRITE mmappings simultaneously. The i_writecount field of an inode
  1994. * can have the following values:
  1995. * 0: no writers, no VM_DENYWRITE mappings
  1996. * < 0: (-i_writecount) vm_area_structs with VM_DENYWRITE set exist
  1997. * > 0: (i_writecount) users are writing to the file.
  1998. *
  1999. * Normally we operate on that counter with atomic_{inc,dec} and it's safe
  2000. * except for the cases where we don't hold i_writecount yet. Then we need to
  2001. * use {get,deny}_write_access() - these functions check the sign and refuse
  2002. * to do the change if sign is wrong.
  2003. */
  2004. static inline int get_write_access(struct inode *inode)
  2005. {
  2006. return atomic_inc_unless_negative(&inode->i_writecount) ? 0 : -ETXTBSY;
  2007. }
  2008. static inline int deny_write_access(struct file *file)
  2009. {
  2010. struct inode *inode = file_inode(file);
  2011. return atomic_dec_unless_positive(&inode->i_writecount) ? 0 : -ETXTBSY;
  2012. }
  2013. static inline void put_write_access(struct inode * inode)
  2014. {
  2015. atomic_dec(&inode->i_writecount);
  2016. }
  2017. static inline void allow_write_access(struct file *file)
  2018. {
  2019. if (file)
  2020. atomic_inc(&file_inode(file)->i_writecount);
  2021. }
  2022. #ifdef CONFIG_IMA
  2023. static inline void i_readcount_dec(struct inode *inode)
  2024. {
  2025. BUG_ON(!atomic_read(&inode->i_readcount));
  2026. atomic_dec(&inode->i_readcount);
  2027. }
  2028. static inline void i_readcount_inc(struct inode *inode)
  2029. {
  2030. atomic_inc(&inode->i_readcount);
  2031. }
  2032. #else
  2033. static inline void i_readcount_dec(struct inode *inode)
  2034. {
  2035. return;
  2036. }
  2037. static inline void i_readcount_inc(struct inode *inode)
  2038. {
  2039. return;
  2040. }
  2041. #endif
  2042. extern int do_pipe_flags(int *, int);
  2043. extern int kernel_read(struct file *, loff_t, char *, unsigned long);
  2044. extern ssize_t kernel_write(struct file *, const char *, size_t, loff_t);
  2045. extern struct file * open_exec(const char *);
  2046. /* fs/dcache.c -- generic fs support functions */
  2047. extern int is_subdir(struct dentry *, struct dentry *);
  2048. extern int path_is_under(struct path *, struct path *);
  2049. #include <linux/err.h>
  2050. /* needed for stackable file system support */
  2051. extern loff_t default_llseek(struct file *file, loff_t offset, int whence);
  2052. extern loff_t vfs_llseek(struct file *file, loff_t offset, int whence);
  2053. extern int inode_init_always(struct super_block *, struct inode *);
  2054. extern void inode_init_once(struct inode *);
  2055. extern void address_space_init_once(struct address_space *mapping);
  2056. extern void ihold(struct inode * inode);
  2057. extern void iput(struct inode *);
  2058. extern struct inode * igrab(struct inode *);
  2059. extern ino_t iunique(struct super_block *, ino_t);
  2060. extern int inode_needs_sync(struct inode *inode);
  2061. extern int generic_delete_inode(struct inode *inode);
  2062. static inline int generic_drop_inode(struct inode *inode)
  2063. {
  2064. return !inode->i_nlink || inode_unhashed(inode);
  2065. }
  2066. extern struct inode *ilookup5_nowait(struct super_block *sb,
  2067. unsigned long hashval, int (*test)(struct inode *, void *),
  2068. void *data);
  2069. extern struct inode *ilookup5(struct super_block *sb, unsigned long hashval,
  2070. int (*test)(struct inode *, void *), void *data);
  2071. extern struct inode *ilookup(struct super_block *sb, unsigned long ino);
  2072. extern struct inode * iget5_locked(struct super_block *, unsigned long, int (*test)(struct inode *, void *), int (*set)(struct inode *, void *), void *);
  2073. extern struct inode * iget_locked(struct super_block *, unsigned long);
  2074. extern int insert_inode_locked4(struct inode *, unsigned long, int (*test)(struct inode *, void *), void *);
  2075. extern int insert_inode_locked(struct inode *);
  2076. #ifdef CONFIG_DEBUG_LOCK_ALLOC
  2077. extern void lockdep_annotate_inode_mutex_key(struct inode *inode);
  2078. #else
  2079. static inline void lockdep_annotate_inode_mutex_key(struct inode *inode) { };
  2080. #endif
  2081. extern void unlock_new_inode(struct inode *);
  2082. extern unsigned int get_next_ino(void);
  2083. extern void __iget(struct inode * inode);
  2084. extern void iget_failed(struct inode *);
  2085. extern void clear_inode(struct inode *);
  2086. extern void __destroy_inode(struct inode *);
  2087. extern struct inode *new_inode_pseudo(struct super_block *sb);
  2088. extern struct inode *new_inode(struct super_block *sb);
  2089. extern void free_inode_nonrcu(struct inode *inode);
  2090. extern int should_remove_suid(struct dentry *);
  2091. extern int file_remove_suid(struct file *);
  2092. extern void __insert_inode_hash(struct inode *, unsigned long hashval);
  2093. static inline void insert_inode_hash(struct inode *inode)
  2094. {
  2095. __insert_inode_hash(inode, inode->i_ino);
  2096. }
  2097. extern void __remove_inode_hash(struct inode *);
  2098. static inline void remove_inode_hash(struct inode *inode)
  2099. {
  2100. if (!inode_unhashed(inode))
  2101. __remove_inode_hash(inode);
  2102. }
  2103. extern void inode_sb_list_add(struct inode *inode);
  2104. #ifdef CONFIG_BLOCK
  2105. extern void submit_bio(int, struct bio *);
  2106. extern int bdev_read_only(struct block_device *);
  2107. #endif
  2108. extern int set_blocksize(struct block_device *, int);
  2109. extern int sb_set_blocksize(struct super_block *, int);
  2110. extern int sb_min_blocksize(struct super_block *, int);
  2111. extern int generic_file_mmap(struct file *, struct vm_area_struct *);
  2112. extern int generic_file_readonly_mmap(struct file *, struct vm_area_struct *);
  2113. extern int generic_file_remap_pages(struct vm_area_struct *, unsigned long addr,
  2114. unsigned long size, pgoff_t pgoff);
  2115. extern int file_read_actor(read_descriptor_t * desc, struct page *page, unsigned long offset, unsigned long size);
  2116. int generic_write_checks(struct file *file, loff_t *pos, size_t *count, int isblk);
  2117. extern ssize_t generic_file_aio_read(struct kiocb *, const struct iovec *, unsigned long, loff_t);
  2118. extern ssize_t __generic_file_aio_write(struct kiocb *, const struct iovec *, unsigned long,
  2119. loff_t *);
  2120. extern ssize_t generic_file_aio_write(struct kiocb *, const struct iovec *, unsigned long, loff_t);
  2121. extern ssize_t generic_file_direct_write(struct kiocb *, const struct iovec *,
  2122. unsigned long *, loff_t, loff_t *, size_t, size_t);
  2123. extern ssize_t generic_file_buffered_write(struct kiocb *, const struct iovec *,
  2124. unsigned long, loff_t, loff_t *, size_t, ssize_t);
  2125. extern ssize_t do_sync_read(struct file *filp, char __user *buf, size_t len, loff_t *ppos);
  2126. extern ssize_t do_sync_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos);
  2127. extern int generic_segment_checks(const struct iovec *iov,
  2128. unsigned long *nr_segs, size_t *count, int access_flags);
  2129. /* fs/block_dev.c */
  2130. extern ssize_t blkdev_aio_write(struct kiocb *iocb, const struct iovec *iov,
  2131. unsigned long nr_segs, loff_t pos);
  2132. extern int blkdev_fsync(struct file *filp, loff_t start, loff_t end,
  2133. int datasync);
  2134. extern void block_sync_page(struct page *page);
  2135. /* fs/splice.c */
  2136. extern ssize_t generic_file_splice_read(struct file *, loff_t *,
  2137. struct pipe_inode_info *, size_t, unsigned int);
  2138. extern ssize_t default_file_splice_read(struct file *, loff_t *,
  2139. struct pipe_inode_info *, size_t, unsigned int);
  2140. extern ssize_t generic_file_splice_write(struct pipe_inode_info *,
  2141. struct file *, loff_t *, size_t, unsigned int);
  2142. extern ssize_t generic_splice_sendpage(struct pipe_inode_info *pipe,
  2143. struct file *out, loff_t *, size_t len, unsigned int flags);
  2144. extern void
  2145. file_ra_state_init(struct file_ra_state *ra, struct address_space *mapping);
  2146. extern loff_t noop_llseek(struct file *file, loff_t offset, int whence);
  2147. extern loff_t no_llseek(struct file *file, loff_t offset, int whence);
  2148. extern loff_t vfs_setpos(struct file *file, loff_t offset, loff_t maxsize);
  2149. extern loff_t generic_file_llseek(struct file *file, loff_t offset, int whence);
  2150. extern loff_t generic_file_llseek_size(struct file *file, loff_t offset,
  2151. int whence, loff_t maxsize, loff_t eof);
  2152. extern loff_t fixed_size_llseek(struct file *file, loff_t offset,
  2153. int whence, loff_t size);
  2154. extern int generic_file_open(struct inode * inode, struct file * filp);
  2155. extern int nonseekable_open(struct inode * inode, struct file * filp);
  2156. #ifdef CONFIG_FS_XIP
  2157. extern ssize_t xip_file_read(struct file *filp, char __user *buf, size_t len,
  2158. loff_t *ppos);
  2159. extern int xip_file_mmap(struct file * file, struct vm_area_struct * vma);
  2160. extern ssize_t xip_file_write(struct file *filp, const char __user *buf,
  2161. size_t len, loff_t *ppos);
  2162. extern int xip_truncate_page(struct address_space *mapping, loff_t from);
  2163. #else
  2164. static inline int xip_truncate_page(struct address_space *mapping, loff_t from)
  2165. {
  2166. return 0;
  2167. }
  2168. #endif
  2169. #ifdef CONFIG_BLOCK
  2170. typedef void (dio_submit_t)(int rw, struct bio *bio, struct inode *inode,
  2171. loff_t file_offset);
  2172. enum {
  2173. /* need locking between buffered and direct access */
  2174. DIO_LOCKING = 0x01,
  2175. /* filesystem does not support filling holes */
  2176. DIO_SKIP_HOLES = 0x02,
  2177. };
  2178. void dio_end_io(struct bio *bio, int error);
  2179. ssize_t __blockdev_direct_IO(int rw, struct kiocb *iocb, struct inode *inode,
  2180. struct block_device *bdev, const struct iovec *iov, loff_t offset,
  2181. unsigned long nr_segs, get_block_t get_block, dio_iodone_t end_io,
  2182. dio_submit_t submit_io, int flags);
  2183. static inline ssize_t blockdev_direct_IO(int rw, struct kiocb *iocb,
  2184. struct inode *inode, const struct iovec *iov, loff_t offset,
  2185. unsigned long nr_segs, get_block_t get_block)
  2186. {
  2187. return __blockdev_direct_IO(rw, iocb, inode, inode->i_sb->s_bdev, iov,
  2188. offset, nr_segs, get_block, NULL, NULL,
  2189. DIO_LOCKING | DIO_SKIP_HOLES);
  2190. }
  2191. #endif
  2192. void inode_dio_wait(struct inode *inode);
  2193. void inode_dio_done(struct inode *inode);
  2194. extern const struct file_operations generic_ro_fops;
  2195. #define special_file(m) (S_ISCHR(m)||S_ISBLK(m)||S_ISFIFO(m)||S_ISSOCK(m))
  2196. extern int vfs_readlink(struct dentry *, char __user *, int, const char *);
  2197. extern int vfs_follow_link(struct nameidata *, const char *);
  2198. extern int page_readlink(struct dentry *, char __user *, int);
  2199. extern void *page_follow_link_light(struct dentry *, struct nameidata *);
  2200. extern void page_put_link(struct dentry *, struct nameidata *, void *);
  2201. extern int __page_symlink(struct inode *inode, const char *symname, int len,
  2202. int nofs);
  2203. extern int page_symlink(struct inode *inode, const char *symname, int len);
  2204. extern const struct inode_operations page_symlink_inode_operations;
  2205. extern int generic_readlink(struct dentry *, char __user *, int);
  2206. extern void generic_fillattr(struct inode *, struct kstat *);
  2207. extern int vfs_getattr(struct path *, struct kstat *);
  2208. void __inode_add_bytes(struct inode *inode, loff_t bytes);
  2209. void inode_add_bytes(struct inode *inode, loff_t bytes);
  2210. void inode_sub_bytes(struct inode *inode, loff_t bytes);
  2211. loff_t inode_get_bytes(struct inode *inode);
  2212. void inode_set_bytes(struct inode *inode, loff_t bytes);
  2213. extern int vfs_readdir(struct file *, filldir_t, void *);
  2214. extern int iterate_dir(struct file *, struct dir_context *);
  2215. extern int vfs_stat(const char __user *, struct kstat *);
  2216. extern int vfs_lstat(const char __user *, struct kstat *);
  2217. extern int vfs_fstat(unsigned int, struct kstat *);
  2218. extern int vfs_fstatat(int , const char __user *, struct kstat *, int);
  2219. extern int do_vfs_ioctl(struct file *filp, unsigned int fd, unsigned int cmd,
  2220. unsigned long arg);
  2221. extern int __generic_block_fiemap(struct inode *inode,
  2222. struct fiemap_extent_info *fieinfo,
  2223. loff_t start, loff_t len,
  2224. get_block_t *get_block);
  2225. extern int generic_block_fiemap(struct inode *inode,
  2226. struct fiemap_extent_info *fieinfo, u64 start,
  2227. u64 len, get_block_t *get_block);
  2228. extern void get_filesystem(struct file_system_type *fs);
  2229. extern void put_filesystem(struct file_system_type *fs);
  2230. extern struct file_system_type *get_fs_type(const char *name);
  2231. extern struct super_block *get_super(struct block_device *);
  2232. extern struct super_block *get_super_thawed(struct block_device *);
  2233. extern struct super_block *get_active_super(struct block_device *bdev);
  2234. extern void drop_super(struct super_block *sb);
  2235. extern void iterate_supers(void (*)(struct super_block *, void *), void *);
  2236. extern void iterate_supers_type(struct file_system_type *,
  2237. void (*)(struct super_block *, void *), void *);
  2238. extern int dcache_dir_open(struct inode *, struct file *);
  2239. extern int dcache_dir_close(struct inode *, struct file *);
  2240. extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
  2241. extern int dcache_readdir(struct file *, struct dir_context *);
  2242. extern int simple_setattr(struct dentry *, struct iattr *);
  2243. extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
  2244. extern int simple_statfs(struct dentry *, struct kstatfs *);
  2245. extern int simple_open(struct inode *inode, struct file *file);
  2246. extern int simple_link(struct dentry *, struct inode *, struct dentry *);
  2247. extern int simple_unlink(struct inode *, struct dentry *);
  2248. extern int simple_rmdir(struct inode *, struct dentry *);
  2249. extern int simple_rename(struct inode *, struct dentry *, struct inode *, struct dentry *);
  2250. extern int noop_fsync(struct file *, loff_t, loff_t, int);
  2251. extern int simple_empty(struct dentry *);
  2252. extern int simple_readpage(struct file *file, struct page *page);
  2253. extern int simple_write_begin(struct file *file, struct address_space *mapping,
  2254. loff_t pos, unsigned len, unsigned flags,
  2255. struct page **pagep, void **fsdata);
  2256. extern int simple_write_end(struct file *file, struct address_space *mapping,
  2257. loff_t pos, unsigned len, unsigned copied,
  2258. struct page *page, void *fsdata);
  2259. extern struct dentry *simple_lookup(struct inode *, struct dentry *, unsigned int flags);
  2260. extern ssize_t generic_read_dir(struct file *, char __user *, size_t, loff_t *);
  2261. extern const struct file_operations simple_dir_operations;
  2262. extern const struct inode_operations simple_dir_inode_operations;
  2263. struct tree_descr { char *name; const struct file_operations *ops; int mode; };
  2264. struct dentry *d_alloc_name(struct dentry *, const char *);
  2265. extern int simple_fill_super(struct super_block *, unsigned long, struct tree_descr *);
  2266. extern int simple_pin_fs(struct file_system_type *, struct vfsmount **mount, int *count);
  2267. extern void simple_release_fs(struct vfsmount **mount, int *count);
  2268. extern ssize_t simple_read_from_buffer(void __user *to, size_t count,
  2269. loff_t *ppos, const void *from, size_t available);
  2270. extern ssize_t simple_write_to_buffer(void *to, size_t available, loff_t *ppos,
  2271. const void __user *from, size_t count);
  2272. extern int generic_file_fsync(struct file *, loff_t, loff_t, int);
  2273. extern int generic_check_addressable(unsigned, u64);
  2274. #ifdef CONFIG_MIGRATION
  2275. extern int buffer_migrate_page(struct address_space *,
  2276. struct page *, struct page *,
  2277. enum migrate_mode);
  2278. #else
  2279. #define buffer_migrate_page NULL
  2280. #endif
  2281. extern int inode_change_ok(const struct inode *, struct iattr *);
  2282. extern int inode_newsize_ok(const struct inode *, loff_t offset);
  2283. extern void setattr_copy(struct inode *inode, const struct iattr *attr);
  2284. extern int file_update_time(struct file *file);
  2285. extern int generic_show_options(struct seq_file *m, struct dentry *root);
  2286. extern void save_mount_options(struct super_block *sb, char *options);
  2287. extern void replace_mount_options(struct super_block *sb, char *options);
  2288. static inline ino_t parent_ino(struct dentry *dentry)
  2289. {
  2290. ino_t res;
  2291. /*
  2292. * Don't strictly need d_lock here? If the parent ino could change
  2293. * then surely we'd have a deeper race in the caller?
  2294. */
  2295. spin_lock(&dentry->d_lock);
  2296. res = dentry->d_parent->d_inode->i_ino;
  2297. spin_unlock(&dentry->d_lock);
  2298. return res;
  2299. }
  2300. /* Transaction based IO helpers */
  2301. /*
  2302. * An argresp is stored in an allocated page and holds the
  2303. * size of the argument or response, along with its content
  2304. */
  2305. struct simple_transaction_argresp {
  2306. ssize_t size;
  2307. char data[0];
  2308. };
  2309. #define SIMPLE_TRANSACTION_LIMIT (PAGE_SIZE - sizeof(struct simple_transaction_argresp))
  2310. char *simple_transaction_get(struct file *file, const char __user *buf,
  2311. size_t size);
  2312. ssize_t simple_transaction_read(struct file *file, char __user *buf,
  2313. size_t size, loff_t *pos);
  2314. int simple_transaction_release(struct inode *inode, struct file *file);
  2315. void simple_transaction_set(struct file *file, size_t n);
  2316. /*
  2317. * simple attribute files
  2318. *
  2319. * These attributes behave similar to those in sysfs:
  2320. *
  2321. * Writing to an attribute immediately sets a value, an open file can be
  2322. * written to multiple times.
  2323. *
  2324. * Reading from an attribute creates a buffer from the value that might get
  2325. * read with multiple read calls. When the attribute has been read
  2326. * completely, no further read calls are possible until the file is opened
  2327. * again.
  2328. *
  2329. * All attributes contain a text representation of a numeric value
  2330. * that are accessed with the get() and set() functions.
  2331. */
  2332. #define DEFINE_SIMPLE_ATTRIBUTE(__fops, __get, __set, __fmt) \
  2333. static int __fops ## _open(struct inode *inode, struct file *file) \
  2334. { \
  2335. __simple_attr_check_format(__fmt, 0ull); \
  2336. return simple_attr_open(inode, file, __get, __set, __fmt); \
  2337. } \
  2338. static const struct file_operations __fops = { \
  2339. .owner = THIS_MODULE, \
  2340. .open = __fops ## _open, \
  2341. .release = simple_attr_release, \
  2342. .read = simple_attr_read, \
  2343. .write = simple_attr_write, \
  2344. .llseek = generic_file_llseek, \
  2345. };
  2346. static inline __printf(1, 2)
  2347. void __simple_attr_check_format(const char *fmt, ...)
  2348. {
  2349. /* don't do anything, just let the compiler check the arguments; */
  2350. }
  2351. int simple_attr_open(struct inode *inode, struct file *file,
  2352. int (*get)(void *, u64 *), int (*set)(void *, u64),
  2353. const char *fmt);
  2354. int simple_attr_release(struct inode *inode, struct file *file);
  2355. ssize_t simple_attr_read(struct file *file, char __user *buf,
  2356. size_t len, loff_t *ppos);
  2357. ssize_t simple_attr_write(struct file *file, const char __user *buf,
  2358. size_t len, loff_t *ppos);
  2359. struct ctl_table;
  2360. int proc_nr_files(struct ctl_table *table, int write,
  2361. void __user *buffer, size_t *lenp, loff_t *ppos);
  2362. int proc_nr_dentry(struct ctl_table *table, int write,
  2363. void __user *buffer, size_t *lenp, loff_t *ppos);
  2364. int proc_nr_inodes(struct ctl_table *table, int write,
  2365. void __user *buffer, size_t *lenp, loff_t *ppos);
  2366. int __init get_filesystem_list(char *buf);
  2367. #define __FMODE_EXEC ((__force int) FMODE_EXEC)
  2368. #define __FMODE_NONOTIFY ((__force int) FMODE_NONOTIFY)
  2369. #define ACC_MODE(x) ("\004\002\006\006"[(x)&O_ACCMODE])
  2370. #define OPEN_FMODE(flag) ((__force fmode_t)(((flag + 1) & O_ACCMODE) | \
  2371. (flag & __FMODE_NONOTIFY)))
  2372. static inline int is_sxid(umode_t mode)
  2373. {
  2374. return (mode & S_ISUID) || ((mode & S_ISGID) && (mode & S_IXGRP));
  2375. }
  2376. static inline void inode_has_no_xattr(struct inode *inode)
  2377. {
  2378. if (!is_sxid(inode->i_mode) && (inode->i_sb->s_flags & MS_NOSEC))
  2379. inode->i_flags |= S_NOSEC;
  2380. }
  2381. static inline bool dir_emit(struct dir_context *ctx,
  2382. const char *name, int namelen,
  2383. u64 ino, unsigned type)
  2384. {
  2385. return ctx->actor(ctx, name, namelen, ctx->pos, ino, type) == 0;
  2386. }
  2387. static inline bool dir_emit_dot(struct file *file, struct dir_context *ctx)
  2388. {
  2389. return ctx->actor(ctx, ".", 1, ctx->pos,
  2390. file->f_path.dentry->d_inode->i_ino, DT_DIR) == 0;
  2391. }
  2392. static inline bool dir_emit_dotdot(struct file *file, struct dir_context *ctx)
  2393. {
  2394. return ctx->actor(ctx, "..", 2, ctx->pos,
  2395. parent_ino(file->f_path.dentry), DT_DIR) == 0;
  2396. }
  2397. static inline bool dir_emit_dots(struct file *file, struct dir_context *ctx)
  2398. {
  2399. if (ctx->pos == 0) {
  2400. if (!dir_emit_dot(file, ctx))
  2401. return false;
  2402. ctx->pos = 1;
  2403. }
  2404. if (ctx->pos == 1) {
  2405. if (!dir_emit_dotdot(file, ctx))
  2406. return false;
  2407. ctx->pos = 2;
  2408. }
  2409. return true;
  2410. }
  2411. static inline bool dir_relax(struct inode *inode)
  2412. {
  2413. mutex_unlock(&inode->i_mutex);
  2414. mutex_lock(&inode->i_mutex);
  2415. return !IS_DEADDIR(inode);
  2416. }
  2417. #endif /* _LINUX_FS_H */