added concrete implementations of putc(), getc(), getchar() and gets()
[tangerine.git] / rom / dos / makelink.c
blobb30b096768e87d80f5cfe3e13a9f833d924e09f4
1 /*
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Create a hard- or softlink.
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(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 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.
42 INPUTS
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
48 RESULT
49 boolean - DOSTRUE or DOSFALSE. On error, IoErr() will contain more
50 information.
52 NOTES
54 EXAMPLE
56 BUGS
57 Soft links were not working in the ROM filesystem before version
58 37.
60 SEE ALSO
61 ReadLink()
63 INTERNALS
64 This function calls either FSA_CREATE_HARDLINK or FSA_CREATE_SOFTLINK
65 on the filesystem of `name`.
67 *****************************************************************************/
69 AROS_LIBFUNC_INIT
71 struct IOFileSys iofs;
72 struct DevProc *dvp;
73 struct FileHandle *fh;
74 LONG err;
76 /* soft link is easy */
77 if (soft) {
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)
85 return DOSFALSE;
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) {
92 FreeDeviceProc(dvp);
93 SetIoErr(ERROR_RENAME_ACROSS_DEVICES);
94 return DOSFALSE;
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);
101 FreeDeviceProc(dvp);
103 return err == 0 ? DOSTRUE : DOSFALSE;
105 AROS_LIBFUNC_EXIT
106 } /* MakeLink */