super.c 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256
  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. sbi->s_flags = uopt.flags;
  525. sbi->s_uid = uopt.uid;
  526. sbi->s_gid = uopt.gid;
  527. sbi->s_umask = uopt.umask;
  528. sbi->s_fmode = uopt.fmode;
  529. sbi->s_dmode = uopt.dmode;
  530. if (sbi->s_lvid_bh) {
  531. int write_rev = le16_to_cpu(udf_sb_lvidiu(sbi)->minUDFWriteRev);
  532. if (write_rev > UDF_MAX_WRITE_VERSION)
  533. *flags |= MS_RDONLY;
  534. }
  535. if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
  536. return 0;
  537. if (*flags & MS_RDONLY)
  538. udf_close_lvid(sb);
  539. else
  540. udf_open_lvid(sb);
  541. return 0;
  542. }
  543. /* Check Volume Structure Descriptors (ECMA 167 2/9.1) */
  544. /* We also check any "CD-ROM Volume Descriptor Set" (ECMA 167 2/8.3.1) */
  545. static loff_t udf_check_vsd(struct super_block *sb)
  546. {
  547. struct volStructDesc *vsd = NULL;
  548. loff_t sector = 32768;
  549. int sectorsize;
  550. struct buffer_head *bh = NULL;
  551. int nsr02 = 0;
  552. int nsr03 = 0;
  553. struct udf_sb_info *sbi;
  554. sbi = UDF_SB(sb);
  555. if (sb->s_blocksize < sizeof(struct volStructDesc))
  556. sectorsize = sizeof(struct volStructDesc);
  557. else
  558. sectorsize = sb->s_blocksize;
  559. sector += (sbi->s_session << sb->s_blocksize_bits);
  560. udf_debug("Starting at sector %u (%ld byte sectors)\n",
  561. (unsigned int)(sector >> sb->s_blocksize_bits),
  562. sb->s_blocksize);
  563. /* Process the sequence (if applicable) */
  564. for (; !nsr02 && !nsr03; sector += sectorsize) {
  565. /* Read a block */
  566. bh = udf_tread(sb, sector >> sb->s_blocksize_bits);
  567. if (!bh)
  568. break;
  569. /* Look for ISO descriptors */
  570. vsd = (struct volStructDesc *)(bh->b_data +
  571. (sector & (sb->s_blocksize - 1)));
  572. if (vsd->stdIdent[0] == 0) {
  573. brelse(bh);
  574. break;
  575. } else if (!strncmp(vsd->stdIdent, VSD_STD_ID_CD001,
  576. VSD_STD_ID_LEN)) {
  577. switch (vsd->structType) {
  578. case 0:
  579. udf_debug("ISO9660 Boot Record found\n");
  580. break;
  581. case 1:
  582. udf_debug("ISO9660 Primary Volume Descriptor "
  583. "found\n");
  584. break;
  585. case 2:
  586. udf_debug("ISO9660 Supplementary Volume "
  587. "Descriptor found\n");
  588. break;
  589. case 3:
  590. udf_debug("ISO9660 Volume Partition Descriptor "
  591. "found\n");
  592. break;
  593. case 255:
  594. udf_debug("ISO9660 Volume Descriptor Set "
  595. "Terminator found\n");
  596. break;
  597. default:
  598. udf_debug("ISO9660 VRS (%u) found\n",
  599. vsd->structType);
  600. break;
  601. }
  602. } else if (!strncmp(vsd->stdIdent, VSD_STD_ID_BEA01,
  603. VSD_STD_ID_LEN))
  604. ; /* nothing */
  605. else if (!strncmp(vsd->stdIdent, VSD_STD_ID_TEA01,
  606. VSD_STD_ID_LEN)) {
  607. brelse(bh);
  608. break;
  609. } else if (!strncmp(vsd->stdIdent, VSD_STD_ID_NSR02,
  610. VSD_STD_ID_LEN))
  611. nsr02 = sector;
  612. else if (!strncmp(vsd->stdIdent, VSD_STD_ID_NSR03,
  613. VSD_STD_ID_LEN))
  614. nsr03 = sector;
  615. brelse(bh);
  616. }
  617. if (nsr03)
  618. return nsr03;
  619. else if (nsr02)
  620. return nsr02;
  621. else if (sector - (sbi->s_session << sb->s_blocksize_bits) == 32768)
  622. return -1;
  623. else
  624. return 0;
  625. }
  626. static int udf_find_fileset(struct super_block *sb,
  627. struct kernel_lb_addr *fileset,
  628. struct kernel_lb_addr *root)
  629. {
  630. struct buffer_head *bh = NULL;
  631. long lastblock;
  632. uint16_t ident;
  633. struct udf_sb_info *sbi;
  634. if (fileset->logicalBlockNum != 0xFFFFFFFF ||
  635. fileset->partitionReferenceNum != 0xFFFF) {
  636. bh = udf_read_ptagged(sb, fileset, 0, &ident);
  637. if (!bh) {
  638. return 1;
  639. } else if (ident != TAG_IDENT_FSD) {
  640. brelse(bh);
  641. return 1;
  642. }
  643. }
  644. sbi = UDF_SB(sb);
  645. if (!bh) {
  646. /* Search backwards through the partitions */
  647. struct kernel_lb_addr newfileset;
  648. /* --> cvg: FIXME - is it reasonable? */
  649. return 1;
  650. for (newfileset.partitionReferenceNum = sbi->s_partitions - 1;
  651. (newfileset.partitionReferenceNum != 0xFFFF &&
  652. fileset->logicalBlockNum == 0xFFFFFFFF &&
  653. fileset->partitionReferenceNum == 0xFFFF);
  654. newfileset.partitionReferenceNum--) {
  655. lastblock = sbi->s_partmaps
  656. [newfileset.partitionReferenceNum]
  657. .s_partition_len;
  658. newfileset.logicalBlockNum = 0;
  659. do {
  660. bh = udf_read_ptagged(sb, &newfileset, 0,
  661. &ident);
  662. if (!bh) {
  663. newfileset.logicalBlockNum++;
  664. continue;
  665. }
  666. switch (ident) {
  667. case TAG_IDENT_SBD:
  668. {
  669. struct spaceBitmapDesc *sp;
  670. sp = (struct spaceBitmapDesc *)
  671. bh->b_data;
  672. newfileset.logicalBlockNum += 1 +
  673. ((le32_to_cpu(sp->numOfBytes) +
  674. sizeof(struct spaceBitmapDesc)
  675. - 1) >> sb->s_blocksize_bits);
  676. brelse(bh);
  677. break;
  678. }
  679. case TAG_IDENT_FSD:
  680. *fileset = newfileset;
  681. break;
  682. default:
  683. newfileset.logicalBlockNum++;
  684. brelse(bh);
  685. bh = NULL;
  686. break;
  687. }
  688. } while (newfileset.logicalBlockNum < lastblock &&
  689. fileset->logicalBlockNum == 0xFFFFFFFF &&
  690. fileset->partitionReferenceNum == 0xFFFF);
  691. }
  692. }
  693. if ((fileset->logicalBlockNum != 0xFFFFFFFF ||
  694. fileset->partitionReferenceNum != 0xFFFF) && bh) {
  695. udf_debug("Fileset at block=%d, partition=%d\n",
  696. fileset->logicalBlockNum,
  697. fileset->partitionReferenceNum);
  698. sbi->s_partition = fileset->partitionReferenceNum;
  699. udf_load_fileset(sb, bh, root);
  700. brelse(bh);
  701. return 0;
  702. }
  703. return 1;
  704. }
  705. static int udf_load_pvoldesc(struct super_block *sb, sector_t block)
  706. {
  707. struct primaryVolDesc *pvoldesc;
  708. struct ustr *instr, *outstr;
  709. struct buffer_head *bh;
  710. uint16_t ident;
  711. int ret = 1;
  712. instr = kmalloc(sizeof(struct ustr), GFP_NOFS);
  713. if (!instr)
  714. return 1;
  715. outstr = kmalloc(sizeof(struct ustr), GFP_NOFS);
  716. if (!outstr)
  717. goto out1;
  718. bh = udf_read_tagged(sb, block, block, &ident);
  719. if (!bh)
  720. goto out2;
  721. BUG_ON(ident != TAG_IDENT_PVD);
  722. pvoldesc = (struct primaryVolDesc *)bh->b_data;
  723. if (udf_disk_stamp_to_time(&UDF_SB(sb)->s_record_time,
  724. pvoldesc->recordingDateAndTime)) {
  725. #ifdef UDFFS_DEBUG
  726. struct timestamp *ts = &pvoldesc->recordingDateAndTime;
  727. udf_debug("recording time %04u/%02u/%02u"
  728. " %02u:%02u (%x)\n",
  729. le16_to_cpu(ts->year), ts->month, ts->day, ts->hour,
  730. ts->minute, le16_to_cpu(ts->typeAndTimezone));
  731. #endif
  732. }
  733. if (!udf_build_ustr(instr, pvoldesc->volIdent, 32))
  734. if (udf_CS0toUTF8(outstr, instr)) {
  735. strncpy(UDF_SB(sb)->s_volume_ident, outstr->u_name,
  736. outstr->u_len > 31 ? 31 : outstr->u_len);
  737. udf_debug("volIdent[] = '%s'\n",
  738. UDF_SB(sb)->s_volume_ident);
  739. }
  740. if (!udf_build_ustr(instr, pvoldesc->volSetIdent, 128))
  741. if (udf_CS0toUTF8(outstr, instr))
  742. udf_debug("volSetIdent[] = '%s'\n", outstr->u_name);
  743. brelse(bh);
  744. ret = 0;
  745. out2:
  746. kfree(outstr);
  747. out1:
  748. kfree(instr);
  749. return ret;
  750. }
  751. static int udf_load_metadata_files(struct super_block *sb, int partition)
  752. {
  753. struct udf_sb_info *sbi = UDF_SB(sb);
  754. struct udf_part_map *map;
  755. struct udf_meta_data *mdata;
  756. struct kernel_lb_addr addr;
  757. int fe_error = 0;
  758. map = &sbi->s_partmaps[partition];
  759. mdata = &map->s_type_specific.s_metadata;
  760. /* metadata address */
  761. addr.logicalBlockNum = mdata->s_meta_file_loc;
  762. addr.partitionReferenceNum = map->s_partition_num;
  763. udf_debug("Metadata file location: block = %d part = %d\n",
  764. addr.logicalBlockNum, addr.partitionReferenceNum);
  765. mdata->s_metadata_fe = udf_iget(sb, &addr);
  766. if (mdata->s_metadata_fe == NULL) {
  767. udf_warning(sb, __func__, "metadata inode efe not found, "
  768. "will try mirror inode.");
  769. fe_error = 1;
  770. } else if (UDF_I(mdata->s_metadata_fe)->i_alloc_type !=
  771. ICBTAG_FLAG_AD_SHORT) {
  772. udf_warning(sb, __func__, "metadata inode efe does not have "
  773. "short allocation descriptors!");
  774. fe_error = 1;
  775. iput(mdata->s_metadata_fe);
  776. mdata->s_metadata_fe = NULL;
  777. }
  778. /* mirror file entry */
  779. addr.logicalBlockNum = mdata->s_mirror_file_loc;
  780. addr.partitionReferenceNum = map->s_partition_num;
  781. udf_debug("Mirror metadata file location: block = %d part = %d\n",
  782. addr.logicalBlockNum, addr.partitionReferenceNum);
  783. mdata->s_mirror_fe = udf_iget(sb, &addr);
  784. if (mdata->s_mirror_fe == NULL) {
  785. if (fe_error) {
  786. udf_error(sb, __func__, "mirror inode efe not found "
  787. "and metadata inode is missing too, exiting...");
  788. goto error_exit;
  789. } else
  790. udf_warning(sb, __func__, "mirror inode efe not found,"
  791. " but metadata inode is OK");
  792. } else if (UDF_I(mdata->s_mirror_fe)->i_alloc_type !=
  793. ICBTAG_FLAG_AD_SHORT) {
  794. udf_warning(sb, __func__, "mirror inode efe does not have "
  795. "short allocation descriptors!");
  796. iput(mdata->s_mirror_fe);
  797. mdata->s_mirror_fe = NULL;
  798. if (fe_error)
  799. goto error_exit;
  800. }
  801. /*
  802. * bitmap file entry
  803. * Note:
  804. * Load only if bitmap file location differs from 0xFFFFFFFF (DCN-5102)
  805. */
  806. if (mdata->s_bitmap_file_loc != 0xFFFFFFFF) {
  807. addr.logicalBlockNum = mdata->s_bitmap_file_loc;
  808. addr.partitionReferenceNum = map->s_partition_num;
  809. udf_debug("Bitmap file location: block = %d part = %d\n",
  810. addr.logicalBlockNum, addr.partitionReferenceNum);
  811. mdata->s_bitmap_fe = udf_iget(sb, &addr);
  812. if (mdata->s_bitmap_fe == NULL) {
  813. if (sb->s_flags & MS_RDONLY)
  814. udf_warning(sb, __func__, "bitmap inode efe "
  815. "not found but it's ok since the disc"
  816. " is mounted read-only");
  817. else {
  818. udf_error(sb, __func__, "bitmap inode efe not "
  819. "found and attempted read-write mount");
  820. goto error_exit;
  821. }
  822. }
  823. }
  824. udf_debug("udf_load_metadata_files Ok\n");
  825. return 0;
  826. error_exit:
  827. return 1;
  828. }
  829. static void udf_load_fileset(struct super_block *sb, struct buffer_head *bh,
  830. struct kernel_lb_addr *root)
  831. {
  832. struct fileSetDesc *fset;
  833. fset = (struct fileSetDesc *)bh->b_data;
  834. *root = lelb_to_cpu(fset->rootDirectoryICB.extLocation);
  835. UDF_SB(sb)->s_serial_number = le16_to_cpu(fset->descTag.tagSerialNum);
  836. udf_debug("Rootdir at block=%d, partition=%d\n",
  837. root->logicalBlockNum, root->partitionReferenceNum);
  838. }
  839. int udf_compute_nr_groups(struct super_block *sb, u32 partition)
  840. {
  841. struct udf_part_map *map = &UDF_SB(sb)->s_partmaps[partition];
  842. return DIV_ROUND_UP(map->s_partition_len +
  843. (sizeof(struct spaceBitmapDesc) << 3),
  844. sb->s_blocksize * 8);
  845. }
  846. static struct udf_bitmap *udf_sb_alloc_bitmap(struct super_block *sb, u32 index)
  847. {
  848. struct udf_bitmap *bitmap;
  849. int nr_groups;
  850. int size;
  851. nr_groups = udf_compute_nr_groups(sb, index);
  852. size = sizeof(struct udf_bitmap) +
  853. (sizeof(struct buffer_head *) * nr_groups);
  854. if (size <= PAGE_SIZE)
  855. bitmap = kmalloc(size, GFP_KERNEL);
  856. else
  857. bitmap = vmalloc(size); /* TODO: get rid of vmalloc */
  858. if (bitmap == NULL) {
  859. udf_error(sb, __func__,
  860. "Unable to allocate space for bitmap "
  861. "and %d buffer_head pointers", nr_groups);
  862. return NULL;
  863. }
  864. memset(bitmap, 0x00, size);
  865. bitmap->s_block_bitmap = (struct buffer_head **)(bitmap + 1);
  866. bitmap->s_nr_groups = nr_groups;
  867. return bitmap;
  868. }
  869. static int udf_fill_partdesc_info(struct super_block *sb,
  870. struct partitionDesc *p, int p_index)
  871. {
  872. struct udf_part_map *map;
  873. struct udf_sb_info *sbi = UDF_SB(sb);
  874. struct partitionHeaderDesc *phd;
  875. map = &sbi->s_partmaps[p_index];
  876. map->s_partition_len = le32_to_cpu(p->partitionLength); /* blocks */
  877. map->s_partition_root = le32_to_cpu(p->partitionStartingLocation);
  878. if (p->accessType == cpu_to_le32(PD_ACCESS_TYPE_READ_ONLY))
  879. map->s_partition_flags |= UDF_PART_FLAG_READ_ONLY;
  880. if (p->accessType == cpu_to_le32(PD_ACCESS_TYPE_WRITE_ONCE))
  881. map->s_partition_flags |= UDF_PART_FLAG_WRITE_ONCE;
  882. if (p->accessType == cpu_to_le32(PD_ACCESS_TYPE_REWRITABLE))
  883. map->s_partition_flags |= UDF_PART_FLAG_REWRITABLE;
  884. if (p->accessType == cpu_to_le32(PD_ACCESS_TYPE_OVERWRITABLE))
  885. map->s_partition_flags |= UDF_PART_FLAG_OVERWRITABLE;
  886. udf_debug("Partition (%d type %x) starts at physical %d, "
  887. "block length %d\n", p_index,
  888. map->s_partition_type, map->s_partition_root,
  889. map->s_partition_len);
  890. if (strcmp(p->partitionContents.ident, PD_PARTITION_CONTENTS_NSR02) &&
  891. strcmp(p->partitionContents.ident, PD_PARTITION_CONTENTS_NSR03))
  892. return 0;
  893. phd = (struct partitionHeaderDesc *)p->partitionContentsUse;
  894. if (phd->unallocSpaceTable.extLength) {
  895. struct kernel_lb_addr loc = {
  896. .logicalBlockNum = le32_to_cpu(
  897. phd->unallocSpaceTable.extPosition),
  898. .partitionReferenceNum = p_index,
  899. };
  900. map->s_uspace.s_table = udf_iget(sb, &loc);
  901. if (!map->s_uspace.s_table) {
  902. udf_debug("cannot load unallocSpaceTable (part %d)\n",
  903. p_index);
  904. return 1;
  905. }
  906. map->s_partition_flags |= UDF_PART_FLAG_UNALLOC_TABLE;
  907. udf_debug("unallocSpaceTable (part %d) @ %ld\n",
  908. p_index, map->s_uspace.s_table->i_ino);
  909. }
  910. if (phd->unallocSpaceBitmap.extLength) {
  911. struct udf_bitmap *bitmap = udf_sb_alloc_bitmap(sb, p_index);
  912. if (!bitmap)
  913. return 1;
  914. map->s_uspace.s_bitmap = bitmap;
  915. bitmap->s_extLength = le32_to_cpu(
  916. phd->unallocSpaceBitmap.extLength);
  917. bitmap->s_extPosition = le32_to_cpu(
  918. phd->unallocSpaceBitmap.extPosition);
  919. map->s_partition_flags |= UDF_PART_FLAG_UNALLOC_BITMAP;
  920. udf_debug("unallocSpaceBitmap (part %d) @ %d\n", p_index,
  921. bitmap->s_extPosition);
  922. }
  923. if (phd->partitionIntegrityTable.extLength)
  924. udf_debug("partitionIntegrityTable (part %d)\n", p_index);
  925. if (phd->freedSpaceTable.extLength) {
  926. struct kernel_lb_addr loc = {
  927. .logicalBlockNum = le32_to_cpu(
  928. phd->freedSpaceTable.extPosition),
  929. .partitionReferenceNum = p_index,
  930. };
  931. map->s_fspace.s_table = udf_iget(sb, &loc);
  932. if (!map->s_fspace.s_table) {
  933. udf_debug("cannot load freedSpaceTable (part %d)\n",
  934. p_index);
  935. return 1;
  936. }
  937. map->s_partition_flags |= UDF_PART_FLAG_FREED_TABLE;
  938. udf_debug("freedSpaceTable (part %d) @ %ld\n",
  939. p_index, map->s_fspace.s_table->i_ino);
  940. }
  941. if (phd->freedSpaceBitmap.extLength) {
  942. struct udf_bitmap *bitmap = udf_sb_alloc_bitmap(sb, p_index);
  943. if (!bitmap)
  944. return 1;
  945. map->s_fspace.s_bitmap = bitmap;
  946. bitmap->s_extLength = le32_to_cpu(
  947. phd->freedSpaceBitmap.extLength);
  948. bitmap->s_extPosition = le32_to_cpu(
  949. phd->freedSpaceBitmap.extPosition);
  950. map->s_partition_flags |= UDF_PART_FLAG_FREED_BITMAP;
  951. udf_debug("freedSpaceBitmap (part %d) @ %d\n", p_index,
  952. bitmap->s_extPosition);
  953. }
  954. return 0;
  955. }
  956. static int udf_load_vat(struct super_block *sb, int p_index, int type1_index)
  957. {
  958. struct udf_sb_info *sbi = UDF_SB(sb);
  959. struct udf_part_map *map = &sbi->s_partmaps[p_index];
  960. struct kernel_lb_addr ino;
  961. struct buffer_head *bh = NULL;
  962. struct udf_inode_info *vati;
  963. uint32_t pos;
  964. struct virtualAllocationTable20 *vat20;
  965. /* VAT file entry is in the last recorded block */
  966. ino.partitionReferenceNum = type1_index;
  967. ino.logicalBlockNum = sbi->s_last_block - map->s_partition_root;
  968. sbi->s_vat_inode = udf_iget(sb, &ino);
  969. if (!sbi->s_vat_inode)
  970. return 1;
  971. if (map->s_partition_type == UDF_VIRTUAL_MAP15) {
  972. map->s_type_specific.s_virtual.s_start_offset = 0;
  973. map->s_type_specific.s_virtual.s_num_entries =
  974. (sbi->s_vat_inode->i_size - 36) >> 2;
  975. } else if (map->s_partition_type == UDF_VIRTUAL_MAP20) {
  976. vati = UDF_I(sbi->s_vat_inode);
  977. if (vati->i_alloc_type != ICBTAG_FLAG_AD_IN_ICB) {
  978. pos = udf_block_map(sbi->s_vat_inode, 0);
  979. bh = sb_bread(sb, pos);
  980. if (!bh)
  981. return 1;
  982. vat20 = (struct virtualAllocationTable20 *)bh->b_data;
  983. } else {
  984. vat20 = (struct virtualAllocationTable20 *)
  985. vati->i_ext.i_data;
  986. }
  987. map->s_type_specific.s_virtual.s_start_offset =
  988. le16_to_cpu(vat20->lengthHeader);
  989. map->s_type_specific.s_virtual.s_num_entries =
  990. (sbi->s_vat_inode->i_size -
  991. map->s_type_specific.s_virtual.
  992. s_start_offset) >> 2;
  993. brelse(bh);
  994. }
  995. return 0;
  996. }
  997. static int udf_load_partdesc(struct super_block *sb, sector_t block)
  998. {
  999. struct buffer_head *bh;
  1000. struct partitionDesc *p;
  1001. struct udf_part_map *map;
  1002. struct udf_sb_info *sbi = UDF_SB(sb);
  1003. int i, type1_idx;
  1004. uint16_t partitionNumber;
  1005. uint16_t ident;
  1006. int ret = 0;
  1007. bh = udf_read_tagged(sb, block, block, &ident);
  1008. if (!bh)
  1009. return 1;
  1010. if (ident != TAG_IDENT_PD)
  1011. goto out_bh;
  1012. p = (struct partitionDesc *)bh->b_data;
  1013. partitionNumber = le16_to_cpu(p->partitionNumber);
  1014. /* First scan for TYPE1, SPARABLE and METADATA partitions */
  1015. for (i = 0; i < sbi->s_partitions; i++) {
  1016. map = &sbi->s_partmaps[i];
  1017. udf_debug("Searching map: (%d == %d)\n",
  1018. map->s_partition_num, partitionNumber);
  1019. if (map->s_partition_num == partitionNumber &&
  1020. (map->s_partition_type == UDF_TYPE1_MAP15 ||
  1021. map->s_partition_type == UDF_SPARABLE_MAP15))
  1022. break;
  1023. }
  1024. if (i >= sbi->s_partitions) {
  1025. udf_debug("Partition (%d) not found in partition map\n",
  1026. partitionNumber);
  1027. goto out_bh;
  1028. }
  1029. ret = udf_fill_partdesc_info(sb, p, i);
  1030. /*
  1031. * Now rescan for VIRTUAL or METADATA partitions when SPARABLE and
  1032. * PHYSICAL partitions are already set up
  1033. */
  1034. type1_idx = i;
  1035. for (i = 0; i < sbi->s_partitions; i++) {
  1036. map = &sbi->s_partmaps[i];
  1037. if (map->s_partition_num == partitionNumber &&
  1038. (map->s_partition_type == UDF_VIRTUAL_MAP15 ||
  1039. map->s_partition_type == UDF_VIRTUAL_MAP20 ||
  1040. map->s_partition_type == UDF_METADATA_MAP25))
  1041. break;
  1042. }
  1043. if (i >= sbi->s_partitions)
  1044. goto out_bh;
  1045. ret = udf_fill_partdesc_info(sb, p, i);
  1046. if (ret)
  1047. goto out_bh;
  1048. if (map->s_partition_type == UDF_METADATA_MAP25) {
  1049. ret = udf_load_metadata_files(sb, i);
  1050. if (ret) {
  1051. printk(KERN_ERR "UDF-fs: error loading MetaData "
  1052. "partition map %d\n", i);
  1053. goto out_bh;
  1054. }
  1055. } else {
  1056. ret = udf_load_vat(sb, i, type1_idx);
  1057. if (ret)
  1058. goto out_bh;
  1059. /*
  1060. * Mark filesystem read-only if we have a partition with
  1061. * virtual map since we don't handle writing to it (we
  1062. * overwrite blocks instead of relocating them).
  1063. */
  1064. sb->s_flags |= MS_RDONLY;
  1065. printk(KERN_NOTICE "UDF-fs: Filesystem marked read-only "
  1066. "because writing to pseudooverwrite partition is "
  1067. "not implemented.\n");
  1068. }
  1069. out_bh:
  1070. /* In case loading failed, we handle cleanup in udf_fill_super */
  1071. brelse(bh);
  1072. return ret;
  1073. }
  1074. static int udf_load_logicalvol(struct super_block *sb, sector_t block,
  1075. struct kernel_lb_addr *fileset)
  1076. {
  1077. struct logicalVolDesc *lvd;
  1078. int i, j, offset;
  1079. uint8_t type;
  1080. struct udf_sb_info *sbi = UDF_SB(sb);
  1081. struct genericPartitionMap *gpm;
  1082. uint16_t ident;
  1083. struct buffer_head *bh;
  1084. int ret = 0;
  1085. bh = udf_read_tagged(sb, block, block, &ident);
  1086. if (!bh)
  1087. return 1;
  1088. BUG_ON(ident != TAG_IDENT_LVD);
  1089. lvd = (struct logicalVolDesc *)bh->b_data;
  1090. i = udf_sb_alloc_partition_maps(sb, le32_to_cpu(lvd->numPartitionMaps));
  1091. if (i != 0) {
  1092. ret = i;
  1093. goto out_bh;
  1094. }
  1095. for (i = 0, offset = 0;
  1096. i < sbi->s_partitions && offset < le32_to_cpu(lvd->mapTableLength);
  1097. i++, offset += gpm->partitionMapLength) {
  1098. struct udf_part_map *map = &sbi->s_partmaps[i];
  1099. gpm = (struct genericPartitionMap *)
  1100. &(lvd->partitionMaps[offset]);
  1101. type = gpm->partitionMapType;
  1102. if (type == 1) {
  1103. struct genericPartitionMap1 *gpm1 =
  1104. (struct genericPartitionMap1 *)gpm;
  1105. map->s_partition_type = UDF_TYPE1_MAP15;
  1106. map->s_volumeseqnum = le16_to_cpu(gpm1->volSeqNum);
  1107. map->s_partition_num = le16_to_cpu(gpm1->partitionNum);
  1108. map->s_partition_func = NULL;
  1109. } else if (type == 2) {
  1110. struct udfPartitionMap2 *upm2 =
  1111. (struct udfPartitionMap2 *)gpm;
  1112. if (!strncmp(upm2->partIdent.ident, UDF_ID_VIRTUAL,
  1113. strlen(UDF_ID_VIRTUAL))) {
  1114. u16 suf =
  1115. le16_to_cpu(((__le16 *)upm2->partIdent.
  1116. identSuffix)[0]);
  1117. if (suf < 0x0200) {
  1118. map->s_partition_type =
  1119. UDF_VIRTUAL_MAP15;
  1120. map->s_partition_func =
  1121. udf_get_pblock_virt15;
  1122. } else {
  1123. map->s_partition_type =
  1124. UDF_VIRTUAL_MAP20;
  1125. map->s_partition_func =
  1126. udf_get_pblock_virt20;
  1127. }
  1128. } else if (!strncmp(upm2->partIdent.ident,
  1129. UDF_ID_SPARABLE,
  1130. strlen(UDF_ID_SPARABLE))) {
  1131. uint32_t loc;
  1132. struct sparingTable *st;
  1133. struct sparablePartitionMap *spm =
  1134. (struct sparablePartitionMap *)gpm;
  1135. map->s_partition_type = UDF_SPARABLE_MAP15;
  1136. map->s_type_specific.s_sparing.s_packet_len =
  1137. le16_to_cpu(spm->packetLength);
  1138. for (j = 0; j < spm->numSparingTables; j++) {
  1139. struct buffer_head *bh2;
  1140. loc = le32_to_cpu(
  1141. spm->locSparingTable[j]);
  1142. bh2 = udf_read_tagged(sb, loc, loc,
  1143. &ident);
  1144. map->s_type_specific.s_sparing.
  1145. s_spar_map[j] = bh2;
  1146. if (bh2 == NULL)
  1147. continue;
  1148. st = (struct sparingTable *)bh2->b_data;
  1149. if (ident != 0 || strncmp(
  1150. st->sparingIdent.ident,
  1151. UDF_ID_SPARING,
  1152. strlen(UDF_ID_SPARING))) {
  1153. brelse(bh2);
  1154. map->s_type_specific.s_sparing.
  1155. s_spar_map[j] = NULL;
  1156. }
  1157. }
  1158. map->s_partition_func = udf_get_pblock_spar15;
  1159. } else if (!strncmp(upm2->partIdent.ident,
  1160. UDF_ID_METADATA,
  1161. strlen(UDF_ID_METADATA))) {
  1162. struct udf_meta_data *mdata =
  1163. &map->s_type_specific.s_metadata;
  1164. struct metadataPartitionMap *mdm =
  1165. (struct metadataPartitionMap *)
  1166. &(lvd->partitionMaps[offset]);
  1167. udf_debug("Parsing Logical vol part %d "
  1168. "type %d id=%s\n", i, type,
  1169. UDF_ID_METADATA);
  1170. map->s_partition_type = UDF_METADATA_MAP25;
  1171. map->s_partition_func = udf_get_pblock_meta25;
  1172. mdata->s_meta_file_loc =
  1173. le32_to_cpu(mdm->metadataFileLoc);
  1174. mdata->s_mirror_file_loc =
  1175. le32_to_cpu(mdm->metadataMirrorFileLoc);
  1176. mdata->s_bitmap_file_loc =
  1177. le32_to_cpu(mdm->metadataBitmapFileLoc);
  1178. mdata->s_alloc_unit_size =
  1179. le32_to_cpu(mdm->allocUnitSize);
  1180. mdata->s_align_unit_size =
  1181. le16_to_cpu(mdm->alignUnitSize);
  1182. mdata->s_dup_md_flag =
  1183. mdm->flags & 0x01;
  1184. udf_debug("Metadata Ident suffix=0x%x\n",
  1185. (le16_to_cpu(
  1186. ((__le16 *)
  1187. mdm->partIdent.identSuffix)[0])));
  1188. udf_debug("Metadata part num=%d\n",
  1189. le16_to_cpu(mdm->partitionNum));
  1190. udf_debug("Metadata part alloc unit size=%d\n",
  1191. le32_to_cpu(mdm->allocUnitSize));
  1192. udf_debug("Metadata file loc=%d\n",
  1193. le32_to_cpu(mdm->metadataFileLoc));
  1194. udf_debug("Mirror file loc=%d\n",
  1195. le32_to_cpu(mdm->metadataMirrorFileLoc));
  1196. udf_debug("Bitmap file loc=%d\n",
  1197. le32_to_cpu(mdm->metadataBitmapFileLoc));
  1198. udf_debug("Duplicate Flag: %d %d\n",
  1199. mdata->s_dup_md_flag, mdm->flags);
  1200. } else {
  1201. udf_debug("Unknown ident: %s\n",
  1202. upm2->partIdent.ident);
  1203. continue;
  1204. }
  1205. map->s_volumeseqnum = le16_to_cpu(upm2->volSeqNum);
  1206. map->s_partition_num = le16_to_cpu(upm2->partitionNum);
  1207. }
  1208. udf_debug("Partition (%d:%d) type %d on volume %d\n",
  1209. i, map->s_partition_num, type,
  1210. map->s_volumeseqnum);
  1211. }
  1212. if (fileset) {
  1213. struct long_ad *la = (struct long_ad *)&(lvd->logicalVolContentsUse[0]);
  1214. *fileset = lelb_to_cpu(la->extLocation);
  1215. udf_debug("FileSet found in LogicalVolDesc at block=%d, "
  1216. "partition=%d\n", fileset->logicalBlockNum,
  1217. fileset->partitionReferenceNum);
  1218. }
  1219. if (lvd->integritySeqExt.extLength)
  1220. udf_load_logicalvolint(sb, leea_to_cpu(lvd->integritySeqExt));
  1221. out_bh:
  1222. brelse(bh);
  1223. return ret;
  1224. }
  1225. /*
  1226. * udf_load_logicalvolint
  1227. *
  1228. */
  1229. static void udf_load_logicalvolint(struct super_block *sb, struct kernel_extent_ad loc)
  1230. {
  1231. struct buffer_head *bh = NULL;
  1232. uint16_t ident;
  1233. struct udf_sb_info *sbi = UDF_SB(sb);
  1234. struct logicalVolIntegrityDesc *lvid;
  1235. while (loc.extLength > 0 &&
  1236. (bh = udf_read_tagged(sb, loc.extLocation,
  1237. loc.extLocation, &ident)) &&
  1238. ident == TAG_IDENT_LVID) {
  1239. sbi->s_lvid_bh = bh;
  1240. lvid = (struct logicalVolIntegrityDesc *)bh->b_data;
  1241. if (lvid->nextIntegrityExt.extLength)
  1242. udf_load_logicalvolint(sb,
  1243. leea_to_cpu(lvid->nextIntegrityExt));
  1244. if (sbi->s_lvid_bh != bh)
  1245. brelse(bh);
  1246. loc.extLength -= sb->s_blocksize;
  1247. loc.extLocation++;
  1248. }
  1249. if (sbi->s_lvid_bh != bh)
  1250. brelse(bh);
  1251. }
  1252. /*
  1253. * udf_process_sequence
  1254. *
  1255. * PURPOSE
  1256. * Process a main/reserve volume descriptor sequence.
  1257. *
  1258. * PRE-CONDITIONS
  1259. * sb Pointer to _locked_ superblock.
  1260. * block First block of first extent of the sequence.
  1261. * lastblock Lastblock of first extent of the sequence.
  1262. *
  1263. * HISTORY
  1264. * July 1, 1997 - Andrew E. Mileski
  1265. * Written, tested, and released.
  1266. */
  1267. static noinline int udf_process_sequence(struct super_block *sb, long block,
  1268. long lastblock, struct kernel_lb_addr *fileset)
  1269. {
  1270. struct buffer_head *bh = NULL;
  1271. struct udf_vds_record vds[VDS_POS_LENGTH];
  1272. struct udf_vds_record *curr;
  1273. struct generic_desc *gd;
  1274. struct volDescPtr *vdp;
  1275. int done = 0;
  1276. uint32_t vdsn;
  1277. uint16_t ident;
  1278. long next_s = 0, next_e = 0;
  1279. memset(vds, 0, sizeof(struct udf_vds_record) * VDS_POS_LENGTH);
  1280. /*
  1281. * Read the main descriptor sequence and find which descriptors
  1282. * are in it.
  1283. */
  1284. for (; (!done && block <= lastblock); block++) {
  1285. bh = udf_read_tagged(sb, block, block, &ident);
  1286. if (!bh) {
  1287. printk(KERN_ERR "udf: Block %Lu of volume descriptor "
  1288. "sequence is corrupted or we could not read "
  1289. "it.\n", (unsigned long long)block);
  1290. return 1;
  1291. }
  1292. /* Process each descriptor (ISO 13346 3/8.3-8.4) */
  1293. gd = (struct generic_desc *)bh->b_data;
  1294. vdsn = le32_to_cpu(gd->volDescSeqNum);
  1295. switch (ident) {
  1296. case TAG_IDENT_PVD: /* ISO 13346 3/10.1 */
  1297. curr = &vds[VDS_POS_PRIMARY_VOL_DESC];
  1298. if (vdsn >= curr->volDescSeqNum) {
  1299. curr->volDescSeqNum = vdsn;
  1300. curr->block = block;
  1301. }
  1302. break;
  1303. case TAG_IDENT_VDP: /* ISO 13346 3/10.3 */
  1304. curr = &vds[VDS_POS_VOL_DESC_PTR];
  1305. if (vdsn >= curr->volDescSeqNum) {
  1306. curr->volDescSeqNum = vdsn;
  1307. curr->block = block;
  1308. vdp = (struct volDescPtr *)bh->b_data;
  1309. next_s = le32_to_cpu(
  1310. vdp->nextVolDescSeqExt.extLocation);
  1311. next_e = le32_to_cpu(
  1312. vdp->nextVolDescSeqExt.extLength);
  1313. next_e = next_e >> sb->s_blocksize_bits;
  1314. next_e += next_s;
  1315. }
  1316. break;
  1317. case TAG_IDENT_IUVD: /* ISO 13346 3/10.4 */
  1318. curr = &vds[VDS_POS_IMP_USE_VOL_DESC];
  1319. if (vdsn >= curr->volDescSeqNum) {
  1320. curr->volDescSeqNum = vdsn;
  1321. curr->block = block;
  1322. }
  1323. break;
  1324. case TAG_IDENT_PD: /* ISO 13346 3/10.5 */
  1325. curr = &vds[VDS_POS_PARTITION_DESC];
  1326. if (!curr->block)
  1327. curr->block = block;
  1328. break;
  1329. case TAG_IDENT_LVD: /* ISO 13346 3/10.6 */
  1330. curr = &vds[VDS_POS_LOGICAL_VOL_DESC];
  1331. if (vdsn >= curr->volDescSeqNum) {
  1332. curr->volDescSeqNum = vdsn;
  1333. curr->block = block;
  1334. }
  1335. break;
  1336. case TAG_IDENT_USD: /* ISO 13346 3/10.8 */
  1337. curr = &vds[VDS_POS_UNALLOC_SPACE_DESC];
  1338. if (vdsn >= curr->volDescSeqNum) {
  1339. curr->volDescSeqNum = vdsn;
  1340. curr->block = block;
  1341. }
  1342. break;
  1343. case TAG_IDENT_TD: /* ISO 13346 3/10.9 */
  1344. vds[VDS_POS_TERMINATING_DESC].block = block;
  1345. if (next_e) {
  1346. block = next_s;
  1347. lastblock = next_e;
  1348. next_s = next_e = 0;
  1349. } else
  1350. done = 1;
  1351. break;
  1352. }
  1353. brelse(bh);
  1354. }
  1355. /*
  1356. * Now read interesting descriptors again and process them
  1357. * in a suitable order
  1358. */
  1359. if (!vds[VDS_POS_PRIMARY_VOL_DESC].block) {
  1360. printk(KERN_ERR "udf: Primary Volume Descriptor not found!\n");
  1361. return 1;
  1362. }
  1363. if (udf_load_pvoldesc(sb, vds[VDS_POS_PRIMARY_VOL_DESC].block))
  1364. return 1;
  1365. if (vds[VDS_POS_LOGICAL_VOL_DESC].block && udf_load_logicalvol(sb,
  1366. vds[VDS_POS_LOGICAL_VOL_DESC].block, fileset))
  1367. return 1;
  1368. if (vds[VDS_POS_PARTITION_DESC].block) {
  1369. /*
  1370. * We rescan the whole descriptor sequence to find
  1371. * partition descriptor blocks and process them.
  1372. */
  1373. for (block = vds[VDS_POS_PARTITION_DESC].block;
  1374. block < vds[VDS_POS_TERMINATING_DESC].block;
  1375. block++)
  1376. if (udf_load_partdesc(sb, block))
  1377. return 1;
  1378. }
  1379. return 0;
  1380. }
  1381. static int udf_load_sequence(struct super_block *sb, struct buffer_head *bh,
  1382. struct kernel_lb_addr *fileset)
  1383. {
  1384. struct anchorVolDescPtr *anchor;
  1385. long main_s, main_e, reserve_s, reserve_e;
  1386. struct udf_sb_info *sbi;
  1387. sbi = UDF_SB(sb);
  1388. anchor = (struct anchorVolDescPtr *)bh->b_data;
  1389. /* Locate the main sequence */
  1390. main_s = le32_to_cpu(anchor->mainVolDescSeqExt.extLocation);
  1391. main_e = le32_to_cpu(anchor->mainVolDescSeqExt.extLength);
  1392. main_e = main_e >> sb->s_blocksize_bits;
  1393. main_e += main_s;
  1394. /* Locate the reserve sequence */
  1395. reserve_s = le32_to_cpu(anchor->reserveVolDescSeqExt.extLocation);
  1396. reserve_e = le32_to_cpu(anchor->reserveVolDescSeqExt.extLength);
  1397. reserve_e = reserve_e >> sb->s_blocksize_bits;
  1398. reserve_e += reserve_s;
  1399. /* Process the main & reserve sequences */
  1400. /* responsible for finding the PartitionDesc(s) */
  1401. if (!udf_process_sequence(sb, main_s, main_e, fileset))
  1402. return 1;
  1403. return !udf_process_sequence(sb, reserve_s, reserve_e, fileset);
  1404. }
  1405. /*
  1406. * Check whether there is an anchor block in the given block and
  1407. * load Volume Descriptor Sequence if so.
  1408. */
  1409. static int udf_check_anchor_block(struct super_block *sb, sector_t block,
  1410. struct kernel_lb_addr *fileset)
  1411. {
  1412. struct buffer_head *bh;
  1413. uint16_t ident;
  1414. int ret;
  1415. if (UDF_QUERY_FLAG(sb, UDF_FLAG_VARCONV) &&
  1416. udf_fixed_to_variable(block) >=
  1417. sb->s_bdev->bd_inode->i_size >> sb->s_blocksize_bits)
  1418. return 0;
  1419. bh = udf_read_tagged(sb, block, block, &ident);
  1420. if (!bh)
  1421. return 0;
  1422. if (ident != TAG_IDENT_AVDP) {
  1423. brelse(bh);
  1424. return 0;
  1425. }
  1426. ret = udf_load_sequence(sb, bh, fileset);
  1427. brelse(bh);
  1428. return ret;
  1429. }
  1430. /* Search for an anchor volume descriptor pointer */
  1431. static sector_t udf_scan_anchors(struct super_block *sb, sector_t lastblock,
  1432. struct kernel_lb_addr *fileset)
  1433. {
  1434. sector_t last[6];
  1435. int i;
  1436. struct udf_sb_info *sbi = UDF_SB(sb);
  1437. int last_count = 0;
  1438. /* First try user provided anchor */
  1439. if (sbi->s_anchor) {
  1440. if (udf_check_anchor_block(sb, sbi->s_anchor, fileset))
  1441. return lastblock;
  1442. }
  1443. /*
  1444. * according to spec, anchor is in either:
  1445. * block 256
  1446. * lastblock-256
  1447. * lastblock
  1448. * however, if the disc isn't closed, it could be 512.
  1449. */
  1450. if (udf_check_anchor_block(sb, sbi->s_session + 256, fileset))
  1451. return lastblock;
  1452. /*
  1453. * The trouble is which block is the last one. Drives often misreport
  1454. * this so we try various possibilities.
  1455. */
  1456. last[last_count++] = lastblock;
  1457. if (lastblock >= 1)
  1458. last[last_count++] = lastblock - 1;
  1459. last[last_count++] = lastblock + 1;
  1460. if (lastblock >= 2)
  1461. last[last_count++] = lastblock - 2;
  1462. if (lastblock >= 150)
  1463. last[last_count++] = lastblock - 150;
  1464. if (lastblock >= 152)
  1465. last[last_count++] = lastblock - 152;
  1466. for (i = 0; i < last_count; i++) {
  1467. if (last[i] >= sb->s_bdev->bd_inode->i_size >>
  1468. sb->s_blocksize_bits)
  1469. continue;
  1470. if (udf_check_anchor_block(sb, last[i], fileset))
  1471. return last[i];
  1472. if (last[i] < 256)
  1473. continue;
  1474. if (udf_check_anchor_block(sb, last[i] - 256, fileset))
  1475. return last[i];
  1476. }
  1477. /* Finally try block 512 in case media is open */
  1478. if (udf_check_anchor_block(sb, sbi->s_session + 512, fileset))
  1479. return last[0];
  1480. return 0;
  1481. }
  1482. /*
  1483. * Find an anchor volume descriptor and load Volume Descriptor Sequence from
  1484. * area specified by it. The function expects sbi->s_lastblock to be the last
  1485. * block on the media.
  1486. *
  1487. * Return 1 if ok, 0 if not found.
  1488. *
  1489. */
  1490. static int udf_find_anchor(struct super_block *sb,
  1491. struct kernel_lb_addr *fileset)
  1492. {
  1493. sector_t lastblock;
  1494. struct udf_sb_info *sbi = UDF_SB(sb);
  1495. lastblock = udf_scan_anchors(sb, sbi->s_last_block, fileset);
  1496. if (lastblock)
  1497. goto out;
  1498. /* No anchor found? Try VARCONV conversion of block numbers */
  1499. UDF_SET_FLAG(sb, UDF_FLAG_VARCONV);
  1500. /* Firstly, we try to not convert number of the last block */
  1501. lastblock = udf_scan_anchors(sb,
  1502. udf_variable_to_fixed(sbi->s_last_block),
  1503. fileset);
  1504. if (lastblock)
  1505. goto out;
  1506. /* Secondly, we try with converted number of the last block */
  1507. lastblock = udf_scan_anchors(sb, sbi->s_last_block, fileset);
  1508. if (!lastblock) {
  1509. /* VARCONV didn't help. Clear it. */
  1510. UDF_CLEAR_FLAG(sb, UDF_FLAG_VARCONV);
  1511. return 0;
  1512. }
  1513. out:
  1514. sbi->s_last_block = lastblock;
  1515. return 1;
  1516. }
  1517. /*
  1518. * Check Volume Structure Descriptor, find Anchor block and load Volume
  1519. * Descriptor Sequence
  1520. */
  1521. static int udf_load_vrs(struct super_block *sb, struct udf_options *uopt,
  1522. int silent, struct kernel_lb_addr *fileset)
  1523. {
  1524. struct udf_sb_info *sbi = UDF_SB(sb);
  1525. loff_t nsr_off;
  1526. if (!sb_set_blocksize(sb, uopt->blocksize)) {
  1527. if (!silent)
  1528. printk(KERN_WARNING "UDF-fs: Bad block size\n");
  1529. return 0;
  1530. }
  1531. sbi->s_last_block = uopt->lastblock;
  1532. if (!uopt->novrs) {
  1533. /* Check that it is NSR02 compliant */
  1534. nsr_off = udf_check_vsd(sb);
  1535. if (!nsr_off) {
  1536. if (!silent)
  1537. printk(KERN_WARNING "UDF-fs: No VRS found\n");
  1538. return 0;
  1539. }
  1540. if (nsr_off == -1)
  1541. udf_debug("Failed to read byte 32768. Assuming open "
  1542. "disc. Skipping validity check\n");
  1543. if (!sbi->s_last_block)
  1544. sbi->s_last_block = udf_get_last_block(sb);
  1545. } else {
  1546. udf_debug("Validity check skipped because of novrs option\n");
  1547. }
  1548. /* Look for anchor block and load Volume Descriptor Sequence */
  1549. sbi->s_anchor = uopt->anchor;
  1550. if (!udf_find_anchor(sb, fileset)) {
  1551. if (!silent)
  1552. printk(KERN_WARNING "UDF-fs: No anchor found\n");
  1553. return 0;
  1554. }
  1555. return 1;
  1556. }
  1557. static void udf_open_lvid(struct super_block *sb)
  1558. {
  1559. struct udf_sb_info *sbi = UDF_SB(sb);
  1560. struct buffer_head *bh = sbi->s_lvid_bh;
  1561. struct logicalVolIntegrityDesc *lvid;
  1562. struct logicalVolIntegrityDescImpUse *lvidiu;
  1563. if (!bh)
  1564. return;
  1565. lvid = (struct logicalVolIntegrityDesc *)bh->b_data;
  1566. lvidiu = udf_sb_lvidiu(sbi);
  1567. lvidiu->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
  1568. lvidiu->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
  1569. udf_time_to_disk_stamp(&lvid->recordingDateAndTime,
  1570. CURRENT_TIME);
  1571. lvid->integrityType = cpu_to_le32(LVID_INTEGRITY_TYPE_OPEN);
  1572. lvid->descTag.descCRC = cpu_to_le16(
  1573. crc_itu_t(0, (char *)lvid + sizeof(struct tag),
  1574. le16_to_cpu(lvid->descTag.descCRCLength)));
  1575. lvid->descTag.tagChecksum = udf_tag_checksum(&lvid->descTag);
  1576. mark_buffer_dirty(bh);
  1577. sbi->s_lvid_dirty = 0;
  1578. }
  1579. static void udf_close_lvid(struct super_block *sb)
  1580. {
  1581. struct udf_sb_info *sbi = UDF_SB(sb);
  1582. struct buffer_head *bh = sbi->s_lvid_bh;
  1583. struct logicalVolIntegrityDesc *lvid;
  1584. struct logicalVolIntegrityDescImpUse *lvidiu;
  1585. if (!bh)
  1586. return;
  1587. lvid = (struct logicalVolIntegrityDesc *)bh->b_data;
  1588. lvidiu = udf_sb_lvidiu(sbi);
  1589. lvidiu->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
  1590. lvidiu->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
  1591. udf_time_to_disk_stamp(&lvid->recordingDateAndTime, CURRENT_TIME);
  1592. if (UDF_MAX_WRITE_VERSION > le16_to_cpu(lvidiu->maxUDFWriteRev))
  1593. lvidiu->maxUDFWriteRev = cpu_to_le16(UDF_MAX_WRITE_VERSION);
  1594. if (sbi->s_udfrev > le16_to_cpu(lvidiu->minUDFReadRev))
  1595. lvidiu->minUDFReadRev = cpu_to_le16(sbi->s_udfrev);
  1596. if (sbi->s_udfrev > le16_to_cpu(lvidiu->minUDFWriteRev))
  1597. lvidiu->minUDFWriteRev = cpu_to_le16(sbi->s_udfrev);
  1598. lvid->integrityType = cpu_to_le32(LVID_INTEGRITY_TYPE_CLOSE);
  1599. lvid->descTag.descCRC = cpu_to_le16(
  1600. crc_itu_t(0, (char *)lvid + sizeof(struct tag),
  1601. le16_to_cpu(lvid->descTag.descCRCLength)));
  1602. lvid->descTag.tagChecksum = udf_tag_checksum(&lvid->descTag);
  1603. mark_buffer_dirty(bh);
  1604. sbi->s_lvid_dirty = 0;
  1605. }
  1606. static void udf_sb_free_bitmap(struct udf_bitmap *bitmap)
  1607. {
  1608. int i;
  1609. int nr_groups = bitmap->s_nr_groups;
  1610. int size = sizeof(struct udf_bitmap) + (sizeof(struct buffer_head *) *
  1611. nr_groups);
  1612. for (i = 0; i < nr_groups; i++)
  1613. if (bitmap->s_block_bitmap[i])
  1614. brelse(bitmap->s_block_bitmap[i]);
  1615. if (size <= PAGE_SIZE)
  1616. kfree(bitmap);
  1617. else
  1618. vfree(bitmap);
  1619. }
  1620. static void udf_free_partition(struct udf_part_map *map)
  1621. {
  1622. int i;
  1623. struct udf_meta_data *mdata;
  1624. if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_TABLE)
  1625. iput(map->s_uspace.s_table);
  1626. if (map->s_partition_flags & UDF_PART_FLAG_FREED_TABLE)
  1627. iput(map->s_fspace.s_table);
  1628. if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_BITMAP)
  1629. udf_sb_free_bitmap(map->s_uspace.s_bitmap);
  1630. if (map->s_partition_flags & UDF_PART_FLAG_FREED_BITMAP)
  1631. udf_sb_free_bitmap(map->s_fspace.s_bitmap);
  1632. if (map->s_partition_type == UDF_SPARABLE_MAP15)
  1633. for (i = 0; i < 4; i++)
  1634. brelse(map->s_type_specific.s_sparing.s_spar_map[i]);
  1635. else if (map->s_partition_type == UDF_METADATA_MAP25) {
  1636. mdata = &map->s_type_specific.s_metadata;
  1637. iput(mdata->s_metadata_fe);
  1638. mdata->s_metadata_fe = NULL;
  1639. iput(mdata->s_mirror_fe);
  1640. mdata->s_mirror_fe = NULL;
  1641. iput(mdata->s_bitmap_fe);
  1642. mdata->s_bitmap_fe = NULL;
  1643. }
  1644. }
  1645. static int udf_fill_super(struct super_block *sb, void *options, int silent)
  1646. {
  1647. int i;
  1648. int ret;
  1649. struct inode *inode = NULL;
  1650. struct udf_options uopt;
  1651. struct kernel_lb_addr rootdir, fileset;
  1652. struct udf_sb_info *sbi;
  1653. uopt.flags = (1 << UDF_FLAG_USE_AD_IN_ICB) | (1 << UDF_FLAG_STRICT);
  1654. uopt.uid = -1;
  1655. uopt.gid = -1;
  1656. uopt.umask = 0;
  1657. uopt.fmode = UDF_INVALID_MODE;
  1658. uopt.dmode = UDF_INVALID_MODE;
  1659. sbi = kzalloc(sizeof(struct udf_sb_info), GFP_KERNEL);
  1660. if (!sbi)
  1661. return -ENOMEM;
  1662. sb->s_fs_info = sbi;
  1663. mutex_init(&sbi->s_alloc_mutex);
  1664. if (!udf_parse_options((char *)options, &uopt, false))
  1665. goto error_out;
  1666. if (uopt.flags & (1 << UDF_FLAG_UTF8) &&
  1667. uopt.flags & (1 << UDF_FLAG_NLS_MAP)) {
  1668. udf_error(sb, "udf_read_super",
  1669. "utf8 cannot be combined with iocharset\n");
  1670. goto error_out;
  1671. }
  1672. #ifdef CONFIG_UDF_NLS
  1673. if ((uopt.flags & (1 << UDF_FLAG_NLS_MAP)) && !uopt.nls_map) {
  1674. uopt.nls_map = load_nls_default();
  1675. if (!uopt.nls_map)
  1676. uopt.flags &= ~(1 << UDF_FLAG_NLS_MAP);
  1677. else
  1678. udf_debug("Using default NLS map\n");
  1679. }
  1680. #endif
  1681. if (!(uopt.flags & (1 << UDF_FLAG_NLS_MAP)))
  1682. uopt.flags |= (1 << UDF_FLAG_UTF8);
  1683. fileset.logicalBlockNum = 0xFFFFFFFF;
  1684. fileset.partitionReferenceNum = 0xFFFF;
  1685. sbi->s_flags = uopt.flags;
  1686. sbi->s_uid = uopt.uid;
  1687. sbi->s_gid = uopt.gid;
  1688. sbi->s_umask = uopt.umask;
  1689. sbi->s_fmode = uopt.fmode;
  1690. sbi->s_dmode = uopt.dmode;
  1691. sbi->s_nls_map = uopt.nls_map;
  1692. if (uopt.session == 0xFFFFFFFF)
  1693. sbi->s_session = udf_get_last_session(sb);
  1694. else
  1695. sbi->s_session = uopt.session;
  1696. udf_debug("Multi-session=%d\n", sbi->s_session);
  1697. /* Fill in the rest of the superblock */
  1698. sb->s_op = &udf_sb_ops;
  1699. sb->s_export_op = &udf_export_ops;
  1700. sb->dq_op = NULL;
  1701. sb->s_dirt = 0;
  1702. sb->s_magic = UDF_SUPER_MAGIC;
  1703. sb->s_time_gran = 1000;
  1704. if (uopt.flags & (1 << UDF_FLAG_BLOCKSIZE_SET)) {
  1705. ret = udf_load_vrs(sb, &uopt, silent, &fileset);
  1706. } else {
  1707. uopt.blocksize = bdev_hardsect_size(sb->s_bdev);
  1708. ret = udf_load_vrs(sb, &uopt, silent, &fileset);
  1709. if (!ret && uopt.blocksize != UDF_DEFAULT_BLOCKSIZE) {
  1710. if (!silent)
  1711. printk(KERN_NOTICE
  1712. "UDF-fs: Rescanning with blocksize "
  1713. "%d\n", UDF_DEFAULT_BLOCKSIZE);
  1714. uopt.blocksize = UDF_DEFAULT_BLOCKSIZE;
  1715. ret = udf_load_vrs(sb, &uopt, silent, &fileset);
  1716. }
  1717. }
  1718. if (!ret) {
  1719. printk(KERN_WARNING "UDF-fs: No partition found (1)\n");
  1720. goto error_out;
  1721. }
  1722. udf_debug("Lastblock=%d\n", sbi->s_last_block);
  1723. if (sbi->s_lvid_bh) {
  1724. struct logicalVolIntegrityDescImpUse *lvidiu =
  1725. udf_sb_lvidiu(sbi);
  1726. uint16_t minUDFReadRev = le16_to_cpu(lvidiu->minUDFReadRev);
  1727. uint16_t minUDFWriteRev = le16_to_cpu(lvidiu->minUDFWriteRev);
  1728. /* uint16_t maxUDFWriteRev =
  1729. le16_to_cpu(lvidiu->maxUDFWriteRev); */
  1730. if (minUDFReadRev > UDF_MAX_READ_VERSION) {
  1731. printk(KERN_ERR "UDF-fs: minUDFReadRev=%x "
  1732. "(max is %x)\n",
  1733. le16_to_cpu(lvidiu->minUDFReadRev),
  1734. UDF_MAX_READ_VERSION);
  1735. goto error_out;
  1736. } else if (minUDFWriteRev > UDF_MAX_WRITE_VERSION)
  1737. sb->s_flags |= MS_RDONLY;
  1738. sbi->s_udfrev = minUDFWriteRev;
  1739. if (minUDFReadRev >= UDF_VERS_USE_EXTENDED_FE)
  1740. UDF_SET_FLAG(sb, UDF_FLAG_USE_EXTENDED_FE);
  1741. if (minUDFReadRev >= UDF_VERS_USE_STREAMS)
  1742. UDF_SET_FLAG(sb, UDF_FLAG_USE_STREAMS);
  1743. }
  1744. if (!sbi->s_partitions) {
  1745. printk(KERN_WARNING "UDF-fs: No partition found (2)\n");
  1746. goto error_out;
  1747. }
  1748. if (sbi->s_partmaps[sbi->s_partition].s_partition_flags &
  1749. UDF_PART_FLAG_READ_ONLY) {
  1750. printk(KERN_NOTICE "UDF-fs: Partition marked readonly; "
  1751. "forcing readonly mount\n");
  1752. sb->s_flags |= MS_RDONLY;
  1753. }
  1754. if (udf_find_fileset(sb, &fileset, &rootdir)) {
  1755. printk(KERN_WARNING "UDF-fs: No fileset found\n");
  1756. goto error_out;
  1757. }
  1758. if (!silent) {
  1759. struct timestamp ts;
  1760. udf_time_to_disk_stamp(&ts, sbi->s_record_time);
  1761. udf_info("UDF: Mounting volume '%s', "
  1762. "timestamp %04u/%02u/%02u %02u:%02u (%x)\n",
  1763. sbi->s_volume_ident, le16_to_cpu(ts.year), ts.month, ts.day,
  1764. ts.hour, ts.minute, le16_to_cpu(ts.typeAndTimezone));
  1765. }
  1766. if (!(sb->s_flags & MS_RDONLY))
  1767. udf_open_lvid(sb);
  1768. /* Assign the root inode */
  1769. /* assign inodes by physical block number */
  1770. /* perhaps it's not extensible enough, but for now ... */
  1771. inode = udf_iget(sb, &rootdir);
  1772. if (!inode) {
  1773. printk(KERN_ERR "UDF-fs: Error in udf_iget, block=%d, "
  1774. "partition=%d\n",
  1775. rootdir.logicalBlockNum, rootdir.partitionReferenceNum);
  1776. goto error_out;
  1777. }
  1778. /* Allocate a dentry for the root inode */
  1779. sb->s_root = d_alloc_root(inode);
  1780. if (!sb->s_root) {
  1781. printk(KERN_ERR "UDF-fs: Couldn't allocate root dentry\n");
  1782. iput(inode);
  1783. goto error_out;
  1784. }
  1785. sb->s_maxbytes = MAX_LFS_FILESIZE;
  1786. return 0;
  1787. error_out:
  1788. if (sbi->s_vat_inode)
  1789. iput(sbi->s_vat_inode);
  1790. if (sbi->s_partitions)
  1791. for (i = 0; i < sbi->s_partitions; i++)
  1792. udf_free_partition(&sbi->s_partmaps[i]);
  1793. #ifdef CONFIG_UDF_NLS
  1794. if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP))
  1795. unload_nls(sbi->s_nls_map);
  1796. #endif
  1797. if (!(sb->s_flags & MS_RDONLY))
  1798. udf_close_lvid(sb);
  1799. brelse(sbi->s_lvid_bh);
  1800. kfree(sbi->s_partmaps);
  1801. kfree(sbi);
  1802. sb->s_fs_info = NULL;
  1803. return -EINVAL;
  1804. }
  1805. static void udf_error(struct super_block *sb, const char *function,
  1806. const char *fmt, ...)
  1807. {
  1808. va_list args;
  1809. if (!(sb->s_flags & MS_RDONLY)) {
  1810. /* mark sb error */
  1811. sb->s_dirt = 1;
  1812. }
  1813. va_start(args, fmt);
  1814. vsnprintf(error_buf, sizeof(error_buf), fmt, args);
  1815. va_end(args);
  1816. printk(KERN_CRIT "UDF-fs error (device %s): %s: %s\n",
  1817. sb->s_id, function, error_buf);
  1818. }
  1819. void udf_warning(struct super_block *sb, const char *function,
  1820. const char *fmt, ...)
  1821. {
  1822. va_list args;
  1823. va_start(args, fmt);
  1824. vsnprintf(error_buf, sizeof(error_buf), fmt, args);
  1825. va_end(args);
  1826. printk(KERN_WARNING "UDF-fs warning (device %s): %s: %s\n",
  1827. sb->s_id, function, error_buf);
  1828. }
  1829. static void udf_put_super(struct super_block *sb)
  1830. {
  1831. int i;
  1832. struct udf_sb_info *sbi;
  1833. sbi = UDF_SB(sb);
  1834. if (sbi->s_vat_inode)
  1835. iput(sbi->s_vat_inode);
  1836. if (sbi->s_partitions)
  1837. for (i = 0; i < sbi->s_partitions; i++)
  1838. udf_free_partition(&sbi->s_partmaps[i]);
  1839. #ifdef CONFIG_UDF_NLS
  1840. if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP))
  1841. unload_nls(sbi->s_nls_map);
  1842. #endif
  1843. if (!(sb->s_flags & MS_RDONLY))
  1844. udf_close_lvid(sb);
  1845. brelse(sbi->s_lvid_bh);
  1846. kfree(sbi->s_partmaps);
  1847. kfree(sb->s_fs_info);
  1848. sb->s_fs_info = NULL;
  1849. }
  1850. static int udf_sync_fs(struct super_block *sb, int wait)
  1851. {
  1852. struct udf_sb_info *sbi = UDF_SB(sb);
  1853. mutex_lock(&sbi->s_alloc_mutex);
  1854. if (sbi->s_lvid_dirty) {
  1855. /*
  1856. * Blockdevice will be synced later so we don't have to submit
  1857. * the buffer for IO
  1858. */
  1859. mark_buffer_dirty(sbi->s_lvid_bh);
  1860. sb->s_dirt = 0;
  1861. sbi->s_lvid_dirty = 0;
  1862. }
  1863. mutex_unlock(&sbi->s_alloc_mutex);
  1864. return 0;
  1865. }
  1866. static int udf_statfs(struct dentry *dentry, struct kstatfs *buf)
  1867. {
  1868. struct super_block *sb = dentry->d_sb;
  1869. struct udf_sb_info *sbi = UDF_SB(sb);
  1870. struct logicalVolIntegrityDescImpUse *lvidiu;
  1871. u64 id = huge_encode_dev(sb->s_bdev->bd_dev);
  1872. if (sbi->s_lvid_bh != NULL)
  1873. lvidiu = udf_sb_lvidiu(sbi);
  1874. else
  1875. lvidiu = NULL;
  1876. buf->f_type = UDF_SUPER_MAGIC;
  1877. buf->f_bsize = sb->s_blocksize;
  1878. buf->f_blocks = sbi->s_partmaps[sbi->s_partition].s_partition_len;
  1879. buf->f_bfree = udf_count_free(sb);
  1880. buf->f_bavail = buf->f_bfree;
  1881. buf->f_files = (lvidiu != NULL ? (le32_to_cpu(lvidiu->numFiles) +
  1882. le32_to_cpu(lvidiu->numDirs)) : 0)
  1883. + buf->f_bfree;
  1884. buf->f_ffree = buf->f_bfree;
  1885. buf->f_namelen = UDF_NAME_LEN - 2;
  1886. buf->f_fsid.val[0] = (u32)id;
  1887. buf->f_fsid.val[1] = (u32)(id >> 32);
  1888. return 0;
  1889. }
  1890. static unsigned int udf_count_free_bitmap(struct super_block *sb,
  1891. struct udf_bitmap *bitmap)
  1892. {
  1893. struct buffer_head *bh = NULL;
  1894. unsigned int accum = 0;
  1895. int index;
  1896. int block = 0, newblock;
  1897. struct kernel_lb_addr loc;
  1898. uint32_t bytes;
  1899. uint8_t *ptr;
  1900. uint16_t ident;
  1901. struct spaceBitmapDesc *bm;
  1902. lock_kernel();
  1903. loc.logicalBlockNum = bitmap->s_extPosition;
  1904. loc.partitionReferenceNum = UDF_SB(sb)->s_partition;
  1905. bh = udf_read_ptagged(sb, &loc, 0, &ident);
  1906. if (!bh) {
  1907. printk(KERN_ERR "udf: udf_count_free failed\n");
  1908. goto out;
  1909. } else if (ident != TAG_IDENT_SBD) {
  1910. brelse(bh);
  1911. printk(KERN_ERR "udf: udf_count_free failed\n");
  1912. goto out;
  1913. }
  1914. bm = (struct spaceBitmapDesc *)bh->b_data;
  1915. bytes = le32_to_cpu(bm->numOfBytes);
  1916. index = sizeof(struct spaceBitmapDesc); /* offset in first block only */
  1917. ptr = (uint8_t *)bh->b_data;
  1918. while (bytes > 0) {
  1919. u32 cur_bytes = min_t(u32, bytes, sb->s_blocksize - index);
  1920. accum += bitmap_weight((const unsigned long *)(ptr + index),
  1921. cur_bytes * 8);
  1922. bytes -= cur_bytes;
  1923. if (bytes) {
  1924. brelse(bh);
  1925. newblock = udf_get_lb_pblock(sb, &loc, ++block);
  1926. bh = udf_tread(sb, newblock);
  1927. if (!bh) {
  1928. udf_debug("read failed\n");
  1929. goto out;
  1930. }
  1931. index = 0;
  1932. ptr = (uint8_t *)bh->b_data;
  1933. }
  1934. }
  1935. brelse(bh);
  1936. out:
  1937. unlock_kernel();
  1938. return accum;
  1939. }
  1940. static unsigned int udf_count_free_table(struct super_block *sb,
  1941. struct inode *table)
  1942. {
  1943. unsigned int accum = 0;
  1944. uint32_t elen;
  1945. struct kernel_lb_addr eloc;
  1946. int8_t etype;
  1947. struct extent_position epos;
  1948. lock_kernel();
  1949. epos.block = UDF_I(table)->i_location;
  1950. epos.offset = sizeof(struct unallocSpaceEntry);
  1951. epos.bh = NULL;
  1952. while ((etype = udf_next_aext(table, &epos, &eloc, &elen, 1)) != -1)
  1953. accum += (elen >> table->i_sb->s_blocksize_bits);
  1954. brelse(epos.bh);
  1955. unlock_kernel();
  1956. return accum;
  1957. }
  1958. static unsigned int udf_count_free(struct super_block *sb)
  1959. {
  1960. unsigned int accum = 0;
  1961. struct udf_sb_info *sbi;
  1962. struct udf_part_map *map;
  1963. sbi = UDF_SB(sb);
  1964. if (sbi->s_lvid_bh) {
  1965. struct logicalVolIntegrityDesc *lvid =
  1966. (struct logicalVolIntegrityDesc *)
  1967. sbi->s_lvid_bh->b_data;
  1968. if (le32_to_cpu(lvid->numOfPartitions) > sbi->s_partition) {
  1969. accum = le32_to_cpu(
  1970. lvid->freeSpaceTable[sbi->s_partition]);
  1971. if (accum == 0xFFFFFFFF)
  1972. accum = 0;
  1973. }
  1974. }
  1975. if (accum)
  1976. return accum;
  1977. map = &sbi->s_partmaps[sbi->s_partition];
  1978. if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_BITMAP) {
  1979. accum += udf_count_free_bitmap(sb,
  1980. map->s_uspace.s_bitmap);
  1981. }
  1982. if (map->s_partition_flags & UDF_PART_FLAG_FREED_BITMAP) {
  1983. accum += udf_count_free_bitmap(sb,
  1984. map->s_fspace.s_bitmap);
  1985. }
  1986. if (accum)
  1987. return accum;
  1988. if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_TABLE) {
  1989. accum += udf_count_free_table(sb,
  1990. map->s_uspace.s_table);
  1991. }
  1992. if (map->s_partition_flags & UDF_PART_FLAG_FREED_TABLE) {
  1993. accum += udf_count_free_table(sb,
  1994. map->s_fspace.s_table);
  1995. }
  1996. return accum;
  1997. }