2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
5 Desc: Create a hard- or softlink.
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(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 by name, and is resolved by
34 the filesystem and the caller. Soft links are not restricted to
35 the same volume. The |dest| argument is a NUL terminated pathname
36 to the pre-existing object. Soft links can be used on directories.
38 A hard link refers to another file by the location on a disk, and
39 is resolved by the filesystem. Hard links are restricted to files
40 on the same volume. The |dest| argument is a lock on another file.
43 name - The name of the link to create
44 dest - If 'soft' is TRUE this must be a filename, if it is FALSE a BPTR
45 pointing to the file to be hard-linked must be provided
46 soft - TRUE, if a soft-link is to be created, FALSE for an hard-link
49 boolean - DOSTRUE or DOSFALSE. On error, IoErr() will contain more
57 Soft links were not working in the ROM filesystem before version
64 This function calls either FSA_CREATE_HARDLINK or FSA_CREATE_SOFTLINK
65 on the filesystem of `name`.
67 *****************************************************************************/
71 struct IOFileSys iofs
;
73 struct FileHandle
*fh
;
76 /* soft link is easy */
78 InitIOFS(&iofs
, FSA_CREATE_SOFTLINK
, DOSBase
);
79 iofs
.io_Union
.io_CREATE_SOFTLINK
.io_Reference
= (STRPTR
) dest
;
80 return DoIOFS(&iofs
, NULL
, name
, DOSBase
) == 0 ? DOSTRUE
: DOSFALSE
;
83 /* hard link. find the handler */
84 if ((dvp
= GetDeviceProc(name
, NULL
)) == NULL
)
87 fh
= (struct FileHandle
*) BADDR(dest
);
89 /* source and target must be on the same device
90 * XXX this is insufficient, see comments in samedevice.c */
91 if (dvp
->dvp_Port
!= fh
->fh_Device
) {
93 SetIoErr(ERROR_RENAME_ACROSS_DEVICES
);
97 InitIOFS(&iofs
, FSA_CREATE_HARDLINK
, DOSBase
);
98 iofs
.io_Union
.io_CREATE_HARDLINK
.io_OldFile
= fh
->fh_Unit
;
99 err
= DoIOFS(&iofs
, dvp
, name
, DOSBase
);
103 return err
== 0 ? DOSTRUE
: DOSFALSE
;