|
@@ -49,10 +49,10 @@
|
|
|
#define FILE_BUF_SIZE (PAL_CB(pagesize))
|
|
|
|
|
|
struct mount_data {
|
|
|
- int data_size;
|
|
|
+ size_t data_size;
|
|
|
enum shim_file_type base_type;
|
|
|
unsigned long ino_base;
|
|
|
- int root_uri_len;
|
|
|
+ size_t root_uri_len;
|
|
|
char root_uri[];
|
|
|
};
|
|
|
|
|
@@ -98,9 +98,9 @@ static int chroot_unmount (void * mount_data)
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-static inline int concat_uri (char * buffer, int size, int type,
|
|
|
- const char * root, int root_len,
|
|
|
- const char * trim, int trim_len)
|
|
|
+static inline ssize_t concat_uri (char * buffer, size_t size, int type,
|
|
|
+ const char * root, size_t root_len,
|
|
|
+ const char * trim, size_t trim_len)
|
|
|
{
|
|
|
char * tmp = NULL;
|
|
|
|
|
@@ -159,18 +159,18 @@ static void __destroy_data (struct shim_file_data * data)
|
|
|
free(data);
|
|
|
}
|
|
|
|
|
|
-static int make_uri (struct shim_dentry * dent)
|
|
|
+static ssize_t make_uri (struct shim_dentry * dent)
|
|
|
{
|
|
|
struct mount_data * mdata = DENTRY_MOUNT_DATA(dent);
|
|
|
assert(mdata);
|
|
|
|
|
|
struct shim_file_data * data = FILE_DENTRY_DATA(dent);
|
|
|
char uri[URI_MAX_SIZE];
|
|
|
- int len = concat_uri(uri, URI_MAX_SIZE, data->type,
|
|
|
- mdata->root_uri,
|
|
|
- mdata->root_uri_len,
|
|
|
- qstrgetstr(&dent->rel_path),
|
|
|
- dent->rel_path.len);
|
|
|
+ ssize_t len = concat_uri(uri, URI_MAX_SIZE, data->type,
|
|
|
+ mdata->root_uri,
|
|
|
+ mdata->root_uri_len,
|
|
|
+ qstrgetstr(&dent->rel_path),
|
|
|
+ dent->rel_path.len);
|
|
|
if (len >= 0)
|
|
|
qstrsetstr(&data->host_uri, uri, len);
|
|
|
|
|
@@ -179,7 +179,7 @@ static int make_uri (struct shim_dentry * dent)
|
|
|
|
|
|
/* create a data in the dentry and compose it's uri. dent->lock needs to
|
|
|
be held */
|
|
|
-static int create_data (struct shim_dentry * dent, const char * uri, int len)
|
|
|
+static int create_data (struct shim_dentry * dent, const char * uri, size_t len)
|
|
|
{
|
|
|
if (dent->data)
|
|
|
return 0;
|
|
@@ -252,7 +252,7 @@ static int __query_attr (struct shim_dentry * dent,
|
|
|
* children it has by hand. */
|
|
|
/* XXX: Keep coherent with rmdir/mkdir/creat, etc */
|
|
|
struct shim_dirent *d, *dbuf = NULL;
|
|
|
- int nlink = 0;
|
|
|
+ size_t nlink = 0;
|
|
|
int rv = chroot_readdir(dent, &dbuf);
|
|
|
if (rv != 0)
|
|
|
return rv;
|
|
@@ -293,7 +293,7 @@ static void chroot_update_ino (struct shim_dentry * dent)
|
|
|
}
|
|
|
|
|
|
static inline int try_create_data (struct shim_dentry * dent,
|
|
|
- const char * uri, int len,
|
|
|
+ const char * uri, size_t len,
|
|
|
struct shim_file_data ** dataptr)
|
|
|
{
|
|
|
struct shim_file_data * data = FILE_DENTRY_DATA(dent);
|
|
@@ -385,7 +385,7 @@ static int chroot_lookup (struct shim_dentry * dent, bool force)
|
|
|
}
|
|
|
|
|
|
static int __chroot_open (struct shim_dentry * dent,
|
|
|
- const char * uri, int len, int flags, mode_t mode,
|
|
|
+ const char * uri, size_t len, int flags, mode_t mode,
|
|
|
struct shim_handle * hdl,
|
|
|
struct shim_file_data * data)
|
|
|
{
|
|
@@ -461,7 +461,7 @@ static int chroot_open (struct shim_handle * hdl, struct shim_dentry * dent,
|
|
|
return ret;
|
|
|
|
|
|
struct shim_file_handle * file = &hdl->info.file;
|
|
|
- int size = atomic_read(&data->size);
|
|
|
+ off_t size = atomic_read(&data->size);
|
|
|
|
|
|
/* initialize hdl, does not need a lock because no one is sharing */
|
|
|
hdl->type = TYPE_FILE;
|
|
@@ -491,7 +491,7 @@ static int chroot_creat (struct shim_handle * hdl, struct shim_dentry * dir,
|
|
|
return 0;
|
|
|
|
|
|
struct shim_file_handle * file = &hdl->info.file;
|
|
|
- int size = atomic_read(&data->size);
|
|
|
+ off_t size = atomic_read(&data->size);
|
|
|
|
|
|
/* initialize hdl, does not need a lock because no one is sharing */
|
|
|
hdl->type = TYPE_FILE;
|
|
@@ -553,7 +553,7 @@ static int chroot_recreate (struct shim_handle * hdl)
|
|
|
return 0;
|
|
|
|
|
|
const char * uri = qstrgetstr(&hdl->uri);
|
|
|
- int len = hdl->uri.len;
|
|
|
+ size_t len = hdl->uri.len;
|
|
|
|
|
|
if (hdl->dentry) {
|
|
|
if ((ret = try_create_data(hdl->dentry, uri, len, &data)) < 0)
|
|
@@ -614,7 +614,7 @@ static int chroot_flush (struct shim_handle * hdl)
|
|
|
if (file->buf_type == FILEBUF_MAP) {
|
|
|
lock(&hdl->lock);
|
|
|
void * mapbuf = file->mapbuf;
|
|
|
- int mapsize = file->mapsize;
|
|
|
+ size_t mapsize = file->mapsize;
|
|
|
file->mapoffset = 0;
|
|
|
file->mapbuf = NULL;
|
|
|
unlock(&hdl->lock);
|
|
@@ -630,7 +630,7 @@ static int chroot_flush (struct shim_handle * hdl)
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-static inline int __map_buffer (struct shim_handle * hdl, int size)
|
|
|
+static inline int __map_buffer (struct shim_handle * hdl, size_t size)
|
|
|
{
|
|
|
struct shim_file_handle * file = &hdl->info.file;
|
|
|
|
|
@@ -649,9 +649,9 @@ static inline int __map_buffer (struct shim_handle * hdl, int size)
|
|
|
}
|
|
|
|
|
|
/* second, reallocate the buffer */
|
|
|
- uint64_t bufsize = file->mapsize ? : FILE_BUFMAP_SIZE;
|
|
|
- uint64_t mapoff = file->marker & ~(bufsize - 1);
|
|
|
- uint64_t maplen = bufsize;
|
|
|
+ size_t bufsize = file->mapsize ? : FILE_BUFMAP_SIZE;
|
|
|
+ off_t mapoff = file->marker & ~(bufsize - 1);
|
|
|
+ size_t maplen = bufsize;
|
|
|
int flags = MAP_FILE | MAP_PRIVATE | VMA_INTERNAL;
|
|
|
int prot = PROT_READ;
|
|
|
|
|
@@ -686,20 +686,20 @@ static inline int __map_buffer (struct shim_handle * hdl, int size)
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-static int map_read (struct shim_handle * hdl, void * buf, size_t count)
|
|
|
+static ssize_t map_read (struct shim_handle * hdl, void * buf, size_t count)
|
|
|
{
|
|
|
struct shim_file_handle * file = &hdl->info.file;
|
|
|
- int ret = 0;
|
|
|
+ ssize_t ret = 0;
|
|
|
lock(&hdl->lock);
|
|
|
|
|
|
struct shim_file_data * data = FILE_HANDLE_DATA(hdl);
|
|
|
- uint64_t size = atomic_read(&data->size);
|
|
|
+ off_t size = atomic_read(&data->size);
|
|
|
|
|
|
if (check_version(hdl) &&
|
|
|
file->size < size)
|
|
|
file->size = size;
|
|
|
|
|
|
- uint64_t marker = file->marker;
|
|
|
+ off_t marker = file->marker;
|
|
|
|
|
|
if (marker >= file->size) {
|
|
|
count = 0;
|
|
@@ -711,7 +711,7 @@ static int map_read (struct shim_handle * hdl, void * buf, size_t count)
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
- if (marker + count > file->size)
|
|
|
+ if ((off_t) (marker + count) > file->size)
|
|
|
count = file->size - marker;
|
|
|
|
|
|
if (count) {
|
|
@@ -724,42 +724,42 @@ out:
|
|
|
return count;
|
|
|
}
|
|
|
|
|
|
-static int map_write (struct shim_handle * hdl, const void * buf,
|
|
|
- size_t count)
|
|
|
+static ssize_t map_write (struct shim_handle * hdl, const void * buf, size_t count)
|
|
|
{
|
|
|
struct shim_file_handle * file = &hdl->info.file;
|
|
|
- int ret = 0;
|
|
|
-
|
|
|
+ ssize_t ret = 0;
|
|
|
lock(&hdl->lock);
|
|
|
|
|
|
struct shim_file_data * data = FILE_HANDLE_DATA(hdl);
|
|
|
- uint64_t marker = file->marker;
|
|
|
+ off_t marker = file->marker;
|
|
|
|
|
|
- if (file->marker + count > file->size) {
|
|
|
+ if ((off_t) (file->marker + count) > file->size) {
|
|
|
file->size = file->marker + count;
|
|
|
|
|
|
- ret = DkStreamWrite(hdl->pal_handle, file->marker, count, (void *) buf, NULL);
|
|
|
+ PAL_NUM pal_ret = DkStreamWrite(hdl->pal_handle, file->marker, count, (void *) buf, NULL);
|
|
|
|
|
|
- if (!ret) {
|
|
|
+ if (!pal_ret) {
|
|
|
ret = -PAL_ERRNO;
|
|
|
goto out;
|
|
|
}
|
|
|
|
|
|
- if (ret < count) {
|
|
|
- file->size -= count - ret;
|
|
|
+ if (pal_ret < count) {
|
|
|
+ file->size -= count - pal_ret;
|
|
|
}
|
|
|
|
|
|
if (check_version(hdl)) {
|
|
|
- uint64_t size;
|
|
|
+ off_t size;
|
|
|
do {
|
|
|
if ((size = atomic_read(&data->size)) >= file->size) {
|
|
|
file->size = size;
|
|
|
break;
|
|
|
}
|
|
|
- } while (atomic_cmpxchg(&data->size, size, file->size) != size);
|
|
|
+ } while ((off_t) atomic_cmpxchg(&data->size, size, file->size) != size);
|
|
|
}
|
|
|
|
|
|
- file->marker = marker + ret;
|
|
|
+ assert(marker + pal_ret > 0 && (ssize_t) pal_ret > 0);
|
|
|
+ file->marker = marker + pal_ret;
|
|
|
+ ret = (ssize_t) pal_ret;
|
|
|
goto out;
|
|
|
}
|
|
|
|
|
@@ -778,10 +778,9 @@ out:
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
-static int chroot_read (struct shim_handle * hdl, void * buf,
|
|
|
- size_t count)
|
|
|
+static ssize_t chroot_read (struct shim_handle * hdl, void * buf, size_t count)
|
|
|
{
|
|
|
- int ret = 0;
|
|
|
+ ssize_t ret = 0;
|
|
|
|
|
|
if (count == 0)
|
|
|
goto out;
|
|
@@ -797,6 +796,11 @@ static int chroot_read (struct shim_handle * hdl, void * buf,
|
|
|
|
|
|
struct shim_file_handle * file = &hdl->info.file;
|
|
|
|
|
|
+ if (file->type != FILE_TTY && (off_t) (file->marker + count) < 0) {
|
|
|
+ ret = -EFBIG;
|
|
|
+ goto out;
|
|
|
+ }
|
|
|
+
|
|
|
if (file->buf_type == FILEBUF_MAP) {
|
|
|
ret = map_read(hdl, buf, count);
|
|
|
if (ret != -EACCES)
|
|
@@ -808,21 +812,26 @@ static int chroot_read (struct shim_handle * hdl, void * buf,
|
|
|
lock(&hdl->lock);
|
|
|
}
|
|
|
|
|
|
- ret = DkStreamRead(hdl->pal_handle, file->marker, count, buf, NULL, 0) ? :
|
|
|
- (PAL_NATIVE_ERRNO == PAL_ERROR_ENDOFSTREAM ? 0 : -PAL_ERRNO);
|
|
|
-
|
|
|
- if (ret > 0 && file->type != FILE_TTY)
|
|
|
- file->marker += ret;
|
|
|
+ PAL_NUM pal_ret = DkStreamRead(hdl->pal_handle, file->marker, count, buf, NULL, 0);
|
|
|
+ if (pal_ret > 0) {
|
|
|
+ ret = (ssize_t) pal_ret;
|
|
|
+ assert(ret > 0);
|
|
|
+ if (file->type != FILE_TTY) {
|
|
|
+ assert(file->marker + pal_ret > 0);
|
|
|
+ file->marker += pal_ret;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ ret = PAL_NATIVE_ERRNO == PAL_ERROR_ENDOFSTREAM ? 0 : -PAL_ERRNO;
|
|
|
+ }
|
|
|
|
|
|
unlock(&hdl->lock);
|
|
|
out:
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
-static int chroot_write (struct shim_handle * hdl, const void * buf,
|
|
|
- size_t count)
|
|
|
+static ssize_t chroot_write (struct shim_handle * hdl, const void * buf, size_t count)
|
|
|
{
|
|
|
- int ret;
|
|
|
+ ssize_t ret;
|
|
|
|
|
|
if (count == 0)
|
|
|
return 0;
|
|
@@ -838,6 +847,11 @@ static int chroot_write (struct shim_handle * hdl, const void * buf,
|
|
|
|
|
|
struct shim_file_handle * file = &hdl->info.file;
|
|
|
|
|
|
+ if (file->type != FILE_TTY && (off_t) (file->marker + count) < 0) {
|
|
|
+ ret = -EFBIG;
|
|
|
+ goto out;
|
|
|
+ }
|
|
|
+
|
|
|
if (hdl->info.file.buf_type == FILEBUF_MAP) {
|
|
|
ret = map_write(hdl, buf, count);
|
|
|
if (ret != -EACCES)
|
|
@@ -849,16 +863,21 @@ static int chroot_write (struct shim_handle * hdl, const void * buf,
|
|
|
lock(&hdl->lock);
|
|
|
}
|
|
|
|
|
|
- ret = DkStreamWrite(hdl->pal_handle, file->marker, count, (void *) buf, NULL) ? :
|
|
|
- -PAL_ERRNO;
|
|
|
-
|
|
|
- if (ret > 0 && file->type != FILE_TTY)
|
|
|
- file->marker += ret;
|
|
|
+ PAL_NUM pal_ret = DkStreamWrite(hdl->pal_handle, file->marker, count, (void *) buf, NULL);
|
|
|
+ if (pal_ret > 0) {
|
|
|
+ ret = (ssize_t) pal_ret;
|
|
|
+ assert(ret > 0);
|
|
|
+ if (file->type != FILE_TTY) {
|
|
|
+ assert(file->marker + pal_ret > 0);
|
|
|
+ file->marker += pal_ret;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ ret = PAL_NATIVE_ERRNO == PAL_ERROR_ENDOFSTREAM ? 0 : -PAL_ERRNO;
|
|
|
+ }
|
|
|
|
|
|
unlock(&hdl->lock);
|
|
|
out:
|
|
|
return ret;
|
|
|
-
|
|
|
}
|
|
|
|
|
|
static int chroot_mmap (struct shim_handle * hdl, void ** addr, size_t size,
|
|
@@ -887,9 +906,9 @@ static int chroot_mmap (struct shim_handle * hdl, void ** addr, size_t size,
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-static int chroot_seek (struct shim_handle * hdl, off_t offset, int wence)
|
|
|
+static off_t chroot_seek (struct shim_handle * hdl, off_t offset, int wence)
|
|
|
{
|
|
|
- int ret = -EINVAL;
|
|
|
+ off_t ret = -EINVAL;
|
|
|
|
|
|
if (NEED_RECREATE(hdl) && (ret = chroot_recreate(hdl)) < 0)
|
|
|
return ret;
|
|
@@ -897,8 +916,8 @@ static int chroot_seek (struct shim_handle * hdl, off_t offset, int wence)
|
|
|
struct shim_file_handle * file = &hdl->info.file;
|
|
|
lock(&hdl->lock);
|
|
|
|
|
|
- int marker = file->marker;
|
|
|
- int size = file->size;
|
|
|
+ off_t marker = file->marker;
|
|
|
+ off_t size = file->size;
|
|
|
|
|
|
if (check_version(hdl)) {
|
|
|
struct shim_file_data * data = FILE_HANDLE_DATA(hdl);
|
|
@@ -931,10 +950,9 @@ out:
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
-static int chroot_truncate (struct shim_handle * hdl, uint64_t len)
|
|
|
+static int chroot_truncate (struct shim_handle * hdl, off_t len)
|
|
|
{
|
|
|
int ret = 0;
|
|
|
- uint64_t rv;
|
|
|
|
|
|
if (NEED_RECREATE(hdl) && (ret = chroot_recreate(hdl)) < 0)
|
|
|
return ret;
|
|
@@ -951,7 +969,8 @@ static int chroot_truncate (struct shim_handle * hdl, uint64_t len)
|
|
|
struct shim_file_data * data = FILE_HANDLE_DATA(hdl);
|
|
|
atomic_set(&data->size, len);
|
|
|
}
|
|
|
- rv = DkStreamSetLength(hdl->pal_handle, len);
|
|
|
+
|
|
|
+ PAL_NUM rv = DkStreamSetLength(hdl->pal_handle, len);
|
|
|
if (rv) {
|
|
|
// For an error, cast it back down to an int return code
|
|
|
ret = -((int)rv);
|
|
@@ -1139,7 +1158,7 @@ static int chroot_checkout (struct shim_handle * hdl)
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-static int chroot_checkpoint (void ** checkpoint, void * mount_data)
|
|
|
+static ssize_t chroot_checkpoint (void ** checkpoint, void * mount_data)
|
|
|
{
|
|
|
struct mount_data * mdata = mount_data;
|
|
|
|
|
@@ -1150,9 +1169,7 @@ static int chroot_checkpoint (void ** checkpoint, void * mount_data)
|
|
|
static int chroot_migrate (void * checkpoint, void ** mount_data)
|
|
|
{
|
|
|
struct mount_data * mdata = checkpoint;
|
|
|
-
|
|
|
- int alloc_len = mdata->root_uri_len +
|
|
|
- sizeof(struct mount_data) + 1;
|
|
|
+ size_t alloc_len = mdata->root_uri_len + sizeof(struct mount_data) + 1;
|
|
|
|
|
|
void * new_data = malloc(alloc_len);
|
|
|
if (!new_data)
|
|
@@ -1196,14 +1213,14 @@ static int chroot_unlink (struct shim_dentry * dir, struct shim_dentry * dent)
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-static int chroot_poll (struct shim_handle * hdl, int poll_type)
|
|
|
+static off_t chroot_poll (struct shim_handle * hdl, int poll_type)
|
|
|
{
|
|
|
int ret;
|
|
|
if (NEED_RECREATE(hdl) && (ret = chroot_recreate(hdl)) < 0)
|
|
|
return ret;
|
|
|
|
|
|
struct shim_file_data * data = FILE_HANDLE_DATA(hdl);
|
|
|
- size_t size = atomic_read(&data->size);
|
|
|
+ off_t size = atomic_read(&data->size);
|
|
|
|
|
|
if (poll_type == FS_POLL_SZ)
|
|
|
return size;
|
|
@@ -1215,7 +1232,7 @@ static int chroot_poll (struct shim_handle * hdl, int poll_type)
|
|
|
file->size < size)
|
|
|
file->size = size;
|
|
|
|
|
|
- int marker = file->marker;
|
|
|
+ off_t marker = file->marker;
|
|
|
|
|
|
if (file->buf_type == FILEBUF_MAP) {
|
|
|
ret = poll_type & FS_POLL_WR;
|