2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
5 Desc: Get a device pointer from a filename.
8 #include <exec/memory.h>
9 #include <proto/exec.h>
11 #include <dos/dosextens.h>
12 #include <dos/filesystem.h>
13 #include <proto/dos.h>
14 #include <proto/utility.h>
16 #include "dos_intern.h"
20 LONG
DevName(CONST_STRPTR name
, struct Device
**devptr
,
21 struct DosLibrary
*DOSBase
)
25 CONST_STRPTR s1
= NULL
;
27 struct FileHandle
*fh
;
28 struct Process
*me
= (struct Process
*)FindTask(NULL
);
30 /* If file is "PROGDIR:" or relative to current directory, just return
31 device from pr_HomeDir or pr_CurrentDir. */
32 if(!Strnicmp(name
, "PROGDIR:", 8))
34 struct FileHandle
*fh
= (struct FileHandle
*)BADDR(me
->pr_HomeDir
);
38 *devptr
= (struct Device
*)0xBADC0DE;
39 return ERROR_DEVICE_NOT_MOUNTED
;
43 *devptr
= fh
->fh_Device
;
49 struct FileHandle
*fh
= (struct FileHandle
*)BADDR(me
->pr_CurrentDir
);
51 if (!fh
) fh
= (struct FileHandle
*)BADDR(DOSBase
->dl_SYSLock
);
55 *devptr
= fh
->fh_Device
;
60 *devptr
= (struct Device
*)0xBADC0DE;
61 return ERROR_DEVICE_NOT_MOUNTED
;
65 /* Copy volume name */
73 volname
= (STRPTR
)AllocVec(s1
- name
, MEMF_ANY
);
77 SetIoErr(ERROR_NO_FREE_STORE
);
78 return ERROR_NO_FREE_STORE
;
81 CopyMem(name
, volname
, s1
- name
- 1);
82 volname
[s1
- name
- 1] = '\0';
87 /* If path is relative to current directory, get device from
91 struct FileHandle
*fh
= (struct FileHandle
*)BADDR(me
->pr_CurrentDir
);
93 if (!fh
) fh
= (struct FileHandle
*)BADDR(DOSBase
->dl_SYSLock
);
97 *devptr
= fh
->fh_Device
;
102 *devptr
= (struct Device
*)0xBADC0DE;
103 return ERROR_DEVICE_NOT_MOUNTED
;
108 /* Get the device pointer from dos-list. */
109 dl
= LockDosList(LDF_ALL
| LDF_READ
);
110 dl
= FindDosEntry(dl
, volname
, LDF_ALL
);
114 if(dl
->dol_Type
== DLT_LATE
)
116 /* Late binding assign: mount first */
117 BPTR lock
= Lock(dl
->dol_misc
.dol_assign
.dol_AssignName
,
119 UnLockDosList(LDF_ALL
| LDF_READ
);
124 AssignLock(volname
, lock
);
125 dl
= LockDosList(LDF_ALL
| LDF_READ
);
126 dl
= FindDosEntry(dl
, volname
, LDF_ALL
);
129 *devptr
= dl
->dol_Device
;
131 error
= ERROR_DEVICE_NOT_MOUNTED
;
133 UnLockDosList(LDF_ALL
| LDF_READ
);
139 else if(dl
->dol_Type
== DLT_NONBINDING
)
141 BPTR lock
= Lock(dl
->dol_misc
.dol_assign
.dol_AssignName
,
143 UnLockDosList(LDF_ALL
| LDF_READ
);
144 fh
= (struct FileHandle
*)BADDR(lock
);
148 *devptr
= fh
->fh_Device
;
156 *devptr
= dl
->dol_Device
;
157 UnLockDosList(LDF_ALL
| LDF_READ
);
162 UnLockDosList(LDF_ALL
| LDF_READ
);
163 error
= ERROR_DEVICE_NOT_MOUNTED
;