super.c 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265
  1. /*
  2. * super.c
  3. *
  4. * PURPOSE
  5. * Super block routines for the OSTA-UDF(tm) filesystem.
  6. *
  7. * DESCRIPTION
  8. * OSTA-UDF(tm) = Optical Storage Technology Association
  9. * Universal Disk Format.
  10. *
  11. * This code is based on version 2.00 of the UDF specification,
  12. * and revision 3 of the ECMA 167 standard [equivalent to ISO 13346].
  13. * http://www.osta.org/
  14. * http://www.ecma.ch/
  15. * http://www.iso.org/
  16. *
  17. * COPYRIGHT
  18. * This file is distributed under the terms of the GNU General Public
  19. * License (GPL). Copies of the GPL can be obtained from:
  20. * ftp://prep.ai.mit.edu/pub/gnu/GPL
  21. * Each contributing author retains all rights to their own work.
  22. *
  23. * (C) 1998 Dave Boynton
  24. * (C) 1998-2004 Ben Fennema
  25. * (C) 2000 Stelias Computing Inc
  26. *
  27. * HISTORY
  28. *
  29. * 09/24/98 dgb changed to allow compiling outside of kernel, and
  30. * added some debugging.
  31. * 10/01/98 dgb updated to allow (some) possibility of compiling w/2.0.34
  32. * 10/16/98 attempting some multi-session support
  33. * 10/17/98 added freespace count for "df"
  34. * 11/11/98 gr added novrs option
  35. * 11/26/98 dgb added fileset,anchor mount options
  36. * 12/06/98 blf really hosed things royally. vat/sparing support. sequenced
  37. * vol descs. rewrote option handling based on isofs
  38. * 12/20/98 find the free space bitmap (if it exists)
  39. */
  40. #include "udfdecl.h"
  41. #include <linux/blkdev.h>
  42. #include <linux/slab.h>
  43. #include <linux/kernel.h>
  44. #include <linux/module.h>
  45. #include <linux/parser.h>
  46. #include <linux/stat.h>
  47. #include <linux/cdrom.h>
  48. #include <linux/nls.h>
  49. #include <linux/smp_lock.h>
  50. #include <linux/buffer_head.h>
  51. #include <linux/vfs.h>
  52. #include <linux/vmalloc.h>
  53. #include <linux/errno.h>
  54. #include <linux/mount.h>
  55. #include <linux/seq_file.h>
  56. #include <linux/bitmap.h>
  57. #include <linux/crc-itu-t.h>
  58. #include <asm/byteorder.h>
  59. #include "udf_sb.h"
  60. #include "udf_i.h"
  61. #include <linux/init.h>
  62. #include <asm/uaccess.h>
  63. #define VDS_POS_PRIMARY_VOL_DESC 0
  64. #define VDS_POS_UNALLOC_SPACE_DESC 1
  65. #define VDS_POS_LOGICAL_VOL_DESC 2
  66. #define VDS_POS_PARTITION_DESC 3
  67. #define VDS_POS_IMP_USE_VOL_DESC 4
  68. #define VDS_POS_VOL_DESC_PTR 5
  69. #define VDS_POS_TERMINATING_DESC 6
  70. #define VDS_POS_LENGTH 7
  71. #define UDF_DEFAULT_BLOCKSIZE 2048
  72. static char error_buf[1024];
  73. /* These are the "meat" - everything else is stuffing */
  74. static int udf_fill_super(struct super_block *, void *, int);
  75. static void udf_put_super(struct super_block *);
  76. static int udf_sync_fs(struct super_block *, int);
  77. static int udf_remount_fs(struct super_block *, int *, char *);
  78. static void udf_load_logicalvolint(struct super_block *, struct kernel_extent_ad);
  79. static int udf_find_fileset(struct super_block *, struct kernel_lb_addr *,
  80. struct kernel_lb_addr *);
  81. static void udf_load_fileset(struct super_block *, struct buffer_head *,
  82. struct kernel_lb_addr *);
  83. static void udf_open_lvid(struct super_block *);
  84. static void udf_close_lvid(struct super_block *);
  85. static unsigned int udf_count_free(struct super_block *);
  86. static int udf_statfs(struct dentry *, struct kstatfs *);
  87. static int udf_show_options(struct seq_file *, struct vfsmount *);
  88. static void udf_error(struct super_block *sb, const char *function,
  89. const char *fmt, ...);
  90. struct logicalVolIntegrityDescImpUse *udf_sb_lvidiu(struct udf_sb_info *sbi)
  91. {
  92. struct logicalVolIntegrityDesc *lvid =
  93. (struct logicalVolIntegrityDesc *)sbi->s_lvid_bh->b_data;
  94. __u32 number_of_partitions = le32_to_cpu(lvid->numOfPartitions);
  95. __u32 offset = number_of_partitions * 2 *
  96. sizeof(uint32_t)/sizeof(uint8_t);
  97. return (struct logicalVolIntegrityDescImpUse *)&(lvid->impUse[offset]);
  98. }
  99. /* UDF filesystem type */
  100. static int udf_get_sb(struct file_system_type *fs_type,
  101. int flags, const char *dev_name, void *data,
  102. struct vfsmount *mnt)
  103. {
  104. return get_sb_bdev(fs_type, flags, dev_name, data, udf_fill_super, mnt);
  105. }
  106. static struct file_system_type udf_fstype = {
  107. .owner = THIS_MODULE,
  108. .name = "udf",
  109. .get_sb = udf_get_sb,
  110. .kill_sb = kill_block_super,
  111. .fs_flags = FS_REQUIRES_DEV,
  112. };
  113. static struct kmem_cache *udf_inode_cachep;
  114. static struct inode *udf_alloc_inode(struct super_block *sb)
  115. {
  116. struct udf_inode_info *ei;
  117. ei = kmem_cache_alloc(udf_inode_cachep, GFP_KERNEL);
  118. if (!ei)
  119. return NULL;
  120. ei->i_unique = 0;
  121. ei->i_lenExtents = 0;
  122. ei->i_next_alloc_block = 0;
  123. ei->i_next_alloc_goal = 0;
  124. ei->i_strat4096 = 0;
  125. return &ei->vfs_inode;
  126. }
  127. static void udf_destroy_inode(struct inode *inode)
  128. {
  129. kmem_cache_free(udf_inode_cachep, UDF_I(inode));
  130. }
  131. static void init_once(void *foo)
  132. {
  133. struct udf_inode_info *ei = (struct udf_inode_info *)foo;
  134. ei->i_ext.i_data = NULL;
  135. inode_init_once(&ei->vfs_inode);
  136. }
  137. static int init_inodecache(void)
  138. {
  139. udf_inode_cachep = kmem_cache_create("udf_inode_cache",
  140. sizeof(struct udf_inode_info),
  141. 0, (SLAB_RECLAIM_ACCOUNT |
  142. SLAB_MEM_SPREAD),
  143. init_once);
  144. if (!udf_inode_cachep)
  145. return -ENOMEM;
  146. return 0;
  147. }
  148. static void destroy_inodecache(void)
  149. {
  150. kmem_cache_destroy(udf_inode_cachep);
  151. }
  152. /* Superblock operations */
  153. static const struct super_operations udf_sb_ops = {
  154. .alloc_inode = udf_alloc_inode,
  155. .destroy_inode = udf_destroy_inode,
  156. .write_inode = udf_write_inode,
  157. .delete_inode = udf_delete_inode,
  158. .clear_inode = udf_clear_inode,
  159. .put_super = udf_put_super,
  160. .sync_fs = udf_sync_fs,
  161. .statfs = udf_statfs,
  162. .remount_fs = udf_remount_fs,
  163. .show_options = udf_show_options,
  164. };
  165. struct udf_options {
  166. unsigned char novrs;
  167. unsigned int blocksize;
  168. unsigned int session;
  169. unsigned int lastblock;
  170. unsigned int anchor;
  171. unsigned int volume;
  172. unsigned short partition;
  173. unsigned int fileset;
  174. unsigned int rootdir;
  175. unsigned int flags;
  176. mode_t umask;
  177. gid_t gid;
  178. uid_t uid;
  179. mode_t fmode;
  180. mode_t dmode;
  181. struct nls_table *nls_map;
  182. };
  183. static int __init init_udf_fs(void)
  184. {
  185. int err;
  186. err = init_inodecache();
  187. if (err)
  188. goto out1;
  189. err = register_filesystem(&udf_fstype);
  190. if (err)
  191. goto out;
  192. return 0;
  193. out:
  194. destroy_inodecache();
  195. out1:
  196. return err;
  197. }
  198. static void __exit exit_udf_fs(void)
  199. {
  200. unregister_filesystem(&udf_fstype);
  201. destroy_inodecache();
  202. }
  203. module_init(init_udf_fs)
  204. module_exit(exit_udf_fs)
  205. static int udf_sb_alloc_partition_maps(struct super_block *sb, u32 count)
  206. {
  207. struct udf_sb_info *sbi = UDF_SB(sb);
  208. sbi->s_partmaps = kcalloc(count, sizeof(struct udf_part_map),
  209. GFP_KERNEL);
  210. if (!sbi->s_partmaps) {
  211. udf_error(sb, __func__,
  212. "Unable to allocate space for %d partition maps",
  213. count);
  214. sbi->s_partitions = 0;
  215. return -ENOMEM;
  216. }
  217. sbi->s_partitions = count;
  218. return 0;
  219. }
  220. static int udf_show_options(struct seq_file *seq, struct vfsmount *mnt)
  221. {
  222. struct super_block *sb = mnt->mnt_sb;
  223. struct udf_sb_info *sbi = UDF_SB(sb);
  224. if (!UDF_QUERY_FLAG(sb, UDF_FLAG_STRICT))
  225. seq_puts(seq, ",nostrict");
  226. if (UDF_QUERY_FLAG(sb, UDF_FLAG_BLOCKSIZE_SET))
  227. seq_printf(seq, ",bs=%lu", sb->s_blocksize);
  228. if (UDF_QUERY_FLAG(sb, UDF_FLAG_UNHIDE))
  229. seq_puts(seq, ",unhide");
  230. if (UDF_QUERY_FLAG(sb, UDF_FLAG_UNDELETE))
  231. seq_puts(seq, ",undelete");
  232. if (!UDF_QUERY_FLAG(sb, UDF_FLAG_USE_AD_IN_ICB))
  233. seq_puts(seq, ",noadinicb");
  234. if (UDF_QUERY_FLAG(sb, UDF_FLAG_USE_SHORT_AD))
  235. seq_puts(seq, ",shortad");
  236. if (UDF_QUERY_FLAG(sb, UDF_FLAG_UID_FORGET))
  237. seq_puts(seq, ",uid=forget");
  238. if (UDF_QUERY_FLAG(sb, UDF_FLAG_UID_IGNORE))
  239. seq_puts(seq, ",uid=ignore");
  240. if (UDF_QUERY_FLAG(sb, UDF_FLAG_GID_FORGET))
  241. seq_puts(seq, ",gid=forget");
  242. if (UDF_QUERY_FLAG(sb, UDF_FLAG_GID_IGNORE))
  243. seq_puts(seq, ",gid=ignore");
  244. if (UDF_QUERY_FLAG(sb, UDF_FLAG_UID_SET))
  245. seq_printf(seq, ",uid=%u", sbi->s_uid);
  246. if (UDF_QUERY_FLAG(sb, UDF_FLAG_GID_SET))
  247. seq_printf(seq, ",gid=%u", sbi->s_gid);
  248. if (sbi->s_umask != 0)
  249. seq_printf(seq, ",umask=%o", sbi->s_umask);
  250. if (sbi->s_fmode != UDF_INVALID_MODE)
  251. seq_printf(seq, ",mode=%o", sbi->s_fmode);
  252. if (sbi->s_dmode != UDF_INVALID_MODE)
  253. seq_printf(seq, ",dmode=%o", sbi->s_dmode);
  254. if (UDF_QUERY_FLAG(sb, UDF_FLAG_SESSION_SET))
  255. seq_printf(seq, ",session=%u", sbi->s_session);
  256. if (UDF_QUERY_FLAG(sb, UDF_FLAG_LASTBLOCK_SET))
  257. seq_printf(seq, ",lastblock=%u", sbi->s_last_block);
  258. if (sbi->s_anchor != 0)
  259. seq_printf(seq, ",anchor=%u", sbi->s_anchor);
  260. /*
  261. * volume, partition, fileset and rootdir seem to be ignored
  262. * currently
  263. */
  264. if (UDF_QUERY_FLAG(sb, UDF_FLAG_UTF8))
  265. seq_puts(seq, ",utf8");
  266. if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP) && sbi->s_nls_map)
  267. seq_printf(seq, ",iocharset=%s", sbi->s_nls_map->charset);
  268. return 0;
  269. }
  270. /*
  271. * udf_parse_options
  272. *
  273. * PURPOSE
  274. * Parse mount options.
  275. *
  276. * DESCRIPTION
  277. * The following mount options are supported:
  278. *
  279. * gid= Set the default group.
  280. * umask= Set the default umask.
  281. * mode= Set the default file permissions.
  282. * dmode= Set the default directory permissions.
  283. * uid= Set the default user.
  284. * bs= Set the block size.
  285. * unhide Show otherwise hidden files.
  286. * undelete Show deleted files in lists.
  287. * adinicb Embed data in the inode (default)
  288. * noadinicb Don't embed data in the inode
  289. * shortad Use short ad's
  290. * longad Use long ad's (default)
  291. * nostrict Unset strict conformance
  292. * iocharset= Set the NLS character set
  293. *
  294. * The remaining are for debugging and disaster recovery:
  295. *
  296. * novrs Skip volume sequence recognition
  297. *
  298. * The following expect a offset from 0.
  299. *
  300. * session= Set the CDROM session (default= last session)
  301. * anchor= Override standard anchor location. (default= 256)
  302. * volume= Override the VolumeDesc location. (unused)
  303. * partition= Override the PartitionDesc location. (unused)
  304. * lastblock= Set the last block of the filesystem/
  305. *
  306. * The following expect a offset from the partition root.
  307. *
  308. * fileset= Override the fileset block location. (unused)
  309. * rootdir= Override the root directory location. (unused)
  310. * WARNING: overriding the rootdir to a non-directory may
  311. * yield highly unpredictable results.
  312. *
  313. * PRE-CONDITIONS
  314. * options Pointer to mount options string.
  315. * uopts Pointer to mount options variable.
  316. *
  317. * POST-CONDITIONS
  318. * <return> 1 Mount options parsed okay.
  319. * <return> 0 Error parsing mount options.
  320. *
  321. * HISTORY
  322. * July 1, 1997 - Andrew E. Mileski
  323. * Written, tested, and released.
  324. */
  325. enum {
  326. Opt_novrs, Opt_nostrict, Opt_bs, Opt_unhide, Opt_undelete,
  327. Opt_noadinicb, Opt_adinicb, Opt_shortad, Opt_longad,
  328. Opt_gid, Opt_uid, Opt_umask, Opt_session, Opt_lastblock,
  329. Opt_anchor, Opt_volume, Opt_partition, Opt_fileset,
  330. Opt_rootdir, Opt_utf8, Opt_iocharset,
  331. Opt_err, Opt_uforget, Opt_uignore, Opt_gforget, Opt_gignore,
  332. Opt_fmode, Opt_dmode
  333. };
  334. static const match_table_t tokens = {
  335. {Opt_novrs, "novrs"},
  336. {Opt_nostrict, "nostrict"},
  337. {Opt_bs, "bs=%u"},
  338. {Opt_unhide, "unhide"},
  339. {Opt_undelete, "undelete"},
  340. {Opt_noadinicb, "noadinicb"},
  341. {Opt_adinicb, "adinicb"},
  342. {Opt_shortad, "shortad"},
  343. {Opt_longad, "longad"},
  344. {Opt_uforget, "uid=forget"},
  345. {Opt_uignore, "uid=ignore"},
  346. {Opt_gforget, "gid=forget"},
  347. {Opt_gignore, "gid=ignore"},
  348. {Opt_gid, "gid=%u"},
  349. {Opt_uid, "uid=%u"},
  350. {Opt_umask, "umask=%o"},
  351. {Opt_session, "session=%u"},
  352. {Opt_lastblock, "lastblock=%u"},
  353. {Opt_anchor, "anchor=%u"},
  354. {Opt_volume, "volume=%u"},
  355. {Opt_partition, "partition=%u"},
  356. {Opt_fileset, "fileset=%u"},
  357. {Opt_rootdir, "rootdir=%u"},
  358. {Opt_utf8, "utf8"},
  359. {Opt_iocharset, "iocharset=%s"},
  360. {Opt_fmode, "mode=%o"},
  361. {Opt_dmode, "dmode=%o"},
  362. {Opt_err, NULL}
  363. };
  364. static int udf_parse_options(char *options, struct udf_options *uopt,
  365. bool remount)
  366. {
  367. char *p;
  368. int option;
  369. uopt->novrs = 0;
  370. uopt->partition = 0xFFFF;
  371. uopt->session = 0xFFFFFFFF;
  372. uopt->lastblock = 0;
  373. uopt->anchor = 0;
  374. uopt->volume = 0xFFFFFFFF;
  375. uopt->rootdir = 0xFFFFFFFF;
  376. uopt->fileset = 0xFFFFFFFF;
  377. uopt->nls_map = NULL;
  378. if (!options)
  379. return 1;
  380. while ((p = strsep(&options, ",")) != NULL) {
  381. substring_t args[MAX_OPT_ARGS];
  382. int token;
  383. if (!*p)
  384. continue;
  385. token = match_token(p, tokens, args);
  386. switch (token) {
  387. case Opt_novrs:
  388. uopt->novrs = 1;
  389. break;
  390. case Opt_bs:
  391. if (match_int(&args[0], &option))
  392. return 0;
  393. uopt->blocksize = option;
  394. uopt->flags |= (1 << UDF_FLAG_BLOCKSIZE_SET);
  395. break;
  396. case Opt_unhide:
  397. uopt->flags |= (1 << UDF_FLAG_UNHIDE);
  398. break;
  399. case Opt_undelete:
  400. uopt->flags |= (1 << UDF_FLAG_UNDELETE);
  401. break;
  402. case Opt_noadinicb:
  403. uopt->flags &= ~(1 << UDF_FLAG_USE_AD_IN_ICB);
  404. break;
  405. case Opt_adinicb:
  406. uopt->flags |= (1 << UDF_FLAG_USE_AD_IN_ICB);
  407. break;
  408. case Opt_shortad:
  409. uopt->flags |= (1 << UDF_FLAG_USE_SHORT_AD);
  410. break;
  411. case Opt_longad:
  412. uopt->flags &= ~(1 << UDF_FLAG_USE_SHORT_AD);
  413. break;
  414. case Opt_gid:
  415. if (match_int(args, &option))
  416. return 0;
  417. uopt->gid = option;
  418. uopt->flags |= (1 << UDF_FLAG_GID_SET);
  419. break;
  420. case Opt_uid:
  421. if (match_int(args, &option))
  422. return 0;
  423. uopt->uid = option;
  424. uopt->flags |= (1 << UDF_FLAG_UID_SET);
  425. break;
  426. case Opt_umask:
  427. if (match_octal(args, &option))
  428. return 0;
  429. uopt->umask = option;
  430. break;
  431. case Opt_nostrict:
  432. uopt->flags &= ~(1 << UDF_FLAG_STRICT);
  433. break;
  434. case Opt_session:
  435. if (match_int(args, &option))
  436. return 0;
  437. uopt->session = option;
  438. if (!remount)
  439. uopt->flags |= (1 << UDF_FLAG_SESSION_SET);
  440. break;
  441. case Opt_lastblock:
  442. if (match_int(args, &option))
  443. return 0;
  444. uopt->lastblock = option;
  445. if (!remount)
  446. uopt->flags |= (1 << UDF_FLAG_LASTBLOCK_SET);
  447. break;
  448. case Opt_anchor:
  449. if (match_int(args, &option))
  450. return 0;
  451. uopt->anchor = option;
  452. break;
  453. case Opt_volume:
  454. if (match_int(args, &option))
  455. return 0;
  456. uopt->volume = option;
  457. break;
  458. case Opt_partition:
  459. if (match_int(args, &option))
  460. return 0;
  461. uopt->partition = option;
  462. break;
  463. case Opt_fileset:
  464. if (match_int(args, &option))
  465. return 0;
  466. uopt->fileset = option;
  467. break;
  468. case Opt_rootdir:
  469. if (match_int(args, &option))
  470. return 0;
  471. uopt->rootdir = option;
  472. break;
  473. case Opt_utf8:
  474. uopt->flags |= (1 << UDF_FLAG_UTF8);
  475. break;
  476. #ifdef CONFIG_UDF_NLS
  477. case Opt_iocharset:
  478. uopt->nls_map = load_nls(args[0].from);
  479. uopt->flags |= (1 << UDF_FLAG_NLS_MAP);
  480. break;
  481. #endif
  482. case Opt_uignore:
  483. uopt->flags |= (1 << UDF_FLAG_UID_IGNORE);
  484. break;
  485. case Opt_uforget:
  486. uopt->flags |= (1 << UDF_FLAG_UID_FORGET);
  487. break;
  488. case Opt_gignore:
  489. uopt->flags |= (1 << UDF_FLAG_GID_IGNORE);
  490. break;
  491. case Opt_gforget:
  492. uopt->flags |= (1 << UDF_FLAG_GID_FORGET);
  493. break;
  494. case Opt_fmode:
  495. if (match_octal(args, &option))
  496. return 0;
  497. uopt->fmode = option & 0777;
  498. break;
  499. case Opt_dmode:
  500. if (match_octal(args, &option))
  501. return 0;
  502. uopt->dmode = option & 0777;
  503. break;
  504. default:
  505. printk(KERN_ERR "udf: bad mount option \"%s\" "
  506. "or missing value\n", p);
  507. return 0;
  508. }
  509. }
  510. return 1;
  511. }
  512. static int udf_remount_fs(struct super_block *sb, int *flags, char *options)
  513. {
  514. struct udf_options uopt;
  515. struct udf_sb_info *sbi = UDF_SB(sb);
  516. uopt.flags = sbi->s_flags;
  517. uopt.uid = sbi->s_uid;
  518. uopt.gid = sbi->s_gid;
  519. uopt.umask = sbi->s_umask;
  520. uopt.fmode = sbi->s_fmode;
  521. uopt.dmode = sbi->s_dmode;
  522. if (!udf_parse_options(options, &uopt, true))
  523. return -EINVAL;
  524. lock_kernel();
  525. sbi->s_flags = uopt.flags;
  526. sbi->s_uid = uopt.uid;
  527. sbi->s_gid = uopt.gid;
  528. sbi->s_umask = uopt.umask;
  529. sbi->s_fmode = uopt.fmode;
  530. sbi->s_dmode = uopt.dmode;
  531. if (sbi->s_lvid_bh) {
  532. int write_rev = le16_to_cpu(udf_sb_lvidiu(sbi)->minUDFWriteRev);
  533. if (write_rev > UDF_MAX_WRITE_VERSION)
  534. *flags |= MS_RDONLY;
  535. }
  536. if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY)) {
  537. unlock_kernel();
  538. return 0;
  539. }
  540. if (*flags & MS_RDONLY)
  541. udf_close_lvid(sb);
  542. else
  543. udf_open_lvid(sb);
  544. unlock_kernel();
  545. return 0;
  546. }
  547. /* Check Volume Structure Descriptors (ECMA 167 2/9.1) */
  548. /* We also check any "CD-ROM Volume Descriptor Set" (ECMA 167 2/8.3.1) */
  549. static loff_t udf_check_vsd(struct super_block *sb)
  550. {
  551. struct volStructDesc *vsd = NULL;
  552. loff_t sector = 32768;
  553. int sectorsize;
  554. struct buffer_head *bh = NULL;
  555. int nsr02 = 0;
  556. int nsr03 = 0;
  557. struct udf_sb_info *sbi;
  558. sbi = UDF_SB(sb);
  559. if (sb->s_blocksize < sizeof(struct volStructDesc))
  560. sectorsize = sizeof(struct volStructDesc);
  561. else
  562. sectorsize = sb->s_blocksize;
  563. sector += (sbi->s_session << sb->s_blocksize_bits);
  564. udf_debug("Starting at sector %u (%ld byte sectors)\n",
  565. (unsigned int)(sector >> sb->s_blocksize_bits),
  566. sb->s_blocksize);
  567. /* Process the sequence (if applicable) */
  568. for (; !nsr02 && !nsr03; sector += sectorsize) {
  569. /* Read a block */
  570. bh = udf_tread(sb, sector >> sb->s_blocksize_bits);
  571. if (!bh)
  572. break;
  573. /* Look for ISO descriptors */
  574. vsd = (struct volStructDesc *)(bh->b_data +
  575. (sector & (sb->s_blocksize - 1)));
  576. if (vsd->stdIdent[0] == 0) {
  577. brelse(bh);
  578. break;
  579. } else if (!strncmp(vsd->stdIdent, VSD_STD_ID_CD001,
  580. VSD_STD_ID_LEN)) {
  581. switch (vsd->structType) {
  582. case 0:
  583. udf_debug("ISO9660 Boot Record found\n");
  584. break;
  585. case 1:
  586. udf_debug("ISO9660 Primary Volume Descriptor "
  587. "found\n");
  588. break;
  589. case 2:
  590. udf_debug("ISO9660 Supplementary Volume "
  591. "Descriptor found\n");
  592. break;
  593. case 3:
  594. udf_debug("ISO9660 Volume Partition Descriptor "
  595. "found\n");
  596. break;
  597. case 255:
  598. udf_debug("ISO9660 Volume Descriptor Set "
  599. "Terminator found\n");
  600. break;
  601. default:
  602. udf_debug("ISO9660 VRS (%u) found\n",
  603. vsd->structType);
  604. break;
  605. }
  606. } else if (!strncmp(vsd->stdIdent, VSD_STD_ID_BEA01,
  607. VSD_STD_ID_LEN))
  608. ; /* nothing */
  609. else if (!strncmp(vsd->stdIdent, VSD_STD_ID_TEA01,
  610. VSD_STD_ID_LEN)) {
  611. brelse(bh);
  612. break;
  613. } else if (!strncmp(vsd->stdIdent, VSD_STD_ID_NSR02,
  614. VSD_STD_ID_LEN))
  615. nsr02 = sector;
  616. else if (!strncmp(vsd->stdIdent, VSD_STD_ID_NSR03,
  617. VSD_STD_ID_LEN))
  618. nsr03 = sector;
  619. brelse(bh);
  620. }
  621. if (nsr03)
  622. return nsr03;
  623. else if (nsr02)
  624. return nsr02;
  625. else if (sector - (sbi->s_session << sb->s_blocksize_bits) == 32768)
  626. return -1;
  627. else
  628. return 0;
  629. }
  630. static int udf_find_fileset(struct super_block *sb,
  631. struct kernel_lb_addr *fileset,
  632. struct kernel_lb_addr *root)
  633. {
  634. struct buffer_head *bh = NULL;
  635. long lastblock;
  636. uint16_t ident;
  637. struct udf_sb_info *sbi;
  638. if (fileset->logicalBlockNum != 0xFFFFFFFF ||
  639. fileset->partitionReferenceNum != 0xFFFF) {
  640. bh = udf_read_ptagged(sb, fileset, 0, &ident);
  641. if (!bh) {
  642. return 1;
  643. } else if (ident != TAG_IDENT_FSD) {
  644. brelse(bh);
  645. return 1;
  646. }
  647. }
  648. sbi = UDF_SB(sb);
  649. if (!bh) {
  650. /* Search backwards through the partitions */
  651. struct kernel_lb_addr newfileset;
  652. /* --> cvg: FIXME - is it reasonable? */
  653. return 1;
  654. for (newfileset.partitionReferenceNum = sbi->s_partitions - 1;
  655. (newfileset.partitionReferenceNum != 0xFFFF &&
  656. fileset->logicalBlockNum == 0xFFFFFFFF &&
  657. fileset->partitionReferenceNum == 0xFFFF);
  658. newfileset.partitionReferenceNum--) {
  659. lastblock = sbi->s_partmaps
  660. [newfileset.partitionReferenceNum]
  661. .s_partition_len;
  662. newfileset.logicalBlockNum = 0;
  663. do {
  664. bh = udf_read_ptagged(sb, &newfileset, 0,
  665. &ident);
  666. if (!bh) {
  667. newfileset.logicalBlockNum++;
  668. continue;
  669. }
  670. switch (ident) {
  671. case TAG_IDENT_SBD:
  672. {
  673. struct spaceBitmapDesc *sp;
  674. sp = (struct spaceBitmapDesc *)
  675. bh->b_data;
  676. newfileset.logicalBlockNum += 1 +
  677. ((le32_to_cpu(sp->numOfBytes) +
  678. sizeof(struct spaceBitmapDesc)
  679. - 1) >> sb->s_blocksize_bits);
  680. brelse(bh);
  681. break;
  682. }
  683. case TAG_IDENT_FSD:
  684. *fileset = newfileset;
  685. break;
  686. default:
  687. newfileset.logicalBlockNum++;
  688. brelse(bh);
  689. bh = NULL;
  690. break;
  691. }
  692. } while (newfileset.logicalBlockNum < lastblock &&
  693. fileset->logicalBlockNum == 0xFFFFFFFF &&
  694. fileset->partitionReferenceNum == 0xFFFF);
  695. }
  696. }
  697. if ((fileset->logicalBlockNum != 0xFFFFFFFF ||
  698. fileset->partitionReferenceNum != 0xFFFF) && bh) {
  699. udf_debug("Fileset at block=%d, partition=%d\n",
  700. fileset->logicalBlockNum,
  701. fileset->partitionReferenceNum);
  702. sbi->s_partition = fileset->partitionReferenceNum;
  703. udf_load_fileset(sb, bh, root);
  704. brelse(bh);
  705. return 0;
  706. }
  707. return 1;
  708. }
  709. static int udf_load_pvoldesc(struct super_block *sb, sector_t block)
  710. {
  711. struct primaryVolDesc *pvoldesc;
  712. struct ustr *instr, *outstr;
  713. struct buffer_head *bh;
  714. uint16_t ident;
  715. int ret = 1;
  716. instr = kmalloc(sizeof(struct ustr), GFP_NOFS);
  717. if (!instr)
  718. return 1;
  719. outstr = kmalloc(sizeof(struct ustr), GFP_NOFS);
  720. if (!outstr)
  721. goto out1;
  722. bh = udf_read_tagged(sb, block, block, &ident);
  723. if (!bh)
  724. goto out2;
  725. BUG_ON(ident != TAG_IDENT_PVD);
  726. pvoldesc = (struct primaryVolDesc *)bh->b_data;
  727. if (udf_disk_stamp_to_time(&UDF_SB(sb)->s_record_time,
  728. pvoldesc->recordingDateAndTime)) {
  729. #ifdef UDFFS_DEBUG
  730. struct timestamp *ts = &pvoldesc->recordingDateAndTime;
  731. udf_debug("recording time %04u/%02u/%02u"
  732. " %02u:%02u (%x)\n",
  733. le16_to_cpu(ts->year), ts->month, ts->day, ts->hour,
  734. ts->minute, le16_to_cpu(ts->typeAndTimezone));
  735. #endif
  736. }
  737. if (!udf_build_ustr(instr, pvoldesc->volIdent, 32))
  738. if (udf_CS0toUTF8(outstr, instr)) {
  739. strncpy(UDF_SB(sb)->s_volume_ident, outstr->u_name,
  740. outstr->u_len > 31 ? 31 : outstr->u_len);
  741. udf_debug("volIdent[] = '%s'\n",
  742. UDF_SB(sb)->s_volume_ident);
  743. }
  744. if (!udf_build_ustr(instr, pvoldesc->volSetIdent, 128))
  745. if (udf_CS0toUTF8(outstr, instr))
  746. udf_debug("volSetIdent[] = '%s'\n", outstr->u_name);
  747. brelse(bh);
  748. ret = 0;
  749. out2:
  750. kfree(outstr);
  751. out1:
  752. kfree(instr);
  753. return ret;
  754. }
  755. static int udf_load_metadata_files(struct super_block *sb, int partition)
  756. {
  757. struct udf_sb_info *sbi = UDF_SB(sb);
  758. struct udf_part_map *map;
  759. struct udf_meta_data *mdata;
  760. struct kernel_lb_addr addr;
  761. int fe_error = 0;
  762. map = &sbi->s_partmaps[partition];
  763. mdata = &map->s_type_specific.s_metadata;
  764. /* metadata address */
  765. addr.logicalBlockNum = mdata->s_meta_file_loc;
  766. addr.partitionReferenceNum = map->s_partition_num;
  767. udf_debug("Metadata file location: block = %d part = %d\n",
  768. addr.logicalBlockNum, addr.partitionReferenceNum);
  769. mdata->s_metadata_fe = udf_iget(sb, &addr);
  770. if (mdata->s_metadata_fe == NULL) {
  771. udf_warning(sb, __func__, "metadata inode efe not found, "
  772. "will try mirror inode.");
  773. fe_error = 1;
  774. } else if (UDF_I(mdata->s_metadata_fe)->i_alloc_type !=
  775. ICBTAG_FLAG_AD_SHORT) {
  776. udf_warning(sb, __func__, "metadata inode efe does not have "
  777. "short allocation descriptors!");
  778. fe_error = 1;
  779. iput(mdata->s_metadata_fe);
  780. mdata->s_metadata_fe = NULL;
  781. }
  782. /* mirror file entry */
  783. addr.logicalBlockNum = mdata->s_mirror_file_loc;
  784. addr.partitionReferenceNum = map->s_partition_num;
  785. udf_debug("Mirror metadata file location: block = %d part = %d\n",
  786. addr.logicalBlockNum, addr.partitionReferenceNum);
  787. mdata->s_mirror_fe = udf_iget(sb, &addr);
  788. if (mdata->s_mirror_fe == NULL) {
  789. if (fe_error) {
  790. udf_error(sb, __func__, "mirror inode efe not found "
  791. "and metadata inode is missing too, exiting...");
  792. goto error_exit;
  793. } else
  794. udf_warning(sb, __func__, "mirror inode efe not found,"
  795. " but metadata inode is OK");
  796. } else if (UDF_I(mdata->s_mirror_fe)->i_alloc_type !=
  797. ICBTAG_FLAG_AD_SHORT) {
  798. udf_warning(sb, __func__, "mirror inode efe does not have "
  799. "short allocation descriptors!");
  800. iput(mdata->s_mirror_fe);
  801. mdata->s_mirror_fe = NULL;
  802. if (fe_error)
  803. goto error_exit;
  804. }
  805. /*
  806. * bitmap file entry
  807. * Note:
  808. * Load only if bitmap file location differs from 0xFFFFFFFF (DCN-5102)
  809. */
  810. if (mdata->s_bitmap_file_loc != 0xFFFFFFFF) {
  811. addr.logicalBlockNum = mdata->s_bitmap_file_loc;
  812. addr.partitionReferenceNum = map->s_partition_num;
  813. udf_debug("Bitmap file location: block = %d part = %d\n",
  814. addr.logicalBlockNum, addr.partitionReferenceNum);
  815. mdata->s_bitmap_fe = udf_iget(sb, &addr);
  816. if (mdata->s_bitmap_fe == NULL) {
  817. if (sb->s_flags & MS_RDONLY)
  818. udf_warning(sb, __func__, "bitmap inode efe "
  819. "not found but it's ok since the disc"
  820. " is mounted read-only");
  821. else {
  822. udf_error(sb, __func__, "bitmap inode efe not "
  823. "found and attempted read-write mount");
  824. goto error_exit;
  825. }
  826. }
  827. }
  828. udf_debug("udf_load_metadata_files Ok\n");
  829. return 0;
  830. error_exit:
  831. return 1;
  832. }
  833. static void udf_load_fileset(struct super_block *sb, struct buffer_head *bh,
  834. struct kernel_lb_addr *root)
  835. {
  836. struct fileSetDesc *fset;
  837. fset = (struct fileSetDesc *)bh->b_data;
  838. *root = lelb_to_cpu(fset->rootDirectoryICB.extLocation);
  839. UDF_SB(sb)->s_serial_number = le16_to_cpu(fset->descTag.tagSerialNum);
  840. udf_debug("Rootdir at block=%d, partition=%d\n",
  841. root->logicalBlockNum, root->partitionReferenceNum);
  842. }
  843. int udf_compute_nr_groups(struct super_block *sb, u32 partition)
  844. {
  845. struct udf_part_map *map = &UDF_SB(sb)->s_partmaps[partition];
  846. return DIV_ROUND_UP(map->s_partition_len +
  847. (sizeof(struct spaceBitmapDesc) << 3),
  848. sb->s_blocksize * 8);
  849. }
  850. static struct udf_bitmap *udf_sb_alloc_bitmap(struct super_block *sb, u32 index)
  851. {
  852. struct udf_bitmap *bitmap;
  853. int nr_groups;
  854. int size;
  855. nr_groups = udf_compute_nr_groups(sb, index);
  856. size = sizeof(struct udf_bitmap) +
  857. (sizeof(struct buffer_head *) * nr_groups);
  858. if (size <= PAGE_SIZE)
  859. bitmap = kmalloc(size, GFP_KERNEL);
  860. else
  861. bitmap = vmalloc(size); /* TODO: get rid of vmalloc */
  862. if (bitmap == NULL) {
  863. udf_error(sb, __func__,
  864. "Unable to allocate space for bitmap "
  865. "and %d buffer_head pointers", nr_groups);
  866. return NULL;
  867. }
  868. memset(bitmap, 0x00, size);
  869. bitmap->s_block_bitmap = (struct buffer_head **)(bitmap + 1);
  870. bitmap->s_nr_groups = nr_groups;
  871. return bitmap;
  872. }
  873. static int udf_fill_partdesc_info(struct super_block *sb,
  874. struct partitionDesc *p, int p_index)
  875. {
  876. struct udf_part_map *map;
  877. struct udf_sb_info *sbi = UDF_SB(sb);
  878. struct partitionHeaderDesc *phd;
  879. map = &sbi->s_partmaps[p_index];
  880. map->s_partition_len = le32_to_cpu(p->partitionLength); /* blocks */
  881. map->s_partition_root = le32_to_cpu(p->partitionStartingLocation);
  882. if (p->accessType == cpu_to_le32(PD_ACCESS_TYPE_READ_ONLY))
  883. map->s_partition_flags |= UDF_PART_FLAG_READ_ONLY;
  884. if (p->accessType == cpu_to_le32(PD_ACCESS_TYPE_WRITE_ONCE))
  885. map->s_partition_flags |= UDF_PART_FLAG_WRITE_ONCE;
  886. if (p->accessType == cpu_to_le32(PD_ACCESS_TYPE_REWRITABLE))
  887. map->s_partition_flags |= UDF_PART_FLAG_REWRITABLE;
  888. if (p->accessType == cpu_to_le32(PD_ACCESS_TYPE_OVERWRITABLE))
  889. map->s_partition_flags |= UDF_PART_FLAG_OVERWRITABLE;
  890. udf_debug("Partition (%d type %x) starts at physical %d, "
  891. "block length %d\n", p_index,
  892. map->s_partition_type, map->s_partition_root,
  893. map->s_partition_len);
  894. if (strcmp(p->partitionContents.ident, PD_PARTITION_CONTENTS_NSR02) &&
  895. strcmp(p->partitionContents.ident, PD_PARTITION_CONTENTS_NSR03))
  896. return 0;
  897. phd = (struct partitionHeaderDesc *)p->partitionContentsUse;
  898. if (phd->unallocSpaceTable.extLength) {
  899. struct kernel_lb_addr loc = {
  900. .logicalBlockNum = le32_to_cpu(
  901. phd->unallocSpaceTable.extPosition),
  902. .partitionReferenceNum = p_index,
  903. };
  904. map->s_uspace.s_table = udf_iget(sb, &loc);
  905. if (!map->s_uspace.s_table) {
  906. udf_debug("cannot load unallocSpaceTable (part %d)\n",
  907. p_index);
  908. return 1;
  909. }
  910. map->s_partition_flags |= UDF_PART_FLAG_UNALLOC_TABLE;
  911. udf_debug("unallocSpaceTable (part %d) @ %ld\n",
  912. p_index, map->s_uspace.s_table->i_ino);
  913. }
  914. if (phd->unallocSpaceBitmap.extLength) {
  915. struct udf_bitmap *bitmap = udf_sb_alloc_bitmap(sb, p_index);
  916. if (!bitmap)
  917. return 1;
  918. map->s_uspace.s_bitmap = bitmap;
  919. bitmap->s_extLength = le32_to_cpu(
  920. phd->unallocSpaceBitmap.extLength);
  921. bitmap->s_extPosition = le32_to_cpu(
  922. phd->unallocSpaceBitmap.extPosition);
  923. map->s_partition_flags |= UDF_PART_FLAG_UNALLOC_BITMAP;
  924. udf_debug("unallocSpaceBitmap (part %d) @ %d\n", p_index,
  925. bitmap->s_extPosition);
  926. }
  927. if (phd->partitionIntegrityTable.extLength)
  928. udf_debug("partitionIntegrityTable (part %d)\n", p_index);
  929. if (phd->freedSpaceTable.extLength) {
  930. struct kernel_lb_addr loc = {
  931. .logicalBlockNum = le32_to_cpu(
  932. phd->freedSpaceTable.extPosition),
  933. .partitionReferenceNum = p_index,
  934. };
  935. map->s_fspace.s_table = udf_iget(sb, &loc);
  936. if (!map->s_fspace.s_table) {
  937. udf_debug("cannot load freedSpaceTable (part %d)\n",
  938. p_index);
  939. return 1;
  940. }
  941. map->s_partition_flags |= UDF_PART_FLAG_FREED_TABLE;
  942. udf_debug("freedSpaceTable (part %d) @ %ld\n",
  943. p_index, map->s_fspace.s_table->i_ino);
  944. }
  945. if (phd->freedSpaceBitmap.extLength) {
  946. struct udf_bitmap *bitmap = udf_sb_alloc_bitmap(sb, p_index);
  947. if (!bitmap)
  948. return 1;
  949. map->s_fspace.s_bitmap = bitmap;
  950. bitmap->s_extLength = le32_to_cpu(
  951. phd->freedSpaceBitmap.extLength);
  952. bitmap->s_extPosition = le32_to_cpu(
  953. phd->freedSpaceBitmap.extPosition);
  954. map->s_partition_flags |= UDF_PART_FLAG_FREED_BITMAP;
  955. udf_debug("freedSpaceBitmap (part %d) @ %d\n", p_index,
  956. bitmap->s_extPosition);
  957. }
  958. return 0;
  959. }
  960. static int udf_load_vat(struct super_block *sb, int p_index, int type1_index)
  961. {
  962. struct udf_sb_info *sbi = UDF_SB(sb);
  963. struct udf_part_map *map = &sbi->s_partmaps[p_index];
  964. struct kernel_lb_addr ino;
  965. struct buffer_head *bh = NULL;
  966. struct udf_inode_info *vati;
  967. uint32_t pos;
  968. struct virtualAllocationTable20 *vat20;
  969. /* VAT file entry is in the last recorded block */
  970. ino.partitionReferenceNum = type1_index;
  971. ino.logicalBlockNum = sbi->s_last_block - map->s_partition_root;
  972. sbi->s_vat_inode = udf_iget(sb, &ino);
  973. if (!sbi->s_vat_inode)
  974. return 1;
  975. if (map->s_partition_type == UDF_VIRTUAL_MAP15) {
  976. map->s_type_specific.s_virtual.s_start_offset = 0;
  977. map->s_type_specific.s_virtual.s_num_entries =
  978. (sbi->s_vat_inode->i_size - 36) >> 2;
  979. } else if (map->s_partition_type == UDF_VIRTUAL_MAP20) {
  980. vati = UDF_I(sbi->s_vat_inode);
  981. if (vati->i_alloc_type != ICBTAG_FLAG_AD_IN_ICB) {
  982. pos = udf_block_map(sbi->s_vat_inode, 0);
  983. bh = sb_bread(sb, pos);
  984. if (!bh)
  985. return 1;
  986. vat20 = (struct virtualAllocationTable20 *)bh->b_data;
  987. } else {
  988. vat20 = (struct virtualAllocationTable20 *)
  989. vati->i_ext.i_data;
  990. }
  991. map->s_type_specific.s_virtual.s_start_offset =
  992. le16_to_cpu(vat20->lengthHeader);
  993. map->s_type_specific.s_virtual.s_num_entries =
  994. (sbi->s_vat_inode->i_size -
  995. map->s_type_specific.s_virtual.
  996. s_start_offset) >> 2;
  997. brelse(bh);
  998. }
  999. return 0;
  1000. }
  1001. static int udf_load_partdesc(struct super_block *sb, sector_t block)
  1002. {
  1003. struct buffer_head *bh;
  1004. struct partitionDesc *p;
  1005. struct udf_part_map *map;
  1006. struct udf_sb_info *sbi = UDF_SB(sb);
  1007. int i, type1_idx;
  1008. uint16_t partitionNumber;
  1009. uint16_t ident;
  1010. int ret = 0;
  1011. bh = udf_read_tagged(sb, block, block, &ident);
  1012. if (!bh)
  1013. return 1;
  1014. if (ident != TAG_IDENT_PD)
  1015. goto out_bh;
  1016. p = (struct partitionDesc *)bh->b_data;
  1017. partitionNumber = le16_to_cpu(p->partitionNumber);
  1018. /* First scan for TYPE1, SPARABLE and METADATA partitions */
  1019. for (i = 0; i < sbi->s_partitions; i++) {
  1020. map = &sbi->s_partmaps[i];
  1021. udf_debug("Searching map: (%d == %d)\n",
  1022. map->s_partition_num, partitionNumber);
  1023. if (map->s_partition_num == partitionNumber &&
  1024. (map->s_partition_type == UDF_TYPE1_MAP15 ||
  1025. map->s_partition_type == UDF_SPARABLE_MAP15))
  1026. break;
  1027. }
  1028. if (i >= sbi->s_partitions) {
  1029. udf_debug("Partition (%d) not found in partition map\n",
  1030. partitionNumber);
  1031. goto out_bh;
  1032. }
  1033. ret = udf_fill_partdesc_info(sb, p, i);
  1034. /*
  1035. * Now rescan for VIRTUAL or METADATA partitions when SPARABLE and
  1036. * PHYSICAL partitions are already set up
  1037. */
  1038. type1_idx = i;
  1039. for (i = 0; i < sbi->s_partitions; i++) {
  1040. map = &sbi->s_partmaps[i];
  1041. if (map->s_partition_num == partitionNumber &&
  1042. (map->s_partition_type == UDF_VIRTUAL_MAP15 ||
  1043. map->s_partition_type == UDF_VIRTUAL_MAP20 ||
  1044. map->s_partition_type == UDF_METADATA_MAP25))
  1045. break;
  1046. }
  1047. if (i >= sbi->s_partitions)
  1048. goto out_bh;
  1049. ret = udf_fill_partdesc_info(sb, p, i);
  1050. if (ret)
  1051. goto out_bh;
  1052. if (map->s_partition_type == UDF_METADATA_MAP25) {
  1053. ret = udf_load_metadata_files(sb, i);
  1054. if (ret) {
  1055. printk(KERN_ERR "UDF-fs: error loading MetaData "
  1056. "partition map %d\n", i);
  1057. goto out_bh;
  1058. }
  1059. } else {
  1060. ret = udf_load_vat(sb, i, type1_idx);
  1061. if (ret)
  1062. goto out_bh;
  1063. /*
  1064. * Mark filesystem read-only if we have a partition with
  1065. * virtual map since we don't handle writing to it (we
  1066. * overwrite blocks instead of relocating them).
  1067. */
  1068. sb->s_flags |= MS_RDONLY;
  1069. printk(KERN_NOTICE "UDF-fs: Filesystem marked read-only "
  1070. "because writing to pseudooverwrite partition is "
  1071. "not implemented.\n");
  1072. }
  1073. out_bh:
  1074. /* In case loading failed, we handle cleanup in udf_fill_super */
  1075. brelse(bh);
  1076. return ret;
  1077. }
  1078. static int udf_load_logicalvol(struct super_block *sb, sector_t block,
  1079. struct kernel_lb_addr *fileset)
  1080. {
  1081. struct logicalVolDesc *lvd;
  1082. int i, j, offset;
  1083. uint8_t type;
  1084. struct udf_sb_info *sbi = UDF_SB(sb);
  1085. struct genericPartitionMap *gpm;
  1086. uint16_t ident;
  1087. struct buffer_head *bh;
  1088. int ret = 0;
  1089. bh = udf_read_tagged(sb, block, block, &ident);
  1090. if (!bh)
  1091. return 1;
  1092. BUG_ON(ident != TAG_IDENT_LVD);
  1093. lvd = (struct logicalVolDesc *)bh->b_data;
  1094. i = udf_sb_alloc_partition_maps(sb, le32_to_cpu(lvd->numPartitionMaps));
  1095. if (i != 0) {
  1096. ret = i;
  1097. goto out_bh;
  1098. }
  1099. for (i = 0, offset = 0;
  1100. i < sbi->s_partitions && offset < le32_to_cpu(lvd->mapTableLength);
  1101. i++, offset += gpm->partitionMapLength) {
  1102. struct udf_part_map *map = &sbi->s_partmaps[i];
  1103. gpm = (struct genericPartitionMap *)
  1104. &(lvd->partitionMaps[offset]);
  1105. type = gpm->partitionMapType;
  1106. if (type == 1) {
  1107. struct genericPartitionMap1 *gpm1 =
  1108. (struct genericPartitionMap1 *)gpm;
  1109. map->s_partition_type = UDF_TYPE1_MAP15;
  1110. map->s_volumeseqnum = le16_to_cpu(gpm1->volSeqNum);
  1111. map->s_partition_num = le16_to_cpu(gpm1->partitionNum);
  1112. map->s_partition_func = NULL;
  1113. } else if (type == 2) {
  1114. struct udfPartitionMap2 *upm2 =
  1115. (struct udfPartitionMap2 *)gpm;
  1116. if (!strncmp(upm2->partIdent.ident, UDF_ID_VIRTUAL,
  1117. strlen(UDF_ID_VIRTUAL))) {
  1118. u16 suf =
  1119. le16_to_cpu(((__le16 *)upm2->partIdent.
  1120. identSuffix)[0]);
  1121. if (suf < 0x0200) {
  1122. map->s_partition_type =
  1123. UDF_VIRTUAL_MAP15;
  1124. map->s_partition_func =
  1125. udf_get_pblock_virt15;
  1126. } else {
  1127. map->s_partition_type =
  1128. UDF_VIRTUAL_MAP20;
  1129. map->s_partition_func =
  1130. udf_get_pblock_virt20;
  1131. }
  1132. } else if (!strncmp(upm2->partIdent.ident,
  1133. UDF_ID_SPARABLE,
  1134. strlen(UDF_ID_SPARABLE))) {
  1135. uint32_t loc;
  1136. struct sparingTable *st;
  1137. struct sparablePartitionMap *spm =
  1138. (struct sparablePartitionMap *)gpm;
  1139. map->s_partition_type = UDF_SPARABLE_MAP15;
  1140. map->s_type_specific.s_sparing.s_packet_len =
  1141. le16_to_cpu(spm->packetLength);
  1142. for (j = 0; j < spm->numSparingTables; j++) {
  1143. struct buffer_head *bh2;
  1144. loc = le32_to_cpu(
  1145. spm->locSparingTable[j]);
  1146. bh2 = udf_read_tagged(sb, loc, loc,
  1147. &ident);
  1148. map->s_type_specific.s_sparing.
  1149. s_spar_map[j] = bh2;
  1150. if (bh2 == NULL)
  1151. continue;
  1152. st = (struct sparingTable *)bh2->b_data;
  1153. if (ident != 0 || strncmp(
  1154. st->sparingIdent.ident,
  1155. UDF_ID_SPARING,
  1156. strlen(UDF_ID_SPARING))) {
  1157. brelse(bh2);
  1158. map->s_type_specific.s_sparing.
  1159. s_spar_map[j] = NULL;
  1160. }
  1161. }
  1162. map->s_partition_func = udf_get_pblock_spar15;
  1163. } else if (!strncmp(upm2->partIdent.ident,
  1164. UDF_ID_METADATA,
  1165. strlen(UDF_ID_METADATA))) {
  1166. struct udf_meta_data *mdata =
  1167. &map->s_type_specific.s_metadata;
  1168. struct metadataPartitionMap *mdm =
  1169. (struct metadataPartitionMap *)
  1170. &(lvd->partitionMaps[offset]);
  1171. udf_debug("Parsing Logical vol part %d "
  1172. "type %d id=%s\n", i, type,
  1173. UDF_ID_METADATA);
  1174. map->s_partition_type = UDF_METADATA_MAP25;
  1175. map->s_partition_func = udf_get_pblock_meta25;
  1176. mdata->s_meta_file_loc =
  1177. le32_to_cpu(mdm->metadataFileLoc);
  1178. mdata->s_mirror_file_loc =
  1179. le32_to_cpu(mdm->metadataMirrorFileLoc);
  1180. mdata->s_bitmap_file_loc =
  1181. le32_to_cpu(mdm->metadataBitmapFileLoc);
  1182. mdata->s_alloc_unit_size =
  1183. le32_to_cpu(mdm->allocUnitSize);
  1184. mdata->s_align_unit_size =
  1185. le16_to_cpu(mdm->alignUnitSize);
  1186. mdata->s_dup_md_flag =
  1187. mdm->flags & 0x01;
  1188. udf_debug("Metadata Ident suffix=0x%x\n",
  1189. (le16_to_cpu(
  1190. ((__le16 *)
  1191. mdm->partIdent.identSuffix)[0])));
  1192. udf_debug("Metadata part num=%d\n",
  1193. le16_to_cpu(mdm->partitionNum));
  1194. udf_debug("Metadata part alloc unit size=%d\n",
  1195. le32_to_cpu(mdm->allocUnitSize));
  1196. udf_debug("Metadata file loc=%d\n",
  1197. le32_to_cpu(mdm->metadataFileLoc));
  1198. udf_debug("Mirror file loc=%d\n",
  1199. le32_to_cpu(mdm->metadataMirrorFileLoc));
  1200. udf_debug("Bitmap file loc=%d\n",
  1201. le32_to_cpu(mdm->metadataBitmapFileLoc));
  1202. udf_debug("Duplicate Flag: %d %d\n",
  1203. mdata->s_dup_md_flag, mdm->flags);
  1204. } else {
  1205. udf_debug("Unknown ident: %s\n",
  1206. upm2->partIdent.ident);
  1207. continue;
  1208. }
  1209. map->s_volumeseqnum = le16_to_cpu(upm2->volSeqNum);
  1210. map->s_partition_num = le16_to_cpu(upm2->partitionNum);
  1211. }
  1212. udf_debug("Partition (%d:%d) type %d on volume %d\n",
  1213. i, map->s_partition_num, type,
  1214. map->s_volumeseqnum);
  1215. }
  1216. if (fileset) {
  1217. struct long_ad *la = (struct long_ad *)&(lvd->logicalVolContentsUse[0]);
  1218. *fileset = lelb_to_cpu(la->extLocation);
  1219. udf_debug("FileSet found in LogicalVolDesc at block=%d, "
  1220. "partition=%d\n", fileset->logicalBlockNum,
  1221. fileset->partitionReferenceNum);
  1222. }
  1223. if (lvd->integritySeqExt.extLength)
  1224. udf_load_logicalvolint(sb, leea_to_cpu(lvd->integritySeqExt));
  1225. out_bh:
  1226. brelse(bh);
  1227. return ret;
  1228. }
  1229. /*
  1230. * udf_load_logicalvolint
  1231. *
  1232. */
  1233. static void udf_load_logicalvolint(struct super_block *sb, struct kernel_extent_ad loc)
  1234. {
  1235. struct buffer_head *bh = NULL;
  1236. uint16_t ident;
  1237. struct udf_sb_info *sbi = UDF_SB(sb);
  1238. struct logicalVolIntegrityDesc *lvid;
  1239. while (loc.extLength > 0 &&
  1240. (bh = udf_read_tagged(sb, loc.extLocation,
  1241. loc.extLocation, &ident)) &&
  1242. ident == TAG_IDENT_LVID) {
  1243. sbi->s_lvid_bh = bh;
  1244. lvid = (struct logicalVolIntegrityDesc *)bh->b_data;
  1245. if (lvid->nextIntegrityExt.extLength)
  1246. udf_load_logicalvolint(sb,
  1247. leea_to_cpu(lvid->nextIntegrityExt));
  1248. if (sbi->s_lvid_bh != bh)
  1249. brelse(bh);
  1250. loc.extLength -= sb->s_blocksize;
  1251. loc.extLocation++;
  1252. }
  1253. if (sbi->s_lvid_bh != bh)
  1254. brelse(bh);
  1255. }
  1256. /*
  1257. * udf_process_sequence
  1258. *
  1259. * PURPOSE
  1260. * Process a main/reserve volume descriptor sequence.
  1261. *
  1262. * PRE-CONDITIONS
  1263. * sb Pointer to _locked_ superblock.
  1264. * block First block of first extent of the sequence.
  1265. * lastblock Lastblock of first extent of the sequence.
  1266. *
  1267. * HISTORY
  1268. * July 1, 1997 - Andrew E. Mileski
  1269. * Written, tested, and released.
  1270. */
  1271. static noinline int udf_process_sequence(struct super_block *sb, long block,
  1272. long lastblock, struct kernel_lb_addr *fileset)
  1273. {
  1274. struct buffer_head *bh = NULL;
  1275. struct udf_vds_record vds[VDS_POS_LENGTH];
  1276. struct udf_vds_record *curr;
  1277. struct generic_desc *gd;
  1278. struct volDescPtr *vdp;
  1279. int done = 0;
  1280. uint32_t vdsn;
  1281. uint16_t ident;
  1282. long next_s = 0, next_e = 0;
  1283. memset(vds, 0, sizeof(struct udf_vds_record) * VDS_POS_LENGTH);
  1284. /*
  1285. * Read the main descriptor sequence and find which descriptors
  1286. * are in it.
  1287. */
  1288. for (; (!done && block <= lastblock); block++) {
  1289. bh = udf_read_tagged(sb, block, block, &ident);
  1290. if (!bh) {
  1291. printk(KERN_ERR "udf: Block %Lu of volume descriptor "
  1292. "sequence is corrupted or we could not read "
  1293. "it.\n", (unsigned long long)block);
  1294. return 1;
  1295. }
  1296. /* Process each descriptor (ISO 13346 3/8.3-8.4) */
  1297. gd = (struct generic_desc *)bh->b_data;
  1298. vdsn = le32_to_cpu(gd->volDescSeqNum);
  1299. switch (ident) {
  1300. case TAG_IDENT_PVD: /* ISO 13346 3/10.1 */
  1301. curr = &vds[VDS_POS_PRIMARY_VOL_DESC];
  1302. if (vdsn >= curr->volDescSeqNum) {
  1303. curr->volDescSeqNum = vdsn;
  1304. curr->block = block;
  1305. }
  1306. break;
  1307. case TAG_IDENT_VDP: /* ISO 13346 3/10.3 */
  1308. curr = &vds[VDS_POS_VOL_DESC_PTR];
  1309. if (vdsn >= curr->volDescSeqNum) {
  1310. curr->volDescSeqNum = vdsn;
  1311. curr->block = block;
  1312. vdp = (struct volDescPtr *)bh->b_data;
  1313. next_s = le32_to_cpu(
  1314. vdp->nextVolDescSeqExt.extLocation);
  1315. next_e = le32_to_cpu(
  1316. vdp->nextVolDescSeqExt.extLength);
  1317. next_e = next_e >> sb->s_blocksize_bits;
  1318. next_e += next_s;
  1319. }
  1320. break;
  1321. case TAG_IDENT_IUVD: /* ISO 13346 3/10.4 */
  1322. curr = &vds[VDS_POS_IMP_USE_VOL_DESC];
  1323. if (vdsn >= curr->volDescSeqNum) {
  1324. curr->volDescSeqNum = vdsn;
  1325. curr->block = block;
  1326. }
  1327. break;
  1328. case TAG_IDENT_PD: /* ISO 13346 3/10.5 */
  1329. curr = &vds[VDS_POS_PARTITION_DESC];
  1330. if (!curr->block)
  1331. curr->block = block;
  1332. break;
  1333. case TAG_IDENT_LVD: /* ISO 13346 3/10.6 */
  1334. curr = &vds[VDS_POS_LOGICAL_VOL_DESC];
  1335. if (vdsn >= curr->volDescSeqNum) {
  1336. curr->volDescSeqNum = vdsn;
  1337. curr->block = block;
  1338. }
  1339. break;
  1340. case TAG_IDENT_USD: /* ISO 13346 3/10.8 */
  1341. curr = &vds[VDS_POS_UNALLOC_SPACE_DESC];
  1342. if (vdsn >= curr->volDescSeqNum) {
  1343. curr->volDescSeqNum = vdsn;
  1344. curr->block = block;
  1345. }
  1346. break;
  1347. case TAG_IDENT_TD: /* ISO 13346 3/10.9 */
  1348. vds[VDS_POS_TERMINATING_DESC].block = block;
  1349. if (next_e) {
  1350. block = next_s;
  1351. lastblock = next_e;
  1352. next_s = next_e = 0;
  1353. } else
  1354. done = 1;
  1355. break;
  1356. }
  1357. brelse(bh);
  1358. }
  1359. /*
  1360. * Now read interesting descriptors again and process them
  1361. * in a suitable order
  1362. */
  1363. if (!vds[VDS_POS_PRIMARY_VOL_DESC].block) {
  1364. printk(KERN_ERR "udf: Primary Volume Descriptor not found!\n");
  1365. return 1;
  1366. }
  1367. if (udf_load_pvoldesc(sb, vds[VDS_POS_PRIMARY_VOL_DESC].block))
  1368. return 1;
  1369. if (vds[VDS_POS_LOGICAL_VOL_DESC].block && udf_load_logicalvol(sb,
  1370. vds[VDS_POS_LOGICAL_VOL_DESC].block, fileset))
  1371. return 1;
  1372. if (vds[VDS_POS_PARTITION_DESC].block) {
  1373. /*
  1374. * We rescan the whole descriptor sequence to find
  1375. * partition descriptor blocks and process them.
  1376. */
  1377. for (block = vds[VDS_POS_PARTITION_DESC].block;
  1378. block < vds[VDS_POS_TERMINATING_DESC].block;
  1379. block++)
  1380. if (udf_load_partdesc(sb, block))
  1381. return 1;
  1382. }
  1383. return 0;
  1384. }
  1385. static int udf_load_sequence(struct super_block *sb, struct buffer_head *bh,
  1386. struct kernel_lb_addr *fileset)
  1387. {
  1388. struct anchorVolDescPtr *anchor;
  1389. long main_s, main_e, reserve_s, reserve_e;
  1390. struct udf_sb_info *sbi;
  1391. sbi = UDF_SB(sb);
  1392. anchor = (struct anchorVolDescPtr *)bh->b_data;
  1393. /* Locate the main sequence */
  1394. main_s = le32_to_cpu(anchor->mainVolDescSeqExt.extLocation);
  1395. main_e = le32_to_cpu(anchor->mainVolDescSeqExt.extLength);
  1396. main_e = main_e >> sb->s_blocksize_bits;
  1397. main_e += main_s;
  1398. /* Locate the reserve sequence */
  1399. reserve_s = le32_to_cpu(anchor->reserveVolDescSeqExt.extLocation);
  1400. reserve_e = le32_to_cpu(anchor->reserveVolDescSeqExt.extLength);
  1401. reserve_e = reserve_e >> sb->s_blocksize_bits;
  1402. reserve_e += reserve_s;
  1403. /* Process the main & reserve sequences */
  1404. /* responsible for finding the PartitionDesc(s) */
  1405. if (!udf_process_sequence(sb, main_s, main_e, fileset))
  1406. return 1;
  1407. return !udf_process_sequence(sb, reserve_s, reserve_e, fileset);
  1408. }
  1409. /*
  1410. * Check whether there is an anchor block in the given block and
  1411. * load Volume Descriptor Sequence if so.
  1412. */
  1413. static int udf_check_anchor_block(struct super_block *sb, sector_t block,
  1414. struct kernel_lb_addr *fileset)
  1415. {
  1416. struct buffer_head *bh;
  1417. uint16_t ident;
  1418. int ret;
  1419. if (UDF_QUERY_FLAG(sb, UDF_FLAG_VARCONV) &&
  1420. udf_fixed_to_variable(block) >=
  1421. sb->s_bdev->bd_inode->i_size >> sb->s_blocksize_bits)
  1422. return 0;
  1423. bh = udf_read_tagged(sb, block, block, &ident);
  1424. if (!bh)
  1425. return 0;
  1426. if (ident != TAG_IDENT_AVDP) {
  1427. brelse(bh);
  1428. return 0;
  1429. }
  1430. ret = udf_load_sequence(sb, bh, fileset);
  1431. brelse(bh);
  1432. return ret;
  1433. }
  1434. /* Search for an anchor volume descriptor pointer */
  1435. static sector_t udf_scan_anchors(struct super_block *sb, sector_t lastblock,
  1436. struct kernel_lb_addr *fileset)
  1437. {
  1438. sector_t last[6];
  1439. int i;
  1440. struct udf_sb_info *sbi = UDF_SB(sb);
  1441. int last_count = 0;
  1442. /* First try user provided anchor */
  1443. if (sbi->s_anchor) {
  1444. if (udf_check_anchor_block(sb, sbi->s_anchor, fileset))
  1445. return lastblock;
  1446. }
  1447. /*
  1448. * according to spec, anchor is in either:
  1449. * block 256
  1450. * lastblock-256
  1451. * lastblock
  1452. * however, if the disc isn't closed, it could be 512.
  1453. */
  1454. if (udf_check_anchor_block(sb, sbi->s_session + 256, fileset))
  1455. return lastblock;
  1456. /*
  1457. * The trouble is which block is the last one. Drives often misreport
  1458. * this so we try various possibilities.
  1459. */
  1460. last[last_count++] = lastblock;
  1461. if (lastblock >= 1)
  1462. last[last_count++] = lastblock - 1;
  1463. last[last_count++] = lastblock + 1;
  1464. if (lastblock >= 2)
  1465. last[last_count++] = lastblock - 2;
  1466. if (lastblock >= 150)
  1467. last[last_count++] = lastblock - 150;
  1468. if (lastblock >= 152)
  1469. last[last_count++] = lastblock - 152;
  1470. for (i = 0; i < last_count; i++) {
  1471. if (last[i] >= sb->s_bdev->bd_inode->i_size >>
  1472. sb->s_blocksize_bits)
  1473. continue;
  1474. if (udf_check_anchor_block(sb, last[i], fileset))
  1475. return last[i];
  1476. if (last[i] < 256)
  1477. continue;
  1478. if (udf_check_anchor_block(sb, last[i] - 256, fileset))
  1479. return last[i];
  1480. }
  1481. /* Finally try block 512 in case media is open */
  1482. if (udf_check_anchor_block(sb, sbi->s_session + 512, fileset))
  1483. return last[0];
  1484. return 0;
  1485. }
  1486. /*
  1487. * Find an anchor volume descriptor and load Volume Descriptor Sequence from
  1488. * area specified by it. The function expects sbi->s_lastblock to be the last
  1489. * block on the media.
  1490. *
  1491. * Return 1 if ok, 0 if not found.
  1492. *
  1493. */
  1494. static int udf_find_anchor(struct super_block *sb,
  1495. struct kernel_lb_addr *fileset)
  1496. {
  1497. sector_t lastblock;
  1498. struct udf_sb_info *sbi = UDF_SB(sb);
  1499. lastblock = udf_scan_anchors(sb, sbi->s_last_block, fileset);
  1500. if (lastblock)
  1501. goto out;
  1502. /* No anchor found? Try VARCONV conversion of block numbers */
  1503. UDF_SET_FLAG(sb, UDF_FLAG_VARCONV);
  1504. /* Firstly, we try to not convert number of the last block */
  1505. lastblock = udf_scan_anchors(sb,
  1506. udf_variable_to_fixed(sbi->s_last_block),
  1507. fileset);
  1508. if (lastblock)
  1509. goto out;
  1510. /* Secondly, we try with converted number of the last block */
  1511. lastblock = udf_scan_anchors(sb, sbi->s_last_block, fileset);
  1512. if (!lastblock) {
  1513. /* VARCONV didn't help. Clear it. */
  1514. UDF_CLEAR_FLAG(sb, UDF_FLAG_VARCONV);
  1515. return 0;
  1516. }
  1517. out:
  1518. sbi->s_last_block = lastblock;
  1519. return 1;
  1520. }
  1521. /*
  1522. * Check Volume Structure Descriptor, find Anchor block and load Volume
  1523. * Descriptor Sequence
  1524. */
  1525. static int udf_load_vrs(struct super_block *sb, struct udf_options *uopt,
  1526. int silent, struct kernel_lb_addr *fileset)
  1527. {
  1528. struct udf_sb_info *sbi = UDF_SB(sb);
  1529. loff_t nsr_off;
  1530. if (!sb_set_blocksize(sb, uopt->blocksize)) {
  1531. if (!silent)
  1532. printk(KERN_WARNING "UDF-fs: Bad block size\n");
  1533. return 0;
  1534. }
  1535. sbi->s_last_block = uopt->lastblock;
  1536. if (!uopt->novrs) {
  1537. /* Check that it is NSR02 compliant */
  1538. nsr_off = udf_check_vsd(sb);
  1539. if (!nsr_off) {
  1540. if (!silent)
  1541. printk(KERN_WARNING "UDF-fs: No VRS found\n");
  1542. return 0;
  1543. }
  1544. if (nsr_off == -1)
  1545. udf_debug("Failed to read byte 32768. Assuming open "
  1546. "disc. Skipping validity check\n");
  1547. if (!sbi->s_last_block)
  1548. sbi->s_last_block = udf_get_last_block(sb);
  1549. } else {
  1550. udf_debug("Validity check skipped because of novrs option\n");
  1551. }
  1552. /* Look for anchor block and load Volume Descriptor Sequence */
  1553. sbi->s_anchor = uopt->anchor;
  1554. if (!udf_find_anchor(sb, fileset)) {
  1555. if (!silent)
  1556. printk(KERN_WARNING "UDF-fs: No anchor found\n");
  1557. return 0;
  1558. }
  1559. return 1;
  1560. }
  1561. static void udf_open_lvid(struct super_block *sb)
  1562. {
  1563. struct udf_sb_info *sbi = UDF_SB(sb);
  1564. struct buffer_head *bh = sbi->s_lvid_bh;
  1565. struct logicalVolIntegrityDesc *lvid;
  1566. struct logicalVolIntegrityDescImpUse *lvidiu;
  1567. if (!bh)
  1568. return;
  1569. lvid = (struct logicalVolIntegrityDesc *)bh->b_data;
  1570. lvidiu = udf_sb_lvidiu(sbi);
  1571. lvidiu->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
  1572. lvidiu->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
  1573. udf_time_to_disk_stamp(&lvid->recordingDateAndTime,
  1574. CURRENT_TIME);
  1575. lvid->integrityType = cpu_to_le32(LVID_INTEGRITY_TYPE_OPEN);
  1576. lvid->descTag.descCRC = cpu_to_le16(
  1577. crc_itu_t(0, (char *)lvid + sizeof(struct tag),
  1578. le16_to_cpu(lvid->descTag.descCRCLength)));
  1579. lvid->descTag.tagChecksum = udf_tag_checksum(&lvid->descTag);
  1580. mark_buffer_dirty(bh);
  1581. sbi->s_lvid_dirty = 0;
  1582. }
  1583. static void udf_close_lvid(struct super_block *sb)
  1584. {
  1585. struct udf_sb_info *sbi = UDF_SB(sb);
  1586. struct buffer_head *bh = sbi->s_lvid_bh;
  1587. struct logicalVolIntegrityDesc *lvid;
  1588. struct logicalVolIntegrityDescImpUse *lvidiu;
  1589. if (!bh)
  1590. return;
  1591. lvid = (struct logicalVolIntegrityDesc *)bh->b_data;
  1592. lvidiu = udf_sb_lvidiu(sbi);
  1593. lvidiu->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
  1594. lvidiu->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
  1595. udf_time_to_disk_stamp(&lvid->recordingDateAndTime, CURRENT_TIME);
  1596. if (UDF_MAX_WRITE_VERSION > le16_to_cpu(lvidiu->maxUDFWriteRev))
  1597. lvidiu->maxUDFWriteRev = cpu_to_le16(UDF_MAX_WRITE_VERSION);
  1598. if (sbi->s_udfrev > le16_to_cpu(lvidiu->minUDFReadRev))
  1599. lvidiu->minUDFReadRev = cpu_to_le16(sbi->s_udfrev);
  1600. if (sbi->s_udfrev > le16_to_cpu(lvidiu->minUDFWriteRev))
  1601. lvidiu->minUDFWriteRev = cpu_to_le16(sbi->s_udfrev);
  1602. lvid->integrityType = cpu_to_le32(LVID_INTEGRITY_TYPE_CLOSE);
  1603. lvid->descTag.descCRC = cpu_to_le16(
  1604. crc_itu_t(0, (char *)lvid + sizeof(struct tag),
  1605. le16_to_cpu(lvid->descTag.descCRCLength)));
  1606. lvid->descTag.tagChecksum = udf_tag_checksum(&lvid->descTag);
  1607. mark_buffer_dirty(bh);
  1608. sbi->s_lvid_dirty = 0;
  1609. }
  1610. static void udf_sb_free_bitmap(struct udf_bitmap *bitmap)
  1611. {
  1612. int i;
  1613. int nr_groups = bitmap->s_nr_groups;
  1614. int size = sizeof(struct udf_bitmap) + (sizeof(struct buffer_head *) *
  1615. nr_groups);
  1616. for (i = 0; i < nr_groups; i++)
  1617. if (bitmap->s_block_bitmap[i])
  1618. brelse(bitmap->s_block_bitmap[i]);
  1619. if (size <= PAGE_SIZE)
  1620. kfree(bitmap);
  1621. else
  1622. vfree(bitmap);
  1623. }
  1624. static void udf_free_partition(struct udf_part_map *map)
  1625. {
  1626. int i;
  1627. struct udf_meta_data *mdata;
  1628. if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_TABLE)
  1629. iput(map->s_uspace.s_table);
  1630. if (map->s_partition_flags & UDF_PART_FLAG_FREED_TABLE)
  1631. iput(map->s_fspace.s_table);
  1632. if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_BITMAP)
  1633. udf_sb_free_bitmap(map->s_uspace.s_bitmap);
  1634. if (map->s_partition_flags & UDF_PART_FLAG_FREED_BITMAP)
  1635. udf_sb_free_bitmap(map->s_fspace.s_bitmap);
  1636. if (map->s_partition_type == UDF_SPARABLE_MAP15)
  1637. for (i = 0; i < 4; i++)
  1638. brelse(map->s_type_specific.s_sparing.s_spar_map[i]);
  1639. else if (map->s_partition_type == UDF_METADATA_MAP25) {
  1640. mdata = &map->s_type_specific.s_metadata;
  1641. iput(mdata->s_metadata_fe);
  1642. mdata->s_metadata_fe = NULL;
  1643. iput(mdata->s_mirror_fe);
  1644. mdata->s_mirror_fe = NULL;
  1645. iput(mdata->s_bitmap_fe);
  1646. mdata->s_bitmap_fe = NULL;
  1647. }
  1648. }
  1649. static int udf_fill_super(struct super_block *sb, void *options, int silent)
  1650. {
  1651. int i;
  1652. int ret;
  1653. struct inode *inode = NULL;
  1654. struct udf_options uopt;
  1655. struct kernel_lb_addr rootdir, fileset;
  1656. struct udf_sb_info *sbi;
  1657. uopt.flags = (1 << UDF_FLAG_USE_AD_IN_ICB) | (1 << UDF_FLAG_STRICT);
  1658. uopt.uid = -1;
  1659. uopt.gid = -1;
  1660. uopt.umask = 0;
  1661. uopt.fmode = UDF_INVALID_MODE;
  1662. uopt.dmode = UDF_INVALID_MODE;
  1663. sbi = kzalloc(sizeof(struct udf_sb_info), GFP_KERNEL);
  1664. if (!sbi)
  1665. return -ENOMEM;
  1666. sb->s_fs_info = sbi;
  1667. mutex_init(&sbi->s_alloc_mutex);
  1668. if (!udf_parse_options((char *)options, &uopt, false))
  1669. goto error_out;
  1670. if (uopt.flags & (1 << UDF_FLAG_UTF8) &&
  1671. uopt.flags & (1 << UDF_FLAG_NLS_MAP)) {
  1672. udf_error(sb, "udf_read_super",
  1673. "utf8 cannot be combined with iocharset\n");
  1674. goto error_out;
  1675. }
  1676. #ifdef CONFIG_UDF_NLS
  1677. if ((uopt.flags & (1 << UDF_FLAG_NLS_MAP)) && !uopt.nls_map) {
  1678. uopt.nls_map = load_nls_default();
  1679. if (!uopt.nls_map)
  1680. uopt.flags &= ~(1 << UDF_FLAG_NLS_MAP);
  1681. else
  1682. udf_debug("Using default NLS map\n");
  1683. }
  1684. #endif
  1685. if (!(uopt.flags & (1 << UDF_FLAG_NLS_MAP)))
  1686. uopt.flags |= (1 << UDF_FLAG_UTF8);
  1687. fileset.logicalBlockNum = 0xFFFFFFFF;
  1688. fileset.partitionReferenceNum = 0xFFFF;
  1689. sbi->s_flags = uopt.flags;
  1690. sbi->s_uid = uopt.uid;
  1691. sbi->s_gid = uopt.gid;
  1692. sbi->s_umask = uopt.umask;
  1693. sbi->s_fmode = uopt.fmode;
  1694. sbi->s_dmode = uopt.dmode;
  1695. sbi->s_nls_map = uopt.nls_map;
  1696. if (uopt.session == 0xFFFFFFFF)
  1697. sbi->s_session = udf_get_last_session(sb);
  1698. else
  1699. sbi->s_session = uopt.session;
  1700. udf_debug("Multi-session=%d\n", sbi->s_session);
  1701. /* Fill in the rest of the superblock */
  1702. sb->s_op = &udf_sb_ops;
  1703. sb->s_export_op = &udf_export_ops;
  1704. sb->dq_op = NULL;
  1705. sb->s_dirt = 0;
  1706. sb->s_magic = UDF_SUPER_MAGIC;
  1707. sb->s_time_gran = 1000;
  1708. if (uopt.flags & (1 << UDF_FLAG_BLOCKSIZE_SET)) {
  1709. ret = udf_load_vrs(sb, &uopt, silent, &fileset);
  1710. } else {
  1711. uopt.blocksize = bdev_logical_block_size(sb->s_bdev);
  1712. ret = udf_load_vrs(sb, &uopt, silent, &fileset);
  1713. if (!ret && uopt.blocksize != UDF_DEFAULT_BLOCKSIZE) {
  1714. if (!silent)
  1715. printk(KERN_NOTICE
  1716. "UDF-fs: Rescanning with blocksize "
  1717. "%d\n", UDF_DEFAULT_BLOCKSIZE);
  1718. uopt.blocksize = UDF_DEFAULT_BLOCKSIZE;
  1719. ret = udf_load_vrs(sb, &uopt, silent, &fileset);
  1720. }
  1721. }
  1722. if (!ret) {
  1723. printk(KERN_WARNING "UDF-fs: No partition found (1)\n");
  1724. goto error_out;
  1725. }
  1726. udf_debug("Lastblock=%d\n", sbi->s_last_block);
  1727. if (sbi->s_lvid_bh) {
  1728. struct logicalVolIntegrityDescImpUse *lvidiu =
  1729. udf_sb_lvidiu(sbi);
  1730. uint16_t minUDFReadRev = le16_to_cpu(lvidiu->minUDFReadRev);
  1731. uint16_t minUDFWriteRev = le16_to_cpu(lvidiu->minUDFWriteRev);
  1732. /* uint16_t maxUDFWriteRev =
  1733. le16_to_cpu(lvidiu->maxUDFWriteRev); */
  1734. if (minUDFReadRev > UDF_MAX_READ_VERSION) {
  1735. printk(KERN_ERR "UDF-fs: minUDFReadRev=%x "
  1736. "(max is %x)\n",
  1737. le16_to_cpu(lvidiu->minUDFReadRev),
  1738. UDF_MAX_READ_VERSION);
  1739. goto error_out;
  1740. } else if (minUDFWriteRev > UDF_MAX_WRITE_VERSION)
  1741. sb->s_flags |= MS_RDONLY;
  1742. sbi->s_udfrev = minUDFWriteRev;
  1743. if (minUDFReadRev >= UDF_VERS_USE_EXTENDED_FE)
  1744. UDF_SET_FLAG(sb, UDF_FLAG_USE_EXTENDED_FE);
  1745. if (minUDFReadRev >= UDF_VERS_USE_STREAMS)
  1746. UDF_SET_FLAG(sb, UDF_FLAG_USE_STREAMS);
  1747. }
  1748. if (!sbi->s_partitions) {
  1749. printk(KERN_WARNING "UDF-fs: No partition found (2)\n");
  1750. goto error_out;
  1751. }
  1752. if (sbi->s_partmaps[sbi->s_partition].s_partition_flags &
  1753. UDF_PART_FLAG_READ_ONLY) {
  1754. printk(KERN_NOTICE "UDF-fs: Partition marked readonly; "
  1755. "forcing readonly mount\n");
  1756. sb->s_flags |= MS_RDONLY;
  1757. }
  1758. if (udf_find_fileset(sb, &fileset, &rootdir)) {
  1759. printk(KERN_WARNING "UDF-fs: No fileset found\n");
  1760. goto error_out;
  1761. }
  1762. if (!silent) {
  1763. struct timestamp ts;
  1764. udf_time_to_disk_stamp(&ts, sbi->s_record_time);
  1765. udf_info("UDF: Mounting volume '%s', "
  1766. "timestamp %04u/%02u/%02u %02u:%02u (%x)\n",
  1767. sbi->s_volume_ident, le16_to_cpu(ts.year), ts.month, ts.day,
  1768. ts.hour, ts.minute, le16_to_cpu(ts.typeAndTimezone));
  1769. }
  1770. if (!(sb->s_flags & MS_RDONLY))
  1771. udf_open_lvid(sb);
  1772. /* Assign the root inode */
  1773. /* assign inodes by physical block number */
  1774. /* perhaps it's not extensible enough, but for now ... */
  1775. inode = udf_iget(sb, &rootdir);
  1776. if (!inode) {
  1777. printk(KERN_ERR "UDF-fs: Error in udf_iget, block=%d, "
  1778. "partition=%d\n",
  1779. rootdir.logicalBlockNum, rootdir.partitionReferenceNum);
  1780. goto error_out;
  1781. }
  1782. /* Allocate a dentry for the root inode */
  1783. sb->s_root = d_alloc_root(inode);
  1784. if (!sb->s_root) {
  1785. printk(KERN_ERR "UDF-fs: Couldn't allocate root dentry\n");
  1786. iput(inode);
  1787. goto error_out;
  1788. }
  1789. sb->s_maxbytes = MAX_LFS_FILESIZE;
  1790. return 0;
  1791. error_out:
  1792. if (sbi->s_vat_inode)
  1793. iput(sbi->s_vat_inode);
  1794. if (sbi->s_partitions)
  1795. for (i = 0; i < sbi->s_partitions; i++)
  1796. udf_free_partition(&sbi->s_partmaps[i]);
  1797. #ifdef CONFIG_UDF_NLS
  1798. if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP))
  1799. unload_nls(sbi->s_nls_map);
  1800. #endif
  1801. if (!(sb->s_flags & MS_RDONLY))
  1802. udf_close_lvid(sb);
  1803. brelse(sbi->s_lvid_bh);
  1804. kfree(sbi->s_partmaps);
  1805. kfree(sbi);
  1806. sb->s_fs_info = NULL;
  1807. return -EINVAL;
  1808. }
  1809. static void udf_error(struct super_block *sb, const char *function,
  1810. const char *fmt, ...)
  1811. {
  1812. va_list args;
  1813. if (!(sb->s_flags & MS_RDONLY)) {
  1814. /* mark sb error */
  1815. sb->s_dirt = 1;
  1816. }
  1817. va_start(args, fmt);
  1818. vsnprintf(error_buf, sizeof(error_buf), fmt, args);
  1819. va_end(args);
  1820. printk(KERN_CRIT "UDF-fs error (device %s): %s: %s\n",
  1821. sb->s_id, function, error_buf);
  1822. }
  1823. void udf_warning(struct super_block *sb, const char *function,
  1824. const char *fmt, ...)
  1825. {
  1826. va_list args;
  1827. va_start(args, fmt);
  1828. vsnprintf(error_buf, sizeof(error_buf), fmt, args);
  1829. va_end(args);
  1830. printk(KERN_WARNING "UDF-fs warning (device %s): %s: %s\n",
  1831. sb->s_id, function, error_buf);
  1832. }
  1833. static void udf_put_super(struct super_block *sb)
  1834. {
  1835. int i;
  1836. struct udf_sb_info *sbi;
  1837. sbi = UDF_SB(sb);
  1838. lock_kernel();
  1839. if (sbi->s_vat_inode)
  1840. iput(sbi->s_vat_inode);
  1841. if (sbi->s_partitions)
  1842. for (i = 0; i < sbi->s_partitions; i++)
  1843. udf_free_partition(&sbi->s_partmaps[i]);
  1844. #ifdef CONFIG_UDF_NLS
  1845. if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP))
  1846. unload_nls(sbi->s_nls_map);
  1847. #endif
  1848. if (!(sb->s_flags & MS_RDONLY))
  1849. udf_close_lvid(sb);
  1850. brelse(sbi->s_lvid_bh);
  1851. kfree(sbi->s_partmaps);
  1852. kfree(sb->s_fs_info);
  1853. sb->s_fs_info = NULL;
  1854. unlock_kernel();
  1855. }
  1856. static int udf_sync_fs(struct super_block *sb, int wait)
  1857. {
  1858. struct udf_sb_info *sbi = UDF_SB(sb);
  1859. mutex_lock(&sbi->s_alloc_mutex);
  1860. if (sbi->s_lvid_dirty) {
  1861. /*
  1862. * Blockdevice will be synced later so we don't have to submit
  1863. * the buffer for IO
  1864. */
  1865. mark_buffer_dirty(sbi->s_lvid_bh);
  1866. sb->s_dirt = 0;
  1867. sbi->s_lvid_dirty = 0;
  1868. }
  1869. mutex_unlock(&sbi->s_alloc_mutex);
  1870. return 0;
  1871. }
  1872. static int udf_statfs(struct dentry *dentry, struct kstatfs *buf)
  1873. {
  1874. struct super_block *sb = dentry->d_sb;
  1875. struct udf_sb_info *sbi = UDF_SB(sb);
  1876. struct logicalVolIntegrityDescImpUse *lvidiu;
  1877. u64 id = huge_encode_dev(sb->s_bdev->bd_dev);
  1878. if (sbi->s_lvid_bh != NULL)
  1879. lvidiu = udf_sb_lvidiu(sbi);
  1880. else
  1881. lvidiu = NULL;
  1882. buf->f_type = UDF_SUPER_MAGIC;
  1883. buf->f_bsize = sb->s_blocksize;
  1884. buf->f_blocks = sbi->s_partmaps[sbi->s_partition].s_partition_len;
  1885. buf->f_bfree = udf_count_free(sb);
  1886. buf->f_bavail = buf->f_bfree;
  1887. buf->f_files = (lvidiu != NULL ? (le32_to_cpu(lvidiu->numFiles) +
  1888. le32_to_cpu(lvidiu->numDirs)) : 0)
  1889. + buf->f_bfree;
  1890. buf->f_ffree = buf->f_bfree;
  1891. buf->f_namelen = UDF_NAME_LEN - 2;
  1892. buf->f_fsid.val[0] = (u32)id;
  1893. buf->f_fsid.val[1] = (u32)(id >> 32);
  1894. return 0;
  1895. }
  1896. static unsigned int udf_count_free_bitmap(struct super_block *sb,
  1897. struct udf_bitmap *bitmap)
  1898. {
  1899. struct buffer_head *bh = NULL;
  1900. unsigned int accum = 0;
  1901. int index;
  1902. int block = 0, newblock;
  1903. struct kernel_lb_addr loc;
  1904. uint32_t bytes;
  1905. uint8_t *ptr;
  1906. uint16_t ident;
  1907. struct spaceBitmapDesc *bm;
  1908. lock_kernel();
  1909. loc.logicalBlockNum = bitmap->s_extPosition;
  1910. loc.partitionReferenceNum = UDF_SB(sb)->s_partition;
  1911. bh = udf_read_ptagged(sb, &loc, 0, &ident);
  1912. if (!bh) {
  1913. printk(KERN_ERR "udf: udf_count_free failed\n");
  1914. goto out;
  1915. } else if (ident != TAG_IDENT_SBD) {
  1916. brelse(bh);
  1917. printk(KERN_ERR "udf: udf_count_free failed\n");
  1918. goto out;
  1919. }
  1920. bm = (struct spaceBitmapDesc *)bh->b_data;
  1921. bytes = le32_to_cpu(bm->numOfBytes);
  1922. index = sizeof(struct spaceBitmapDesc); /* offset in first block only */
  1923. ptr = (uint8_t *)bh->b_data;
  1924. while (bytes > 0) {
  1925. u32 cur_bytes = min_t(u32, bytes, sb->s_blocksize - index);
  1926. accum += bitmap_weight((const unsigned long *)(ptr + index),
  1927. cur_bytes * 8);
  1928. bytes -= cur_bytes;
  1929. if (bytes) {
  1930. brelse(bh);
  1931. newblock = udf_get_lb_pblock(sb, &loc, ++block);
  1932. bh = udf_tread(sb, newblock);
  1933. if (!bh) {
  1934. udf_debug("read failed\n");
  1935. goto out;
  1936. }
  1937. index = 0;
  1938. ptr = (uint8_t *)bh->b_data;
  1939. }
  1940. }
  1941. brelse(bh);
  1942. out:
  1943. unlock_kernel();
  1944. return accum;
  1945. }
  1946. static unsigned int udf_count_free_table(struct super_block *sb,
  1947. struct inode *table)
  1948. {
  1949. unsigned int accum = 0;
  1950. uint32_t elen;
  1951. struct kernel_lb_addr eloc;
  1952. int8_t etype;
  1953. struct extent_position epos;
  1954. lock_kernel();
  1955. epos.block = UDF_I(table)->i_location;
  1956. epos.offset = sizeof(struct unallocSpaceEntry);
  1957. epos.bh = NULL;
  1958. while ((etype = udf_next_aext(table, &epos, &eloc, &elen, 1)) != -1)
  1959. accum += (elen >> table->i_sb->s_blocksize_bits);
  1960. brelse(epos.bh);
  1961. unlock_kernel();
  1962. return accum;
  1963. }
  1964. static unsigned int udf_count_free(struct super_block *sb)
  1965. {
  1966. unsigned int accum = 0;
  1967. struct udf_sb_info *sbi;
  1968. struct udf_part_map *map;
  1969. sbi = UDF_SB(sb);
  1970. if (sbi->s_lvid_bh) {
  1971. struct logicalVolIntegrityDesc *lvid =
  1972. (struct logicalVolIntegrityDesc *)
  1973. sbi->s_lvid_bh->b_data;
  1974. if (le32_to_cpu(lvid->numOfPartitions) > sbi->s_partition) {
  1975. accum = le32_to_cpu(
  1976. lvid->freeSpaceTable[sbi->s_partition]);
  1977. if (accum == 0xFFFFFFFF)
  1978. accum = 0;
  1979. }
  1980. }
  1981. if (accum)
  1982. return accum;
  1983. map = &sbi->s_partmaps[sbi->s_partition];
  1984. if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_BITMAP) {
  1985. accum += udf_count_free_bitmap(sb,
  1986. map->s_uspace.s_bitmap);
  1987. }
  1988. if (map->s_partition_flags & UDF_PART_FLAG_FREED_BITMAP) {
  1989. accum += udf_count_free_bitmap(sb,
  1990. map->s_fspace.s_bitmap);
  1991. }
  1992. if (accum)
  1993. return accum;
  1994. if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_TABLE) {
  1995. accum += udf_count_free_table(sb,
  1996. map->s_uspace.s_table);
  1997. }
  1998. if (map->s_partition_flags & UDF_PART_FLAG_FREED_TABLE) {
  1999. accum += udf_count_free_table(sb,
  2000. map->s_fspace.s_table);
  2001. }
  2002. return accum;
  2003. }