8 * Convert a relative pathname to an absolute pathname
9 * In the future this might also resolve symlinks...
11 void pm_realpath(com32sys_t
*regs
)
13 const char *src
= MK_PTR(regs
->ds
, regs
->esi
.w
[0]);
14 char *dst
= MK_PTR(regs
->es
, regs
->edi
.w
[0]);
16 realpath(dst
, src
, FILENAME_MAX
);
19 size_t realpath(char *dst
, const char *src
, size_t bufsize
)
21 if (this_fs
->fs_ops
->realpath
) {
22 return this_fs
->fs_ops
->realpath(this_fs
, dst
, src
, bufsize
);
24 /* Filesystems with "common" pathname resolution */
25 return snprintf(dst
, bufsize
, "%s%s",
26 src
[0] == '/' ? "" : this_fs
->cwd_name
,
31 int chdir(const char *src
)
37 if (this_fs
->fs_ops
->chdir
)
38 return this_fs
->fs_ops
->chdir(this_fs
, src
);
40 /* Otherwise it is a "conventional filesystem" */
45 file
= handle_to_file(rv
);
46 if (file
->inode
->mode
!= DT_DIR
) {
51 put_inode(this_fs
->cwd
);
52 this_fs
->cwd
= get_inode(file
->inode
);
55 /* Save the current working directory */
56 realpath(this_fs
->cwd_name
, src
, CURRENTDIR_MAX
);
57 p
= strchr(this_fs
->cwd_name
, '\0');
59 /* Make sure the cwd_name ends in a slash, it's supposed to be a prefix */
60 if (p
< this_fs
->cwd_name
+ CURRENTDIR_MAX
- 1 &&
61 (p
== this_fs
->cwd_name
|| p
[1] != '/')) {