All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] sim: allow partial reads of tranparent files
@ 2010-07-27 23:12 Kristen Carlson Accardi
  0 siblings, 0 replies; 3+ messages in thread
From: Kristen Carlson Accardi @ 2010-07-27 23:12 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 3170 bytes --]

Implement ofono_sim_read_bytes().  For transparent files, this
will read num_bytes from a specified offset of a given fileid.
---
 include/sim.h |    5 +++++
 src/sim.c     |   29 ++++++++++++++++++++++++++---
 2 files changed, 31 insertions(+), 3 deletions(-)

diff --git a/include/sim.h b/include/sim.h
index 36a99b9..15cd6b8 100644
--- a/include/sim.h
+++ b/include/sim.h
@@ -198,6 +198,11 @@ int ofono_sim_read(struct ofono_sim *sim, int id,
 			enum ofono_sim_file_structure expected,
 			ofono_sim_file_read_cb_t cb, void *data);
 
+int ofono_sim_read_bytes(struct ofono_sim *sim, int id,
+			enum ofono_sim_file_structure expected,
+			unsigned short offset, int num_bytes,
+			ofono_sim_file_read_cb_t cb, void *data);
+
 int ofono_sim_write(struct ofono_sim *sim, int id,
 			ofono_sim_file_write_cb_t cb,
 			enum ofono_sim_file_structure structure, int record,
diff --git a/src/sim.c b/src/sim.c
index 2514e7b..cd1cbf5 100644
--- a/src/sim.c
+++ b/src/sim.c
@@ -60,6 +60,8 @@ struct sim_file_op {
 	int id;
 	gboolean cache;
 	enum ofono_sim_file_structure structure;
+	unsigned short offset;
+	int num_bytes;
 	int length;
 	int record_length;
 	int current;
@@ -1434,7 +1436,7 @@ static void sim_op_retrieve_cb(const struct ofono_error *error,
 		return;
 	}
 
-	cb(1, op->length, op->current, data, op->record_length, op->userdata);
+	cb(1, len, op->current, data, op->record_length, op->userdata);
 
 	if (op->cache && imsi) {
 		char *path = g_strdup_printf(SIM_CACHE_PATH,
@@ -1472,7 +1474,16 @@ static gboolean sim_op_retrieve_next(gpointer user)
 			return FALSE;
 		}
 
-		sim->driver->read_file_transparent(sim, op->id, 0, op->length,
+		if (op->offset + op->num_bytes > op->length) {
+			sim_op_error(sim);
+			return FALSE;
+		}
+
+		if (op->num_bytes < 0)
+			op->num_bytes = op->length;
+
+		sim->driver->read_file_transparent(sim, op->id, op->offset,
+						op->num_bytes,
 						sim_op_retrieve_cb, sim);
 		break;
 	case OFONO_SIM_FILE_STRUCTURE_FIXED:
@@ -1723,8 +1734,9 @@ static gboolean sim_op_next(gpointer user_data)
 	return FALSE;
 }
 
-int ofono_sim_read(struct ofono_sim *sim, int id,
+int ofono_sim_read_bytes(struct ofono_sim *sim, int id,
 			enum ofono_sim_file_structure expected_type,
+			unsigned short offset, int num_bytes,
 			ofono_sim_file_read_cb_t cb, void *data)
 {
 	struct sim_file_op *op;
@@ -1755,6 +1767,10 @@ int ofono_sim_read(struct ofono_sim *sim, int id,
 	op->cb = cb;
 	op->userdata = data;
 	op->is_read = TRUE;
+	op->offset = offset;
+
+	if (num_bytes > 0)
+		op->num_bytes = num_bytes;
 
 	g_queue_push_tail(sim->simop_q, op);
 
@@ -1764,6 +1780,13 @@ int ofono_sim_read(struct ofono_sim *sim, int id,
 	return 0;
 }
 
+int ofono_sim_read(struct ofono_sim *sim, int id,
+			enum ofono_sim_file_structure expected_type,
+			ofono_sim_file_read_cb_t cb, void *data)
+{
+	return ofono_sim_read_bytes(sim, id, expected_type, 0, -1, cb, data);
+}
+
 int ofono_sim_write(struct ofono_sim *sim, int id,
 			ofono_sim_file_write_cb_t cb,
 			enum ofono_sim_file_structure structure, int record,
-- 
1.7.1.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH] sim: allow partial reads of tranparent files
@ 2010-07-27 23:22 Kristen Carlson Accardi
  2010-08-02 17:23 ` Denis Kenzior
  0 siblings, 1 reply; 3+ messages in thread
From: Kristen Carlson Accardi @ 2010-07-27 23:22 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 3141 bytes --]

Implement ofono_sim_read_bytes().  For transparent files, this
will read num_bytes from a specified offset of a given fileid.
---
 include/sim.h |    5 +++++
 src/sim.c     |   27 ++++++++++++++++++++++++---
 2 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/include/sim.h b/include/sim.h
index 36a99b9..15cd6b8 100644
--- a/include/sim.h
+++ b/include/sim.h
@@ -198,6 +198,11 @@ int ofono_sim_read(struct ofono_sim *sim, int id,
 			enum ofono_sim_file_structure expected,
 			ofono_sim_file_read_cb_t cb, void *data);
 
+int ofono_sim_read_bytes(struct ofono_sim *sim, int id,
+			enum ofono_sim_file_structure expected,
+			unsigned short offset, int num_bytes,
+			ofono_sim_file_read_cb_t cb, void *data);
+
 int ofono_sim_write(struct ofono_sim *sim, int id,
 			ofono_sim_file_write_cb_t cb,
 			enum ofono_sim_file_structure structure, int record,
diff --git a/src/sim.c b/src/sim.c
index 2514e7b..63dea19 100644
--- a/src/sim.c
+++ b/src/sim.c
@@ -60,6 +60,8 @@ struct sim_file_op {
 	int id;
 	gboolean cache;
 	enum ofono_sim_file_structure structure;
+	unsigned short offset;
+	int num_bytes;
 	int length;
 	int record_length;
 	int current;
@@ -1434,7 +1436,7 @@ static void sim_op_retrieve_cb(const struct ofono_error *error,
 		return;
 	}
 
-	cb(1, op->length, op->current, data, op->record_length, op->userdata);
+	cb(1, len, op->current, data, op->record_length, op->userdata);
 
 	if (op->cache && imsi) {
 		char *path = g_strdup_printf(SIM_CACHE_PATH,
@@ -1472,7 +1474,16 @@ static gboolean sim_op_retrieve_next(gpointer user)
 			return FALSE;
 		}
 
-		sim->driver->read_file_transparent(sim, op->id, 0, op->length,
+		if (op->num_bytes < 0)
+			op->num_bytes = op->length;
+
+		if (op->offset + op->num_bytes > op->length) {
+			sim_op_error(sim);
+			return FALSE;
+		}
+
+		sim->driver->read_file_transparent(sim, op->id, op->offset,
+						op->num_bytes,
 						sim_op_retrieve_cb, sim);
 		break;
 	case OFONO_SIM_FILE_STRUCTURE_FIXED:
@@ -1723,8 +1734,9 @@ static gboolean sim_op_next(gpointer user_data)
 	return FALSE;
 }
 
-int ofono_sim_read(struct ofono_sim *sim, int id,
+int ofono_sim_read_bytes(struct ofono_sim *sim, int id,
 			enum ofono_sim_file_structure expected_type,
+			unsigned short offset, int num_bytes,
 			ofono_sim_file_read_cb_t cb, void *data)
 {
 	struct sim_file_op *op;
@@ -1755,6 +1767,8 @@ int ofono_sim_read(struct ofono_sim *sim, int id,
 	op->cb = cb;
 	op->userdata = data;
 	op->is_read = TRUE;
+	op->offset = offset;
+	op->num_bytes = num_bytes;
 
 	g_queue_push_tail(sim->simop_q, op);
 
@@ -1764,6 +1778,13 @@ int ofono_sim_read(struct ofono_sim *sim, int id,
 	return 0;
 }
 
+int ofono_sim_read(struct ofono_sim *sim, int id,
+			enum ofono_sim_file_structure expected_type,
+			ofono_sim_file_read_cb_t cb, void *data)
+{
+	return ofono_sim_read_bytes(sim, id, expected_type, 0, -1, cb, data);
+}
+
 int ofono_sim_write(struct ofono_sim *sim, int id,
 			ofono_sim_file_write_cb_t cb,
 			enum ofono_sim_file_structure structure, int record,
-- 
1.7.1.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] sim: allow partial reads of tranparent files
  2010-07-27 23:22 [PATCH] sim: allow partial reads of tranparent files Kristen Carlson Accardi
@ 2010-08-02 17:23 ` Denis Kenzior
  0 siblings, 0 replies; 3+ messages in thread
From: Denis Kenzior @ 2010-08-02 17:23 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 3088 bytes --]

Hi Kristen,

On 07/27/2010 06:22 PM, Kristen Carlson Accardi wrote:
> Implement ofono_sim_read_bytes().  For transparent files, this
> will read num_bytes from a specified offset of a given fileid.
> ---
>  include/sim.h |    5 +++++
>  src/sim.c     |   27 ++++++++++++++++++++++++---
>  2 files changed, 29 insertions(+), 3 deletions(-)
> 
> diff --git a/include/sim.h b/include/sim.h
> index 36a99b9..15cd6b8 100644
> --- a/include/sim.h
> +++ b/include/sim.h
> @@ -198,6 +198,11 @@ int ofono_sim_read(struct ofono_sim *sim, int id,
>  			enum ofono_sim_file_structure expected,
>  			ofono_sim_file_read_cb_t cb, void *data);
>  
> +int ofono_sim_read_bytes(struct ofono_sim *sim, int id,
> +			enum ofono_sim_file_structure expected,
> +			unsigned short offset, int num_bytes,
> +			ofono_sim_file_read_cb_t cb, void *data);
> +

The read_bytes function has a slightly different audience than the
sim_read function.  Namely, ofono_sim_read stats the file first for
structure / length / record size and then reads it.

For EFiidf files you will need to initiate multiple reads, so 'stat'ing
the file first every time is inefficient.  Maybe a more low-level
semantic is in order, i.e one that attempts to read directly.

>  int ofono_sim_write(struct ofono_sim *sim, int id,
>  			ofono_sim_file_write_cb_t cb,
>  			enum ofono_sim_file_structure structure, int record,
> diff --git a/src/sim.c b/src/sim.c
> index 2514e7b..63dea19 100644
> --- a/src/sim.c
> +++ b/src/sim.c
> @@ -60,6 +60,8 @@ struct sim_file_op {
>  	int id;
>  	gboolean cache;
>  	enum ofono_sim_file_structure structure;
> +	unsigned short offset;
> +	int num_bytes;
>  	int length;
>  	int record_length;
>  	int current;
> @@ -1434,7 +1436,7 @@ static void sim_op_retrieve_cb(const struct ofono_error *error,
>  		return;
>  	}
>  
> -	cb(1, op->length, op->current, data, op->record_length, op->userdata);
> +	cb(1, len, op->current, data, op->record_length, op->userdata);
>  
>  	if (op->cache && imsi) {
>  		char *path = g_strdup_printf(SIM_CACHE_PATH,
> @@ -1472,7 +1474,16 @@ static gboolean sim_op_retrieve_next(gpointer user)
>  			return FALSE;
>  		}
>  
> -		sim->driver->read_file_transparent(sim, op->id, 0, op->length,
> +		if (op->num_bytes < 0)
> +			op->num_bytes = op->length;
> +
> +		if (op->offset + op->num_bytes > op->length) {
> +			sim_op_error(sim);
> +			return FALSE;
> +		}
> +
> +		sim->driver->read_file_transparent(sim, op->id, op->offset,
> +						op->num_bytes,
>  						sim_op_retrieve_cb, sim);

Unfortunately you cannot read large files in one go.  You must separate
the reads into 256 byte chunks.  See 3GPP 11.11 for more details.

My rough thinking is as follows:

- Read EFimg
- Cleverly read chunks of EFiidf 1..n, caching the needed chunks and
minimizing the # of reads.  Perhaps using some sort of a bitmap of 256
byte chunks.
- Generate icons and write to a cache on the filesystem
- Free memory resources
- Use memmap to return icons to the user in GetIcon

Regards,
-Denis

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-08-02 17:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-07-27 23:22 [PATCH] sim: allow partial reads of tranparent files Kristen Carlson Accardi
2010-08-02 17:23 ` Denis Kenzior
  -- strict thread matches above, loose matches on Subject: below --
2010-07-27 23:12 Kristen Carlson Accardi

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.