Previous 199869 Revisions Next

r17926 Sunday 16th September, 2012 at 12:45:58 UTC by smf
(MESS) builds after normalization (nw)
[src/mess/tools/imgtool/modules]mac.c

trunk/src/mess/tools/imgtool/modules/mac.c
r17925r17926
803803   mac_str31 filename;            /* file name (undefined for extent & catalog files) */
804804};
805805
806struct mac_l2_imgref;
807
806808/*
807809    MFS/HFS open file ref
808810*/
809struct u
811struct mac_fileref
810812{
811   mac_l2_imgref *l2_img;         /* image pointer */
813   struct mac_l2_imgref *l2_img;   /* image pointer */
812814
813815   UINT32 fileID;               /* file ID (a.k.a. CNID in HFS/HFS+) */
814816
r17925r17926
827829      mfs_fileref mfs;
828830      hfs_fileref hfs;
829831   };
830} mac_fileref;
832};
831833
832834/*
833835    open BT ref
834836*/
835837struct mac_BTref
836838{
837   mac_fileref fileref;   /* open B-tree file ref */
839   struct mac_fileref fileref;   /* open B-tree file ref */
838840
839841   UINT16 nodeSize;      /* size of a node, in bytes */
840842   UINT32 rootNode;      /* node number of root node */
r17925r17926
901903/*
902904    MFS Master Directory Block
903905*/
904struct mfs_mdb_
906struct mfs_mdb
905907{
906908   UINT8    sigWord[2];   /* volume signature - always $D2D7 */
907909   UINT32BE crDate;      /* date and time of volume creation */
r17925r17926
941943/*
942944    HFS Master Directory Block
943945*/
944struct v1
946struct hfs_mdb
945947{
946948/* First fields are similar to MFS, though several fields have a different meaning */
947949   UINT8    sigWord[2];   /* volume signature - always $D2D7 */
r17925r17926
993995   hfs_extent_3 xtExtRec;   /* extent record for extents overflow file */
994996   UINT32BE ctFlSize;      /* size (in bytes) of catalog file */
995997   hfs_extent_3 ctExtRec;   /* extent record for catalog file */
996} hfs_mdb_t;
998};
997999
9981000/* to save a little stack space, we use the same buffer for MDB and next blocks */
9991001union img_open_buf
10001002{
1001   mfs_mdb_t mfs_mdb;
1002   hfs_mdb_t hfs_mdb;
1003   struct mfs_mdb mfs_mdb;
1004   struct hfs_mdb hfs_mdb;
10031005   UINT8 raw[512];
10041006};
10051007
r17925r17926
10521054};
10531055
10541056#ifdef UNUSED_FUNCTION
1055static void hfs_image_close(mac_l2_imgref *l2_img);
1057static void hfs_image_close(struct mac_l2_imgref *l2_img);
10561058#endif
1057static imgtoolerr_t mfs_file_get_nth_block_address(mac_fileref *fileref, UINT32 block_num, UINT32 *block_address);
1058static imgtoolerr_t hfs_file_get_nth_block_address(mac_fileref *fileref, UINT32 block_num, UINT32 *block_address);
1059static imgtoolerr_t mfs_lookup_path(mac_l2_imgref *l2_img, const char *fpath, mac_str255 filename, mac_dirent *cat_info, int create_it);
1060static imgtoolerr_t hfs_lookup_path(mac_l2_imgref *l2_img, const char *fpath, UINT32 *parID, mac_str255 filename, mac_dirent *cat_info);
1061static imgtoolerr_t mfs_file_open(mac_l2_imgref *l2_img, const mac_str255 filename, mac_forkID fork, mac_fileref *fileref);
1062static imgtoolerr_t hfs_file_open(mac_l2_imgref *l2_img, UINT32 parID, const mac_str255 filename, mac_forkID fork, mac_fileref *fileref);
1063static imgtoolerr_t mfs_file_setABeof(mac_fileref *fileref, UINT32 newABeof);
1064static imgtoolerr_t mfs_dir_update(mac_fileref *fileref);
1059static imgtoolerr_t mfs_file_get_nth_block_address(struct mac_fileref *fileref, UINT32 block_num, UINT32 *block_address);
1060static imgtoolerr_t hfs_file_get_nth_block_address(struct mac_fileref *fileref, UINT32 block_num, UINT32 *block_address);
1061static imgtoolerr_t mfs_lookup_path(struct mac_l2_imgref *l2_img, const char *fpath, mac_str255 filename, mac_dirent *cat_info, int create_it);
1062static imgtoolerr_t hfs_lookup_path(struct mac_l2_imgref *l2_img, const char *fpath, UINT32 *parID, mac_str255 filename, mac_dirent *cat_info);
1063static imgtoolerr_t mfs_file_open(struct mac_l2_imgref *l2_img, const mac_str255 filename, mac_forkID fork, struct mac_fileref *fileref);
1064static imgtoolerr_t hfs_file_open(struct mac_l2_imgref *l2_img, UINT32 parID, const mac_str255 filename, mac_forkID fork, struct mac_fileref *fileref);
1065static imgtoolerr_t mfs_file_setABeof(struct mac_fileref *fileref, UINT32 newABeof);
1066static imgtoolerr_t mfs_dir_update(struct mac_fileref *fileref);
10651067
1066static mac_l2_imgref *get_imgref(imgtool_image *img)
1068static struct mac_l2_imgref *get_imgref(imgtool_image *img)
10671069{
1068   return (mac_l2_imgref *) imgtool_floppy_extrabytes(img);
1070   return (struct mac_l2_imgref *) imgtool_floppy_extrabytes(img);
10691071}
10701072
10711073
r17925r17926
10771079
10781080    l2_img (I/O): level-2 image reference
10791081*/
1080static void mac_image_close(mac_l2_imgref *l2_img)
1082static void mac_image_close(struct mac_l2_imgref *l2_img)
10811083{
10821084   switch (l2_img->format)
10831085   {
r17925r17926
11111113
11121114    Return imgtool error code
11131115*/
1114static imgtoolerr_t mac_lookup_path(mac_l2_imgref *l2_img, const char *fpath, UINT32 *parID, mac_str255 filename, mac_dirent *cat_info, int create_it)
1116static imgtoolerr_t mac_lookup_path(struct mac_l2_imgref *l2_img, const char *fpath, UINT32 *parID, mac_str255 filename, mac_dirent *cat_info, int create_it)
11151117{
11161118   imgtoolerr_t err = IMGTOOLERR_UNEXPECTED;
11171119
r17925r17926
11431145
11441146    Return imgtool error code
11451147*/
1146static imgtoolerr_t mac_file_open(mac_l2_imgref *l2_img, UINT32 parID, const mac_str255 filename, mac_forkID fork, mac_fileref *fileref)
1148static imgtoolerr_t mac_file_open(struct mac_l2_imgref *l2_img, UINT32 parID, const mac_str255 filename, mac_forkID fork, struct mac_fileref *fileref)
11471149{
11481150   switch (l2_img->format)
11491151   {
r17925r17926
11681170
11691171    Return imgtool error code
11701172*/
1171static imgtoolerr_t mac_file_read(mac_fileref *fileref, UINT32 len, void *dest)
1173static imgtoolerr_t mac_file_read(struct mac_fileref *fileref, UINT32 len, void *dest)
11721174{
11731175   UINT32 block = 0;
11741176   floppy_tag_record tag;
r17925r17926
12441246
12451247    Return imgtool error code
12461248*/
1247static imgtoolerr_t mac_file_write(mac_fileref *fileref, UINT32 len, const void *src)
1249static imgtoolerr_t mac_file_write(struct mac_fileref *fileref, UINT32 len, const void *src)
12481250{
12491251   UINT32 block = 0;
12501252   floppy_tag_record tag;
r17925r17926
13491351
13501352    Return imgtool error code
13511353*/
1352static imgtoolerr_t mac_file_tell(mac_fileref *fileref, UINT32 *filePos)
1354static imgtoolerr_t mac_file_tell(struct mac_fileref *fileref, UINT32 *filePos)
13531355{
13541356   *filePos = fileref->crPs;
13551357
r17925r17926
13671369
13681370    Return imgtool error code
13691371*/
1370static imgtoolerr_t mac_file_seek(mac_fileref *fileref, UINT32 filePos)
1372static imgtoolerr_t mac_file_seek(struct mac_fileref *fileref, UINT32 filePos)
13711373{
13721374   if ((fileref->crPs / 512) != (filePos / 512))
13731375      fileref->reload_buf = TRUE;
r17925r17926
13871389
13881390    Return imgtool error code
13891391*/
1390static imgtoolerr_t mac_file_seteof(mac_fileref *fileref, UINT32 newEof)
1392static imgtoolerr_t mac_file_seteof(struct mac_fileref *fileref, UINT32 newEof)
13911393{
13921394   UINT32 newABEof;
13931395   imgtoolerr_t err = IMGTOOLERR_SUCCESS;
r17925r17926
15271529*/
15281530struct mfs_dirref
15291531{
1530   mac_l2_imgref *l2_img;         /* image pointer */
1532   struct mac_l2_imgref *l2_img;   /* image pointer */
15311533   UINT16 index;               /* current file index in the disk directory */
15321534   UINT16 cur_block;            /* current block offset in directory file */
15331535   UINT16 cur_offset;            /* current byte offset in current block of directory file */
r17925r17926
16031605static imgtoolerr_t mfs_image_open(imgtool_image *image, imgtool_stream *stream)
16041606{
16051607   imgtoolerr_t err;
1606   mac_l2_imgref *l2_img;
1608   struct mac_l2_imgref *l2_img;
16071609   img_open_buf buf_local;
16081610   img_open_buf *buf;
16091611
r17925r17926
16921694
16931695    Return imgtool error code
16941696*/
1695static imgtoolerr_t mfs_update_mdb(mac_l2_imgref *l2_img)
1697static imgtoolerr_t mfs_update_mdb(struct mac_l2_imgref *l2_img)
16961698{
16971699   imgtoolerr_t err;
16981700   union
16991701   {
1700      mfs_mdb_t mfs_mdb;
1702      struct mfs_mdb mfs_mdb;
17011703      UINT8 raw[512];
17021704   } buf;
17031705
r17925r17926
17881790
17891791    Return imgtool error code
17901792*/
1791static imgtoolerr_t mfs_dir_open(mac_l2_imgref *l2_img, const char *path, mfs_dirref *dirref)
1793static imgtoolerr_t mfs_dir_open(struct mac_l2_imgref *l2_img, const char *path, mfs_dirref *dirref)
17921794{
17931795   imgtoolerr_t err;
17941796
r17925r17926
18821884
18831885    Return imgtool error code
18841886*/
1885static imgtoolerr_t mfs_dir_insert(mac_l2_imgref *l2_img, mfs_dirref *dirref, const UINT8 *new_fname, mfs_dir_entry **dir_entry)
1887static imgtoolerr_t mfs_dir_insert(struct mac_l2_imgref *l2_img, mfs_dirref *dirref, const UINT8 *new_fname, mfs_dir_entry **dir_entry)
18861888{
18871889   size_t new_dir_entry_len;
18881890   mfs_dir_entry *cur_dir_entry;
r17925r17926
19731975
19741976    Return imgtool error code
19751977*/
1976static imgtoolerr_t mfs_dir_update(mac_fileref *fileref)
1978static imgtoolerr_t mfs_dir_update(struct mac_fileref *fileref)
19771979{
19781980   UINT16 cur_block;
19791981   UINT16 cur_offset;
r17925r17926
19992001            switch (fileref->forkType)
20002002            {
20012003            case data_fork:
2002               set_UINT16BE(&cur_dir_entry->dataStartBlock, fileref->u.mfs.stBlk);
2004               set_UINT16BE(&cur_dir_entry->dataStartBlock, fileref->mfs.stBlk);
20032005               set_UINT32BE(&cur_dir_entry->dataLogicalSize, fileref->eof);
20042006               set_UINT32BE(&cur_dir_entry->dataPhysicalSize, fileref->pLen);
20052007               break;
20062008
20072009            case rsrc_fork:
2008               set_UINT16BE(&cur_dir_entry->rsrcStartBlock, fileref->u.mfs.stBlk);
2010               set_UINT16BE(&cur_dir_entry->rsrcStartBlock, fileref->mfs.stBlk);
20092011               set_UINT32BE(&cur_dir_entry->rsrcLogicalSize, fileref->eof);
20102012               set_UINT32BE(&cur_dir_entry->rsrcPhysicalSize, fileref->pLen);
20112013               break;
r17925r17926
20922094
20932095    Return imgtool error code
20942096*/
2095static imgtoolerr_t mfs_lookup_path(mac_l2_imgref *l2_img, const char *fpath, mac_str255 filename, mac_dirent *cat_info, int create_it)
2097static imgtoolerr_t mfs_lookup_path(struct mac_l2_imgref *l2_img, const char *fpath, mac_str255 filename, mac_dirent *cat_info, int create_it)
20962098{
20972099   mfs_dirref dirref;
20982100   mfs_dir_entry *dir_entry;
r17925r17926
21612163
21622164    Return imgtool error code
21632165*/
2164static imgtoolerr_t mfs_file_open_internal(mac_l2_imgref *l2_img, const mfs_dir_entry *dir_entry, mac_forkID fork, mac_fileref *fileref)
2166static imgtoolerr_t mfs_file_open_internal(struct mac_l2_imgref *l2_img, const mfs_dir_entry *dir_entry, mac_forkID fork, struct mac_fileref *fileref)
21652167{
21662168   assert(l2_img->format == L2I_MFS);
21672169
r17925r17926
21732175   switch (fork)
21742176   {
21752177   case data_fork:
2176      fileref->u.mfs.stBlk = get_UINT16BE(dir_entry->dataStartBlock);
2178      fileref->mfs.stBlk = get_UINT16BE(dir_entry->dataStartBlock);
21772179      fileref->eof = get_UINT32BE(dir_entry->dataLogicalSize);
21782180      fileref->pLen = get_UINT32BE(dir_entry->dataPhysicalSize);
21792181      break;
21802182
21812183   case rsrc_fork:
2182      fileref->u.mfs.stBlk = get_UINT16BE(dir_entry->rsrcStartBlock);
2184      fileref->mfs.stBlk = get_UINT16BE(dir_entry->rsrcStartBlock);
21832185      fileref->eof = get_UINT32BE(dir_entry->rsrcLogicalSize);
21842186      fileref->pLen = get_UINT32BE(dir_entry->rsrcPhysicalSize);
21852187      break;
r17925r17926
22052207
22062208    Return imgtool error code
22072209*/
2208static imgtoolerr_t mfs_file_open(mac_l2_imgref *l2_img, const mac_str255 filename, mac_forkID fork, mac_fileref *fileref)
2210static imgtoolerr_t mfs_file_open(struct mac_l2_imgref *l2_img, const mac_str255 filename, mac_forkID fork, struct mac_fileref *fileref)
22092211{
22102212   mfs_dirref dirref;
22112213   mfs_dir_entry *dir_entry;
r17925r17926
22332235
22342236    Returns the 12-bit value read in array.
22352237*/
2236static UINT16 mfs_get_ABlink(mac_l2_imgref *l2_img, UINT16 AB_address)
2238static UINT16 mfs_get_ABlink(struct mac_l2_imgref *l2_img, UINT16 AB_address)
22372239{
22382240   UINT16 reply;
22392241   int base;
r17925r17926
22592261    AB_address (I): index in the array, which is an AB address
22602262    data (I): 12-bit value to write in array
22612263*/
2262static void mfs_set_ABlink(mac_l2_imgref *l2_img, UINT16 AB_address, UINT16 data)
2264static void mfs_set_ABlink(struct mac_l2_imgref *l2_img, UINT16 AB_address, UINT16 data)
22632265{
22642266   int base;
22652267
r17925r17926
22972299
22982300    Return imgtool error code
22992301*/
2300static imgtoolerr_t mfs_file_get_nth_block_address(mac_fileref *fileref, UINT32 block_num, UINT32 *block_address)
2302static imgtoolerr_t mfs_file_get_nth_block_address(struct mac_fileref *fileref, UINT32 block_num, UINT32 *block_address)
23012303{
23022304   UINT32 AB_num;
23032305   UINT32 i;
r17925r17926
23072309
23082310   AB_num = block_num / fileref->l2_img->blocksperAB;
23092311
2310   AB_address = fileref->u.mfs.stBlk;
2312   AB_address = fileref->mfs.stBlk;
23112313   if ((AB_address == 0) || (AB_address >= fileref->l2_img->numABs+2))
23122314      /* 0 -> ??? */
23132315      return IMGTOOLERR_CORRUPTIMAGE;
r17925r17926
23412343
23422344    fileref (I/O): open mac file reference
23432345    lastAB (I): AB address on disk of last file AB (only if
2344        fileref->u.mfs.stBlk != 1)
2346        fileref->mfs.stBlk != 1)
23452347    allocABs (I): number of ABs to allocate in addition to the current file
23462348        allocation
23472349    fblock (I): first file block to allocate (used for tag data)
23482350
23492351    Return imgtool error code
23502352*/
2351static imgtoolerr_t mfs_file_allocABs(mac_fileref *fileref, UINT16 lastAB, UINT32 allocABs, UINT32 fblock)
2353static imgtoolerr_t mfs_file_allocABs(struct mac_fileref *fileref, UINT16 lastAB, UINT32 allocABs, UINT32 fblock)
23522354{
23532355   int numABs = fileref->l2_img->numABs;
23542356   int free_ABs;
r17925r17926
23992401   if (free_ABs < allocABs)
24002402      return IMGTOOLERR_NOSPACE;
24012403
2402   if (fileref->u.mfs.stBlk != 1)
2404   if (fileref->mfs.stBlk != 1)
24032405   {   /* try to extend last file extent */
24042406      /* append free ABs after last AB */
24052407      for (i=lastAB+1; (mfs_get_ABlink(fileref->l2_img, i) == 0) && (allocABs > 0) && (i < numABs); i++)
r17925r17926
24992501         extentABlen = allocABs;
25002502         for (i=0; i<allocABs; i++)
25012503         {
2502            if (fileref->u.mfs.stBlk != 1)
2504            if (fileref->mfs.stBlk != 1)
25032505               mfs_set_ABlink(fileref->l2_img, lastAB, firstBestExtentBaseAB+i+2);
25042506            else
2505               fileref->u.mfs.stBlk = firstBestExtentBaseAB+i+2;
2507               fileref->mfs.stBlk = firstBestExtentBaseAB+i+2;
25062508            lastAB = firstBestExtentBaseAB+i;
25072509            free_ABs--;
25082510            /* set tag to allocated */
r17925r17926
25372539      {   /* jeez, we need to fragment it.  We use the largest smaller block to limit fragmentation. */
25382540         for (i=0; i<secondBestExtentABlen; i++)
25392541         {
2540            if (fileref->u.mfs.stBlk != 1)
2542            if (fileref->mfs.stBlk != 1)
25412543               mfs_set_ABlink(fileref->l2_img, lastAB, secondBestExtentBaseAB+i+2);
25422544            else
2543               fileref->u.mfs.stBlk = secondBestExtentBaseAB+i+2;
2545               fileref->mfs.stBlk = secondBestExtentBaseAB+i+2;
25442546            lastAB = secondBestExtentBaseAB+i;
25452547            free_ABs--;
25462548            /* set tag to allocated */
r17925r17926
25882590
25892591    Return imgtool error code
25902592*/
2591static imgtoolerr_t mfs_file_setABeof(mac_fileref *fileref, UINT32 newABeof)
2593static imgtoolerr_t mfs_file_setABeof(struct mac_fileref *fileref, UINT32 newABeof)
25922594{
25932595   UINT16 AB_address = 0;
25942596   UINT16 AB_link;
r17925r17926
26012603   assert(fileref->l2_img->format == L2I_MFS);
26022604
26032605   /* run through link chain until we reach the old or the new EOF */
2604   AB_link = fileref->u.mfs.stBlk;
2606   AB_link = fileref->mfs.stBlk;
26052607   if ((AB_link == 0) || (AB_link >= fileref->l2_img->numABs+2))
26062608      /* 0 -> ??? */
26072609      return IMGTOOLERR_CORRUPTIMAGE;
r17925r17926
26402642   {   /* new EOF is shorter than old one */
26412643      /* mark new eof */
26422644      if (i==0)
2643         fileref->u.mfs.stBlk = 1;
2645         fileref->mfs.stBlk = 1;
26442646      else
26452647      {
26462648         mfs_set_ABlink(fileref->l2_img, AB_address, 1);
r17925r17926
29072909
29082910struct hfs_cat_enumerator
29092911{
2910   mac_l2_imgref *l2_img;
2912   struct mac_l2_imgref *l2_img;
29112913   BT_leaf_rec_enumerator BT_enumerator;
29122914   UINT32 parID;
29132915};
r17925r17926
29232925
29242926    Return imgtool error code
29252927*/
2926static imgtoolerr_t hfs_open_extents_file(mac_l2_imgref *l2_img, const hfs_mdb_t *mdb, mac_fileref *fileref)
2928static imgtoolerr_t hfs_open_extents_file(struct mac_l2_imgref *l2_img, const struct hfs_mdb *mdb, struct mac_fileref *fileref)
29272929{
29282930   assert(l2_img->format == L2I_HFS);
29292931
r17925r17926
29332935   fileref->forkType = (mac_forkID)0x00;
29342936
29352937   fileref->eof = fileref->pLen = get_UINT32BE(mdb->xtFlSize);
2936   memcpy(fileref->u.hfs.extents, mdb->xtExtRec, sizeof(hfs_extent_3));
2938   memcpy(fileref->hfs.extents, mdb->xtExtRec, sizeof(hfs_extent_3));
29372939
29382940   fileref->crPs = 0;
29392941
r17925r17926
29532955
29542956    Return imgtool error code
29552957*/
2956static imgtoolerr_t hfs_open_cat_file(mac_l2_imgref *l2_img, const hfs_mdb_t *mdb, mac_fileref *fileref)
2958static imgtoolerr_t hfs_open_cat_file(struct mac_l2_imgref *l2_img, const struct hfs_mdb *mdb, struct mac_fileref *fileref)
29572959{
29582960   assert(l2_img->format == L2I_HFS);
29592961
r17925r17926
29632965   fileref->forkType = (mac_forkID)0x00;
29642966
29652967   fileref->eof = fileref->pLen = get_UINT32BE(mdb->ctFlSize);
2966   memcpy(fileref->u.hfs.extents, mdb->ctExtRec, sizeof(hfs_extent_3));
2968   memcpy(fileref->hfs.extents, mdb->ctExtRec, sizeof(hfs_extent_3));
29672969
29682970   fileref->crPs = 0;
29692971
r17925r17926
30303032static imgtoolerr_t hfs_image_open(imgtool_image *image, imgtool_stream *stream)
30313033{
30323034   imgtoolerr_t err;
3033   mac_l2_imgref *l2_img;
3035   struct mac_l2_imgref *l2_img;
30343036   img_open_buf buf_local;
30353037   img_open_buf *buf;
30363038
r17925r17926
31353137
31363138    l2_img (I/O): level-2 image reference
31373139*/
3138static void hfs_image_close(mac_l2_imgref *l2_img)
3140static void hfs_image_close(struct mac_l2_imgref *l2_img)
31393141{
31403142   assert(l2_img->format == L2I_HFS);
31413143
r17925r17926
31593161
31603162    Return imgtool error code
31613163*/
3162static imgtoolerr_t hfs_get_cat_record_data(mac_l2_imgref *l2_img, void *rec_raw, int rec_len, hfs_catKey **rec_key, hfs_catData **rec_data)
3164static imgtoolerr_t hfs_get_cat_record_data(struct mac_l2_imgref *l2_img, void *rec_raw, int rec_len, hfs_catKey **rec_key, hfs_catData **rec_data)
31633165{
31643166   hfs_catKey *lrec_key;
31653167   void *rec_data_raw;
r17925r17926
32293231
32303232    Return imgtool error code
32313233*/
3232static imgtoolerr_t hfs_cat_open(mac_l2_imgref *l2_img, const char *path, hfs_cat_enumerator *enumerator)
3234static imgtoolerr_t hfs_cat_open(struct mac_l2_imgref *l2_img, const char *path, hfs_cat_enumerator *enumerator)
32333235{
32343236   imgtoolerr_t err;
32353237   UINT32 parID;
r17925r17926
33023304
33033305    Return imgtool error code
33043306*/
3305static imgtoolerr_t hfs_cat_search(mac_l2_imgref *l2_img, UINT32 parID, const mac_str31 cName, hfs_catKey **rec_key, hfs_catData **rec_data)
3307static imgtoolerr_t hfs_cat_search(struct mac_l2_imgref *l2_img, UINT32 parID, const mac_str31 cName, hfs_catKey **rec_key, hfs_catData **rec_data)
33063308{
33073309   hfs_catKey search_key;
33083310   void *rec;
r17925r17926
33503352
33513353    Return imgtool error code
33523354*/
3353static imgtoolerr_t hfs_lookup_path(mac_l2_imgref *l2_img, const char *fpath, UINT32 *parID, mac_str255 filename, mac_dirent *cat_info)
3355static imgtoolerr_t hfs_lookup_path(struct mac_l2_imgref *l2_img, const char *fpath, UINT32 *parID, mac_str255 filename, mac_dirent *cat_info)
33543356{
33553357   const char *element_start;
33563358   int element_len;
r17925r17926
34343436
34353437    Return imgtool error code
34363438*/
3437static imgtoolerr_t hfs_file_open_internal(mac_l2_imgref *l2_img, const hfs_catFileData *file_rec, mac_forkID fork, mac_fileref *fileref)
3439static imgtoolerr_t hfs_file_open_internal(struct mac_l2_imgref *l2_img, const hfs_catFileData *file_rec, mac_forkID fork, struct mac_fileref *fileref)
34383440{
34393441   assert(l2_img->format == L2I_HFS);
34403442
r17925r17926
34483450   case data_fork:
34493451      fileref->eof = get_UINT32BE(file_rec->dataLogicalSize);
34503452      fileref->pLen = get_UINT32BE(file_rec->dataPhysicalSize);
3451      memcpy(fileref->u.hfs.extents, file_rec->dataExtents, sizeof(hfs_extent_3));
3453      memcpy(fileref->hfs.extents, file_rec->dataExtents, sizeof(hfs_extent_3));
34523454      break;
34533455
34543456   case rsrc_fork:
34553457      fileref->eof = get_UINT32BE(file_rec->rsrcLogicalSize);
34563458      fileref->pLen = get_UINT32BE(file_rec->rsrcPhysicalSize);
3457      memcpy(fileref->u.hfs.extents, file_rec->rsrcExtents, sizeof(hfs_extent_3));
3459      memcpy(fileref->hfs.extents, file_rec->rsrcExtents, sizeof(hfs_extent_3));
34583460      break;
34593461   }
34603462
r17925r17926
34793481
34803482    Return imgtool error code
34813483*/
3482static imgtoolerr_t hfs_file_open(mac_l2_imgref *l2_img, UINT32 parID, const mac_str255 filename, mac_forkID fork, mac_fileref *fileref)
3484static imgtoolerr_t hfs_file_open(struct mac_l2_imgref *l2_img, UINT32 parID, const mac_str255 filename, mac_forkID fork, struct mac_fileref *fileref)
34833485{
34843486   hfs_catKey *catrec_key;
34853487   hfs_catData *catrec_data;
r17925r17926
34973499   if (dataRecType != hcrt_File)
34983500      return IMGTOOLERR_BADFILENAME;
34993501
3500   fileref->u.hfs.parID = get_UINT32BE(catrec_key->parID);
3501   mac_strcpy(fileref->u.hfs.filename, catrec_key->cName);
3502   fileref->hfs.parID = get_UINT32BE(catrec_key->parID);
3503   mac_strcpy(fileref->hfs.filename, catrec_key->cName);
35023504
35033505   /* open it */
35043506   return hfs_file_open_internal(l2_img, &catrec_data->file, fork, fileref);
r17925r17926
35163518
35173519    Return imgtool error code
35183520*/
3519static imgtoolerr_t hfs_file_get_nth_block_address(mac_fileref *fileref, UINT32 block_num, UINT32 *block_address)
3521static imgtoolerr_t hfs_file_get_nth_block_address(struct mac_fileref *fileref, UINT32 block_num, UINT32 *block_address)
35203522{
35213523   UINT32 AB_num;
35223524   UINT32 cur_AB;
r17925r17926
35333535
35343536   AB_num = block_num / fileref->l2_img->blocksperAB;
35353537   cur_AB = 0;
3536   cur_extents = fileref->u.hfs.extents;
3538   cur_extents = fileref->hfs.extents;
35373539
35383540   /* first look in catalog tree extents */
35393541   for (i=0; i<3; i++)
r17925r17926
39943996      case L2I_HFS:
39953997         maxExtentAB = 0;
39963998         for (j=0; j<3; j++)
3997            maxExtentAB += get_UINT16BE(BTref->fileref.u.hfs.extents[j].numABlks);
3999            maxExtentAB += get_UINT16BE(BTref->fileref.hfs.extents[j].numABlks);
39984000         maxExtentNode = (UINT64)maxExtentAB * 512 * BTref->fileref.l2_img->blocksperAB
39994001                              / BTref->nodeSize;
40004002         extentEOL = FALSE;
r17925r17926
52105212
52115213    Return imgtool error code
52125214*/
5213static imgtoolerr_t get_comment(mac_l2_imgref *l2_img, UINT16 id, mac_str255 comment)
5215static imgtoolerr_t get_comment(struct mac_l2_imgref *l2_img, UINT16 id, mac_str255 comment)
52145216{
52155217   static const UINT8 desktop_fname[] = {'\7','D','e','s','k','t','o','p'};
52165218   #define restype_FCMT (('F' << 24) | ('C' << 16) | ('M' << 8) | 'T')
r17925r17926
52795281*/
52805282static void mac_image_exit(imgtool_image *img)
52815283{
5282   mac_l2_imgref *image = get_imgref(img);
5284   struct mac_l2_imgref *image = get_imgref(img);
52835285
52845286   mac_image_close(image);
52855287}
r17925r17926
52925294*/
52935295static void mac_image_info(imgtool_image *img, char *string, size_t len)
52945296{
5295   mac_l2_imgref *image = get_imgref(img);
5297   struct mac_l2_imgref *image = get_imgref(img);
52965298
52975299   switch (image->format)
52985300   {
r17925r17926
53125314struct mac_iterator
53135315{
53145316   mac_format format;
5315   mac_l2_imgref *l2_img;
5317   struct mac_l2_imgref *l2_img;
53165318   union
53175319   {
53185320      struct
r17925r17926
53315333*/
53325334static imgtoolerr_t mac_image_beginenum(imgtool_directory *enumeration, const char *path)
53335335{
5334   mac_l2_imgref *image = get_imgref(imgtool_directory_image(enumeration));
5336   struct mac_l2_imgref *image = get_imgref(imgtool_directory_image(enumeration));
53355337   mac_iterator *iter = (mac_iterator *) imgtool_directory_extrabytes(enumeration);
53365338   imgtoolerr_t err = IMGTOOLERR_UNEXPECTED;
53375339
r17925r17926
55725574}
55735575
55745576#ifdef UNUSED_FUNCTION
5575static imgtoolerr_t mac_get_comment(mac_l2_imgref *image, mac_str255 filename, const mac_dirent *cat_info, mac_str255 comment)
5577static imgtoolerr_t mac_get_comment(struct mac_l2_imgref *image, mac_str255 filename, const mac_dirent *cat_info, mac_str255 comment)
55765578{
55775579   imgtoolerr_t err = IMGTOOLERR_SUCCESS;
55785580   UINT16 commentID;
r17925r17926
56075609{
56085610   imgtoolerr_t err;
56095611   imgtool_image *img = imgtool_partition_image(partition);
5610   mac_l2_imgref *image = get_imgref(img);
5612   struct mac_l2_imgref *image = get_imgref(img);
56115613   UINT32 parID;
56125614   mac_str255 filename;
56135615   mac_dirent cat_info;
r17925r17926
56575659static imgtoolerr_t mac_image_writefile(imgtool_partition *partition, const char *fpath, const char *fork, imgtool_stream *sourcef, option_resolution *writeoptions)
56585660{
56595661   imgtool_image *img = imgtool_partition_image(partition);
5660   mac_l2_imgref *image = get_imgref(img);
5662   struct mac_l2_imgref *image = get_imgref(img);
56615663   UINT32 parID;
56625664   mac_str255 filename;
56635665   mac_dirent cat_info;
r17925r17926
57395741   mac_dirent cat_info;
57405742   int fork_num = 0;
57415743   imgtool_image *img = imgtool_partition_image(partition);
5742   mac_l2_imgref *image = get_imgref(img);
5744   struct mac_l2_imgref *image = get_imgref(img);
57435745
57445746   /* resolve path and fetch file info from directory/catalog */
57455747   err = mac_lookup_path(image, path, &parID, filename, &cat_info, FALSE);
r17925r17926
57765778   UINT32 parID;
57775779   mac_str255 filename;
57785780   mac_dirent cat_info;
5779   mac_l2_imgref *image = get_imgref(img);
5781   struct mac_l2_imgref *image = get_imgref(img);
57805782   int i;
57815783
57825784   /* resolve path and fetch file info from directory/catalog */
r17925r17926
58445846   mac_str255 filename;
58455847   mac_dirent cat_info;
58465848   imgtool_image *img = imgtool_partition_image(partition);
5847   mac_l2_imgref *image = get_imgref(img);
5849   struct mac_l2_imgref *image = get_imgref(img);
58485850   int i;
58495851
58505852   /* resolve path and fetch file info from directory/catalog */
r17925r17926
63176319   mac_str255 filename;
63186320   mac_dirent cat_info;
63196321   imgtool_image *img = imgtool_partition_image(partition);
6320   mac_l2_imgref *image = get_imgref(img);
6322   struct mac_l2_imgref *image = get_imgref(img);
63216323   mac_filecategory_t file_category = MAC_FILECATEGORY_DATA;
63226324
63236325   if (path)

Previous 199869 Revisions Next


© 1997-2024 The MAME Team