Updated PCI IDs to latest snapshot.
[tangerine.git] / rom / dos / makelink.c
blob7027ac908f02b8b1a2a9433e1bcd83cee8602fa2
1 /*
2 Copyright © 1995-2008, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Create a hard or soft link.
6 Lang: English
7 */
8 #include <dos/dosextens.h>
9 #include <dos/filesystem.h>
10 #include "dos_intern.h"
11 #include <proto/exec.h>
13 /*****************************************************************************
15 NAME */
16 #include <exec/types.h>
17 #include <proto/dos.h>
19 AROS_LH3(LONG, MakeLink,
21 /* SYNOPSIS */
22 AROS_LHA(CONST_STRPTR, name, D1),
23 AROS_LHA(APTR, dest, D2),
24 AROS_LHA(LONG , soft, D3),
26 /* LOCATION */
27 struct DosLibrary *, DOSBase, 74, Dos)
29 /* FUNCTION
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.
41 INPUTS
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
47 RESULT
48 boolean - DOSTRUE or DOSFALSE. On error, IoErr() will contain more
49 information.
51 NOTES
53 EXAMPLE
55 BUGS
56 Soft links were not working in the ROM filesystem before version
57 37.
59 SEE ALSO
60 ReadLink()
62 INTERNALS
63 This function calls either FSA_CREATE_HARDLINK or FSA_CREATE_SOFTLINK
64 on the filesystem of `name`.
66 *****************************************************************************/
68 AROS_LIBFUNC_INIT
70 struct IOFileSys iofs;
71 struct DevProc *dvp;
72 struct FileHandle *fh;
73 LONG err;
75 /* soft link is easy */
76 if (soft) {
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)
84 return DOSFALSE;
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) {
91 FreeDeviceProc(dvp);
92 SetIoErr(ERROR_RENAME_ACROSS_DEVICES);
93 return DOSFALSE;
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);
100 FreeDeviceProc(dvp);
102 return err == 0 ? DOSTRUE : DOSFALSE;
104 AROS_LIBFUNC_EXIT
105 } /* MakeLink */