Reading tuples in a devicetree - linux-device-driver

I am trying to find a way to use tuples in a device tree and read it from a driver.
Example:
property = <"str1" 0x01>, <"str2" 0x45>, <"str3", 0x60>, ...
I want to read the strings "str1", "str2" with their respective values i.e. 0x01 and 0x45.
Could you guys help me in confirming that this is possible? And how can I read these from my driver.

Related

AD: How can I modify the nTSecurityDescriptor/DACL/ACL from DirectoryServices.Protocols.LdapConnection?

I have tried with ModifyRequest but unfortunately I was not able to find the proper way.
I see it is very straightforward to do with DirectoryEntry but I must use the raw LdapConnection since it is the only way that allows authentication through client certificates.
If anyone has any solution or ideas, it would be great to discuss it.
I haven't really used LdapConnection as I usually use DirectoryEntry, however, I did write an article about how to work with security descriptor attributes, which might help you: Active Directory: Handling NT Security Descriptor attributes
I talked about getting the value from DirectoryEntry and DirectorySearcher. However, I suspect LdapConnnection will give you a raw byte array, in which case the section on Getting the value from DirectorySearcher may help you, since that shows how to create an ActiveDirectorySecurity object from a byte array. For example, if you have the byte array in a variable called byteArray, you can do this:
var adSecurity = new ActiveDirectorySecurity();
adSecurity.SetSecurityDescriptorBinaryForm(byteArray);
Then you can use adSecurity.GetSecurityDescriptorBinaryForm() to convert it back to a byte array before writing it back to AD.

How could I get offset of a field in flatbuffers binary file?

I am using a library, and the library requires me to provide the offset of the desired data in the file, so it can use mmap to read the data (I can't edit the code of this library but only provide the offset).
So I want to use flatbuffers to serialize my whole data because there isn't any packing and unpacking in flatbuffers, (I think) which means that it is easy to get the offset of the desired part in the binary file.
But I don't know how to get the offset. I have tried loading the binary file and calculate the offset of the pointer of the desired field, for example, the address of the root is 1111, the address of the desired field is 1222, so the offset of the field in the binary file is 1222 - 1111 = 111 (because there is no unpacking step). But in fact, the offset of the pointer is a huge negative number.
Could someone help me with this problem? Thanks in advance!
FlatBuffers is indeed very suitable for mmap. There are no offsets to be computed, since the generated code does that all for you. You should simply mmap the whole FlatBuffers file, and then use the field accessors as normal, starting from auto root = GetRoot<MyRootType>(my_mmapped_buffer). If you want to get a direct pointer to the data in a larger field such as a string or a vector, again simply use the provided API: root->my_string_field()->c_str() for example (which will point to inside your mmapped buffer).

SQLBindParameter with variable length strings

How do you use SQLBindParameter to write an array of strings to a VARCHAR field in DB2 in a memory-efficient way?
The example in the DB2 docs does this
SQLCHAR Description[NUM_PRODS][257] = {
"Aquarium-Glass-25 litres", "Aquarium-Glass-50 litres",
"Aquarium-Acrylic-25 litres", "Aquarium-Acrylic-50 litres",
"Aquarium-Stand-Small", "Aquarium-Stand-Large",
"Pump-Basic-25 litre", "Pump-Basic-50 litre",
"Pump-Deluxe-25 litre", "Pump-Deluxe-50 litre",
"Pump-Filter-(for Basic Pump)",
"Pump-Filter-(for Deluxe Pump)",
"Aquarium-Kit-Small", "Aquarium-Kit-Large",
"Gravel-Colored", "Fish-Food-Deluxe-Bulk",
"Plastic-Tubing"
};
rc = SQLBindParameter(hstmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR, 257, 0, Description, 257, NULL);
I can get that to work without issues but it isn't very efficient since each string is stored using 256 characters(+null-terminator) regardless of its actual length. More generally, if you had one very long string (say 500 chars) and every other string was one character, you would still need a two-dimensional array of size [NUM_STRINGS][500] which wastes a lot of memory.
What I would like to do is pass SQLBindParameter an array that looks like
SQLCHAR* Description[NUM_STRINGS];
where each element of the array points to a string. This would be more memory-efficient since each string only uses the space it needs but I can't figure out how to get it to work using SQLBindParameter. Any help would be appreciated.
NOTE: General answers for any DB would be great but answers that are specific to DB2 would also be helpful.
The sizes I am working with involve millions of strings with widely varying lengths so being memory-efficient is a significant factor.
I am actually using DB2 on Linux, but for this specific usecase, the only example I could find was in the DB2 for z/OS docs. It does work correctly though except for the memory usage issue.

How to get the field name from llvm's metadata

I have a question:
Given the getelementptr instruction, how can I get the field name using metadata?
e.g.
%b = getelementptr inbounds %struct.T* %7, i32 0, i32 1, !dbg !31
I want get its field name "b".
Please post the code! Thank you in advance!
If you mean you just want to get the string b from that instruction, you can do that by calling getName() on it. But that's not a reliable way to find the actual field name the gep is referring to. Finding this takes a lot more effort: basically you need to find out the type the gep's first parameter is pointing to (%struct.T), then from the gep's offsets understand which field in the struct the gep is referring to.
It's too complicated for me to write the full code for doing this here, but generally you'd want to use DI classes from DebugInfo.h - read the documentation in that file to learn how to use those classes. Specifically, to match the offsets to a type, I think you'll need to use a DICompositeType and go over all the types contained in it (getTypeArray() will probaby do that).
To get the type to start with you'll need to find the #llvm.dbg.value for the gep's first parameter (the one where the 1st argument is the metadata referring to that struct pointer) - the 3rd argument should be the metadata from the arg, and using DIVariable::getType() should help you here.
It's possible that there are simpler solutions for your question than the above, but I don't know any...
1) If there is a pointer points to a structure, whose metadata is meta,we can use the following function getFieldName to get the field name for an offset offset.
std::string getFieldName(MDNode* meta,int offset){
if(!meta){
errs()<<"The meta is NULL\n";
return "";
}
DIVariable div(meta);
DIType dit=div.getType();
DIDerivedType didt=static_cast<DIDerivedType>(dit);
DICompositeType dict=static_cast<DICompositeType>(didt.getTypeDerivedFrom());
DIArray dia=dict.getTypeArray();
assert(offset<dia.getNumElements());
DIType field=static_cast<DIType>(dia.getElement(offset));
//errs()<<"Field'name is "<<field.getName()<<"\n";
return field.getName();
}
2) If I is an GetElementPtr instruction, we can use the following code to get it's offset.
int offset=0;
ConstantInt* CI=dyn_cast<ConstantInt>(I->getOperand(2));
offset=CI->getSExtValue();

