/core/sdk-objc/GMAppleDouble.h

http://macfuse.googlecode.com/ · C Header · 167 lines · 41 code · 17 blank · 109 comment · 0 complexity · 21c8682a26590b59819230d4925e2ca0 MD5 · raw file

  1. // ================================================================
  2. // Copyright (c) 2007, Google Inc.
  3. // All rights reserved.
  4. //
  5. // Redistribution and use in source and binary forms, with or without
  6. // modification, are permitted provided that the following conditions are
  7. // met:
  8. //
  9. // * Redistributions of source code must retain the above copyright
  10. // notice, this list of conditions and the following disclaimer.
  11. // * Redistributions in binary form must reproduce the above
  12. // copyright notice, this list of conditions and the following disclaimer
  13. // in the documentation and/or other materials provided with the
  14. // distribution.
  15. // * Neither the name of Google Inc. nor the names of its
  16. // contributors may be used to endorse or promote products derived from
  17. // this software without specific prior written permission.
  18. //
  19. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  22. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  23. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  24. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  25. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  26. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  27. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  28. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  29. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. // ================================================================
  31. //
  32. // GMAppleDouble.h
  33. // MacFUSE
  34. //
  35. // Created by ted on 12/29/07.
  36. //
  37. /*!
  38. * @header GMAppleDouble
  39. *
  40. * A utility class to construct an AppleDouble (._) file.
  41. *
  42. * AppleDouble files contain information about a corresponding file and are
  43. * typically used on file systems that do not support extended attributes.
  44. */
  45. #import <Foundation/Foundation.h>
  46. #define GM_EXPORT __attribute__((visibility("default")))
  47. /*!
  48. * <pre>
  49. * Based on "AppleSingle/AppleDouble Formats for Foreign Files Developer's Note"
  50. *
  51. * Notes:
  52. * DoubleEntryFileDatesInfo
  53. * File creation, modification, backup, and access times as number of seconds
  54. * before or after 12:00 AM Jan 1 2000 GMT as SInt32.
  55. * DoubleEntryFinderInfo
  56. * 16 bytes of FinderInfo followed by 16 bytes of extended FinderInfo.
  57. * New FinderInfo should be zero'd out. For a directory, when the Finder
  58. * encounters an entry with the init'd bit cleared, it will initialize the
  59. * frView field of the to a value indicating how the contents of the
  60. * directory should be shown. Recommend to set frView to value of 256.
  61. * DoubleEntryMacFileInfo
  62. * This is a 32 bit flag that stores locked (bit 0) and protected (bit 1).
  63. * </pre>
  64. */
  65. typedef enum {
  66. DoubleEntryInvalid = 0,
  67. DoubleEntryDataFork = 1,
  68. DoubleEntryResourceFork = 2,
  69. DoubleEntryRealName = 3,
  70. DoubleEntryComment = 4,
  71. DoubleEntryBlackAndWhiteIcon = 5,
  72. DoubleEntryColorIcon = 6,
  73. DoubleEntryFileDatesInfo = 8, // See notes
  74. DoubleEntryFinderInfo = 9, // See notes
  75. DoubleEntryMacFileInfo = 10, // See notes
  76. DoubleEntryProDosFileInfo = 11,
  77. DoubleEntryMSDosFileinfo = 12,
  78. DoubleEntryShortName = 13,
  79. DoubleEntryAFPFileInfo = 14,
  80. DoubleEntryDirectoryID = 15,
  81. } GMAppleDoubleEntryID;
  82. /*!
  83. * @class
  84. * @discussion This class represents a single entry in an AppleDouble file.
  85. */
  86. GM_EXPORT @interface GMAppleDoubleEntry : NSObject {
  87. @private
  88. GMAppleDoubleEntryID entryID_;
  89. NSData* data_; // Format depends on entryID_
  90. }
  91. /*!
  92. * @abstract Initializes an AppleDouble entry with ID and data.
  93. * @param entryID A valid entry identifier
  94. * @param data Raw data for the entry
  95. */
  96. - (id)initWithEntryID:(GMAppleDoubleEntryID)entryID data:(NSData *)data;
  97. /*! @abstract The entry ID */
  98. - (GMAppleDoubleEntryID)entryID;
  99. /*! @abstract The entry data */
  100. - (NSData *)data;
  101. @end
  102. /*!
  103. * @class
  104. * @discussion This class can be used to construct raw AppleDouble data.
  105. */
  106. GM_EXPORT @interface GMAppleDouble : NSObject {
  107. @private
  108. NSMutableArray* entries_;
  109. }
  110. /*! @abstract An autoreleased empty GMAppleDouble file */
  111. + (GMAppleDouble *)appleDouble;
  112. /*!
  113. * @abstract An autoreleased GMAppleDouble file.
  114. * @discussion The GMAppleDouble is pre-filled with entries from the raw
  115. * AppleDouble file data.
  116. * @param data Raw AppleDouble file data.
  117. */
  118. + (GMAppleDouble *)appleDoubleWithData:(NSData *)data;
  119. /*!
  120. * @abstract Adds an entry to the AppleDouble file.
  121. * @param entry The entry to add
  122. */
  123. - (void)addEntry:(GMAppleDoubleEntry *)entry;
  124. /*!
  125. * @abstract Adds an entry to the AppleDouble file with ID and data.
  126. * @param entryID The ID of the entry to add
  127. * @param data The raw data for the entry to add (retained)
  128. */
  129. - (void)addEntryWithID:(GMAppleDoubleEntryID)entryID data:(NSData *)data;
  130. /*!
  131. * @abstract Adds entries based on the provided raw AppleDouble file data.
  132. * @discussion This will attempt to parse the given data as an AppleDouble file
  133. * and add all entries found.
  134. * @param data Raw AppleDouble file data
  135. * @param data The raw data for the entry to add (retained)
  136. * @result YES if the provided data was parsed correctly.
  137. */
  138. - (BOOL)addEntriesFromAppleDoubleData:(NSData *)data;
  139. /*!
  140. * @abstract The set of GMAppleDoubleEntry present in this GMAppleDouble.
  141. * @result An array of GMAppleDoubleEntry.
  142. */
  143. - (NSArray *)entries;
  144. /*!
  145. * @abstract Constructs raw data for the AppleDouble file.
  146. * @result The raw data for an AppleDouble file represented by this GMAppleDouble.
  147. */
  148. - (NSData *)data;
  149. @end
  150. #undef GM_EXPORT