2 Copyright © 1995-2008, The AROS Development Team. All rights reserved.
5 Desc: Create a hard or soft link.
8 #include <dos/dosextens.h>
9 #include <dos/filesystem.h>
10 #include "dos_intern.h"
11 #include <proto/exec.h>
13 /*****************************************************************************
16 #include <exec/types.h>
17 #include <proto/dos.h>
19 AROS_LH3(LONG
, MakeLink
,
22 AROS_LHA(CONST_STRPTR
, name
, D1
),
23 AROS_LHA(APTR
, dest
, D2
),
24 AROS_LHA(LONG
, soft
, D3
),
27 struct DosLibrary
*, DOSBase
, 74, Dos
)
30 MakeLink() will create a link between two files or directories.
31 A link is a filesystem object that refers to another file.
33 A soft link refers to another file or directory by name, and is
34 resolved by the filesystem and the caller. Soft links are not
35 restricted to the same volume and the target does not have to exist.
37 A hard link refers to another file by the location on a disk, and
38 is resolved by the filesystem. Hard links are restricted to files
39 or directories on the same volume.
42 name - The name of the link to create
43 dest - If 'soft' is TRUE this must be a filename; if it is FALSE a lock
44 pointing to the file to be hard-linked must be provided
45 soft - TRUE, if a soft link is to be created, FALSE for a hard link
48 boolean - DOSTRUE or DOSFALSE. On error, IoErr() will contain more
56 Soft links were not working in the ROM filesystem before version
63 This function calls either FSA_CREATE_HARDLINK or FSA_CREATE_SOFTLINK
64 on the filesystem of `name`.
66 *****************************************************************************/
70 struct IOFileSys iofs
;
72 struct FileHandle
*fh
;
75 /* soft link is easy */
77 InitIOFS(&iofs
, FSA_CREATE_SOFTLINK
, DOSBase
);
78 iofs
.io_Union
.io_CREATE_SOFTLINK
.io_Reference
= (STRPTR
) dest
;
79 return DoIOFS(&iofs
, NULL
, name
, DOSBase
) == 0 ? DOSTRUE
: DOSFALSE
;
82 /* hard link. find the handler */
83 if ((dvp
= GetDeviceProc(name
, NULL
)) == NULL
)
86 fh
= (struct FileHandle
*) BADDR(dest
);
88 /* source and target must be on the same device
89 * XXX this is insufficient, see comments in samedevice.c */
90 if (dvp
->dvp_Port
!= (struct MsgPort
*)fh
->fh_Device
) {
92 SetIoErr(ERROR_RENAME_ACROSS_DEVICES
);
96 InitIOFS(&iofs
, FSA_CREATE_HARDLINK
, DOSBase
);
97 iofs
.io_Union
.io_CREATE_HARDLINK
.io_OldFile
= fh
->fh_Unit
;
98 err
= DoIOFS(&iofs
, dvp
, name
, DOSBase
);
102 return err
== 0 ? DOSTRUE
: DOSFALSE
;