inode.c 59 KB

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