On Friday 23 September 2005 10:26, Kern Sibbald wrote: > On Friday 23 September 2005 15:53, Ruben Lang wrote: > > Hi bacula-users, > > > > i'm currently working on a little project where i have to get the > > "File-Attributes" from the "File.LStat" field. I've already done some > > research, but i could'nt find out how to read the contents of this field. > > All i know is, that the file-attributes are received via stat() and > > somehow put together with some additional attributes/information and > > then base64 encoded. > > For example the following content of a record (taken from the bacula-db > > i'm using): > > > > gR DwABPN EHA C Pn Pn A G BAA A BC3sbr BC3moS BC3sbr A A C > > The encoding/decoding of the "attributes" or stat packet are done in: > <bacula-source>/src/findlib/attribs.c > > The base64 routines are Bacula home-brew, if I remember right, so you will > need to look at that code too: <bacula-source>/src/lib/base64.c > Unfortunately, when I wrote it, I didn't realize there was an RFC on base64 > so my choice of the two special characters was different from the > "standard". This will cause non-C/C++ programmers a bit of extra work :-(
Perl programmers too. Luckily, base64 is very straightforward. :) --- start --- # Brian McDonald, 2005 my $base64_digits = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; my $base64_values = { }; my $val = 0; foreach my $letter ( split(//, $base64_digits ) ) { $base64_values->{ $letter } = $val++; } sub decode_stats { my $stats = shift; my $hash = { }; # The stats data is in base64 format. Yuck! - I mean Yay! # Each value is base64 encoded incorrectly, a deficiency we have # to correct here. In particular, some values are encoded with a single # base64 character. This results in a 6 bit value, and you have to # understand how bacula padded and manipulated those values before storing # them in the DB. # the fields are, in order: my @fields = qw( st_dev st_ino st_mode st_nlink st_uid st_gid st_rdev st_size st_blksize st_blocks st_atime st_mtime st_ctime LinkFI st_flags data ); # Decoding this mess is based on reading src/lib/base64.c in bacula, in # particular the to_base64 function, which is how these got in the DB in # the first place. my $field_idx = 0; foreach my $element ( split( /\s+/, $stats ) ) { my $result = 0; for ( my $i = 0; $i<length($element); $i++ ) { if ($i) { $result <<= 6; } my $r = substr($element, $i, 1 ); $result += $base64_values->{$r}; } $hash->{ $fields[$field_idx] } = $result; $field_idx++; } return $hash; } --- end --- Sorry about the slightly derogatory comments. It was late when I wrote it. It does work, though. Just drop this in your perl script and call it with the string you get out of the database. It returns the stat structure as a hash reference. Brian > > > As i know the attributes are separated by spaces, so how to map the > > upper string to (which) attributes. Since there are also > > "Extended-Attributes", "Link" and so on, refering to the "Unix File > > Attributes" - section of the developers manual. > > In the above string there are 16 space separated, base64 encoded strings > > (am i right ?) but stat() only returns 13 attributes. > > > > I'm working directly on the database, not using a software (trying to > > write a script returning me the size of a given file). > > > > Would be great if someone can provide useful hints. > > Thanks in advance, > > > > R. Lang > > > > > > ------------------------------------------------------- > > SF.Net email is sponsored by: > > Tame your development challenges with Apache's Geronimo App Server. > > Download it for free - -and be entered to win a 42" plasma tv or your > > very own Sony(tm)PSP. Click here to play: > > http://sourceforge.net/geronimo.php > > _______________________________________________ > > Bacula-users mailing list > > Bacula-users@lists.sourceforge.net > > https://lists.sourceforge.net/lists/listinfo/bacula-users -- Brian McDonald Never confuse being nice with being a tool. ------------------------------------------------------- SF.Net email is sponsored by: Tame your development challenges with Apache's Geronimo App Server. Download it for free - -and be entered to win a 42" plasma tv or your very own Sony(tm)PSP. Click here to play: http://sourceforge.net/geronimo.php _______________________________________________ Bacula-users mailing list Bacula-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/bacula-users