storageproxyd: Added support for getting max size of file
This handles the STORAGE_FILE_GET_MAX_SIZE. The new behavior will return a max size of 0x10000000000 (former default value in Trusty) for a regular file and the partition size for a block device. Test: N/A Bug: 247003431 Change-Id: Ib8b8504b63496d64487cf2f96a1c0758bfafdd97 Signed-off-by: Jay Monkman <jtmjtmjtmjtmjtmjtmjtm@gmail.com>
This commit is contained in:
parent
20d45cc9ce
commit
2ad61bf01b
|
@ -136,6 +136,10 @@ static int handle_req(struct storage_msg* msg, const void* req, size_t req_len)
|
|||
rc = storage_file_set_size(msg, req, req_len);
|
||||
break;
|
||||
|
||||
case STORAGE_FILE_GET_MAX_SIZE:
|
||||
rc = storage_file_get_max_size(msg, req, req_len);
|
||||
break;
|
||||
|
||||
case STORAGE_RPMB_SEND:
|
||||
rc = rpmb_send(msg, req, req_len);
|
||||
break;
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include <fcntl.h>
|
||||
#include <inttypes.h>
|
||||
#include <libgen.h>
|
||||
#include <linux/fs.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
@ -36,6 +37,9 @@
|
|||
|
||||
#define ALTERNATE_DATA_DIR "alternate/"
|
||||
|
||||
/* Maximum file size for filesystem backed storage (i.e. not block dev backed storage) */
|
||||
#define MAX_FILE_SIZE (0x10000000000)
|
||||
|
||||
enum sync_state {
|
||||
SS_UNUSED = -1,
|
||||
SS_CLEAN = 0,
|
||||
|
@ -549,6 +553,45 @@ err_response:
|
|||
return ipc_respond(msg, NULL, 0);
|
||||
}
|
||||
|
||||
int storage_file_get_max_size(struct storage_msg* msg, const void* r, size_t req_len) {
|
||||
const struct storage_file_get_max_size_req* req = r;
|
||||
struct storage_file_get_max_size_resp resp = {0};
|
||||
uint64_t max_size = 0;
|
||||
|
||||
if (req_len != sizeof(*req)) {
|
||||
ALOGE("%s: invalid request length (%zd != %zd)\n", __func__, req_len, sizeof(*req));
|
||||
msg->result = STORAGE_ERR_NOT_VALID;
|
||||
goto err_response;
|
||||
}
|
||||
|
||||
struct stat stat;
|
||||
int fd = lookup_fd(req->handle, false);
|
||||
int rc = fstat(fd, &stat);
|
||||
if (rc < 0) {
|
||||
ALOGE("%s: error stat'ing file (fd=%d): %s\n", __func__, fd, strerror(errno));
|
||||
goto err_response;
|
||||
}
|
||||
|
||||
if ((stat.st_mode & S_IFMT) == S_IFBLK) {
|
||||
rc = ioctl(fd, BLKGETSIZE64, &max_size);
|
||||
if (rc < 0) {
|
||||
rc = errno;
|
||||
ALOGE("%s: error calling ioctl on file (fd=%d): %s\n", __func__, fd, strerror(errno));
|
||||
msg->result = translate_errno(rc);
|
||||
goto err_response;
|
||||
}
|
||||
} else {
|
||||
max_size = MAX_FILE_SIZE;
|
||||
}
|
||||
|
||||
resp.max_size = max_size;
|
||||
msg->result = STORAGE_NO_ERROR;
|
||||
return ipc_respond(msg, &resp, sizeof(resp));
|
||||
|
||||
err_response:
|
||||
return ipc_respond(msg, NULL, 0);
|
||||
}
|
||||
|
||||
int storage_init(const char *dirname)
|
||||
{
|
||||
/* If there is an active DSU image, use the alternate fs mode. */
|
||||
|
|
|
@ -39,6 +39,8 @@ int storage_file_get_size(struct storage_msg *msg,
|
|||
int storage_file_set_size(struct storage_msg *msg,
|
||||
const void *req, size_t req_len);
|
||||
|
||||
int storage_file_get_max_size(struct storage_msg* msg, const void* req, size_t req_len);
|
||||
|
||||
int storage_init(const char *dirname);
|
||||
|
||||
int storage_sync_checkpoint(void);
|
||||
|
|
Loading…
Reference in New Issue