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.9 by cebix, 1999-12-22T16:16:14Z vs.
Revision 1.18 by gbeauche, 2008-01-01T09:40:32Z

# 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-1999 Christian Bauer
4 > *  Basilisk II (C) 1997-2008 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, bool is_dir)
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
151 <        char mime[256];
152 <        ssize_t actual = fs_read_attr(fd, "BEOS:TYPE", B_MIME_STRING_TYPE, 0, mime, 256);
153 <        mime[255] = 0;
154 >        if (!is_dir) {
155  
156 <        if (actual > 0) {
157 <
158 <                // Translate MIME type to MacOS type/creator
159 <                char mactype[4];
160 <                if (sscanf(mime, "application/x-MacOS-%c%c%c%c", mactype, mactype+1, mactype+2, mactype+3) == 4) {
161 <
162 <                        // MacOS style type
163 <                        memcpy(&type, mactype, 4);
164 <
165 <                } else {
166 <
167 <                        // MIME string, look in table
168 <                        for (int i=0; m2t_translation[i].mime; i++) {
169 <                                if (!strcmp(mime, m2t_translation[i].mime)) {
170 <                                        type = m2t_translation[i].type;
171 <                                        creator = m2t_translation[i].creator;
172 <                                        break;
156 >                // Read BeOS MIME type
157 >                ssize_t actual = fs_read_attr(fd, "BEOS:TYPE", B_MIME_STRING_TYPE, 0, tmp_buf, 256);
158 >                tmp_buf[255] = 0;
159 >
160 >                if (actual > 0) {
161 >
162 >                        // Translate MIME type to MacOS type/creator
163 >                        uint8 mactype[4];
164 >                        if (sscanf((char *)tmp_buf, "application/x-MacOS-%c%c%c%c", mactype, mactype+1, mactype+2, mactype+3) == 4) {
165 >
166 >                                // MacOS style type
167 >                                WriteMacInt32(finfo + fdType, (mactype[0] << 24) | (mactype[1] << 16) | (mactype[2] << 8) | mactype[3]);
168 >
169 >                        } else {
170 >
171 >                                // MIME string, look in table
172 >                                for (int i=0; m2t_translation[i].mime; i++) {
173 >                                        if (!strcmp((char *)tmp_buf, m2t_translation[i].mime)) {
174 >                                                WriteMacInt32(finfo + fdType, m2t_translation[i].type);
175 >                                                WriteMacInt32(finfo + fdCreator, m2t_translation[i].creator);
176 >                                                break;
177 >                                        }
178                                  }
179                          }
180                  }
181 +
182 +                // Override file type with MACOS:CREATOR attribute
183 +                if (fs_read_attr(fd, "MACOS:CREATOR", B_UINT32_TYPE, 0, tmp_buf, 4) == 4)
184 +                        WriteMacInt32(finfo + fdCreator, (tmp_buf[0] << 24) | (tmp_buf[1] << 16) | (tmp_buf[2] << 8) | tmp_buf[3]);
185          }
186  
187 <        // Override file type with MACOS:CREATOR attribute
188 <        fs_read_attr(fd, "MACOS:CREATOR", B_UINT32_TYPE, 0, &creator, 4);
187 >        // Read MACOS:HFS_FLAGS attribute
188 >        if (fs_read_attr(fd, "MACOS:HFS_FLAGS", B_UINT16_TYPE, 0, tmp_buf, 2) == 2)
189 >                WriteMacInt16(finfo + fdFlags, (tmp_buf[0] << 8) | tmp_buf[1]);
190  
191          // Close file
192          close(fd);
193   }
194  
195 < void set_finder_type(const char *path, uint32 type, uint32 creator)
195 > void set_finfo(const char *path, uint32 finfo, uint32 fxinfo, bool is_dir)
196   {
197          // Open file
198          int fd = open(path, O_WRONLY);
199          if (fd < 0)
200                  return;
201  
202 <        // Set BEOS:TYPE attribute
203 <        if (type) {
204 <                bool written = false;
205 <                for (int i=0; m2t_translation[i].mime; i++) {
206 <                        if (m2t_translation[i].type == type && m2t_translation[i].reversible) {
207 <                                fs_write_attr(fd, "BEOS:TYPE", B_MIME_STRING_TYPE, 0, m2t_translation[i].mime, strlen(m2t_translation[i].mime) + 1);
208 <                                written = true;
209 <                                break;
202 >        if (!is_dir) {
203 >
204 >                // Set BEOS:TYPE attribute
205 >                uint32 type = ReadMacInt32(finfo + fdType);
206 >                if (type) {
207 >                        for (int i=0; m2t_translation[i].mime; i++) {
208 >                                if (m2t_translation[i].type == type && m2t_translation[i].reversible) {
209 >                                        fs_write_attr(fd, "BEOS:TYPE", B_MIME_STRING_TYPE, 0, m2t_translation[i].mime, strlen(m2t_translation[i].mime) + 1);
210 >                                        break;
211 >                                }
212                          }
213                  }
214 <                if (!written) {
215 <                        char mime[256];
216 <                        sprintf(mime, "application/x-MacOS-%c%c%c%c", type >> 24, type >> 16, type >> 8, type);
217 <                        fs_write_attr(fd, "BEOS:TYPE", B_MIME_STRING_TYPE, 0, mime, strlen(mime) + 1);
214 >
215 >                // Set MACOS:CREATOR attribute
216 >                uint32 creator = ReadMacInt32(finfo + fdCreator);
217 >                if (creator) {
218 >                        tmp_buf[0] = creator >> 24;
219 >                        tmp_buf[1] = creator >> 16;
220 >                        tmp_buf[2] = creator >> 8;
221 >                        tmp_buf[3] = creator;
222 >                        fs_write_attr(fd, "MACOS:CREATOR", B_UINT32_TYPE, 0, tmp_buf, 4);
223                  }
224          }
225  
208        // Set MACOS:CREATOR attribute
209        if (creator)
210                fs_write_attr(fd, "MACOS:CREATOR", B_UINT32_TYPE, 0, &creator, 4);
211
212        // Close file
213        close(fd);
214 }
215
216
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;
243
226          // Write MACOS:HFS_FLAGS attribute
227 <        if (flags != DEFAULT_FINDER_FLAGS)
228 <                fs_write_attr(fd, "MACOS:HFS_FLAGS", B_UINT16_TYPE, 0, &flags, 2);
229 <        else
227 >        uint16 flags = ReadMacInt16(finfo + fdFlags);
228 >        if (flags != DEFAULT_FINDER_FLAGS) {
229 >                tmp_buf[0] = flags >> 8;
230 >                tmp_buf[1] = flags;
231 >                fs_write_attr(fd, "MACOS:HFS_FLAGS", B_UINT16_TYPE, 0, tmp_buf, 2);
232 >        } else
233                  fs_remove_attr(fd, "MACOS:HFS_FLAGS");
234  
235          // Close file

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines