Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 2751 → Rev 2752

/trunk/uspace/srv/vfs/vfs_ops.c
75,8 → 75,7
.dev_handle = dev_handle,
};
 
return vfs_lookup_internal("/", strlen("/"), L_DIRECTORY, result,
&altroot);
return vfs_lookup_internal("/", L_DIRECTORY, result, &altroot);
}
 
void vfs_mount(ipc_callid_t rid, ipc_call_t *request)
149,7 → 148,7
}
/* Allocate buffer for the mount point data being received. */
uint8_t *buf;
buf = malloc(size);
buf = malloc(size + 1);
if (!buf) {
ipc_answer_0(callid, ENOMEM);
ipc_answer_0(rid, ENOMEM);
158,6 → 157,7
 
/* Deliver the mount point. */
(void) ipc_data_write_finalize(callid, buf, size);
buf[size] = '\0';
 
/*
* Lookup the root node of the filesystem being mounted.
186,8 → 186,7
if (rootfs.fs_handle) {
/* We already have the root FS. */
rwlock_write_lock(&namespace_rwlock);
rc = vfs_lookup_internal(buf, size, L_DIRECTORY, &mp_res,
NULL);
rc = vfs_lookup_internal(buf, L_DIRECTORY, &mp_res, NULL);
if (rc != EOK) {
/* The lookup failed for some reason. */
rwlock_write_unlock(&namespace_rwlock);
314,7 → 313,7
* There is one optimization we could do in the future: copy the path
* directly into the PLB using some kind of a callback.
*/
char *path = malloc(len);
char *path = malloc(len + 1);
if (!path) {
ipc_answer_0(callid, ENOMEM);
328,6 → 327,7
free(path);
return;
}
path[len] = '\0';
/*
* Avoid the race condition in which the file can be deleted before we
341,7 → 341,7
 
/* The path is now populated and we can call vfs_lookup_internal(). */
vfs_lookup_res_t lr;
rc = vfs_lookup_internal(path, len, lflag, &lr, NULL);
rc = vfs_lookup_internal(path, lflag, &lr, NULL);
if (rc) {
if (lflag & L_CREATE)
rwlock_write_unlock(&namespace_rwlock);
636,7 → 636,7
* There is one optimization we could do in the future: copy the path
* directly into the PLB using some kind of a callback.
*/
char *path = malloc(len);
char *path = malloc(len + 1);
if (!path) {
ipc_answer_0(callid, ENOMEM);
650,10 → 650,11
free(path);
return;
}
path[len] = '\0';
rwlock_write_lock(&namespace_rwlock);
int lflag = L_DIRECTORY | L_CREATE | L_EXCLUSIVE;
rc = vfs_lookup_internal(path, len, lflag, NULL, NULL);
rc = vfs_lookup_internal(path, lflag, NULL, NULL);
rwlock_write_unlock(&namespace_rwlock);
free(path);
ipc_answer_0(rid, rc);
678,7 → 679,7
* There is one optimization we could do in the future: copy the path
* directly into the PLB using some kind of a callback.
*/
char *path = malloc(len);
char *path = malloc(len + 1);
if (!path) {
ipc_answer_0(callid, ENOMEM);
692,11 → 693,12
free(path);
return;
}
path[len] = '\0';
rwlock_write_lock(&namespace_rwlock);
lflag &= L_DIRECTORY; /* sanitize lflag */
vfs_lookup_res_t lr;
rc = vfs_lookup_internal(path, len, lflag | L_DESTROY, &lr, NULL);
rc = vfs_lookup_internal(path, lflag | L_DESTROY, &lr, NULL);
free(path);
if (rc != EOK) {
rwlock_write_unlock(&namespace_rwlock);
/trunk/uspace/srv/vfs/vfs.h
250,8 → 250,7
 
extern int fs_name_to_handle(char *, bool);
 
extern int vfs_lookup_internal(char *, size_t, int, vfs_lookup_res_t *,
vfs_pair_t *);
extern int vfs_lookup_internal(char *, int, vfs_lookup_res_t *, vfs_pair_t *);
 
extern bool vfs_nodes_init(void);
extern vfs_node_t *vfs_node_get(vfs_lookup_res_t *);
/trunk/uspace/srv/vfs/vfs_lookup.c
49,7 → 49,7
#define min(a, b) ((a) < (b) ? (a) : (b))
 
/* Forward static declarations. */
static char *canonify(char *path);
static char *canonify(char *path, size_t *lenp);
 
atomic_t plb_futex = FUTEX_INITIALIZER;
link_t plb_head; /**< PLB entry ring buffer. */
57,8 → 57,8
 
/** Perform a path lookup.
*
* @param path Path to be resolved; it needn't be an ASCIIZ string.
* @param len Number of path characters pointed by path.
* @param path Path to be resolved; it must be a NULL-terminated
* string.
* @param lflag Flags to be used during lookup.
* @param result Empty structure where the lookup result will be stored.
* Can be NULL.
67,14 → 67,11
*
* @return EOK on success or an error code from errno.h.
*/
int vfs_lookup_internal(char *path, size_t len, int lflag,
vfs_lookup_res_t *result, vfs_pair_t *altroot)
int vfs_lookup_internal(char *path, int lflag, vfs_lookup_res_t *result,
vfs_pair_t *altroot)
{
vfs_pair_t *root;
 
if (!len)
return EINVAL;
 
if (altroot)
root = altroot;
else
83,6 → 80,11
if (!root->fs_handle)
return ENOENT;
size_t len;
path = canonify(path, &len);
if (!path)
return EINVAL;
futex_down(&plb_futex);
 
plb_entry_t entry;
273,7 → 275,8
}
static void terminate_slash(token_t *t, token_t *tfsl, token_t *tlcomp)
{
tfsl->stop[1] = '\0';
if (tfsl->stop[1]) /* avoid writing to a well-formatted path */
tfsl->stop[1] = '\0';
}
static void remove_trailing_slash(token_t *t, token_t *tfsl, token_t *tlcomp)
{
434,11 → 437,13
* This function makes a potentially non-canonical file system path canonical.
* It works in-place and requires a NULL-terminated input string.
*
* @param Path to be canonified.
* @param path Path to be canonified.
* @param lenp Pointer where the length of the final path will be
* stored. Can be NULL.
*
* @return Canonified path or NULL on failure.
*/
char *canonify(char *path)
char *canonify(char *path, size_t *lenp)
{
state_t state;
token_t t;
450,6 → 455,7
restart:
state = S_INI;
t = tfsl;
tlcomp = tfsl;
while (state != S_ACCEPT && state != S_RESTART && state != S_REJECT) {
if (trans[state][t.kind].f)
trans[state][t.kind].f(&t, &tfsl, &tlcomp);
463,6 → 469,8
case S_REJECT:
return NULL;
case S_ACCEPT:
if (lenp)
*lenp = (size_t)((tlcomp.stop - tfsl.start) + 1);
return tfsl.start;
default:
abort();