syncfiles/tech/resource-forks.html

2 lines
14 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html> <html lang="en-US"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=Edge"> <title>Resource Forks - SyncFiles Documentation</title> <link rel="shortcut icon" href="/syncfiles/favicon.ico" type="image/x-icon"> <link rel="stylesheet" href="/syncfiles/assets/css/just-the-docs-default.css"> <script type="text/javascript" src="/syncfiles/assets/js/vendor/lunr.min.js"></script> <script type="text/javascript" src="/syncfiles/assets/js/just-the-docs.js"></script> <meta name="viewport" content="width=device-width, initial-scale=1"> <!-- Begin Jekyll SEO tag v2.8.0 --> <title>Resource Forks | SyncFiles Documentation</title> <meta name="generator" content="Jekyll v4.2.2" /> <meta property="og:title" content="Resource Forks" /> <meta property="og:locale" content="en_US" /> <meta name="description" content="Write an awesome description for your new site here. You can edit this line in _config.yml. It will appear in your document head meta (for Google search results) and in your feed.xml site description." /> <meta property="og:description" content="Write an awesome description for your new site here. You can edit this line in _config.yml. It will appear in your document head meta (for Google search results) and in your feed.xml site description." /> <link rel="canonical" href="https://depp.github.io/syncfiles/tech/resource-forks" /> <meta property="og:url" content="https://depp.github.io/syncfiles/tech/resource-forks" /> <meta property="og:site_name" content="SyncFiles Documentation" /> <meta property="og:type" content="website" /> <meta name="twitter:card" content="summary" /> <meta property="twitter:title" content="Resource Forks" /> <script type="application/ld+json"> {"@context":"https://schema.org","@type":"WebPage","description":"Write an awesome description for your new site here. You can edit this line in _config.yml. It will appear in your document head meta (for Google search results) and in your feed.xml site description.","headline":"Resource Forks","url":"https://depp.github.io/syncfiles/tech/resource-forks"}</script> <!-- End Jekyll SEO tag --> </head> <body> <svg xmlns="http://www.w3.org/2000/svg" style="display: none;"> <symbol id="svg-link" viewBox="0 0 24 24"> <title>Link</title> <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-link"> <path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path> </svg> </symbol> <symbol id="svg-search" viewBox="0 0 24 24"> <title>Search</title> <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-search"> <circle cx="11" cy="11" r="8"></circle><line x1="21" y1="21" x2="16.65" y2="16.65"></line> </svg> </symbol> <symbol id="svg-menu" viewBox="0 0 24 24"> <title>Menu</title> <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-menu"> <line x1="3" y1="12" x2="21" y2="12"></line><line x1="3" y1="6" x2="21" y2="6"></line><line x1="3" y1="18" x2="21" y2="18"></line> </svg> </symbol> <symbol id="svg-arrow-right" viewBox="0 0 24 24"> <title>Expand</title> <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-chevron-right"> <polyline points="9 18 15 12 9 6"></polyline> </svg> </symbol> <symbol id="svg-doc" viewBox="0 0 24 24"> <title>Document</title> <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-file"> <path d="M13 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V9z"></path><polyline points="13 2 13 9 20 9"></polyline> </svg> </symbol> </svg> <div class="side-bar"> <div class="site-header"> <a href="https://depp.github.io/syncfiles/" class="site-title lh-tight"> SyncFiles Documentation </a> <a href="#" id="menu-button" class="site-button"> <svg viewBox="0 0 24 24" class="icon"><use xlink:href="#svg-menu"></use></svg> </a> </div> <nav role="navigation" aria-label="Main" id="site-nav" class="site-nav"> <ul class="nav-list"><li class="nav-list-item active"><a href="#" class="nav-list-expander"><svg viewBox="0 0 24 24"><use xlink:href="#svg-arrow-right"></use></svg></a><a href="https://depp.github.io/syncfiles/tech/" class="nav-list-link">Technical Guide</a><ul class="nav-list "><li class="nav-list-item "><a href="https://depp.github.io/syncfiles/tech/archive-formats" class="nav-list-link">Archive Formats</a></li><li class="nav-list-item active"><a href="https://depp.github.io/syncfiles/tech/resource-forks" class="nav-list-link active">Resource Forks</a></li><li class="nav-list-item "><a href="https://depp.github.io/syncfiles/tech/finder-info" class="nav-list-link">Finder Info</a></li><li class="nav-list-item "><a href="https://depp.github.io/syncfiles/tech/apis" class="nav-list-link">File APIs</a></li><li class="nav-list-item "><a href="https://depp.github.io/syncfiles/tech/filesystems" class="nav-list-link">Filesystems</a></li><li class="nav-list-item "><a href="https://depp.github.io/syncfiles/tech/safe-saving" class="nav-list-link">Safe Saving</a></li></ul></li><li class="nav-list-item"><a href="#" class="nav-list-expander"><svg viewBox="0 0 24 24"><use xlink:href="#svg-arrow-right"></use></svg></a><a href="https://depp.github.io/syncfiles/" class="nav-list-link">Home</a><ul class="nav-list "></ul></li></ul> </nav> <footer class="site-footer"> This site uses <a href="https://github.com/pmarsceill/just-the-docs">Just the Docs</a>, a documentation theme for Jekyll. </footer> </div> <div class="main" id="top"> <div id="main-header" class="main-header"> <div class="search"> <div class="search-input-wrap"> <input type="text" id="search-input" class="search-input" tabindex="0" placeholder="Search SyncFiles Documentation" aria-label="Search SyncFiles Documentation" autocomplete="off"> <label for="search-input" class="search-label"><svg viewBox="0 0 24 24" class="search-icon"><use xlink:href="#svg-search"></use></svg></label> </div> <div id="search-results" class="search-results"></div> </div> </div> <div id="main-content-wrap" class="main-content-wrap"> <nav aria-label="Breadcrumb" class="breadcrumb-nav"> <ol class="breadcrumb-nav-list"> <li class="breadcrumb-nav-list-item"><a href="https://depp.github.io/syncfiles/tech/">Technical Guide</a></li> <li class="breadcrumb-nav-list-item"><span>Resource Forks</span></li> </ol> </nav> <div id="main-content" class="main-content" role="main"> <h1 id="resource-forks"> <a href="#resource-forks" class="anchor-heading" aria-labelledby="resource-forks"><svg viewBox="0 0 16 16" aria-hidden="true"><use xlink:href="#svg-link"></use></svg></a> Resource Forks </h1> <p>Mac OS traditionally provided two <em>forks</em> for a file: the data fork and the resource fork. A fork is a data stream within a file which can be independently manipulated. You can open one fork and write data to it, change the length of data, or delete the fork entirely without affecting the files other fork. Think of the forks as two separate files, bundled up as one file.</p> <p>When you copy a file from a non-Mac OS system to a Mac, what you get is a file that only contains a data fork. The resource fork is used to store Mac-specific data. Its almost always organized into chunks called <em>resources</em>, which are discrete pieces of data surch as icons, images, sounds, strings, or 68K code segments. Each resource is identified by a four-character type code and 16-bit ID number.</p> <p>The resource fork format has a maximum size of about 16 MiB because it encodes file offsets using 24 bits.</p> <h2 id="historical-use"> <a href="#historical-use" class="anchor-heading" aria-labelledby="historical-use"><svg viewBox="0 0 16 16" aria-hidden="true"><use xlink:href="#svg-link"></use></svg></a> Historical Use </h2> <p>Prior to Mac OS X, programs on the Mac make heavy use of the resource fork. For example, an applications resource fork contains 68K code, icons, dialog box layouts, version information, text data, and sometimes various custom data types. PowerPC code is stored in the data fork, although various resources are still necessary for PowerPC applications to run correctly.</p> <p>Applications also use resource forks in other files to store data. Some text editors use the resource fork of a text file to remember the state of the text editor when editing that file. Games often use files with resource forks to store images, sound effects, or level data.</p> <p>Starting with Mac OS X, data that was previously stored as resources in the resource fork are stored as a separate file instead. For example, application and file icons prior to Mac OS X are stored in the resource fork, but in Mac OS X, each icon is stored as a separate file. It is unusual to find a Mac OS X program that uses the resource fork at all.</p> <h2 id="are-resource-forks-really-structured"> <a href="#are-resource-forks-really-structured" class="anchor-heading" aria-labelledby="are-resource-forks-really-structured"><svg viewBox="0 0 16 16" aria-hidden="true"><use xlink:href="#svg-link"></use></svg></a> Are Resource Forks Really Structured? </h2> <p>Note the key words above: a resource fork is <strong>almost always</strong> organized into chunks called resources.</p> <p>A files resource fork is really just an alternate stream of data, like the data fork. You can put whatever data you like in the resource fork. In practice, the resource fork almost always uses a specific format.</p> <p>Note that this goes both ways. Just like you can store arbitrary data in the resource fork, you can also use the data fork to store resources. Using the data fork to store resources has disadvantages, because you cant edit those resources with ResEdit or use the Macintosh resource manager API to read those resources, so it is rarely done.</p> <p>Some applications store application preferences or other data in the resource fork of a file, and because resource forks can get corrupted, you occasionally see a backup copy of the resource fork stored in the data fork of the same file. This is not common, however.</p> <h2 id="preserving-resource-forks"> <a href="#preserving-resource-forks" class="anchor-heading" aria-labelledby="preserving-resource-forks"><svg viewBox="0 0 16 16" aria-hidden="true"><use xlink:href="#svg-link"></use></svg></a> Preserving Resource Forks </h2> <p>Resource forks do not always need to be preserved when synchronizing files between systems. It depends on the file and what is being stored in the resource fork. For example, when you save a text file in BBEdit or MPW, the editor state is recorded as a resource in the text file. Deleting this resource fork doesnt affect your ability to use the file. On the other hand, if you delete the resource fork of an application, it wont work at all.</p> <h2 id="examining-the-resource-fork"> <a href="#examining-the-resource-fork" class="anchor-heading" aria-labelledby="examining-the-resource-fork"><svg viewBox="0 0 16 16" aria-hidden="true"><use xlink:href="#svg-link"></use></svg></a> Examining the Resource Fork </h2> <p>You can use <em>ResEdit</em> or <em>Resorcerer</em> to view and edit the resources in a resource fork, or the MPW tools <em>Rez</em> and <em>DeRez</em>.</p> <p>ResEdit is the most common tool to use, because its free (unlike Resorcerer, which costs $256) and has a nice user interface (unlike Rez and DeRez, which convert resource files to and from text files). ResEdit is available from Apple and the latest version is 2.1.3. Heres what the resource fork of the MacBinary application looks like in ResEdit:</p> <p><img src="rsrc-macbinary.png" alt="Screenshot of ResEdit, depicting MacBinary II" /></p> <p>When you open a file in ResEdit, ResEdit shows you an overview of the different types of resources in the file. MacBinary contains 18 different types of resources. When you open one of the types, ResEdit shows you a list of resources for that type. For example, we can look at the <code class="language-plaintext highlighter-rouge">CODE</code> resources in MacBinary, which contain segments of executable 68K code which can be independently loaded. Each individual resource has an ID, which is a signed 16-bit number, and optionally has a name.</p> <p><img src="rsrc-code.png" alt="Screenshot of ResEdit, depicting a list of CODE resources" /></p> <p>ResEdit provides simple editors for certain types of resources, like icons. This makes it easy to create your own custom icons for Macintosh applications. You didnt have to be a programmer to take advantage of this—if you wanted to create your own custom folder icons for certain folders, you could do that too. You could find custom icon collections online or on CDs bundled with magazines.</p> <p>Application and folder icons are made from several types of icons with the same ID number, creating an icon family. An icon family allows you to create custom icons for different sizes and color depths.</p> <p><img src="rsrc-icon.png" alt="Screenshot of ResEdit, depicting the MacBinary application icon being edited" /></p> <p>Another common type of resource is string resources. Applications sometimes store strings used by the application in these resources. This might be done to reduce the memory footprint of the application, or it might be done to make it easier to translate an application into another language.</p> <p>Its not necessary to use string resources at all, and MacBinary doesnt contain any string resources. There are string resources in <em>SimpleText</em>, however, containing help messages, error messages, and various other strings.</p> <p><img src="rsrc-strings.png" alt="Screenshot of ResEdit, depicting a string resource in SimpleText" /></p> </div> </div> <div class="search-overlay"></div> </div> </body> </html>