udf_sb.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #ifndef __LINUX_UDF_SB_H
  2. #define __LINUX_UDF_SB_H
  3. /* Since UDF 2.01 is ISO 13346 based... */
  4. #define UDF_SUPER_MAGIC 0x15013346
  5. #define UDF_MAX_READ_VERSION 0x0201
  6. #define UDF_MAX_WRITE_VERSION 0x0201
  7. #define UDF_FLAG_USE_EXTENDED_FE 0
  8. #define UDF_VERS_USE_EXTENDED_FE 0x0200
  9. #define UDF_FLAG_USE_STREAMS 1
  10. #define UDF_VERS_USE_STREAMS 0x0200
  11. #define UDF_FLAG_USE_SHORT_AD 2
  12. #define UDF_FLAG_USE_AD_IN_ICB 3
  13. #define UDF_FLAG_USE_FILE_CTIME_EA 4
  14. #define UDF_FLAG_STRICT 5
  15. #define UDF_FLAG_UNDELETE 6
  16. #define UDF_FLAG_UNHIDE 7
  17. #define UDF_FLAG_VARCONV 8
  18. #define UDF_FLAG_NLS_MAP 9
  19. #define UDF_FLAG_UTF8 10
  20. #define UDF_FLAG_UID_FORGET 11 /* save -1 for uid to disk */
  21. #define UDF_FLAG_UID_IGNORE 12 /* use sb uid instead of on disk uid */
  22. #define UDF_FLAG_GID_FORGET 13
  23. #define UDF_FLAG_GID_IGNORE 14
  24. #define UDF_FLAG_UID_SET 15
  25. #define UDF_FLAG_GID_SET 16
  26. #define UDF_PART_FLAG_UNALLOC_BITMAP 0x0001
  27. #define UDF_PART_FLAG_UNALLOC_TABLE 0x0002
  28. #define UDF_PART_FLAG_FREED_BITMAP 0x0004
  29. #define UDF_PART_FLAG_FREED_TABLE 0x0008
  30. #define UDF_PART_FLAG_READ_ONLY 0x0010
  31. #define UDF_PART_FLAG_WRITE_ONCE 0x0020
  32. #define UDF_PART_FLAG_REWRITABLE 0x0040
  33. #define UDF_PART_FLAG_OVERWRITABLE 0x0080
  34. static inline struct udf_sb_info *UDF_SB(struct super_block *sb)
  35. {
  36. return sb->s_fs_info;
  37. }
  38. #define UDF_SB_FREE(X)\
  39. {\
  40. if (UDF_SB(X)) {\
  41. kfree(UDF_SB_PARTMAPS(X));\
  42. UDF_SB_PARTMAPS(X) = NULL;\
  43. }\
  44. }
  45. #define UDF_SB_ALLOC_PARTMAPS(X,Y)\
  46. {\
  47. UDF_SB_PARTMAPS(X) = kmalloc(sizeof(struct udf_part_map) * Y, GFP_KERNEL);\
  48. if (UDF_SB_PARTMAPS(X) != NULL) {\
  49. UDF_SB_NUMPARTS(X) = Y;\
  50. memset(UDF_SB_PARTMAPS(X), 0x00, sizeof(struct udf_part_map) * Y);\
  51. } else {\
  52. UDF_SB_NUMPARTS(X) = 0;\
  53. udf_error(X, __FUNCTION__, "Unable to allocate space for %d partition maps", Y);\
  54. }\
  55. }
  56. #define UDF_SB_ALLOC_BITMAP(X,Y,Z)\
  57. {\
  58. int nr_groups = ((UDF_SB_PARTLEN((X),(Y)) + (sizeof(struct spaceBitmapDesc) << 3) +\
  59. ((X)->s_blocksize * 8) - 1) / ((X)->s_blocksize * 8));\
  60. int size = sizeof(struct udf_bitmap) + (sizeof(struct buffer_head *) * nr_groups);\
  61. if (size <= PAGE_SIZE)\
  62. UDF_SB_PARTMAPS(X)[(Y)].Z.s_bitmap = kmalloc(size, GFP_KERNEL);\
  63. else\
  64. UDF_SB_PARTMAPS(X)[(Y)].Z.s_bitmap = vmalloc(size);\
  65. if (UDF_SB_PARTMAPS(X)[(Y)].Z.s_bitmap != NULL) {\
  66. memset(UDF_SB_PARTMAPS(X)[(Y)].Z.s_bitmap, 0x00, size);\
  67. UDF_SB_PARTMAPS(X)[(Y)].Z.s_bitmap->s_block_bitmap =\
  68. (struct buffer_head **)(UDF_SB_PARTMAPS(X)[(Y)].Z.s_bitmap + 1);\
  69. UDF_SB_PARTMAPS(X)[(Y)].Z.s_bitmap->s_nr_groups = nr_groups;\
  70. } else {\
  71. udf_error(X, __FUNCTION__, "Unable to allocate space for bitmap and %d buffer_head pointers", nr_groups);\
  72. }\
  73. }
  74. #define UDF_SB_FREE_BITMAP(X,Y,Z)\
  75. {\
  76. int i;\
  77. int nr_groups = UDF_SB_BITMAP_NR_GROUPS(X,Y,Z);\
  78. int size = sizeof(struct udf_bitmap) + (sizeof(struct buffer_head *) * nr_groups);\
  79. for (i = 0; i < nr_groups; i++) {\
  80. if (UDF_SB_BITMAP(X,Y,Z,i))\
  81. brelse(UDF_SB_BITMAP(X,Y,Z,i));\
  82. }\
  83. if (size <= PAGE_SIZE)\
  84. kfree(UDF_SB_PARTMAPS(X)[Y].Z.s_bitmap);\
  85. else\
  86. vfree(UDF_SB_PARTMAPS(X)[Y].Z.s_bitmap);\
  87. }
  88. #define UDF_QUERY_FLAG(X,Y) ( UDF_SB(X)->s_flags & ( 1 << (Y) ) )
  89. #define UDF_SET_FLAG(X,Y) ( UDF_SB(X)->s_flags |= ( 1 << (Y) ) )
  90. #define UDF_CLEAR_FLAG(X,Y) ( UDF_SB(X)->s_flags &= ~( 1 << (Y) ) )
  91. #define UDF_UPDATE_UDFREV(X,Y) ( ((Y) > UDF_SB_UDFREV(X)) ? UDF_SB_UDFREV(X) = (Y) : UDF_SB_UDFREV(X) )
  92. #define UDF_SB_PARTMAPS(X) ( UDF_SB(X)->s_partmaps )
  93. #define UDF_SB_PARTTYPE(X,Y) ( UDF_SB_PARTMAPS(X)[(Y)].s_partition_type )
  94. #define UDF_SB_PARTROOT(X,Y) ( UDF_SB_PARTMAPS(X)[(Y)].s_partition_root )
  95. #define UDF_SB_PARTLEN(X,Y) ( UDF_SB_PARTMAPS(X)[(Y)].s_partition_len )
  96. #define UDF_SB_PARTVSN(X,Y) ( UDF_SB_PARTMAPS(X)[(Y)].s_volumeseqnum )
  97. #define UDF_SB_PARTNUM(X,Y) ( UDF_SB_PARTMAPS(X)[(Y)].s_partition_num )
  98. #define UDF_SB_TYPESPAR(X,Y) ( UDF_SB_PARTMAPS(X)[(Y)].s_type_specific.s_sparing )
  99. #define UDF_SB_TYPEVIRT(X,Y) ( UDF_SB_PARTMAPS(X)[(Y)].s_type_specific.s_virtual )
  100. #define UDF_SB_PARTFUNC(X,Y) ( UDF_SB_PARTMAPS(X)[(Y)].s_partition_func )
  101. #define UDF_SB_PARTFLAGS(X,Y) ( UDF_SB_PARTMAPS(X)[(Y)].s_partition_flags )
  102. #define UDF_SB_BITMAP(X,Y,Z,I) ( UDF_SB_PARTMAPS(X)[(Y)].Z.s_bitmap->s_block_bitmap[I] )
  103. #define UDF_SB_BITMAP_NR_GROUPS(X,Y,Z) ( UDF_SB_PARTMAPS(X)[(Y)].Z.s_bitmap->s_nr_groups )
  104. #define UDF_SB_VOLIDENT(X) ( UDF_SB(X)->s_volident )
  105. #define UDF_SB_NUMPARTS(X) ( UDF_SB(X)->s_partitions )
  106. #define UDF_SB_PARTITION(X) ( UDF_SB(X)->s_partition )
  107. #define UDF_SB_SESSION(X) ( UDF_SB(X)->s_session )
  108. #define UDF_SB_ANCHOR(X) ( UDF_SB(X)->s_anchor )
  109. #define UDF_SB_LASTBLOCK(X) ( UDF_SB(X)->s_lastblock )
  110. #define UDF_SB_LVIDBH(X) ( UDF_SB(X)->s_lvidbh )
  111. #define UDF_SB_LVID(X) ( (struct logicalVolIntegrityDesc *)UDF_SB_LVIDBH(X)->b_data )
  112. #define UDF_SB_LVIDIU(X) ( (struct logicalVolIntegrityDescImpUse *)&(UDF_SB_LVID(X)->impUse[le32_to_cpu(UDF_SB_LVID(X)->numOfPartitions) * 2 * sizeof(uint32_t)/sizeof(uint8_t)]) )
  113. #define UDF_SB_UMASK(X) ( UDF_SB(X)->s_umask )
  114. #define UDF_SB_GID(X) ( UDF_SB(X)->s_gid )
  115. #define UDF_SB_UID(X) ( UDF_SB(X)->s_uid )
  116. #define UDF_SB_RECORDTIME(X) ( UDF_SB(X)->s_recordtime )
  117. #define UDF_SB_SERIALNUM(X) ( UDF_SB(X)->s_serialnum )
  118. #define UDF_SB_UDFREV(X) ( UDF_SB(X)->s_udfrev )
  119. #define UDF_SB_FLAGS(X) ( UDF_SB(X)->s_flags )
  120. #define UDF_SB_VAT(X) ( UDF_SB(X)->s_vat )
  121. #endif /* __LINUX_UDF_SB_H */