inode.c 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136
  1. /*
  2. * inode.c
  3. *
  4. * PURPOSE
  5. * Inode handling routines for the OSTA-UDF(tm) filesystem.
  6. *
  7. * COPYRIGHT
  8. * This file is distributed under the terms of the GNU General Public
  9. * License (GPL). Copies of the GPL can be obtained from:
  10. * ftp://prep.ai.mit.edu/pub/gnu/GPL
  11. * Each contributing author retains all rights to their own work.
  12. *
  13. * (C) 1998 Dave Boynton
  14. * (C) 1998-2004 Ben Fennema
  15. * (C) 1999-2000 Stelias Computing Inc
  16. *
  17. * HISTORY
  18. *
  19. * 10/04/98 dgb Added rudimentary directory functions
  20. * 10/07/98 Fully working udf_block_map! It works!
  21. * 11/25/98 bmap altered to better support extents
  22. * 12/06/98 blf partition support in udf_iget, udf_block_map and udf_read_inode
  23. * 12/12/98 rewrote udf_block_map to handle next extents and descs across
  24. * block boundaries (which is not actually allowed)
  25. * 12/20/98 added support for strategy 4096
  26. * 03/07/99 rewrote udf_block_map (again)
  27. * New funcs, inode_bmap, udf_next_aext
  28. * 04/19/99 Support for writing device EA's for major/minor #
  29. */
  30. #include "udfdecl.h"
  31. #include <linux/mm.h>
  32. #include <linux/smp_lock.h>
  33. #include <linux/module.h>
  34. #include <linux/pagemap.h>
  35. #include <linux/buffer_head.h>
  36. #include <linux/writeback.h>
  37. #include <linux/slab.h>
  38. #include "udf_i.h"
  39. #include "udf_sb.h"
  40. MODULE_AUTHOR("Ben Fennema");
  41. MODULE_DESCRIPTION("Universal Disk Format Filesystem");
  42. MODULE_LICENSE("GPL");
  43. #define EXTENT_MERGE_SIZE 5
  44. static mode_t udf_convert_permissions(struct fileEntry *);
  45. static int udf_update_inode(struct inode *, int);
  46. static void udf_fill_inode(struct inode *, struct buffer_head *);
  47. static struct buffer_head *inode_getblk(struct inode *, sector_t, int *,
  48. long *, int *);
  49. static int8_t udf_insert_aext(struct inode *, struct extent_position,
  50. kernel_lb_addr, uint32_t);
  51. static void udf_split_extents(struct inode *, int *, int, int,
  52. kernel_long_ad [EXTENT_MERGE_SIZE], int *);
  53. static void udf_prealloc_extents(struct inode *, int, int,
  54. kernel_long_ad [EXTENT_MERGE_SIZE], int *);
  55. static void udf_merge_extents(struct inode *,
  56. kernel_long_ad [EXTENT_MERGE_SIZE], int *);
  57. static void udf_update_extents(struct inode *,
  58. kernel_long_ad [EXTENT_MERGE_SIZE], int, int,
  59. struct extent_position *);
  60. static int udf_get_block(struct inode *, sector_t, struct buffer_head *, int);
  61. /*
  62. * udf_delete_inode
  63. *
  64. * PURPOSE
  65. * Clean-up before the specified inode is destroyed.
  66. *
  67. * DESCRIPTION
  68. * This routine is called when the kernel destroys an inode structure
  69. * ie. when iput() finds i_count == 0.
  70. *
  71. * HISTORY
  72. * July 1, 1997 - Andrew E. Mileski
  73. * Written, tested, and released.
  74. *
  75. * Called at the last iput() if i_nlink is zero.
  76. */
  77. void udf_delete_inode(struct inode * inode)
  78. {
  79. truncate_inode_pages(&inode->i_data, 0);
  80. if (is_bad_inode(inode))
  81. goto no_delete;
  82. inode->i_size = 0;
  83. udf_truncate(inode);
  84. lock_kernel();
  85. udf_update_inode(inode, IS_SYNC(inode));
  86. udf_free_inode(inode);
  87. unlock_kernel();
  88. return;
  89. no_delete:
  90. clear_inode(inode);
  91. }
  92. /*
  93. * If we are going to release inode from memory, we discard preallocation and
  94. * truncate last inode extent to proper length. We could use drop_inode() but
  95. * it's called under inode_lock and thus we cannot mark inode dirty there. We
  96. * use clear_inode() but we have to make sure to write inode as it's not written
  97. * automatically.
  98. */
  99. void udf_clear_inode(struct inode *inode)
  100. {
  101. if (!(inode->i_sb->s_flags & MS_RDONLY)) {
  102. lock_kernel();
  103. /* Discard preallocation for directories, symlinks, etc. */
  104. udf_discard_prealloc(inode);
  105. udf_truncate_tail_extent(inode);
  106. unlock_kernel();
  107. write_inode_now(inode, 1);
  108. }
  109. kfree(UDF_I_DATA(inode));
  110. UDF_I_DATA(inode) = NULL;
  111. }
  112. static int udf_writepage(struct page *page, struct writeback_control *wbc)
  113. {
  114. return block_write_full_page(page, udf_get_block, wbc);
  115. }
  116. static int udf_readpage(struct file *file, struct page *page)
  117. {
  118. return block_read_full_page(page, udf_get_block);
  119. }
  120. static int udf_prepare_write(struct file *file, struct page *page, unsigned from, unsigned to)
  121. {
  122. return block_prepare_write(page, from, to, udf_get_block);
  123. }
  124. static sector_t udf_bmap(struct address_space *mapping, sector_t block)
  125. {
  126. return generic_block_bmap(mapping,block,udf_get_block);
  127. }
  128. const struct address_space_operations udf_aops = {
  129. .readpage = udf_readpage,
  130. .writepage = udf_writepage,
  131. .sync_page = block_sync_page,
  132. .prepare_write = udf_prepare_write,
  133. .commit_write = generic_commit_write,
  134. .bmap = udf_bmap,
  135. };
  136. void udf_expand_file_adinicb(struct inode * inode, int newsize, int * err)
  137. {
  138. struct page *page;
  139. char *kaddr;
  140. struct writeback_control udf_wbc = {
  141. .sync_mode = WB_SYNC_NONE,
  142. .nr_to_write = 1,
  143. };
  144. /* from now on we have normal address_space methods */
  145. inode->i_data.a_ops = &udf_aops;
  146. if (!UDF_I_LENALLOC(inode))
  147. {
  148. if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_SHORT_AD))
  149. UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_SHORT;
  150. else
  151. UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_LONG;
  152. mark_inode_dirty(inode);
  153. return;
  154. }
  155. page = grab_cache_page(inode->i_mapping, 0);
  156. BUG_ON(!PageLocked(page));
  157. if (!PageUptodate(page))
  158. {
  159. kaddr = kmap(page);
  160. memset(kaddr + UDF_I_LENALLOC(inode), 0x00,
  161. PAGE_CACHE_SIZE - UDF_I_LENALLOC(inode));
  162. memcpy(kaddr, UDF_I_DATA(inode) + UDF_I_LENEATTR(inode),
  163. UDF_I_LENALLOC(inode));
  164. flush_dcache_page(page);
  165. SetPageUptodate(page);
  166. kunmap(page);
  167. }
  168. memset(UDF_I_DATA(inode) + UDF_I_LENEATTR(inode), 0x00,
  169. UDF_I_LENALLOC(inode));
  170. UDF_I_LENALLOC(inode) = 0;
  171. if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_SHORT_AD))
  172. UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_SHORT;
  173. else
  174. UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_LONG;
  175. inode->i_data.a_ops->writepage(page, &udf_wbc);
  176. page_cache_release(page);
  177. mark_inode_dirty(inode);
  178. }
  179. struct buffer_head * udf_expand_dir_adinicb(struct inode *inode, int *block, int *err)
  180. {
  181. int newblock;
  182. struct buffer_head *dbh = NULL;
  183. kernel_lb_addr eloc;
  184. uint32_t elen;
  185. uint8_t alloctype;
  186. struct extent_position epos;
  187. struct udf_fileident_bh sfibh, dfibh;
  188. loff_t f_pos = udf_ext0_offset(inode) >> 2;
  189. int size = (udf_ext0_offset(inode) + inode->i_size) >> 2;
  190. struct fileIdentDesc cfi, *sfi, *dfi;
  191. if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_SHORT_AD))
  192. alloctype = ICBTAG_FLAG_AD_SHORT;
  193. else
  194. alloctype = ICBTAG_FLAG_AD_LONG;
  195. if (!inode->i_size)
  196. {
  197. UDF_I_ALLOCTYPE(inode) = alloctype;
  198. mark_inode_dirty(inode);
  199. return NULL;
  200. }
  201. /* alloc block, and copy data to it */
  202. *block = udf_new_block(inode->i_sb, inode,
  203. UDF_I_LOCATION(inode).partitionReferenceNum,
  204. UDF_I_LOCATION(inode).logicalBlockNum, err);
  205. if (!(*block))
  206. return NULL;
  207. newblock = udf_get_pblock(inode->i_sb, *block,
  208. UDF_I_LOCATION(inode).partitionReferenceNum, 0);
  209. if (!newblock)
  210. return NULL;
  211. dbh = udf_tgetblk(inode->i_sb, newblock);
  212. if (!dbh)
  213. return NULL;
  214. lock_buffer(dbh);
  215. memset(dbh->b_data, 0x00, inode->i_sb->s_blocksize);
  216. set_buffer_uptodate(dbh);
  217. unlock_buffer(dbh);
  218. mark_buffer_dirty_inode(dbh, inode);
  219. sfibh.soffset = sfibh.eoffset = (f_pos & ((inode->i_sb->s_blocksize - 1) >> 2)) << 2;
  220. sfibh.sbh = sfibh.ebh = NULL;
  221. dfibh.soffset = dfibh.eoffset = 0;
  222. dfibh.sbh = dfibh.ebh = dbh;
  223. while ( (f_pos < size) )
  224. {
  225. UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_IN_ICB;
  226. sfi = udf_fileident_read(inode, &f_pos, &sfibh, &cfi, NULL, NULL, NULL, NULL);
  227. if (!sfi)
  228. {
  229. brelse(dbh);
  230. return NULL;
  231. }
  232. UDF_I_ALLOCTYPE(inode) = alloctype;
  233. sfi->descTag.tagLocation = cpu_to_le32(*block);
  234. dfibh.soffset = dfibh.eoffset;
  235. dfibh.eoffset += (sfibh.eoffset - sfibh.soffset);
  236. dfi = (struct fileIdentDesc *)(dbh->b_data + dfibh.soffset);
  237. if (udf_write_fi(inode, sfi, dfi, &dfibh, sfi->impUse,
  238. sfi->fileIdent + le16_to_cpu(sfi->lengthOfImpUse)))
  239. {
  240. UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_IN_ICB;
  241. brelse(dbh);
  242. return NULL;
  243. }
  244. }
  245. mark_buffer_dirty_inode(dbh, inode);
  246. memset(UDF_I_DATA(inode) + UDF_I_LENEATTR(inode), 0, UDF_I_LENALLOC(inode));
  247. UDF_I_LENALLOC(inode) = 0;
  248. eloc.logicalBlockNum = *block;
  249. eloc.partitionReferenceNum = UDF_I_LOCATION(inode).partitionReferenceNum;
  250. elen = inode->i_size;
  251. UDF_I_LENEXTENTS(inode) = elen;
  252. epos.bh = NULL;
  253. epos.block = UDF_I_LOCATION(inode);
  254. epos.offset = udf_file_entry_alloc_offset(inode);
  255. udf_add_aext(inode, &epos, eloc, elen, 0);
  256. /* UniqueID stuff */
  257. brelse(epos.bh);
  258. mark_inode_dirty(inode);
  259. return dbh;
  260. }
  261. static int udf_get_block(struct inode *inode, sector_t block, struct buffer_head *bh_result, int create)
  262. {
  263. int err, new;
  264. struct buffer_head *bh;
  265. unsigned long phys;
  266. if (!create)
  267. {
  268. phys = udf_block_map(inode, block);
  269. if (phys)
  270. map_bh(bh_result, inode->i_sb, phys);
  271. return 0;
  272. }
  273. err = -EIO;
  274. new = 0;
  275. bh = NULL;
  276. lock_kernel();
  277. if (block < 0)
  278. goto abort_negative;
  279. if (block == UDF_I_NEXT_ALLOC_BLOCK(inode) + 1)
  280. {
  281. UDF_I_NEXT_ALLOC_BLOCK(inode) ++;
  282. UDF_I_NEXT_ALLOC_GOAL(inode) ++;
  283. }
  284. err = 0;
  285. bh = inode_getblk(inode, block, &err, &phys, &new);
  286. BUG_ON(bh);
  287. if (err)
  288. goto abort;
  289. BUG_ON(!phys);
  290. if (new)
  291. set_buffer_new(bh_result);
  292. map_bh(bh_result, inode->i_sb, phys);
  293. abort:
  294. unlock_kernel();
  295. return err;
  296. abort_negative:
  297. udf_warning(inode->i_sb, "udf_get_block", "block < 0");
  298. goto abort;
  299. }
  300. static struct buffer_head *
  301. udf_getblk(struct inode *inode, long block, int create, int *err)
  302. {
  303. struct buffer_head dummy;
  304. dummy.b_state = 0;
  305. dummy.b_blocknr = -1000;
  306. *err = udf_get_block(inode, block, &dummy, create);
  307. if (!*err && buffer_mapped(&dummy))
  308. {
  309. struct buffer_head *bh;
  310. bh = sb_getblk(inode->i_sb, dummy.b_blocknr);
  311. if (buffer_new(&dummy))
  312. {
  313. lock_buffer(bh);
  314. memset(bh->b_data, 0x00, inode->i_sb->s_blocksize);
  315. set_buffer_uptodate(bh);
  316. unlock_buffer(bh);
  317. mark_buffer_dirty_inode(bh, inode);
  318. }
  319. return bh;
  320. }
  321. return NULL;
  322. }
  323. /* Extend the file by 'blocks' blocks, return the number of extents added */
  324. int udf_extend_file(struct inode *inode, struct extent_position *last_pos,
  325. kernel_long_ad *last_ext, sector_t blocks)
  326. {
  327. sector_t add;
  328. int count = 0, fake = !(last_ext->extLength & UDF_EXTENT_LENGTH_MASK);
  329. struct super_block *sb = inode->i_sb;
  330. kernel_lb_addr prealloc_loc = {0, 0};
  331. int prealloc_len = 0;
  332. /* The previous extent is fake and we should not extend by anything
  333. * - there's nothing to do... */
  334. if (!blocks && fake)
  335. return 0;
  336. /* Round the last extent up to a multiple of block size */
  337. if (last_ext->extLength & (sb->s_blocksize - 1)) {
  338. last_ext->extLength =
  339. (last_ext->extLength & UDF_EXTENT_FLAG_MASK) |
  340. (((last_ext->extLength & UDF_EXTENT_LENGTH_MASK) +
  341. sb->s_blocksize - 1) & ~(sb->s_blocksize - 1));
  342. UDF_I_LENEXTENTS(inode) =
  343. (UDF_I_LENEXTENTS(inode) + sb->s_blocksize - 1) &
  344. ~(sb->s_blocksize - 1);
  345. }
  346. /* Last extent are just preallocated blocks? */
  347. if ((last_ext->extLength & UDF_EXTENT_FLAG_MASK) == EXT_NOT_RECORDED_ALLOCATED) {
  348. /* Save the extent so that we can reattach it to the end */
  349. prealloc_loc = last_ext->extLocation;
  350. prealloc_len = last_ext->extLength;
  351. /* Mark the extent as a hole */
  352. last_ext->extLength = EXT_NOT_RECORDED_NOT_ALLOCATED |
  353. (last_ext->extLength & UDF_EXTENT_LENGTH_MASK);
  354. last_ext->extLocation.logicalBlockNum = 0;
  355. last_ext->extLocation.partitionReferenceNum = 0;
  356. }
  357. /* Can we merge with the previous extent? */
  358. if ((last_ext->extLength & UDF_EXTENT_FLAG_MASK) == EXT_NOT_RECORDED_NOT_ALLOCATED) {
  359. add = ((1<<30) - sb->s_blocksize - (last_ext->extLength &
  360. UDF_EXTENT_LENGTH_MASK)) >> sb->s_blocksize_bits;
  361. if (add > blocks)
  362. add = blocks;
  363. blocks -= add;
  364. last_ext->extLength += add << sb->s_blocksize_bits;
  365. }
  366. if (fake) {
  367. udf_add_aext(inode, last_pos, last_ext->extLocation,
  368. last_ext->extLength, 1);
  369. count++;
  370. }
  371. else
  372. udf_write_aext(inode, last_pos, last_ext->extLocation, last_ext->extLength, 1);
  373. /* Managed to do everything necessary? */
  374. if (!blocks)
  375. goto out;
  376. /* All further extents will be NOT_RECORDED_NOT_ALLOCATED */
  377. last_ext->extLocation.logicalBlockNum = 0;
  378. last_ext->extLocation.partitionReferenceNum = 0;
  379. add = (1 << (30-sb->s_blocksize_bits)) - 1;
  380. last_ext->extLength = EXT_NOT_RECORDED_NOT_ALLOCATED | (add << sb->s_blocksize_bits);
  381. /* Create enough extents to cover the whole hole */
  382. while (blocks > add) {
  383. blocks -= add;
  384. if (udf_add_aext(inode, last_pos, last_ext->extLocation,
  385. last_ext->extLength, 1) == -1)
  386. return -1;
  387. count++;
  388. }
  389. if (blocks) {
  390. last_ext->extLength = EXT_NOT_RECORDED_NOT_ALLOCATED |
  391. (blocks << sb->s_blocksize_bits);
  392. if (udf_add_aext(inode, last_pos, last_ext->extLocation,
  393. last_ext->extLength, 1) == -1)
  394. return -1;
  395. count++;
  396. }
  397. out:
  398. /* Do we have some preallocated blocks saved? */
  399. if (prealloc_len) {
  400. if (udf_add_aext(inode, last_pos, prealloc_loc, prealloc_len, 1) == -1)
  401. return -1;
  402. last_ext->extLocation = prealloc_loc;
  403. last_ext->extLength = prealloc_len;
  404. count++;
  405. }
  406. /* last_pos should point to the last written extent... */
  407. if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_SHORT)
  408. last_pos->offset -= sizeof(short_ad);
  409. else if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_LONG)
  410. last_pos->offset -= sizeof(long_ad);
  411. else
  412. return -1;
  413. return count;
  414. }
  415. static struct buffer_head * inode_getblk(struct inode * inode, sector_t block,
  416. int *err, long *phys, int *new)
  417. {
  418. static sector_t last_block;
  419. struct buffer_head *result = NULL;
  420. kernel_long_ad laarr[EXTENT_MERGE_SIZE];
  421. struct extent_position prev_epos, cur_epos, next_epos;
  422. int count = 0, startnum = 0, endnum = 0;
  423. uint32_t elen = 0, tmpelen;
  424. kernel_lb_addr eloc, tmpeloc;
  425. int c = 1;
  426. loff_t lbcount = 0, b_off = 0;
  427. uint32_t newblocknum, newblock;
  428. sector_t offset = 0;
  429. int8_t etype;
  430. int goal = 0, pgoal = UDF_I_LOCATION(inode).logicalBlockNum;
  431. int lastblock = 0;
  432. prev_epos.offset = udf_file_entry_alloc_offset(inode);
  433. prev_epos.block = UDF_I_LOCATION(inode);
  434. prev_epos.bh = NULL;
  435. cur_epos = next_epos = prev_epos;
  436. b_off = (loff_t)block << inode->i_sb->s_blocksize_bits;
  437. /* find the extent which contains the block we are looking for.
  438. alternate between laarr[0] and laarr[1] for locations of the
  439. current extent, and the previous extent */
  440. do
  441. {
  442. if (prev_epos.bh != cur_epos.bh)
  443. {
  444. brelse(prev_epos.bh);
  445. get_bh(cur_epos.bh);
  446. prev_epos.bh = cur_epos.bh;
  447. }
  448. if (cur_epos.bh != next_epos.bh)
  449. {
  450. brelse(cur_epos.bh);
  451. get_bh(next_epos.bh);
  452. cur_epos.bh = next_epos.bh;
  453. }
  454. lbcount += elen;
  455. prev_epos.block = cur_epos.block;
  456. cur_epos.block = next_epos.block;
  457. prev_epos.offset = cur_epos.offset;
  458. cur_epos.offset = next_epos.offset;
  459. if ((etype = udf_next_aext(inode, &next_epos, &eloc, &elen, 1)) == -1)
  460. break;
  461. c = !c;
  462. laarr[c].extLength = (etype << 30) | elen;
  463. laarr[c].extLocation = eloc;
  464. if (etype != (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30))
  465. pgoal = eloc.logicalBlockNum +
  466. ((elen + inode->i_sb->s_blocksize - 1) >>
  467. inode->i_sb->s_blocksize_bits);
  468. count ++;
  469. } while (lbcount + elen <= b_off);
  470. b_off -= lbcount;
  471. offset = b_off >> inode->i_sb->s_blocksize_bits;
  472. /*
  473. * Move prev_epos and cur_epos into indirect extent if we are at
  474. * the pointer to it
  475. */
  476. udf_next_aext(inode, &prev_epos, &tmpeloc, &tmpelen, 0);
  477. udf_next_aext(inode, &cur_epos, &tmpeloc, &tmpelen, 0);
  478. /* if the extent is allocated and recorded, return the block
  479. if the extent is not a multiple of the blocksize, round up */
  480. if (etype == (EXT_RECORDED_ALLOCATED >> 30))
  481. {
  482. if (elen & (inode->i_sb->s_blocksize - 1))
  483. {
  484. elen = EXT_RECORDED_ALLOCATED |
  485. ((elen + inode->i_sb->s_blocksize - 1) &
  486. ~(inode->i_sb->s_blocksize - 1));
  487. etype = udf_write_aext(inode, &cur_epos, eloc, elen, 1);
  488. }
  489. brelse(prev_epos.bh);
  490. brelse(cur_epos.bh);
  491. brelse(next_epos.bh);
  492. newblock = udf_get_lb_pblock(inode->i_sb, eloc, offset);
  493. *phys = newblock;
  494. return NULL;
  495. }
  496. last_block = block;
  497. /* Are we beyond EOF? */
  498. if (etype == -1)
  499. {
  500. int ret;
  501. if (count) {
  502. if (c)
  503. laarr[0] = laarr[1];
  504. startnum = 1;
  505. }
  506. else {
  507. /* Create a fake extent when there's not one */
  508. memset(&laarr[0].extLocation, 0x00, sizeof(kernel_lb_addr));
  509. laarr[0].extLength = EXT_NOT_RECORDED_NOT_ALLOCATED;
  510. /* Will udf_extend_file() create real extent from a fake one? */
  511. startnum = (offset > 0);
  512. }
  513. /* Create extents for the hole between EOF and offset */
  514. ret = udf_extend_file(inode, &prev_epos, laarr, offset);
  515. if (ret == -1) {
  516. brelse(prev_epos.bh);
  517. brelse(cur_epos.bh);
  518. brelse(next_epos.bh);
  519. /* We don't really know the error here so we just make
  520. * something up */
  521. *err = -ENOSPC;
  522. return NULL;
  523. }
  524. c = 0;
  525. offset = 0;
  526. count += ret;
  527. /* We are not covered by a preallocated extent? */
  528. if ((laarr[0].extLength & UDF_EXTENT_FLAG_MASK) != EXT_NOT_RECORDED_ALLOCATED) {
  529. /* Is there any real extent? - otherwise we overwrite
  530. * the fake one... */
  531. if (count)
  532. c = !c;
  533. laarr[c].extLength = EXT_NOT_RECORDED_NOT_ALLOCATED |
  534. inode->i_sb->s_blocksize;
  535. memset(&laarr[c].extLocation, 0x00, sizeof(kernel_lb_addr));
  536. count ++;
  537. endnum ++;
  538. }
  539. endnum = c+1;
  540. lastblock = 1;
  541. }
  542. else {
  543. endnum = startnum = ((count > 2) ? 2 : count);
  544. /* if the current extent is in position 0, swap it with the previous */
  545. if (!c && count != 1)
  546. {
  547. laarr[2] = laarr[0];
  548. laarr[0] = laarr[1];
  549. laarr[1] = laarr[2];
  550. c = 1;
  551. }
  552. /* if the current block is located in an extent, read the next extent */
  553. if ((etype = udf_next_aext(inode, &next_epos, &eloc, &elen, 0)) != -1)
  554. {
  555. laarr[c+1].extLength = (etype << 30) | elen;
  556. laarr[c+1].extLocation = eloc;
  557. count ++;
  558. startnum ++;
  559. endnum ++;
  560. }
  561. else {
  562. lastblock = 1;
  563. }
  564. }
  565. /* if the current extent is not recorded but allocated, get the
  566. block in the extent corresponding to the requested block */
  567. if ((laarr[c].extLength >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30))
  568. newblocknum = laarr[c].extLocation.logicalBlockNum + offset;
  569. else /* otherwise, allocate a new block */
  570. {
  571. if (UDF_I_NEXT_ALLOC_BLOCK(inode) == block)
  572. goal = UDF_I_NEXT_ALLOC_GOAL(inode);
  573. if (!goal)
  574. {
  575. if (!(goal = pgoal))
  576. goal = UDF_I_LOCATION(inode).logicalBlockNum + 1;
  577. }
  578. if (!(newblocknum = udf_new_block(inode->i_sb, inode,
  579. UDF_I_LOCATION(inode).partitionReferenceNum, goal, err)))
  580. {
  581. brelse(prev_epos.bh);
  582. *err = -ENOSPC;
  583. return NULL;
  584. }
  585. UDF_I_LENEXTENTS(inode) += inode->i_sb->s_blocksize;
  586. }
  587. /* if the extent the requsted block is located in contains multiple blocks,
  588. split the extent into at most three extents. blocks prior to requested
  589. block, requested block, and blocks after requested block */
  590. udf_split_extents(inode, &c, offset, newblocknum, laarr, &endnum);
  591. #ifdef UDF_PREALLOCATE
  592. /* preallocate blocks */
  593. udf_prealloc_extents(inode, c, lastblock, laarr, &endnum);
  594. #endif
  595. /* merge any continuous blocks in laarr */
  596. udf_merge_extents(inode, laarr, &endnum);
  597. /* write back the new extents, inserting new extents if the new number
  598. of extents is greater than the old number, and deleting extents if
  599. the new number of extents is less than the old number */
  600. udf_update_extents(inode, laarr, startnum, endnum, &prev_epos);
  601. brelse(prev_epos.bh);
  602. if (!(newblock = udf_get_pblock(inode->i_sb, newblocknum,
  603. UDF_I_LOCATION(inode).partitionReferenceNum, 0)))
  604. {
  605. return NULL;
  606. }
  607. *phys = newblock;
  608. *err = 0;
  609. *new = 1;
  610. UDF_I_NEXT_ALLOC_BLOCK(inode) = block;
  611. UDF_I_NEXT_ALLOC_GOAL(inode) = newblocknum;
  612. inode->i_ctime = current_fs_time(inode->i_sb);
  613. if (IS_SYNC(inode))
  614. udf_sync_inode(inode);
  615. else
  616. mark_inode_dirty(inode);
  617. return result;
  618. }
  619. static void udf_split_extents(struct inode *inode, int *c, int offset, int newblocknum,
  620. kernel_long_ad laarr[EXTENT_MERGE_SIZE], int *endnum)
  621. {
  622. if ((laarr[*c].extLength >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30) ||
  623. (laarr[*c].extLength >> 30) == (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30))
  624. {
  625. int curr = *c;
  626. int blen = ((laarr[curr].extLength & UDF_EXTENT_LENGTH_MASK) +
  627. inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits;
  628. int8_t etype = (laarr[curr].extLength >> 30);
  629. if (blen == 1)
  630. ;
  631. else if (!offset || blen == offset + 1)
  632. {
  633. laarr[curr+2] = laarr[curr+1];
  634. laarr[curr+1] = laarr[curr];
  635. }
  636. else
  637. {
  638. laarr[curr+3] = laarr[curr+1];
  639. laarr[curr+2] = laarr[curr+1] = laarr[curr];
  640. }
  641. if (offset)
  642. {
  643. if (etype == (EXT_NOT_RECORDED_ALLOCATED >> 30))
  644. {
  645. udf_free_blocks(inode->i_sb, inode, laarr[curr].extLocation, 0, offset);
  646. laarr[curr].extLength = EXT_NOT_RECORDED_NOT_ALLOCATED |
  647. (offset << inode->i_sb->s_blocksize_bits);
  648. laarr[curr].extLocation.logicalBlockNum = 0;
  649. laarr[curr].extLocation.partitionReferenceNum = 0;
  650. }
  651. else
  652. laarr[curr].extLength = (etype << 30) |
  653. (offset << inode->i_sb->s_blocksize_bits);
  654. curr ++;
  655. (*c) ++;
  656. (*endnum) ++;
  657. }
  658. laarr[curr].extLocation.logicalBlockNum = newblocknum;
  659. if (etype == (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30))
  660. laarr[curr].extLocation.partitionReferenceNum =
  661. UDF_I_LOCATION(inode).partitionReferenceNum;
  662. laarr[curr].extLength = EXT_RECORDED_ALLOCATED |
  663. inode->i_sb->s_blocksize;
  664. curr ++;
  665. if (blen != offset + 1)
  666. {
  667. if (etype == (EXT_NOT_RECORDED_ALLOCATED >> 30))
  668. laarr[curr].extLocation.logicalBlockNum += (offset + 1);
  669. laarr[curr].extLength = (etype << 30) |
  670. ((blen - (offset + 1)) << inode->i_sb->s_blocksize_bits);
  671. curr ++;
  672. (*endnum) ++;
  673. }
  674. }
  675. }
  676. static void udf_prealloc_extents(struct inode *inode, int c, int lastblock,
  677. kernel_long_ad laarr[EXTENT_MERGE_SIZE], int *endnum)
  678. {
  679. int start, length = 0, currlength = 0, i;
  680. if (*endnum >= (c+1))
  681. {
  682. if (!lastblock)
  683. return;
  684. else
  685. start = c;
  686. }
  687. else
  688. {
  689. if ((laarr[c+1].extLength >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30))
  690. {
  691. start = c+1;
  692. length = currlength = (((laarr[c+1].extLength & UDF_EXTENT_LENGTH_MASK) +
  693. inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits);
  694. }
  695. else
  696. start = c;
  697. }
  698. for (i=start+1; i<=*endnum; i++)
  699. {
  700. if (i == *endnum)
  701. {
  702. if (lastblock)
  703. length += UDF_DEFAULT_PREALLOC_BLOCKS;
  704. }
  705. else if ((laarr[i].extLength >> 30) == (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30))
  706. length += (((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) +
  707. inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits);
  708. else
  709. break;
  710. }
  711. if (length)
  712. {
  713. int next = laarr[start].extLocation.logicalBlockNum +
  714. (((laarr[start].extLength & UDF_EXTENT_LENGTH_MASK) +
  715. inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits);
  716. int numalloc = udf_prealloc_blocks(inode->i_sb, inode,
  717. laarr[start].extLocation.partitionReferenceNum,
  718. next, (UDF_DEFAULT_PREALLOC_BLOCKS > length ? length :
  719. UDF_DEFAULT_PREALLOC_BLOCKS) - currlength);
  720. if (numalloc)
  721. {
  722. if (start == (c+1))
  723. laarr[start].extLength +=
  724. (numalloc << inode->i_sb->s_blocksize_bits);
  725. else
  726. {
  727. memmove(&laarr[c+2], &laarr[c+1],
  728. sizeof(long_ad) * (*endnum - (c+1)));
  729. (*endnum) ++;
  730. laarr[c+1].extLocation.logicalBlockNum = next;
  731. laarr[c+1].extLocation.partitionReferenceNum =
  732. laarr[c].extLocation.partitionReferenceNum;
  733. laarr[c+1].extLength = EXT_NOT_RECORDED_ALLOCATED |
  734. (numalloc << inode->i_sb->s_blocksize_bits);
  735. start = c+1;
  736. }
  737. for (i=start+1; numalloc && i<*endnum; i++)
  738. {
  739. int elen = ((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) +
  740. inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits;
  741. if (elen > numalloc)
  742. {
  743. laarr[i].extLength -=
  744. (numalloc << inode->i_sb->s_blocksize_bits);
  745. numalloc = 0;
  746. }
  747. else
  748. {
  749. numalloc -= elen;
  750. if (*endnum > (i+1))
  751. memmove(&laarr[i], &laarr[i+1],
  752. sizeof(long_ad) * (*endnum - (i+1)));
  753. i --;
  754. (*endnum) --;
  755. }
  756. }
  757. UDF_I_LENEXTENTS(inode) += numalloc << inode->i_sb->s_blocksize_bits;
  758. }
  759. }
  760. }
  761. static void udf_merge_extents(struct inode *inode,
  762. kernel_long_ad laarr[EXTENT_MERGE_SIZE], int *endnum)
  763. {
  764. int i;
  765. for (i=0; i<(*endnum-1); i++)
  766. {
  767. if ((laarr[i].extLength >> 30) == (laarr[i+1].extLength >> 30))
  768. {
  769. if (((laarr[i].extLength >> 30) == (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30)) ||
  770. ((laarr[i+1].extLocation.logicalBlockNum - laarr[i].extLocation.logicalBlockNum) ==
  771. (((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) +
  772. inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits)))
  773. {
  774. if (((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) +
  775. (laarr[i+1].extLength & UDF_EXTENT_LENGTH_MASK) +
  776. inode->i_sb->s_blocksize - 1) & ~UDF_EXTENT_LENGTH_MASK)
  777. {
  778. laarr[i+1].extLength = (laarr[i+1].extLength -
  779. (laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) +
  780. UDF_EXTENT_LENGTH_MASK) & ~(inode->i_sb->s_blocksize-1);
  781. laarr[i].extLength = (laarr[i].extLength & UDF_EXTENT_FLAG_MASK) +
  782. (UDF_EXTENT_LENGTH_MASK + 1) - inode->i_sb->s_blocksize;
  783. laarr[i+1].extLocation.logicalBlockNum =
  784. laarr[i].extLocation.logicalBlockNum +
  785. ((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) >>
  786. inode->i_sb->s_blocksize_bits);
  787. }
  788. else
  789. {
  790. laarr[i].extLength = laarr[i+1].extLength +
  791. (((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) +
  792. inode->i_sb->s_blocksize - 1) & ~(inode->i_sb->s_blocksize-1));
  793. if (*endnum > (i+2))
  794. memmove(&laarr[i+1], &laarr[i+2],
  795. sizeof(long_ad) * (*endnum - (i+2)));
  796. i --;
  797. (*endnum) --;
  798. }
  799. }
  800. }
  801. else if (((laarr[i].extLength >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30)) &&
  802. ((laarr[i+1].extLength >> 30) == (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30)))
  803. {
  804. udf_free_blocks(inode->i_sb, inode, laarr[i].extLocation, 0,
  805. ((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) +
  806. inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits);
  807. laarr[i].extLocation.logicalBlockNum = 0;
  808. laarr[i].extLocation.partitionReferenceNum = 0;
  809. if (((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) +
  810. (laarr[i+1].extLength & UDF_EXTENT_LENGTH_MASK) +
  811. inode->i_sb->s_blocksize - 1) & ~UDF_EXTENT_LENGTH_MASK)
  812. {
  813. laarr[i+1].extLength = (laarr[i+1].extLength -
  814. (laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) +
  815. UDF_EXTENT_LENGTH_MASK) & ~(inode->i_sb->s_blocksize-1);
  816. laarr[i].extLength = (laarr[i].extLength & UDF_EXTENT_FLAG_MASK) +
  817. (UDF_EXTENT_LENGTH_MASK + 1) - inode->i_sb->s_blocksize;
  818. }
  819. else
  820. {
  821. laarr[i].extLength = laarr[i+1].extLength +
  822. (((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) +
  823. inode->i_sb->s_blocksize - 1) & ~(inode->i_sb->s_blocksize-1));
  824. if (*endnum > (i+2))
  825. memmove(&laarr[i+1], &laarr[i+2],
  826. sizeof(long_ad) * (*endnum - (i+2)));
  827. i --;
  828. (*endnum) --;
  829. }
  830. }
  831. else if ((laarr[i].extLength >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30))
  832. {
  833. udf_free_blocks(inode->i_sb, inode, laarr[i].extLocation, 0,
  834. ((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) +
  835. inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits);
  836. laarr[i].extLocation.logicalBlockNum = 0;
  837. laarr[i].extLocation.partitionReferenceNum = 0;
  838. laarr[i].extLength = (laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) |
  839. EXT_NOT_RECORDED_NOT_ALLOCATED;
  840. }
  841. }
  842. }
  843. static void udf_update_extents(struct inode *inode,
  844. kernel_long_ad laarr[EXTENT_MERGE_SIZE], int startnum, int endnum,
  845. struct extent_position *epos)
  846. {
  847. int start = 0, i;
  848. kernel_lb_addr tmploc;
  849. uint32_t tmplen;
  850. if (startnum > endnum)
  851. {
  852. for (i=0; i<(startnum-endnum); i++)
  853. udf_delete_aext(inode, *epos, laarr[i].extLocation,
  854. laarr[i].extLength);
  855. }
  856. else if (startnum < endnum)
  857. {
  858. for (i=0; i<(endnum-startnum); i++)
  859. {
  860. udf_insert_aext(inode, *epos, laarr[i].extLocation,
  861. laarr[i].extLength);
  862. udf_next_aext(inode, epos, &laarr[i].extLocation,
  863. &laarr[i].extLength, 1);
  864. start ++;
  865. }
  866. }
  867. for (i=start; i<endnum; i++)
  868. {
  869. udf_next_aext(inode, epos, &tmploc, &tmplen, 0);
  870. udf_write_aext(inode, epos, laarr[i].extLocation,
  871. laarr[i].extLength, 1);
  872. }
  873. }
  874. struct buffer_head * udf_bread(struct inode * inode, int block,
  875. int create, int * err)
  876. {
  877. struct buffer_head * bh = NULL;
  878. bh = udf_getblk(inode, block, create, err);
  879. if (!bh)
  880. return NULL;
  881. if (buffer_uptodate(bh))
  882. return bh;
  883. ll_rw_block(READ, 1, &bh);
  884. wait_on_buffer(bh);
  885. if (buffer_uptodate(bh))
  886. return bh;
  887. brelse(bh);
  888. *err = -EIO;
  889. return NULL;
  890. }
  891. void udf_truncate(struct inode * inode)
  892. {
  893. int offset;
  894. int err;
  895. if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
  896. S_ISLNK(inode->i_mode)))
  897. return;
  898. if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
  899. return;
  900. lock_kernel();
  901. if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB)
  902. {
  903. if (inode->i_sb->s_blocksize < (udf_file_entry_alloc_offset(inode) +
  904. inode->i_size))
  905. {
  906. udf_expand_file_adinicb(inode, inode->i_size, &err);
  907. if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB)
  908. {
  909. inode->i_size = UDF_I_LENALLOC(inode);
  910. unlock_kernel();
  911. return;
  912. }
  913. else
  914. udf_truncate_extents(inode);
  915. }
  916. else
  917. {
  918. offset = inode->i_size & (inode->i_sb->s_blocksize - 1);
  919. memset(UDF_I_DATA(inode) + UDF_I_LENEATTR(inode) + offset, 0x00, inode->i_sb->s_blocksize - offset - udf_file_entry_alloc_offset(inode));
  920. UDF_I_LENALLOC(inode) = inode->i_size;
  921. }
  922. }
  923. else
  924. {
  925. block_truncate_page(inode->i_mapping, inode->i_size, udf_get_block);
  926. udf_truncate_extents(inode);
  927. }
  928. inode->i_mtime = inode->i_ctime = current_fs_time(inode->i_sb);
  929. if (IS_SYNC(inode))
  930. udf_sync_inode (inode);
  931. else
  932. mark_inode_dirty(inode);
  933. unlock_kernel();
  934. }
  935. static void
  936. __udf_read_inode(struct inode *inode)
  937. {
  938. struct buffer_head *bh = NULL;
  939. struct fileEntry *fe;
  940. uint16_t ident;
  941. /*
  942. * Set defaults, but the inode is still incomplete!
  943. * Note: get_new_inode() sets the following on a new inode:
  944. * i_sb = sb
  945. * i_no = ino
  946. * i_flags = sb->s_flags
  947. * i_state = 0
  948. * clean_inode(): zero fills and sets
  949. * i_count = 1
  950. * i_nlink = 1
  951. * i_op = NULL;
  952. */
  953. bh = udf_read_ptagged(inode->i_sb, UDF_I_LOCATION(inode), 0, &ident);
  954. if (!bh)
  955. {
  956. printk(KERN_ERR "udf: udf_read_inode(ino %ld) failed !bh\n",
  957. inode->i_ino);
  958. make_bad_inode(inode);
  959. return;
  960. }
  961. if (ident != TAG_IDENT_FE && ident != TAG_IDENT_EFE &&
  962. ident != TAG_IDENT_USE)
  963. {
  964. printk(KERN_ERR "udf: udf_read_inode(ino %ld) failed ident=%d\n",
  965. inode->i_ino, ident);
  966. brelse(bh);
  967. make_bad_inode(inode);
  968. return;
  969. }
  970. fe = (struct fileEntry *)bh->b_data;
  971. if (le16_to_cpu(fe->icbTag.strategyType) == 4096)
  972. {
  973. struct buffer_head *ibh = NULL, *nbh = NULL;
  974. struct indirectEntry *ie;
  975. ibh = udf_read_ptagged(inode->i_sb, UDF_I_LOCATION(inode), 1, &ident);
  976. if (ident == TAG_IDENT_IE)
  977. {
  978. if (ibh)
  979. {
  980. kernel_lb_addr loc;
  981. ie = (struct indirectEntry *)ibh->b_data;
  982. loc = lelb_to_cpu(ie->indirectICB.extLocation);
  983. if (ie->indirectICB.extLength &&
  984. (nbh = udf_read_ptagged(inode->i_sb, loc, 0, &ident)))
  985. {
  986. if (ident == TAG_IDENT_FE ||
  987. ident == TAG_IDENT_EFE)
  988. {
  989. memcpy(&UDF_I_LOCATION(inode), &loc, sizeof(kernel_lb_addr));
  990. brelse(bh);
  991. brelse(ibh);
  992. brelse(nbh);
  993. __udf_read_inode(inode);
  994. return;
  995. }
  996. else
  997. {
  998. brelse(nbh);
  999. brelse(ibh);
  1000. }
  1001. }
  1002. else
  1003. brelse(ibh);
  1004. }
  1005. }
  1006. else
  1007. brelse(ibh);
  1008. }
  1009. else if (le16_to_cpu(fe->icbTag.strategyType) != 4)
  1010. {
  1011. printk(KERN_ERR "udf: unsupported strategy type: %d\n",
  1012. le16_to_cpu(fe->icbTag.strategyType));
  1013. brelse(bh);
  1014. make_bad_inode(inode);
  1015. return;
  1016. }
  1017. udf_fill_inode(inode, bh);
  1018. brelse(bh);
  1019. }
  1020. static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
  1021. {
  1022. struct fileEntry *fe;
  1023. struct extendedFileEntry *efe;
  1024. time_t convtime;
  1025. long convtime_usec;
  1026. int offset;
  1027. fe = (struct fileEntry *)bh->b_data;
  1028. efe = (struct extendedFileEntry *)bh->b_data;
  1029. if (le16_to_cpu(fe->icbTag.strategyType) == 4)
  1030. UDF_I_STRAT4096(inode) = 0;
  1031. else /* if (le16_to_cpu(fe->icbTag.strategyType) == 4096) */
  1032. UDF_I_STRAT4096(inode) = 1;
  1033. UDF_I_ALLOCTYPE(inode) = le16_to_cpu(fe->icbTag.flags) & ICBTAG_FLAG_AD_MASK;
  1034. UDF_I_UNIQUE(inode) = 0;
  1035. UDF_I_LENEATTR(inode) = 0;
  1036. UDF_I_LENEXTENTS(inode) = 0;
  1037. UDF_I_LENALLOC(inode) = 0;
  1038. UDF_I_NEXT_ALLOC_BLOCK(inode) = 0;
  1039. UDF_I_NEXT_ALLOC_GOAL(inode) = 0;
  1040. if (le16_to_cpu(fe->descTag.tagIdent) == TAG_IDENT_EFE)
  1041. {
  1042. UDF_I_EFE(inode) = 1;
  1043. UDF_I_USE(inode) = 0;
  1044. UDF_I_DATA(inode) = kmalloc(inode->i_sb->s_blocksize - sizeof(struct extendedFileEntry), GFP_KERNEL);
  1045. memcpy(UDF_I_DATA(inode), bh->b_data + sizeof(struct extendedFileEntry), inode->i_sb->s_blocksize - sizeof(struct extendedFileEntry));
  1046. }
  1047. else if (le16_to_cpu(fe->descTag.tagIdent) == TAG_IDENT_FE)
  1048. {
  1049. UDF_I_EFE(inode) = 0;
  1050. UDF_I_USE(inode) = 0;
  1051. UDF_I_DATA(inode) = kmalloc(inode->i_sb->s_blocksize - sizeof(struct fileEntry), GFP_KERNEL);
  1052. memcpy(UDF_I_DATA(inode), bh->b_data + sizeof(struct fileEntry), inode->i_sb->s_blocksize - sizeof(struct fileEntry));
  1053. }
  1054. else if (le16_to_cpu(fe->descTag.tagIdent) == TAG_IDENT_USE)
  1055. {
  1056. UDF_I_EFE(inode) = 0;
  1057. UDF_I_USE(inode) = 1;
  1058. UDF_I_LENALLOC(inode) =
  1059. le32_to_cpu(
  1060. ((struct unallocSpaceEntry *)bh->b_data)->lengthAllocDescs);
  1061. UDF_I_DATA(inode) = kmalloc(inode->i_sb->s_blocksize - sizeof(struct unallocSpaceEntry), GFP_KERNEL);
  1062. memcpy(UDF_I_DATA(inode), bh->b_data + sizeof(struct unallocSpaceEntry), inode->i_sb->s_blocksize - sizeof(struct unallocSpaceEntry));
  1063. return;
  1064. }
  1065. inode->i_uid = le32_to_cpu(fe->uid);
  1066. if (inode->i_uid == -1 || UDF_QUERY_FLAG(inode->i_sb,
  1067. UDF_FLAG_UID_IGNORE))
  1068. inode->i_uid = UDF_SB(inode->i_sb)->s_uid;
  1069. inode->i_gid = le32_to_cpu(fe->gid);
  1070. if (inode->i_gid == -1 || UDF_QUERY_FLAG(inode->i_sb,
  1071. UDF_FLAG_GID_IGNORE))
  1072. inode->i_gid = UDF_SB(inode->i_sb)->s_gid;
  1073. inode->i_nlink = le16_to_cpu(fe->fileLinkCount);
  1074. if (!inode->i_nlink)
  1075. inode->i_nlink = 1;
  1076. inode->i_size = le64_to_cpu(fe->informationLength);
  1077. UDF_I_LENEXTENTS(inode) = inode->i_size;
  1078. inode->i_mode = udf_convert_permissions(fe);
  1079. inode->i_mode &= ~UDF_SB(inode->i_sb)->s_umask;
  1080. if (UDF_I_EFE(inode) == 0)
  1081. {
  1082. inode->i_blocks = le64_to_cpu(fe->logicalBlocksRecorded) <<
  1083. (inode->i_sb->s_blocksize_bits - 9);
  1084. if ( udf_stamp_to_time(&convtime, &convtime_usec,
  1085. lets_to_cpu(fe->accessTime)) )
  1086. {
  1087. inode->i_atime.tv_sec = convtime;
  1088. inode->i_atime.tv_nsec = convtime_usec * 1000;
  1089. }
  1090. else
  1091. {
  1092. inode->i_atime = UDF_SB_RECORDTIME(inode->i_sb);
  1093. }
  1094. if ( udf_stamp_to_time(&convtime, &convtime_usec,
  1095. lets_to_cpu(fe->modificationTime)) )
  1096. {
  1097. inode->i_mtime.tv_sec = convtime;
  1098. inode->i_mtime.tv_nsec = convtime_usec * 1000;
  1099. }
  1100. else
  1101. {
  1102. inode->i_mtime = UDF_SB_RECORDTIME(inode->i_sb);
  1103. }
  1104. if ( udf_stamp_to_time(&convtime, &convtime_usec,
  1105. lets_to_cpu(fe->attrTime)) )
  1106. {
  1107. inode->i_ctime.tv_sec = convtime;
  1108. inode->i_ctime.tv_nsec = convtime_usec * 1000;
  1109. }
  1110. else
  1111. {
  1112. inode->i_ctime = UDF_SB_RECORDTIME(inode->i_sb);
  1113. }
  1114. UDF_I_UNIQUE(inode) = le64_to_cpu(fe->uniqueID);
  1115. UDF_I_LENEATTR(inode) = le32_to_cpu(fe->lengthExtendedAttr);
  1116. UDF_I_LENALLOC(inode) = le32_to_cpu(fe->lengthAllocDescs);
  1117. offset = sizeof(struct fileEntry) + UDF_I_LENEATTR(inode);
  1118. }
  1119. else
  1120. {
  1121. inode->i_blocks = le64_to_cpu(efe->logicalBlocksRecorded) <<
  1122. (inode->i_sb->s_blocksize_bits - 9);
  1123. if ( udf_stamp_to_time(&convtime, &convtime_usec,
  1124. lets_to_cpu(efe->accessTime)) )
  1125. {
  1126. inode->i_atime.tv_sec = convtime;
  1127. inode->i_atime.tv_nsec = convtime_usec * 1000;
  1128. }
  1129. else
  1130. {
  1131. inode->i_atime = UDF_SB_RECORDTIME(inode->i_sb);
  1132. }
  1133. if ( udf_stamp_to_time(&convtime, &convtime_usec,
  1134. lets_to_cpu(efe->modificationTime)) )
  1135. {
  1136. inode->i_mtime.tv_sec = convtime;
  1137. inode->i_mtime.tv_nsec = convtime_usec * 1000;
  1138. }
  1139. else
  1140. {
  1141. inode->i_mtime = UDF_SB_RECORDTIME(inode->i_sb);
  1142. }
  1143. if ( udf_stamp_to_time(&convtime, &convtime_usec,
  1144. lets_to_cpu(efe->createTime)) )
  1145. {
  1146. UDF_I_CRTIME(inode).tv_sec = convtime;
  1147. UDF_I_CRTIME(inode).tv_nsec = convtime_usec * 1000;
  1148. }
  1149. else
  1150. {
  1151. UDF_I_CRTIME(inode) = UDF_SB_RECORDTIME(inode->i_sb);
  1152. }
  1153. if ( udf_stamp_to_time(&convtime, &convtime_usec,
  1154. lets_to_cpu(efe->attrTime)) )
  1155. {
  1156. inode->i_ctime.tv_sec = convtime;
  1157. inode->i_ctime.tv_nsec = convtime_usec * 1000;
  1158. }
  1159. else
  1160. {
  1161. inode->i_ctime = UDF_SB_RECORDTIME(inode->i_sb);
  1162. }
  1163. UDF_I_UNIQUE(inode) = le64_to_cpu(efe->uniqueID);
  1164. UDF_I_LENEATTR(inode) = le32_to_cpu(efe->lengthExtendedAttr);
  1165. UDF_I_LENALLOC(inode) = le32_to_cpu(efe->lengthAllocDescs);
  1166. offset = sizeof(struct extendedFileEntry) + UDF_I_LENEATTR(inode);
  1167. }
  1168. switch (fe->icbTag.fileType)
  1169. {
  1170. case ICBTAG_FILE_TYPE_DIRECTORY:
  1171. {
  1172. inode->i_op = &udf_dir_inode_operations;
  1173. inode->i_fop = &udf_dir_operations;
  1174. inode->i_mode |= S_IFDIR;
  1175. inc_nlink(inode);
  1176. break;
  1177. }
  1178. case ICBTAG_FILE_TYPE_REALTIME:
  1179. case ICBTAG_FILE_TYPE_REGULAR:
  1180. case ICBTAG_FILE_TYPE_UNDEF:
  1181. {
  1182. if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB)
  1183. inode->i_data.a_ops = &udf_adinicb_aops;
  1184. else
  1185. inode->i_data.a_ops = &udf_aops;
  1186. inode->i_op = &udf_file_inode_operations;
  1187. inode->i_fop = &udf_file_operations;
  1188. inode->i_mode |= S_IFREG;
  1189. break;
  1190. }
  1191. case ICBTAG_FILE_TYPE_BLOCK:
  1192. {
  1193. inode->i_mode |= S_IFBLK;
  1194. break;
  1195. }
  1196. case ICBTAG_FILE_TYPE_CHAR:
  1197. {
  1198. inode->i_mode |= S_IFCHR;
  1199. break;
  1200. }
  1201. case ICBTAG_FILE_TYPE_FIFO:
  1202. {
  1203. init_special_inode(inode, inode->i_mode | S_IFIFO, 0);
  1204. break;
  1205. }
  1206. case ICBTAG_FILE_TYPE_SOCKET:
  1207. {
  1208. init_special_inode(inode, inode->i_mode | S_IFSOCK, 0);
  1209. break;
  1210. }
  1211. case ICBTAG_FILE_TYPE_SYMLINK:
  1212. {
  1213. inode->i_data.a_ops = &udf_symlink_aops;
  1214. inode->i_op = &page_symlink_inode_operations;
  1215. inode->i_mode = S_IFLNK|S_IRWXUGO;
  1216. break;
  1217. }
  1218. default:
  1219. {
  1220. printk(KERN_ERR "udf: udf_fill_inode(ino %ld) failed unknown file type=%d\n",
  1221. inode->i_ino, fe->icbTag.fileType);
  1222. make_bad_inode(inode);
  1223. return;
  1224. }
  1225. }
  1226. if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
  1227. {
  1228. struct deviceSpec *dsea =
  1229. (struct deviceSpec *)
  1230. udf_get_extendedattr(inode, 12, 1);
  1231. if (dsea)
  1232. {
  1233. init_special_inode(inode, inode->i_mode, MKDEV(
  1234. le32_to_cpu(dsea->majorDeviceIdent),
  1235. le32_to_cpu(dsea->minorDeviceIdent)));
  1236. /* Developer ID ??? */
  1237. }
  1238. else
  1239. {
  1240. make_bad_inode(inode);
  1241. }
  1242. }
  1243. }
  1244. static mode_t
  1245. udf_convert_permissions(struct fileEntry *fe)
  1246. {
  1247. mode_t mode;
  1248. uint32_t permissions;
  1249. uint32_t flags;
  1250. permissions = le32_to_cpu(fe->permissions);
  1251. flags = le16_to_cpu(fe->icbTag.flags);
  1252. mode = (( permissions ) & S_IRWXO) |
  1253. (( permissions >> 2 ) & S_IRWXG) |
  1254. (( permissions >> 4 ) & S_IRWXU) |
  1255. (( flags & ICBTAG_FLAG_SETUID) ? S_ISUID : 0) |
  1256. (( flags & ICBTAG_FLAG_SETGID) ? S_ISGID : 0) |
  1257. (( flags & ICBTAG_FLAG_STICKY) ? S_ISVTX : 0);
  1258. return mode;
  1259. }
  1260. /*
  1261. * udf_write_inode
  1262. *
  1263. * PURPOSE
  1264. * Write out the specified inode.
  1265. *
  1266. * DESCRIPTION
  1267. * This routine is called whenever an inode is synced.
  1268. * Currently this routine is just a placeholder.
  1269. *
  1270. * HISTORY
  1271. * July 1, 1997 - Andrew E. Mileski
  1272. * Written, tested, and released.
  1273. */
  1274. int udf_write_inode(struct inode * inode, int sync)
  1275. {
  1276. int ret;
  1277. lock_kernel();
  1278. ret = udf_update_inode(inode, sync);
  1279. unlock_kernel();
  1280. return ret;
  1281. }
  1282. int udf_sync_inode(struct inode * inode)
  1283. {
  1284. return udf_update_inode(inode, 1);
  1285. }
  1286. static int
  1287. udf_update_inode(struct inode *inode, int do_sync)
  1288. {
  1289. struct buffer_head *bh = NULL;
  1290. struct fileEntry *fe;
  1291. struct extendedFileEntry *efe;
  1292. uint32_t udfperms;
  1293. uint16_t icbflags;
  1294. uint16_t crclen;
  1295. int i;
  1296. kernel_timestamp cpu_time;
  1297. int err = 0;
  1298. bh = udf_tread(inode->i_sb,
  1299. udf_get_lb_pblock(inode->i_sb, UDF_I_LOCATION(inode), 0));
  1300. if (!bh)
  1301. {
  1302. udf_debug("bread failure\n");
  1303. return -EIO;
  1304. }
  1305. memset(bh->b_data, 0x00, inode->i_sb->s_blocksize);
  1306. fe = (struct fileEntry *)bh->b_data;
  1307. efe = (struct extendedFileEntry *)bh->b_data;
  1308. if (le16_to_cpu(fe->descTag.tagIdent) == TAG_IDENT_USE)
  1309. {
  1310. struct unallocSpaceEntry *use =
  1311. (struct unallocSpaceEntry *)bh->b_data;
  1312. use->lengthAllocDescs = cpu_to_le32(UDF_I_LENALLOC(inode));
  1313. memcpy(bh->b_data + sizeof(struct unallocSpaceEntry), UDF_I_DATA(inode), inode->i_sb->s_blocksize - sizeof(struct unallocSpaceEntry));
  1314. crclen = sizeof(struct unallocSpaceEntry) + UDF_I_LENALLOC(inode) -
  1315. sizeof(tag);
  1316. use->descTag.tagLocation = cpu_to_le32(UDF_I_LOCATION(inode).logicalBlockNum);
  1317. use->descTag.descCRCLength = cpu_to_le16(crclen);
  1318. use->descTag.descCRC = cpu_to_le16(udf_crc((char *)use + sizeof(tag), crclen, 0));
  1319. use->descTag.tagChecksum = 0;
  1320. for (i=0; i<16; i++)
  1321. if (i != 4)
  1322. use->descTag.tagChecksum += ((uint8_t *)&(use->descTag))[i];
  1323. mark_buffer_dirty(bh);
  1324. brelse(bh);
  1325. return err;
  1326. }
  1327. if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_UID_FORGET))
  1328. fe->uid = cpu_to_le32(-1);
  1329. else fe->uid = cpu_to_le32(inode->i_uid);
  1330. if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_GID_FORGET))
  1331. fe->gid = cpu_to_le32(-1);
  1332. else fe->gid = cpu_to_le32(inode->i_gid);
  1333. udfperms = ((inode->i_mode & S_IRWXO) ) |
  1334. ((inode->i_mode & S_IRWXG) << 2) |
  1335. ((inode->i_mode & S_IRWXU) << 4);
  1336. udfperms |= (le32_to_cpu(fe->permissions) &
  1337. (FE_PERM_O_DELETE | FE_PERM_O_CHATTR |
  1338. FE_PERM_G_DELETE | FE_PERM_G_CHATTR |
  1339. FE_PERM_U_DELETE | FE_PERM_U_CHATTR));
  1340. fe->permissions = cpu_to_le32(udfperms);
  1341. if (S_ISDIR(inode->i_mode))
  1342. fe->fileLinkCount = cpu_to_le16(inode->i_nlink - 1);
  1343. else
  1344. fe->fileLinkCount = cpu_to_le16(inode->i_nlink);
  1345. fe->informationLength = cpu_to_le64(inode->i_size);
  1346. if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
  1347. {
  1348. regid *eid;
  1349. struct deviceSpec *dsea =
  1350. (struct deviceSpec *)
  1351. udf_get_extendedattr(inode, 12, 1);
  1352. if (!dsea)
  1353. {
  1354. dsea = (struct deviceSpec *)
  1355. udf_add_extendedattr(inode,
  1356. sizeof(struct deviceSpec) +
  1357. sizeof(regid), 12, 0x3);
  1358. dsea->attrType = cpu_to_le32(12);
  1359. dsea->attrSubtype = 1;
  1360. dsea->attrLength = cpu_to_le32(sizeof(struct deviceSpec) +
  1361. sizeof(regid));
  1362. dsea->impUseLength = cpu_to_le32(sizeof(regid));
  1363. }
  1364. eid = (regid *)dsea->impUse;
  1365. memset(eid, 0, sizeof(regid));
  1366. strcpy(eid->ident, UDF_ID_DEVELOPER);
  1367. eid->identSuffix[0] = UDF_OS_CLASS_UNIX;
  1368. eid->identSuffix[1] = UDF_OS_ID_LINUX;
  1369. dsea->majorDeviceIdent = cpu_to_le32(imajor(inode));
  1370. dsea->minorDeviceIdent = cpu_to_le32(iminor(inode));
  1371. }
  1372. if (UDF_I_EFE(inode) == 0)
  1373. {
  1374. memcpy(bh->b_data + sizeof(struct fileEntry), UDF_I_DATA(inode), inode->i_sb->s_blocksize - sizeof(struct fileEntry));
  1375. fe->logicalBlocksRecorded = cpu_to_le64(
  1376. (inode->i_blocks + (1 << (inode->i_sb->s_blocksize_bits - 9)) - 1) >>
  1377. (inode->i_sb->s_blocksize_bits - 9));
  1378. if (udf_time_to_stamp(&cpu_time, inode->i_atime))
  1379. fe->accessTime = cpu_to_lets(cpu_time);
  1380. if (udf_time_to_stamp(&cpu_time, inode->i_mtime))
  1381. fe->modificationTime = cpu_to_lets(cpu_time);
  1382. if (udf_time_to_stamp(&cpu_time, inode->i_ctime))
  1383. fe->attrTime = cpu_to_lets(cpu_time);
  1384. memset(&(fe->impIdent), 0, sizeof(regid));
  1385. strcpy(fe->impIdent.ident, UDF_ID_DEVELOPER);
  1386. fe->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
  1387. fe->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
  1388. fe->uniqueID = cpu_to_le64(UDF_I_UNIQUE(inode));
  1389. fe->lengthExtendedAttr = cpu_to_le32(UDF_I_LENEATTR(inode));
  1390. fe->lengthAllocDescs = cpu_to_le32(UDF_I_LENALLOC(inode));
  1391. fe->descTag.tagIdent = cpu_to_le16(TAG_IDENT_FE);
  1392. crclen = sizeof(struct fileEntry);
  1393. }
  1394. else
  1395. {
  1396. memcpy(bh->b_data + sizeof(struct extendedFileEntry), UDF_I_DATA(inode), inode->i_sb->s_blocksize - sizeof(struct extendedFileEntry));
  1397. efe->objectSize = cpu_to_le64(inode->i_size);
  1398. efe->logicalBlocksRecorded = cpu_to_le64(
  1399. (inode->i_blocks + (1 << (inode->i_sb->s_blocksize_bits - 9)) - 1) >>
  1400. (inode->i_sb->s_blocksize_bits - 9));
  1401. if (UDF_I_CRTIME(inode).tv_sec > inode->i_atime.tv_sec ||
  1402. (UDF_I_CRTIME(inode).tv_sec == inode->i_atime.tv_sec &&
  1403. UDF_I_CRTIME(inode).tv_nsec > inode->i_atime.tv_nsec))
  1404. {
  1405. UDF_I_CRTIME(inode) = inode->i_atime;
  1406. }
  1407. if (UDF_I_CRTIME(inode).tv_sec > inode->i_mtime.tv_sec ||
  1408. (UDF_I_CRTIME(inode).tv_sec == inode->i_mtime.tv_sec &&
  1409. UDF_I_CRTIME(inode).tv_nsec > inode->i_mtime.tv_nsec))
  1410. {
  1411. UDF_I_CRTIME(inode) = inode->i_mtime;
  1412. }
  1413. if (UDF_I_CRTIME(inode).tv_sec > inode->i_ctime.tv_sec ||
  1414. (UDF_I_CRTIME(inode).tv_sec == inode->i_ctime.tv_sec &&
  1415. UDF_I_CRTIME(inode).tv_nsec > inode->i_ctime.tv_nsec))
  1416. {
  1417. UDF_I_CRTIME(inode) = inode->i_ctime;
  1418. }
  1419. if (udf_time_to_stamp(&cpu_time, inode->i_atime))
  1420. efe->accessTime = cpu_to_lets(cpu_time);
  1421. if (udf_time_to_stamp(&cpu_time, inode->i_mtime))
  1422. efe->modificationTime = cpu_to_lets(cpu_time);
  1423. if (udf_time_to_stamp(&cpu_time, UDF_I_CRTIME(inode)))
  1424. efe->createTime = cpu_to_lets(cpu_time);
  1425. if (udf_time_to_stamp(&cpu_time, inode->i_ctime))
  1426. efe->attrTime = cpu_to_lets(cpu_time);
  1427. memset(&(efe->impIdent), 0, sizeof(regid));
  1428. strcpy(efe->impIdent.ident, UDF_ID_DEVELOPER);
  1429. efe->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
  1430. efe->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
  1431. efe->uniqueID = cpu_to_le64(UDF_I_UNIQUE(inode));
  1432. efe->lengthExtendedAttr = cpu_to_le32(UDF_I_LENEATTR(inode));
  1433. efe->lengthAllocDescs = cpu_to_le32(UDF_I_LENALLOC(inode));
  1434. efe->descTag.tagIdent = cpu_to_le16(TAG_IDENT_EFE);
  1435. crclen = sizeof(struct extendedFileEntry);
  1436. }
  1437. if (UDF_I_STRAT4096(inode))
  1438. {
  1439. fe->icbTag.strategyType = cpu_to_le16(4096);
  1440. fe->icbTag.strategyParameter = cpu_to_le16(1);
  1441. fe->icbTag.numEntries = cpu_to_le16(2);
  1442. }
  1443. else
  1444. {
  1445. fe->icbTag.strategyType = cpu_to_le16(4);
  1446. fe->icbTag.numEntries = cpu_to_le16(1);
  1447. }
  1448. if (S_ISDIR(inode->i_mode))
  1449. fe->icbTag.fileType = ICBTAG_FILE_TYPE_DIRECTORY;
  1450. else if (S_ISREG(inode->i_mode))
  1451. fe->icbTag.fileType = ICBTAG_FILE_TYPE_REGULAR;
  1452. else if (S_ISLNK(inode->i_mode))
  1453. fe->icbTag.fileType = ICBTAG_FILE_TYPE_SYMLINK;
  1454. else if (S_ISBLK(inode->i_mode))
  1455. fe->icbTag.fileType = ICBTAG_FILE_TYPE_BLOCK;
  1456. else if (S_ISCHR(inode->i_mode))
  1457. fe->icbTag.fileType = ICBTAG_FILE_TYPE_CHAR;
  1458. else if (S_ISFIFO(inode->i_mode))
  1459. fe->icbTag.fileType = ICBTAG_FILE_TYPE_FIFO;
  1460. else if (S_ISSOCK(inode->i_mode))
  1461. fe->icbTag.fileType = ICBTAG_FILE_TYPE_SOCKET;
  1462. icbflags = UDF_I_ALLOCTYPE(inode) |
  1463. ((inode->i_mode & S_ISUID) ? ICBTAG_FLAG_SETUID : 0) |
  1464. ((inode->i_mode & S_ISGID) ? ICBTAG_FLAG_SETGID : 0) |
  1465. ((inode->i_mode & S_ISVTX) ? ICBTAG_FLAG_STICKY : 0) |
  1466. (le16_to_cpu(fe->icbTag.flags) &
  1467. ~(ICBTAG_FLAG_AD_MASK | ICBTAG_FLAG_SETUID |
  1468. ICBTAG_FLAG_SETGID | ICBTAG_FLAG_STICKY));
  1469. fe->icbTag.flags = cpu_to_le16(icbflags);
  1470. if (UDF_SB_UDFREV(inode->i_sb) >= 0x0200)
  1471. fe->descTag.descVersion = cpu_to_le16(3);
  1472. else
  1473. fe->descTag.descVersion = cpu_to_le16(2);
  1474. fe->descTag.tagSerialNum = cpu_to_le16(UDF_SB_SERIALNUM(inode->i_sb));
  1475. fe->descTag.tagLocation = cpu_to_le32(UDF_I_LOCATION(inode).logicalBlockNum);
  1476. crclen += UDF_I_LENEATTR(inode) + UDF_I_LENALLOC(inode) - sizeof(tag);
  1477. fe->descTag.descCRCLength = cpu_to_le16(crclen);
  1478. fe->descTag.descCRC = cpu_to_le16(udf_crc((char *)fe + sizeof(tag), crclen, 0));
  1479. fe->descTag.tagChecksum = 0;
  1480. for (i=0; i<16; i++)
  1481. if (i != 4)
  1482. fe->descTag.tagChecksum += ((uint8_t *)&(fe->descTag))[i];
  1483. /* write the data blocks */
  1484. mark_buffer_dirty(bh);
  1485. if (do_sync)
  1486. {
  1487. sync_dirty_buffer(bh);
  1488. if (buffer_req(bh) && !buffer_uptodate(bh))
  1489. {
  1490. printk("IO error syncing udf inode [%s:%08lx]\n",
  1491. inode->i_sb->s_id, inode->i_ino);
  1492. err = -EIO;
  1493. }
  1494. }
  1495. brelse(bh);
  1496. return err;
  1497. }
  1498. struct inode *
  1499. udf_iget(struct super_block *sb, kernel_lb_addr ino)
  1500. {
  1501. unsigned long block = udf_get_lb_pblock(sb, ino, 0);
  1502. struct inode *inode = iget_locked(sb, block);
  1503. if (!inode)
  1504. return NULL;
  1505. if (inode->i_state & I_NEW) {
  1506. memcpy(&UDF_I_LOCATION(inode), &ino, sizeof(kernel_lb_addr));
  1507. __udf_read_inode(inode);
  1508. unlock_new_inode(inode);
  1509. }
  1510. if (is_bad_inode(inode))
  1511. goto out_iput;
  1512. if (ino.logicalBlockNum >= UDF_SB_PARTLEN(sb, ino.partitionReferenceNum)) {
  1513. udf_debug("block=%d, partition=%d out of range\n",
  1514. ino.logicalBlockNum, ino.partitionReferenceNum);
  1515. make_bad_inode(inode);
  1516. goto out_iput;
  1517. }
  1518. return inode;
  1519. out_iput:
  1520. iput(inode);
  1521. return NULL;
  1522. }
  1523. int8_t udf_add_aext(struct inode *inode, struct extent_position *epos,
  1524. kernel_lb_addr eloc, uint32_t elen, int inc)
  1525. {
  1526. int adsize;
  1527. short_ad *sad = NULL;
  1528. long_ad *lad = NULL;
  1529. struct allocExtDesc *aed;
  1530. int8_t etype;
  1531. uint8_t *ptr;
  1532. if (!epos->bh)
  1533. ptr = UDF_I_DATA(inode) + epos->offset - udf_file_entry_alloc_offset(inode) + UDF_I_LENEATTR(inode);
  1534. else
  1535. ptr = epos->bh->b_data + epos->offset;
  1536. if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_SHORT)
  1537. adsize = sizeof(short_ad);
  1538. else if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_LONG)
  1539. adsize = sizeof(long_ad);
  1540. else
  1541. return -1;
  1542. if (epos->offset + (2 * adsize) > inode->i_sb->s_blocksize)
  1543. {
  1544. char *sptr, *dptr;
  1545. struct buffer_head *nbh;
  1546. int err, loffset;
  1547. kernel_lb_addr obloc = epos->block;
  1548. if (!(epos->block.logicalBlockNum = udf_new_block(inode->i_sb, NULL,
  1549. obloc.partitionReferenceNum, obloc.logicalBlockNum, &err)))
  1550. {
  1551. return -1;
  1552. }
  1553. if (!(nbh = udf_tgetblk(inode->i_sb, udf_get_lb_pblock(inode->i_sb,
  1554. epos->block, 0))))
  1555. {
  1556. return -1;
  1557. }
  1558. lock_buffer(nbh);
  1559. memset(nbh->b_data, 0x00, inode->i_sb->s_blocksize);
  1560. set_buffer_uptodate(nbh);
  1561. unlock_buffer(nbh);
  1562. mark_buffer_dirty_inode(nbh, inode);
  1563. aed = (struct allocExtDesc *)(nbh->b_data);
  1564. if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT))
  1565. aed->previousAllocExtLocation = cpu_to_le32(obloc.logicalBlockNum);
  1566. if (epos->offset + adsize > inode->i_sb->s_blocksize)
  1567. {
  1568. loffset = epos->offset;
  1569. aed->lengthAllocDescs = cpu_to_le32(adsize);
  1570. sptr = ptr - adsize;
  1571. dptr = nbh->b_data + sizeof(struct allocExtDesc);
  1572. memcpy(dptr, sptr, adsize);
  1573. epos->offset = sizeof(struct allocExtDesc) + adsize;
  1574. }
  1575. else
  1576. {
  1577. loffset = epos->offset + adsize;
  1578. aed->lengthAllocDescs = cpu_to_le32(0);
  1579. sptr = ptr;
  1580. epos->offset = sizeof(struct allocExtDesc);
  1581. if (epos->bh)
  1582. {
  1583. aed = (struct allocExtDesc *)epos->bh->b_data;
  1584. aed->lengthAllocDescs =
  1585. cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) + adsize);
  1586. }
  1587. else
  1588. {
  1589. UDF_I_LENALLOC(inode) += adsize;
  1590. mark_inode_dirty(inode);
  1591. }
  1592. }
  1593. if (UDF_SB_UDFREV(inode->i_sb) >= 0x0200)
  1594. udf_new_tag(nbh->b_data, TAG_IDENT_AED, 3, 1,
  1595. epos->block.logicalBlockNum, sizeof(tag));
  1596. else
  1597. udf_new_tag(nbh->b_data, TAG_IDENT_AED, 2, 1,
  1598. epos->block.logicalBlockNum, sizeof(tag));
  1599. switch (UDF_I_ALLOCTYPE(inode))
  1600. {
  1601. case ICBTAG_FLAG_AD_SHORT:
  1602. {
  1603. sad = (short_ad *)sptr;
  1604. sad->extLength = cpu_to_le32(
  1605. EXT_NEXT_EXTENT_ALLOCDECS |
  1606. inode->i_sb->s_blocksize);
  1607. sad->extPosition = cpu_to_le32(epos->block.logicalBlockNum);
  1608. break;
  1609. }
  1610. case ICBTAG_FLAG_AD_LONG:
  1611. {
  1612. lad = (long_ad *)sptr;
  1613. lad->extLength = cpu_to_le32(
  1614. EXT_NEXT_EXTENT_ALLOCDECS |
  1615. inode->i_sb->s_blocksize);
  1616. lad->extLocation = cpu_to_lelb(epos->block);
  1617. memset(lad->impUse, 0x00, sizeof(lad->impUse));
  1618. break;
  1619. }
  1620. }
  1621. if (epos->bh)
  1622. {
  1623. if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) || UDF_SB_UDFREV(inode->i_sb) >= 0x0201)
  1624. udf_update_tag(epos->bh->b_data, loffset);
  1625. else
  1626. udf_update_tag(epos->bh->b_data, sizeof(struct allocExtDesc));
  1627. mark_buffer_dirty_inode(epos->bh, inode);
  1628. brelse(epos->bh);
  1629. }
  1630. else
  1631. mark_inode_dirty(inode);
  1632. epos->bh = nbh;
  1633. }
  1634. etype = udf_write_aext(inode, epos, eloc, elen, inc);
  1635. if (!epos->bh)
  1636. {
  1637. UDF_I_LENALLOC(inode) += adsize;
  1638. mark_inode_dirty(inode);
  1639. }
  1640. else
  1641. {
  1642. aed = (struct allocExtDesc *)epos->bh->b_data;
  1643. aed->lengthAllocDescs =
  1644. cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) + adsize);
  1645. if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) || UDF_SB_UDFREV(inode->i_sb) >= 0x0201)
  1646. udf_update_tag(epos->bh->b_data, epos->offset + (inc ? 0 : adsize));
  1647. else
  1648. udf_update_tag(epos->bh->b_data, sizeof(struct allocExtDesc));
  1649. mark_buffer_dirty_inode(epos->bh, inode);
  1650. }
  1651. return etype;
  1652. }
  1653. int8_t udf_write_aext(struct inode *inode, struct extent_position *epos,
  1654. kernel_lb_addr eloc, uint32_t elen, int inc)
  1655. {
  1656. int adsize;
  1657. uint8_t *ptr;
  1658. if (!epos->bh)
  1659. ptr = UDF_I_DATA(inode) + epos->offset - udf_file_entry_alloc_offset(inode) + UDF_I_LENEATTR(inode);
  1660. else
  1661. ptr = epos->bh->b_data + epos->offset;
  1662. switch (UDF_I_ALLOCTYPE(inode))
  1663. {
  1664. case ICBTAG_FLAG_AD_SHORT:
  1665. {
  1666. short_ad *sad = (short_ad *)ptr;
  1667. sad->extLength = cpu_to_le32(elen);
  1668. sad->extPosition = cpu_to_le32(eloc.logicalBlockNum);
  1669. adsize = sizeof(short_ad);
  1670. break;
  1671. }
  1672. case ICBTAG_FLAG_AD_LONG:
  1673. {
  1674. long_ad *lad = (long_ad *)ptr;
  1675. lad->extLength = cpu_to_le32(elen);
  1676. lad->extLocation = cpu_to_lelb(eloc);
  1677. memset(lad->impUse, 0x00, sizeof(lad->impUse));
  1678. adsize = sizeof(long_ad);
  1679. break;
  1680. }
  1681. default:
  1682. return -1;
  1683. }
  1684. if (epos->bh)
  1685. {
  1686. if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) || UDF_SB_UDFREV(inode->i_sb) >= 0x0201)
  1687. {
  1688. struct allocExtDesc *aed = (struct allocExtDesc *)epos->bh->b_data;
  1689. udf_update_tag(epos->bh->b_data,
  1690. le32_to_cpu(aed->lengthAllocDescs) + sizeof(struct allocExtDesc));
  1691. }
  1692. mark_buffer_dirty_inode(epos->bh, inode);
  1693. }
  1694. else
  1695. mark_inode_dirty(inode);
  1696. if (inc)
  1697. epos->offset += adsize;
  1698. return (elen >> 30);
  1699. }
  1700. int8_t udf_next_aext(struct inode *inode, struct extent_position *epos,
  1701. kernel_lb_addr *eloc, uint32_t *elen, int inc)
  1702. {
  1703. int8_t etype;
  1704. while ((etype = udf_current_aext(inode, epos, eloc, elen, inc)) ==
  1705. (EXT_NEXT_EXTENT_ALLOCDECS >> 30))
  1706. {
  1707. epos->block = *eloc;
  1708. epos->offset = sizeof(struct allocExtDesc);
  1709. brelse(epos->bh);
  1710. if (!(epos->bh = udf_tread(inode->i_sb, udf_get_lb_pblock(inode->i_sb, epos->block, 0))))
  1711. {
  1712. udf_debug("reading block %d failed!\n",
  1713. udf_get_lb_pblock(inode->i_sb, epos->block, 0));
  1714. return -1;
  1715. }
  1716. }
  1717. return etype;
  1718. }
  1719. int8_t udf_current_aext(struct inode *inode, struct extent_position *epos,
  1720. kernel_lb_addr *eloc, uint32_t *elen, int inc)
  1721. {
  1722. int alen;
  1723. int8_t etype;
  1724. uint8_t *ptr;
  1725. if (!epos->bh)
  1726. {
  1727. if (!epos->offset)
  1728. epos->offset = udf_file_entry_alloc_offset(inode);
  1729. ptr = UDF_I_DATA(inode) + epos->offset - udf_file_entry_alloc_offset(inode) + UDF_I_LENEATTR(inode);
  1730. alen = udf_file_entry_alloc_offset(inode) + UDF_I_LENALLOC(inode);
  1731. }
  1732. else
  1733. {
  1734. if (!epos->offset)
  1735. epos->offset = sizeof(struct allocExtDesc);
  1736. ptr = epos->bh->b_data + epos->offset;
  1737. alen = sizeof(struct allocExtDesc) + le32_to_cpu(((struct allocExtDesc *)epos->bh->b_data)->lengthAllocDescs);
  1738. }
  1739. switch (UDF_I_ALLOCTYPE(inode))
  1740. {
  1741. case ICBTAG_FLAG_AD_SHORT:
  1742. {
  1743. short_ad *sad;
  1744. if (!(sad = udf_get_fileshortad(ptr, alen, &epos->offset, inc)))
  1745. return -1;
  1746. etype = le32_to_cpu(sad->extLength) >> 30;
  1747. eloc->logicalBlockNum = le32_to_cpu(sad->extPosition);
  1748. eloc->partitionReferenceNum = UDF_I_LOCATION(inode).partitionReferenceNum;
  1749. *elen = le32_to_cpu(sad->extLength) & UDF_EXTENT_LENGTH_MASK;
  1750. break;
  1751. }
  1752. case ICBTAG_FLAG_AD_LONG:
  1753. {
  1754. long_ad *lad;
  1755. if (!(lad = udf_get_filelongad(ptr, alen, &epos->offset, inc)))
  1756. return -1;
  1757. etype = le32_to_cpu(lad->extLength) >> 30;
  1758. *eloc = lelb_to_cpu(lad->extLocation);
  1759. *elen = le32_to_cpu(lad->extLength) & UDF_EXTENT_LENGTH_MASK;
  1760. break;
  1761. }
  1762. default:
  1763. {
  1764. udf_debug("alloc_type = %d unsupported\n", UDF_I_ALLOCTYPE(inode));
  1765. return -1;
  1766. }
  1767. }
  1768. return etype;
  1769. }
  1770. static int8_t
  1771. udf_insert_aext(struct inode *inode, struct extent_position epos,
  1772. kernel_lb_addr neloc, uint32_t nelen)
  1773. {
  1774. kernel_lb_addr oeloc;
  1775. uint32_t oelen;
  1776. int8_t etype;
  1777. if (epos.bh)
  1778. get_bh(epos.bh);
  1779. while ((etype = udf_next_aext(inode, &epos, &oeloc, &oelen, 0)) != -1)
  1780. {
  1781. udf_write_aext(inode, &epos, neloc, nelen, 1);
  1782. neloc = oeloc;
  1783. nelen = (etype << 30) | oelen;
  1784. }
  1785. udf_add_aext(inode, &epos, neloc, nelen, 1);
  1786. brelse(epos.bh);
  1787. return (nelen >> 30);
  1788. }
  1789. int8_t udf_delete_aext(struct inode *inode, struct extent_position epos,
  1790. kernel_lb_addr eloc, uint32_t elen)
  1791. {
  1792. struct extent_position oepos;
  1793. int adsize;
  1794. int8_t etype;
  1795. struct allocExtDesc *aed;
  1796. if (epos.bh)
  1797. {
  1798. get_bh(epos.bh);
  1799. get_bh(epos.bh);
  1800. }
  1801. if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_SHORT)
  1802. adsize = sizeof(short_ad);
  1803. else if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_LONG)
  1804. adsize = sizeof(long_ad);
  1805. else
  1806. adsize = 0;
  1807. oepos = epos;
  1808. if (udf_next_aext(inode, &epos, &eloc, &elen, 1) == -1)
  1809. return -1;
  1810. while ((etype = udf_next_aext(inode, &epos, &eloc, &elen, 1)) != -1)
  1811. {
  1812. udf_write_aext(inode, &oepos, eloc, (etype << 30) | elen, 1);
  1813. if (oepos.bh != epos.bh)
  1814. {
  1815. oepos.block = epos.block;
  1816. brelse(oepos.bh);
  1817. get_bh(epos.bh);
  1818. oepos.bh = epos.bh;
  1819. oepos.offset = epos.offset - adsize;
  1820. }
  1821. }
  1822. memset(&eloc, 0x00, sizeof(kernel_lb_addr));
  1823. elen = 0;
  1824. if (epos.bh != oepos.bh)
  1825. {
  1826. udf_free_blocks(inode->i_sb, inode, epos.block, 0, 1);
  1827. udf_write_aext(inode, &oepos, eloc, elen, 1);
  1828. udf_write_aext(inode, &oepos, eloc, elen, 1);
  1829. if (!oepos.bh)
  1830. {
  1831. UDF_I_LENALLOC(inode) -= (adsize * 2);
  1832. mark_inode_dirty(inode);
  1833. }
  1834. else
  1835. {
  1836. aed = (struct allocExtDesc *)oepos.bh->b_data;
  1837. aed->lengthAllocDescs =
  1838. cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) - (2*adsize));
  1839. if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) || UDF_SB_UDFREV(inode->i_sb) >= 0x0201)
  1840. udf_update_tag(oepos.bh->b_data, oepos.offset - (2*adsize));
  1841. else
  1842. udf_update_tag(oepos.bh->b_data, sizeof(struct allocExtDesc));
  1843. mark_buffer_dirty_inode(oepos.bh, inode);
  1844. }
  1845. }
  1846. else
  1847. {
  1848. udf_write_aext(inode, &oepos, eloc, elen, 1);
  1849. if (!oepos.bh)
  1850. {
  1851. UDF_I_LENALLOC(inode) -= adsize;
  1852. mark_inode_dirty(inode);
  1853. }
  1854. else
  1855. {
  1856. aed = (struct allocExtDesc *)oepos.bh->b_data;
  1857. aed->lengthAllocDescs =
  1858. cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) - adsize);
  1859. if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) || UDF_SB_UDFREV(inode->i_sb) >= 0x0201)
  1860. udf_update_tag(oepos.bh->b_data, epos.offset - adsize);
  1861. else
  1862. udf_update_tag(oepos.bh->b_data, sizeof(struct allocExtDesc));
  1863. mark_buffer_dirty_inode(oepos.bh, inode);
  1864. }
  1865. }
  1866. brelse(epos.bh);
  1867. brelse(oepos.bh);
  1868. return (elen >> 30);
  1869. }
  1870. int8_t inode_bmap(struct inode *inode, sector_t block, struct extent_position *pos,
  1871. kernel_lb_addr *eloc, uint32_t *elen, sector_t *offset)
  1872. {
  1873. loff_t lbcount = 0, bcount = (loff_t)block << inode->i_sb->s_blocksize_bits;
  1874. int8_t etype;
  1875. if (block < 0)
  1876. {
  1877. printk(KERN_ERR "udf: inode_bmap: block < 0\n");
  1878. return -1;
  1879. }
  1880. pos->offset = 0;
  1881. pos->block = UDF_I_LOCATION(inode);
  1882. pos->bh = NULL;
  1883. *elen = 0;
  1884. do
  1885. {
  1886. if ((etype = udf_next_aext(inode, pos, eloc, elen, 1)) == -1)
  1887. {
  1888. *offset = (bcount - lbcount) >> inode->i_sb->s_blocksize_bits;
  1889. UDF_I_LENEXTENTS(inode) = lbcount;
  1890. return -1;
  1891. }
  1892. lbcount += *elen;
  1893. } while (lbcount <= bcount);
  1894. *offset = (bcount + *elen - lbcount) >> inode->i_sb->s_blocksize_bits;
  1895. return etype;
  1896. }
  1897. long udf_block_map(struct inode *inode, sector_t block)
  1898. {
  1899. kernel_lb_addr eloc;
  1900. uint32_t elen;
  1901. sector_t offset;
  1902. struct extent_position epos = { NULL, 0, { 0, 0}};
  1903. int ret;
  1904. lock_kernel();
  1905. if (inode_bmap(inode, block, &epos, &eloc, &elen, &offset) == (EXT_RECORDED_ALLOCATED >> 30))
  1906. ret = udf_get_lb_pblock(inode->i_sb, eloc, offset);
  1907. else
  1908. ret = 0;
  1909. unlock_kernel();
  1910. brelse(epos.bh);
  1911. if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_VARCONV))
  1912. return udf_fixed_to_variable(ret);
  1913. else
  1914. return ret;
  1915. }