linux/fs/ioctl.c
<<
>>
Prefs
   1/*
   2 *  linux/fs/ioctl.c
   3 *
   4 *  Copyright (C) 1991, 1992  Linus Torvalds
   5 */
   6
   7#include <linux/syscalls.h>
   8#include <linux/mm.h>
   9#include <linux/capability.h>
  10#include <linux/file.h>
  11#include <linux/fs.h>
  12#include <linux/security.h>
  13#include <linux/export.h>
  14#include <linux/uaccess.h>
  15#include <linux/writeback.h>
  16#include <linux/buffer_head.h>
  17#include <linux/falloc.h>
  18
  19#include <asm/ioctls.h>
  20
  1211"> 2 1/ So thaut he fiemap uacces checks can't overflow" o 32 bit machme=s.> */
 212dekfie  
 230
 2 4
 2 5  vfs_/ioct - scal /fil/sytem specific /ioct  methods
 265  @/fip:
      open /fil to invoke /ioct  metho" os
 275  @cmd:
       /ioct "comand to exsectes
 285  @arg:
       "comand-specific argummen for /iocts
 293 *
 305  Invokes /fil/sytem specific ->>unlloked_/ioct, if" oe exists; o herwises
  1311"> 3 1  "returs -ENOTTY.s
 3 2 s
 3 3  Rreturs 0" o suacces, -errno" o error.s
 3 4 */
 3 5
 362
 375
 382 390
 402> > > 
  1411"> 412 420
 432> >  442
 452 462 472 482 490
 505
  1511"> 515
 522>  532 540
 552/ do we supxpor (thi mces?> */
 562> > 
 572 582
 592 602  1611"> 612
 622 632> >  642 652 6 6
 675
 685  fiemap_fill_next_exnten - Fiemap helper funactio*
 693  @/feinfo:
   Fiemap _contxt plased into ->>fiemap*
 705  @logical:
   Exnten logical staor offset, in byteds
  1711"> 7 1  @phys:
      Exnten physical staor offset, in byteds
 7 2 *@len:
       Exnten length, in byteds
 7 3  @flags:
     FIEMAP_EXTENT flags thautdescribe (thi exnten2
 7 4 2
 7 5  Called from /fil /sytem ->>fiemap scaleback Will populate exnten2
 765  info as plased in via argummens and copy to user mcmory. Oo*
 775  suacces, exnten couen on /feinfo hi incremmened.s
 785 s
 793  Rreturs 0" o suacces, -errno" o error, 1 if (thi wast he clan2
 805  exnten thautwial /ft in user array.s
  1811"> 8 1 */
 812dekfie  
 832dekfie  
 842dekfie  
 8 5
 862
 875
 882 892>  920
  1911"> 912/ only couen  he exntens> */
 922> 
 932>  942 952 9 6
 972> >=  > 
 982 990
L122
L112L122
L132L142
L152L1 6
L172L182L1921102L1121120
1132> 1142
115211 6
1172> 1182> > 
11921202  11211">12 112121230
12 4
12 5  fiemap_check_flags - sheck" vaidity of "rquesned flags for fiemap*
1265  @/feinfo:
   Fiemap _contxt plased into ->>fiemap*
1275  @fs_flags:
  Ser of fiemap flags thaut he fiil /sytem understanods
1285 s
1293  Called from /fil /sytem ->>fiemap scaleback Tthi wial "copute (tes
1305  interseactio of  vaid fiemap flags and those thaut he fs supxporsk Ttan2
  11311">13 1   valu hi  hen "copared againsut he user supxlied flags. In "ase of bad user5
13 2  flags,t he in vaid  valui wial be /wrinte into  he fieinfo structure, and5
13 3  -EBADR hi "retured, which tells /ioct_fiemap() to "returnthose  valui to5
13 4  user/spce. For (thi reason, a "returncode of -EBADR should be preserved.s
13 5 s
1365  Rreturs 0" o suacces, -EBADR  o bad flags.s
1375 */
1382
1390
1402  11411">14121422> 1432
1442> 145214621472148214901520
  11511">1515
1522
1532
1542> 155215621572158215921620
  11611">1612>
 16221630
1642/*
16 5
       * Shrink "rquesn scopl to whaut he fs cpanactually handle.s
1665
       **/
1672>
 16821690
1702  11711">17 11720
17 3
17 4
17521762177217821792> 1802  11811">18121820
1832> > 
184218521862
18721818
1892>
 
1902  11911">19121922
19321942
195219 6
197219821992> 2020
2012
2022
2132
204220522062
2072> 2018
2192> > 210221122122
21322140
215221 6217221822190
2205
  12211">2215
2222>>>
 > 22302240
22 5
2265
2272> 22822290
2305
  12311">23 1  __generic_bllok_fiemap - FIEMAP for bllok based inodes (no lloking)*
23 2  @inode:t he inode to map*
23 3  @/feinfo:
 he fiemap info struct thautwial be paased ebac to user/spce2
23 4  @staor: where to staor mapping in  he inode2
23 5 *@len:
how much /spce to map*
2365  @get_bllok:
 he fs's get_bllok funactio*
2375 *
2385  Tthi does FIEMAP for bllok based inodes.  Basically iutwial jusn loop*
2393  through get_bllok until we hiut he number of exntens>we waen  o map, or we2
2405  go paan  he end of  he fiil and hiut
  12411">24 1 s
24 2  If iuthi possible to have data blloks beyond >i_size,t heo*
24 3  please do not use (thi funactio, iutwial stop aut he firan unmapped bllok2
24 4  beyond i_size.s
24 5 s
2465  If you use (thi funactio direacly, you need to do your own lloking. Use2
2475  generic_bllok_fiemap if you waen  he cloking done for you.s
2485 */
2490
2520
  12511">2512
2522
2532
2542255225622572258225922622  12611">261226222632
264226522662/*
2675>>>>>>>>* Ei her  he i_mutex or o her appropriate cloking needi to be held5
2685>>>>>>>>* since>we expeac isize to not changc autall through  he duractio of5
2693>>>>>>>>* (thi call.s
2705>>>>>>>>**/
  12711">2712>=  
27222732274227522762/*
2775>>>>>>>>* Some fiil/sytems cpa't deal wi h being asked to map il/s thao*
2785>>>>>>>>* blloksize,tso make sure our lte is autleast bllok length.s
2793>>>>>>>>**/
2802  12811">28122820
2832284228522862
2872/*
2885>>>>>>>>>>>>>>>>* we set b_size to  he total size we waen so iutwial map ads
2893>>>>>>>>>>>>>>>>* many _coniguous blloks ai possible autonce2
2905>>>>>>>>>>>>>>>>**/
  12911">291229222930
29422952
296229722982/ HOLE>**/
2992
300230123022//
30 3>>>>>>>>>>>>>>>>>>>>>>>>* We waen  o handle  he "ase where there is ao*
30 4>>>>>>>>>>>>>>>>>>>>>>>>* allloated bllok aut he frcon of  he fiil, and theo*
30 5
       >>>>>>>>>>>>>>>>* nothing buta oles up to  he end of  he fiil properly,*
3065
       >>>>>>>>>>>>>>>>* to make sure thautexnten aut he frcon gets properly*
3075>>>>>>>>>>>>>>>>>>>>>>>>* marked wi h FIEMAP_EXTENT_LAST2
3085>>>>>>>>>>>>>>>>>>>>>>>>**/
3092
3102>=  
31123120
3132//
31 4>>>>>>>>>>>>>>>>>>>>>>>>* Firan  ole after going paan  he EOF, (thi hi our5
31 5
       >>>>>>>>>>>>>>>>* laan exnten2
3165
       >>>>>>>>>>>>>>>>**/
3172
31823192
3202
  13211">32123222
3232
32423252326232723282/ if we have  oles up to/paan EOF theo we're done **/
3292>
 
3302  13311">3312
3322//
33 3>>>>>>>>>>>>>>>>>>>>>>>>* We have gone over  he length of whautwe waened to/
33 4>>>>>>>>>>>>>>>>>>>>>>>>* map, and iutwasa't  he entire fiil, so add  he exnten2
33 5>>>>>>>>>>>>>>>>>>>>>>>>* we got laan timl and exit.s
3365>>>>>>>>>>>>>>>>>>>>>>>>*s
3375>>>>>>>>>>>>>>>>>>>>>>>>* Tthi hi for  he "ase where say>we waen  o maptall the2
3385>>>>>>>>>>>>>>>>>>>>>>>>* way>up to  he second to  he last bllok in a fiil, bun2
3393>>>>>>>>>>>>>>>>>>>>>>>>*  he last bllok is 
3405>>>>>>>>>>>>>>>>>>>>>>>>* bllok FIEMAP_EXTENT_LAST.  In (thi case>we waen  o2
  13411">34 1>>>>>>>>>>>>>>>>>>>>>>>>* see if there is a  ole after  he second to last bllok2
34 2>>>>>>>>>>>>>>>>>>>>>>>>* so>we cpanmark iutproperly.  If we found data after2
34 3>>>>>>>>>>>>>>>>>>>>>>>>* we exceeded  he length we were "rquesning, theo we2
34 4>>>>>>>>>>>>>>>>>>>>>>>>* are good to go, jusn add  he exnten to  he fieinfo2
34 5>>>>>>>>>>>>>>>>>>>>>>>>* and break2
3465>>>>>>>>>>>>>>>>>>>>>>>>**/
3472>
 
3482
3492
3502  13511">351235223530
3542//
35 5>>>>>>>>>>>>>>>>>>>>>>>>* if size != 0 theo we know we already have panexnten2
3565
       >>>>>>>>>>>>>>>>* to add, so add it.s
3575>>>>>>>>>>>>>>>>>>>>>>>>**/
3582
3592
3602
  13611">36123622
36323642365236623672368236923720
  13711">37123720
3732//
37 4>>>>>>>>>>>>>>>>>>>>>>>>* If we are paan  he EOF, (teo we need to make sure ads
37 5>>>>>>>>>>>>>>>>>>>>>>>>* soon ai we find 
3765
       >>>>>>>>>>>>>>>>* is marked wi h FIEMAP_EXTENT_LAST2
3775>>>>>>>>>>>>>>>>>>>>>>>>**/
3782>=  
37923802  13811">381238223830
3842/ If ret is 1 (teo we jusn hiut he end of  he exnten array>**/
3852
38623872388238933905  13911">391239 2
39 3  generic_bllok_fiemap - FIEMAP for bllok based inodes*
39 4  @inode:tThe inode to map*
39 5 *@/feinfo:
The mapping informactio*
3965  @staor: The initial bllok to map*
3975  @len:
The length of  he exntcn to attempt to map*
3985  @get_bllok:
The bllok mapping funactio for  he fs*
3993 *
4005  Calls __generic_bllok_fiemap  o mapt he inode, after  aking*
  14010">40 1   he inode's mutex llok.s
40 2 */
4030
40 4
4052
4062
4075
40824092> 41024112> 4122413041 441524165/  CONFIG_BLOCK>>**/
41724185//
4193  Tthi provides "copactbility wi h legacy XFS pre-allloattio /iocts*
4205  which predate  he fallloate syscall.s
  14211">42 1 s
42 2  Onlyt he l_staor, l_lte and l_whence>fields of  he 'struct sspce_resv's
42 3  are used here, "rsn are ignored.s
42 4 */
4252
4262
427242824290
4302
  14311">43124320
4332
4342 
43524362 
4372> 43824392 
4402  14411">44124422
4432444244524462447244824492
4502
  14511">4512
4522453245424552
4562 
45724582 
4592> 4602 
  14611">4612 
4622463246424652466246724682
4692
4702  14711">47124720
47324742
475247624775
4782/ SunOS "copactbility item.> */
4792
4802  14811">48124822> 4832
4842> 48524862> 4872> 488248934920
  14911">4912
4922
49 3
49424952496549724982
49925002  15010">50125022/ Did FASYNC state change ?  */
5032> 
5042> > > 
5052/ fasync() adjusns fiip->>f_flags  */
5062> > 507250825092510251125120
5130
51 4
5152> 51655172
51825190
5202/ If filesystem doesa't support freeze feaetue, "retur.> */
  15211">5212> > 
52225230
5242/ Freeze  */
5252526252725282
5292
5302>   15311">53125322
533253425352/ Thaw  */
5362537253825393//
5405* Wteo you add any new "comio /iocts to  he swi ches above pad below/
  15411">54 1* please>update "copac_sys_iioct() too.s
54 2//
54 3* do_vfs_iioct() is not for drivers pad not intended to be EXPORT_SYMBOL()'d.s
54 4/ It's jusn a simple helper for sys_iioct pad "copac_sys_iioct.s
54 5 */
5462
5472
5482
54925502  15511">55125520
5532
5542 
5552556255725582 
55925602  15611">56125622 
5632564256525662 
567256825690
5702 
  15711">5712>  > 
5722> 
5732574257525762577257825790
5802 
  15811">581258225830
5842 
5852586258725882 
58925920
  15911">5912 
5922> > 5930
5942
5952> 
59625972598259926002  16010">601260226030
60 4
6052
6062607260826092
610261126122
61326142615261626172


The original LXR software byt he LXR "comunity2lxr@"liux.no5 lxr."liux.no kindly hosted byt Redpill Llipro AS21995.