dataFrame keying using pandas groupby method

I new to pandas and trying to learn how to work with it. Im having a problem when trying to use an example I saw in one of wes videos and notebooks on my data. I have a csv file that looks like this:
filePath,vp,score
E:\Audio\7168965711_5601_4.wav,Cust_9709495726,-2
E:\Audio\7168965711_5601_4.wav,Cust_9708568031,-80
E:\Audio\7168965711_5601_4.wav,Cust_9702445777,-2
E:\Audio\7168965711_5601_4.wav,Cust_7023544759,-35
E:\Audio\7168965711_5601_4.wav,Cust_9702229339,-77
E:\Audio\7168965711_5601_4.wav,Cust_9513243289,25
E:\Audio\7168965711_5601_4.wav,Cust_2102513187,18
E:\Audio\7168965711_5601_4.wav,Cust_6625625104,-56
E:\Audio\7168965711_5601_4.wav,Cust_6073165338,-40
E:\Audio\7168965711_5601_4.wav,Cust_5105831247,-30
E:\Audio\7168965711_5601_4.wav,Cust_9513082770,-55
E:\Audio\7168965711_5601_4.wav,Cust_5753907026,-79
E:\Audio\7168965711_5601_4.wav,Cust_7403410322,11
E:\Audio\7168965711_5601_4.wav,Cust_4062144116,-70
I loading it to a data frame and the group it by "filePath" and "vp", the code is:
res = df.groupby(['filePath','vp']).size()
res.index
and the output is:
[E:\Audio\7168965711_5601_4.wav Cust_2102513187,
Cust_4062144116, Cust_5105831247,
Cust_5753907026, Cust_6073165338,
Cust_6625625104, Cust_7023544759,
Cust_7403410322, Cust_9513082770,
Cust_9513243289, Cust_9702229339,
Cust_9702445777, Cust_9708568031,
Cust_9709495726]
Now Im trying to approach the index like a dict, as i saw in examples, but when im doing
res['Cust_4062144116']
I get an error:
KeyError: 'Cust_4062144116'
I do succeed to get a result when im putting the filepath, but as i understand and saw in previouse examples i should be able to use the vp keys as well, isnt is so?
Sorry if its a trivial one, i just cant understand why it is working in one example but not in the other.
Rutger you are not correct. It is possible to "partial" index a multiIndex series. I simply did it the wrong way.
The index first level is the file name (e.g. E:\Audio\7168965711_5601_4.wav above) and the second level is vp. Meaning, for each file name i have multiple vps.
Now, this is correct:
res['E:\Audio\7168965711_5601_4.wav]
and will return:
Cust_2102513187 2
Cust_4062144116 8
....
but trying to index by the inner index (the Cust_ indexes) will fail.
You groupby two columns and therefore get a MultiIndex in return. This means you also have to slice using those to columns, not with a single index value.
Your .size() on the groupby object converts it into a Series. If you force it in a DataFrame you can use the .xs method to slice a single level:
res = pd.DataFrame(df.groupby(['filePath','vp']).size())
res.xs('Cust_4062144116', level=1)
That works. If you want to keep it as a series, boolean indexing can help, something like:
res[res.index.get_level_values(1) == 'Cust_4062144116']
The last option is a bit less readable, but sometimes also more flexibile, you could test for multiple values at once for example:
res[res.index.get_level_values(1).isin(['Cust_4062144116', 'Cust_6073165338'])]