ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/BeOS/extfs_beos.cpp
(Generate patch)

Comparing BasiliskII/src/BeOS/extfs_beos.cpp (file contents):
Revision 1.10 by cebix, 2000-04-10T18:52:49Z vs.
Revision 1.13 by cebix, 2001-02-09T20:04:15Z

# Line 1 | Line 1
1   /*
2   *  extfs_beos.cpp - MacOS file system for access native file system access, BeOS specific stuff
3   *
4 < *  Basilisk II (C) 1997-2000 Christian Bauer
4 > *  Basilisk II (C) 1997-2001 Christian Bauer
5   *
6   *  This program is free software; you can redistribute it and/or modify
7   *  it under the terms of the GNU General Public License as published by
# Line 87 | Line 87 | void add_path_component(char *path, cons
87  
88  
89   /*
90 < *  Get/set finder type/creator for file specified by full path
90 > *  Get/set finder info for file/directory specified by full path
91   */
92  
93   struct mime2type {
# Line 137 | Line 137 | static const mime2type m2t_translation[]
137          {NULL, 0, 0, false}     // End marker
138   };
139  
140 < void get_finder_type(const char *path, uint32 &type, uint32 &creator)
140 > void get_finfo(const char *path, uint32 finfo, uint32 fxinfo)
141   {
142 <        type = 0;
143 <        creator = 0;
142 >        // Set default finder info
143 >        Mac_memset(finfo, 0, SIZEOF_FInfo);
144 >        if (fxinfo)
145 >                Mac_memset(fxinfo, 0, SIZEOF_FXInfo);
146 >        WriteMacInt16(finfo + fdFlags, DEFAULT_FINDER_FLAGS);
147 >        WriteMacInt32(finfo + fdLocation, (uint32)-1);
148  
149          // Open file
150          int fd = open(path, O_RDONLY);
151          if (fd < 0)
152                  return;
153  
154 <        // Read BeOS MIME type and close file
154 >        // Read BeOS MIME type
155          char mime[256];
156          ssize_t actual = fs_read_attr(fd, "BEOS:TYPE", B_MIME_STRING_TYPE, 0, mime, 256);
157          mime[255] = 0;
# Line 155 | Line 159 | void get_finder_type(const char *path, u
159          if (actual > 0) {
160  
161                  // Translate MIME type to MacOS type/creator
162 <                char mactype[4];
162 >                uint8 mactype[4];
163                  if (sscanf(mime, "application/x-MacOS-%c%c%c%c", mactype, mactype+1, mactype+2, mactype+3) == 4) {
164  
165                          // MacOS style type
166 <                        memcpy(&type, mactype, 4);
166 >                        WriteMacInt32(finfo + fdType, (mactype[0] << 24) | (mactype[1] << 16) | (mactype[2] << 8) | mactype[3]);
167  
168                  } else {
169  
170                          // MIME string, look in table
171                          for (int i=0; m2t_translation[i].mime; i++) {
172                                  if (!strcmp(mime, m2t_translation[i].mime)) {
173 <                                        type = m2t_translation[i].type;
174 <                                        creator = m2t_translation[i].creator;
173 >                                        WriteMacInt32(finfo + fdType, m2t_translation[i].type);
174 >                                        WriteMacInt32(finfo + fdCreator, m2t_translation[i].creator);
175                                          break;
176                                  }
177                          }
# Line 175 | Line 179 | void get_finder_type(const char *path, u
179          }
180  
181          // Override file type with MACOS:CREATOR attribute
182 <        fs_read_attr(fd, "MACOS:CREATOR", B_UINT32_TYPE, 0, &creator, 4);
182 >        if (fs_read_attr(fd, "MACOS:CREATOR", B_UINT32_TYPE, 0, &mime, 4) == 4)
183 >                WriteMacInt32(finfo + fdCreator, (mime[0] << 24) | (mime[1] << 16) | (mime[2] << 8) | mime[3]);
184 >
185 >        // Read MACOS:HFS_FLAGS attribute
186 >        if (fs_read_attr(fd, "MACOS:HFS_FLAGS", B_UINT16_TYPE, 0, &mime, 2) == 2)
187 >                WriteMacInt16(finfo + fdFlags, (mime[0] << 8) | mime[1]);
188  
189          // Close file
190          close(fd);
191   }
192  
193 < void set_finder_type(const char *path, uint32 type, uint32 creator)
193 > void set_finfo(const char *path, uint32 finfo, uint32 fxinfo)
194   {
195 +        char mime[256];
196 +
197          // Open file
198          int fd = open(path, O_WRONLY);
199          if (fd < 0)
200                  return;
201  
202          // Set BEOS:TYPE attribute
203 +        uint32 type = ReadMacInt32(finfo + fdType);
204          if (type) {
205                  bool written = false;
206                  for (int i=0; m2t_translation[i].mime; i++) {
# Line 199 | Line 211 | void set_finder_type(const char *path, u
211                          }
212                  }
213                  if (!written) {
202                        char mime[256];
214                          sprintf(mime, "application/x-MacOS-%c%c%c%c", type >> 24, type >> 16, type >> 8, type);
215                          fs_write_attr(fd, "BEOS:TYPE", B_MIME_STRING_TYPE, 0, mime, strlen(mime) + 1);
216                  }
217          }
218  
219          // Set MACOS:CREATOR attribute
220 <        if (creator)
221 <                fs_write_attr(fd, "MACOS:CREATOR", B_UINT32_TYPE, 0, &creator, 4);
222 <
223 <        // Close file
224 <        close(fd);
225 < }
226 <
227 <
217 < /*
218 < *  Get/set finder flags for file/dir specified by full path (MACOS:HFS_FLAGS attribute)
219 < */
220 <
221 < void get_finder_flags(const char *path, uint16 &flags)
222 < {
223 <        flags = DEFAULT_FINDER_FLAGS;   // Default
224 <
225 <        // Open file
226 <        int fd = open(path, O_RDONLY);
227 <        if (fd < 0)
228 <                return;
229 <
230 <        // Read MACOS:HFS_FLAGS attribute
231 <        fs_read_attr(fd, "MACOS:HFS_FLAGS", B_UINT16_TYPE, 0, &flags, 2);
232 <
233 <        // Close file
234 <        close(fd);
235 < }
236 <
237 < void set_finder_flags(const char *path, uint16 flags)
238 < {
239 <        // Open file
240 <        int fd = open(path, O_WRONLY);
241 <        if (fd < 0)
242 <                return;
220 >        uint32 creator = ReadMacInt32(finfo + fdType);
221 >        if (creator) {
222 >                mime[0] = creator >> 24;
223 >                mime[1] = creator >> 16;
224 >                mime[2] = creator >> 8;
225 >                mime[3] = creator;
226 >                fs_write_attr(fd, "MACOS:CREATOR", B_UINT32_TYPE, 0, &mime, 4);
227 >        }
228  
229          // Write MACOS:HFS_FLAGS attribute
230 <        if (flags != DEFAULT_FINDER_FLAGS)
231 <                fs_write_attr(fd, "MACOS:HFS_FLAGS", B_UINT16_TYPE, 0, &flags, 2);
232 <        else
230 >        uint16 flags = ReadMacInt16(finfo + fdFlags);
231 >        if (flags != DEFAULT_FINDER_FLAGS) {
232 >                mime[0] = flags >> 8;
233 >                mime[1] = flags;
234 >                fs_write_attr(fd, "MACOS:HFS_FLAGS", B_UINT16_TYPE, 0, &mime, 2);
235 >        } else
236                  fs_remove_attr(fd, "MACOS:HFS_FLAGS");
237  
238          // Close file

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines