Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 4295 → Rev 4296

/branches/dd/uspace/lib/libc/generic/vfs/vfs.c
57,7 → 57,7
futex_t cwd_futex = FUTEX_INITIALIZER;
DIR *cwd_dir = NULL;
char *cwd_path = NULL;
size_t cwd_len = 0;
size_t cwd_size = 0;
 
char *absolutize(const char *path, size_t *retlen)
{
65,22 → 65,22
char *ncwd_path_nc;
 
futex_down(&cwd_futex);
size_t len = strlen(path);
size_t size = str_size(path);
if (*path != '/') {
if (!cwd_path) {
futex_up(&cwd_futex);
return NULL;
}
ncwd_path_nc = malloc(cwd_len + 1 + len + 1);
ncwd_path_nc = malloc(cwd_size + 1 + size + 1);
if (!ncwd_path_nc) {
futex_up(&cwd_futex);
return NULL;
}
strcpy(ncwd_path_nc, cwd_path);
ncwd_path_nc[cwd_len] = '/';
ncwd_path_nc[cwd_len + 1] = '\0';
str_cpy(ncwd_path_nc, cwd_size + 1 + size + 1, cwd_path);
ncwd_path_nc[cwd_size] = '/';
ncwd_path_nc[cwd_size + 1] = '\0';
} else {
ncwd_path_nc = malloc(len + 1);
ncwd_path_nc = malloc(size + 1);
if (!ncwd_path_nc) {
futex_up(&cwd_futex);
return NULL;
87,7 → 87,7
}
ncwd_path_nc[0] = '\0';
}
strcat(ncwd_path_nc, path);
str_append(ncwd_path_nc, cwd_size + 1 + size + 1, path);
ncwd_path = canonify(ncwd_path_nc, retlen);
if (!ncwd_path) {
futex_up(&cwd_futex);
99,7 → 99,7
* the address in ncwd_path need not be the same as ncwd_path_nc, even
* though they both point into the same dynamically allocated buffer.
*/
ncwd_path = strdup(ncwd_path);
ncwd_path = str_dup(ncwd_path);
free(ncwd_path_nc);
if (!ncwd_path) {
futex_up(&cwd_futex);
132,7 → 132,7
aid_t req = async_send_2(phone, DEVMAP_DEVICE_GET_HANDLE, flags, 0,
&answer);
ipcarg_t retval = ipc_data_write_start(phone, name, strlen(name) + 1);
ipcarg_t retval = ipc_data_write_start(phone, name, str_size(name) + 1);
if (retval != EOK) {
async_wait_for(req, NULL);
166,8 → 166,8
if (res != EOK)
return res;
size_t mpa_len;
char *mpa = absolutize(mp, &mpa_len);
size_t mpa_size;
char *mpa = absolutize(mp, &mpa_size);
if (!mpa)
return ENOMEM;
176,7 → 176,7
vfs_connect();
req = async_send_2(vfs_phone, VFS_MOUNT, dev_handle, flags, NULL);
rc = ipc_data_write_start(vfs_phone, (void *) mpa, mpa_len);
rc = ipc_data_write_start(vfs_phone, (void *) mpa, mpa_size);
if (rc != EOK) {
async_wait_for(req, NULL);
async_serialize_end();
185,7 → 185,7
return (int) rc;
}
rc = ipc_data_write_start(vfs_phone, (void *) fs_name, strlen(fs_name));
rc = ipc_data_write_start(vfs_phone, (void *) fs_name, str_size(fs_name));
if (rc != EOK) {
async_wait_for(req, NULL);
async_serialize_end();
208,8 → 208,8
ipc_call_t answer;
aid_t req;
size_t pa_len;
char *pa = absolutize(path, &pa_len);
size_t pa_size;
char *pa = absolutize(path, &pa_size);
if (!pa)
return ENOMEM;
218,7 → 218,7
vfs_connect();
req = async_send_3(vfs_phone, VFS_OPEN, lflag, oflag, 0, &answer);
rc = ipc_data_write_start(vfs_phone, pa, pa_len);
rc = ipc_data_write_start(vfs_phone, pa, pa_size);
if (rc != EOK) {
async_wait_for(req, NULL);
async_serialize_end();
384,8 → 384,8
ipcarg_t rc;
aid_t req;
size_t pa_len;
char *pa = absolutize(path, &pa_len);
size_t pa_size;
char *pa = absolutize(path, &pa_size);
if (!pa)
return ENOMEM;
394,7 → 394,7
vfs_connect();
req = async_send_1(vfs_phone, VFS_MKDIR, mode, NULL);
rc = ipc_data_write_start(vfs_phone, pa, pa_len);
rc = ipc_data_write_start(vfs_phone, pa, pa_size);
if (rc != EOK) {
async_wait_for(req, NULL);
async_serialize_end();
414,8 → 414,8
ipcarg_t rc;
aid_t req;
size_t pa_len;
char *pa = absolutize(path, &pa_len);
size_t pa_size;
char *pa = absolutize(path, &pa_size);
if (!pa)
return ENOMEM;
 
424,7 → 424,7
vfs_connect();
req = async_send_0(vfs_phone, VFS_UNLINK, NULL);
rc = ipc_data_write_start(vfs_phone, pa, pa_len);
rc = ipc_data_write_start(vfs_phone, pa, pa_size);
if (rc != EOK) {
async_wait_for(req, NULL);
async_serialize_end();
454,13 → 454,13
ipcarg_t rc;
aid_t req;
size_t olda_len;
char *olda = absolutize(old, &olda_len);
size_t olda_size;
char *olda = absolutize(old, &olda_size);
if (!olda)
return ENOMEM;
 
size_t newa_len;
char *newa = absolutize(new, &newa_len);
size_t newa_size;
char *newa = absolutize(new, &newa_size);
if (!newa) {
free(olda);
return ENOMEM;
471,7 → 471,7
vfs_connect();
req = async_send_0(vfs_phone, VFS_RENAME, NULL);
rc = ipc_data_write_start(vfs_phone, olda, olda_len);
rc = ipc_data_write_start(vfs_phone, olda, olda_size);
if (rc != EOK) {
async_wait_for(req, NULL);
async_serialize_end();
480,7 → 480,7
free(newa);
return (int) rc;
}
rc = ipc_data_write_start(vfs_phone, newa, newa_len);
rc = ipc_data_write_start(vfs_phone, newa, newa_size);
if (rc != EOK) {
async_wait_for(req, NULL);
async_serialize_end();
499,8 → 499,8
 
int chdir(const char *path)
{
size_t pa_len;
char *pa = absolutize(path, &pa_len);
size_t pa_size;
char *pa = absolutize(path, &pa_size);
if (!pa)
return ENOMEM;
 
516,11 → 516,11
cwd_dir = NULL;
free(cwd_path);
cwd_path = NULL;
cwd_len = 0;
cwd_size = 0;
}
cwd_dir = d;
cwd_path = pa;
cwd_len = pa_len;
cwd_size = pa_size;
futex_up(&cwd_futex);
return EOK;
}
530,11 → 530,11
if (!size)
return NULL;
futex_down(&cwd_futex);
if (size < cwd_len + 1) {
if (size < cwd_size + 1) {
futex_up(&cwd_futex);
return NULL;
}
strcpy(buf, cwd_path);
str_cpy(buf, size, cwd_path);
futex_up(&cwd_futex);
return buf;
}