diff options
| author | Android (Google) Code Review <android-gerrit@google.com> | 2009-06-02 05:28:47 -0700 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2009-06-02 05:28:47 -0700 |
| commit | 3f6272056275a00c30c07394d63bbe81cc9c5eba (patch) | |
| tree | dab44b322f4756f9481c5ec699158c7be67ca4a1 | |
| parent | 8b48cf61704bbd1cd6e672fe73d8491f8984b484 (diff) | |
| parent | 7be52b1a0e052635b361f9d8c186adbbcc981b7e (diff) | |
| download | system_core-3f6272056275a00c30c07394d63bbe81cc9c5eba.tar.gz system_core-3f6272056275a00c30c07394d63bbe81cc9c5eba.tar.bz2 system_core-3f6272056275a00c30c07394d63bbe81cc9c5eba.zip | |
Merge change 2875 into donut
* changes:
Added ashmem_get_size_region() function.
| -rw-r--r-- | include/cutils/ashmem.h | 1 | ||||
| -rw-r--r-- | libcutils/ashmem-dev.c | 5 | ||||
| -rw-r--r-- | libcutils/ashmem-host.c | 20 |
3 files changed, 26 insertions, 0 deletions
diff --git a/include/cutils/ashmem.h b/include/cutils/ashmem.h index fd71352e..0683bf25 100644 --- a/include/cutils/ashmem.h +++ b/include/cutils/ashmem.h @@ -18,6 +18,7 @@ int ashmem_create_region(const char *name, size_t size); int ashmem_set_prot_region(int fd, int prot); int ashmem_pin_region(int fd, size_t offset, size_t len); int ashmem_unpin_region(int fd, size_t offset, size_t len); +int ashmem_get_size_region(int fd); #ifdef __cplusplus } diff --git a/libcutils/ashmem-dev.c b/libcutils/ashmem-dev.c index 5e158af7..8b71f87d 100644 --- a/libcutils/ashmem-dev.c +++ b/libcutils/ashmem-dev.c @@ -83,3 +83,8 @@ int ashmem_unpin_region(int fd, size_t offset, size_t len) struct ashmem_pin pin = { offset, len }; return ioctl(fd, ASHMEM_UNPIN, &pin); } + +int ashmem_get_size_region(int fd) +{ + return ioctl(fd, ASHMEM_GET_SIZE, NULL); +} diff --git a/libcutils/ashmem-host.c b/libcutils/ashmem-host.c index dbb52bc4..f03e1303 100644 --- a/libcutils/ashmem-host.c +++ b/libcutils/ashmem-host.c @@ -92,3 +92,23 @@ int ashmem_unpin_region(int fd, size_t offset, size_t len) { return ASHMEM_IS_UNPINNED; } + +int ashmem_get_size_region(int fd) +{ + struct stat buf; + int result; + + result = fstat(fd, &buf); + if (result == -1) { + return -1; + } + + // Check if this is an "ashmem" region. + // TODO: This is very hacky, and can easily break. We need some reliable indicator. + if (!(buf.st_nlink == 0 && S_ISREG(buf.st_mode))) { + errno = ENOTTY; + return -1; + } + + return (int)buf.st_size; // TODO: care about overflow (> 2GB file)? +} |
