1 /*
2     OWFS -- One-Wire filesystem
3     OWHTTPD -- One-Wire Web Server
4     Written 2003 Paul H Alfille
5 	email: paul.alfille@gmail.com
6 	Released under the GPL
7 	See the header file: ow.h for full attribution
8 	1wire/iButton system from Dallas Semiconductor
9 */
10 
11 /* General Device File format:
12     This device file corresponds to a specific 1wire/iButton chip type
13 	( or a closely related family of chips )
14 
15 	The connection to the larger program is through the "device" data structure,
16 	  which must be declared in the acompanying header file.
17 
18 	The device structure holds the
19 	  family code,
20 	  name,
21 	  device type (chip, interface or pseudo)
22 	  number of properties,
23 	  list of property structures, called "filetype".
24 
25 	Each filetype structure holds the
26 	  name,
27 	  estimated length (in bytes),
28 	  aggregate structure pointer,
29 	  data format,
30 	  read function,
31 	  write funtion,
32 	  generic data pointer
33 
34 	The aggregate structure, is present for properties that several members
35 	(e.g. pages of memory or entries in a temperature log. It holds:
36 	  number of elements
37 	  whether the members are lettered or numbered
38 	  whether the elements are stored together and split, or separately and joined
39 */
40 
41 #include <config.h>
42 #include "owfs_config.h"
43 #include "ow.h"
44 
FS_r_sibling_binary(BYTE * data,size_t * size,const char * sibling,struct one_wire_query * owq)45 ZERO_OR_ERROR FS_r_sibling_binary(BYTE * data, size_t * size, const char * sibling, struct one_wire_query *owq)
46 {
47 	struct one_wire_query * owq_sibling  = OWQ_create_sibling( sibling, owq ) ;
48 	SIZE_OR_ERROR sib_status ;
49 
50 	if ( owq_sibling == NO_ONE_WIRE_QUERY ) {
51 		return -EINVAL ;
52 	}
53 
54 	if ( GOOD( OWQ_allocate_read_buffer(owq_sibling)) ) {
55 		OWQ_offset(owq_sibling) = 0 ;
56 		sib_status = FS_read_local(owq_sibling) ;
57 		if ( (sib_status >= 0) && (OWQ_length(owq_sibling) <= size[0]) ) {
58 			memset(data, 0, size[0] ) ;
59 			size[0] = OWQ_length(owq_sibling) ;
60 			memcpy( data, OWQ_buffer(owq_sibling), size[0] ) ;
61 			sib_status = 0 ;
62 		} else {
63 			sib_status = -ENOMEM ;
64 		}
65 	} else {
66 		sib_status = -ENOMEM ;
67 	}
68 	OWQ_destroy(owq_sibling) ;
69 	return sib_status ;
70 }
71 
FS_w_sibling_binary(BYTE * data,size_t size,off_t offset,const char * sibling,struct one_wire_query * owq)72 ZERO_OR_ERROR FS_w_sibling_binary(BYTE * data, size_t size, off_t offset, const char * sibling, struct one_wire_query *owq)
73 {
74 	struct one_wire_query * owq_sibling  = OWQ_create_sibling( sibling, owq ) ;
75 	SIZE_OR_ERROR write_error ;
76 
77 	if ( owq_sibling == NO_ONE_WIRE_QUERY ) {
78 		return -EINVAL ;
79 	}
80 
81 	OWQ_assign_write_buffer( (ASCII *) data, size, offset, owq_sibling) ;
82 	write_error = FS_write_local(owq_sibling) ;
83 	OWQ_destroy(owq_sibling) ;
84 	return write_error ;
85 }
86