Mac Creation of a file using FSpCreate()??

naveen

macrumors member
Original poster
Oct 27, 2004
43
0
Hi

I am using the function FSMakeFSSpec() to get a valid FSSpec but still file is not created. I have made this program in QT Programming for Mac(C++ GUI programming kit by trolltech.org). I am trying to make a text file using programming.

I have used the following code:-

OSErr err;
FSSpec spec;
err=FSMakeFSSpec(0,0,"/unique/hello.txt",&spec);
if(err == fnfErr)
QMessageBox::information(0, "message","hiiiiiiiiii");

FSpCreate(&spec, 'CWIE', 'TEXT', smSystemScript);


I have included the following Libs in my application:-
LIBS+=/System/Library/Frameworks/Carbon.framework/Carbon
LIBS+=/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation

I have included the "Files.h" in my project settings:-
/System/Library/Frameworks/CoreServices.framework/CarbonCore.framework/Versions/A/Headers/Files.h

Plz help me where i am wrong??

Thanks and Regards
 

HiRez

macrumors 603
Jan 6, 2004
5,848
1,803
Western US
naveen said:
Plz help me where i am wrong??s
Are you getting any errors or does it just do nothing? The FSpCreate function returns an error code, so you should be checking on that as well. Maybe it's a permissions problem? Is the file path you specified an absolute path or a relative one?
 

naveen

macrumors member
Original poster
Oct 27, 2004
43
0
HiRez said:
Are you getting any errors or does it just do nothing? The FSpCreate function returns an error code, so you should be checking on that as well. Maybe it's a permissions problem? Is the file path you specified an absolute path or a relative one?
hi
I am not getting any error but it just do nothing. In my code i have given a messagebox but this message box not appeared when i run the program. There is an error in FSMakeFSSpec() function. But i am still not able to get the error.


Thanks and Regards
 

naveen

macrumors member
Original poster
Oct 27, 2004
43
0
hi

I have checked the "err" in my code I have got the result code "-37" Which represent the "Bad filename or volume name". I have given a full path of existing directory named "unique" on root and want to create a hello.txt file in that directory. Where i am wrong plz help me.

Thanks and Regards
 

iMeowbot

macrumors G3
Aug 30, 2003
8,634
0
err=FSMakeFSSpec(0,0,"/unique/hello.txt",&spec);
This is going to be a problem, FSMakeFSSpec is made to work with a traditional Mac path as a Pascal string.

To use a unix path, try FSPathMakeRef to get an FSRef, then FSGetCatalogInfo to get your FSSpec.
 

naveen

macrumors member
Original poster
Oct 27, 2004
43
0
Hi

Actually I am writting a program to recover a file from a crashed Apple Macintosh Disk having HFS or HFS+ file system. I have enough knowledge of HFS and HFS+ file system. All is well in my program now i am on saving part a file.

I know Where the Data Fork and Resource Fork sectors or clusters of a file lies on the Hard Disk. I am able to raw read those particular sectors for crashed hard disk.

I want to Create a file and then open the Data Fork of created file and Write the data fork data from crashed hard disk and then open the Resource Fork of created file and Write the resource fork data from the crashed hard disk and then close the file.

I have made this program in QT Programming for Mac(C++ GUI programming kit by trolltech.org). I am trying to make a text file using programming.

I have used the following code in my application:-
OSErr err;
FSSpec spec;
err=FSMakeFSSpec(0,0,":unique:hello.txt",&spec);
if(err != fnfErr)
{
//Display message and exit
}

FSpCreate(&spec, 'CWIE', 'TEXT', smSystemScript);

I have included the following Libs in my application:-
LIBS+=/System/Library/Frameworks/Carbon.framework/Carbon
LIBS+=/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation

I have included the "Files.h" in my project settings:-
/System/Library/Frameworks/CoreServices.framework/CarbonCore.framework/Versions/A/Headers/Files.h

When i am compiling the program there is no error but file is not created.

I have checked the "err" in my code I have got the result code "-35" Which represent the "Bad volume name". I have given a full path of existing directory named "unique" on root and want to create a hello.txt file in that directory. Where i am wrong plz help me.


How i can use the FSPathMakeRef to get an FSRef, then FSGetCatalogInfo to get your FSSpec. Plz anybody have example code then help me.

Thanks and Regards
 

iMeowbot

macrumors G3
Aug 30, 2003
8,634
0
Okay, first, the argument you have there to MakeFSSpec should be a Pascal string, i.e. "\p:unique:hello.txt" (that sets the first byte of the string to a length code). Can you set that and see how much farther you get?
 

naveen

macrumors member
Original poster
Oct 27, 2004
43
0
iMeowbot said:
Okay, first, the argument you have there to MakeFSSpec should be a Pascal string, i.e. "\p:unique:hello.txt" (that sets the first byte of the string to a length code). Can you set that and see how much farther you get?

I have changed the code to :- err=FSMakeFSSpec(0,0,"\punique:hello.txt",&spec);
I am getting the same error code=-35 which represent bad volume name.


Thanks and regards
 

iMeowbot

macrumors G3
Aug 30, 2003
8,634
0
naveen said:
I have changed the code to :- err=FSMakeFSSpec(0,0,"\punique:hello.txt",&spec);
I am getting the same error code=-35 which represent bad volume name.


Thanks and regards
What you have there would mean that you have a volume named "unique". I thought that "unique" was a top level directory on the disk you were trying to fix? If "unique" is a folder, you do still need the leading colon as in the message I posted above, that is "\p:unique:hello.txt"

Inside Macintosh reference for Carbon directory syntax

(You haven't mentioned what the volume and directory names actually are, so it is kind of hard to guess at exactly what you are trying to do!)

----

As an aside, Carbon seems to be causing you a lot of trouble (as it does everybody!). If you are more comfortable with traditional C programming, the following information might make life easier for you.

Under the POSIX filesystem syntax, every file on an HFS volume is also a hidden directory of sorts. Suppose you have a file called /Users/whosie/foofile and it has a resource fork. To open the resource fork, you can use the path /Users/whosie/foofile/rsrc . Every HFS file has that hidden rsrc name attached to it. Using this you can avoid dealing with the Carbon filesystem functions.

This method doesn't provide for adding or changing creator and type information, but there are other ways (such as /Developer/Tools/SetFile, Applescript, and various third party tools) to add that later.
 

naveen

macrumors member
Original poster
Oct 27, 2004
43
0
Hi all

I have search the carbon mailing archive which suggest me to create file using the FSCreateFileUnicode() I have studied this fuction but i have got little bit confused. Plz help by giving some code example to create file using FSCreateFileUnicode().


Thanks and Regards
 

Similar threads

  • view60
1
Replies
1
Views
168
Replies
1
Views
622
  • Puppuccino
2
Replies
2
Views
659
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.