Is it possible to decode filenames from event tracing? - linux

I am currently debugging performance using Linux ftrace and I noticed a few events of the following form appearing in the trace.
sys_open(filename: 42130b, flags: 441, mode: 1b6)
Is it possible to decode this filename into a hierarchical name in the filesystem?
Alternatively, is there a configuration parameter that would automatically show the decoded versions of the filename?

Related

caret ^ is converting to some special symbol

I'm transferring the file which has the content like below from mainframe system to a Unix instance. I've a delimiter in the file as ^&*. I'm sending the same in mainframe but when we receive the file in the unix we're receiving as Ø&*.
I'm using connect direct to transfer the file from one system to another.
File Type: Flat File, File transfer: CD (Connect Direct)
file content
H^&*20220407^&*160009^&*2006
T^&*1
But when I receive the file in the unix server I can the file content is changed. Mainly ^ is converted to Ø.
HØ&*20220407Ø&*160009Ø&*2006
TØ&*1
This is most surely a code page problem.
The data in the file on the mainframe is (most probably) in some EBCDIC code page. ConnectDirect is doing a code page tranformation when sending the file to that UNIX system. This is what the XLATE(YES) means.
However, there is some default code page "from"-"to" pair configured, which is being used with XLATE(YES). But this probably is not the correct pair. You need to
find out what EBCDIC code page the data on the mainframe is encoded in. Is it IBM-037, IBM-1047, IBM-500, IBM-273, etc. There are many.
find out what code page the data shall be in on the UNIX side: UTF-8, ISO8859-1, 437, etc. There are many.
make sure ConnectDirect will transform using the correct source and target code pages.
Ask your ConnectDirect support people to help you with this.

fs.createReadStream(path[, options]) - What are those options?

According to Node's v6.10.2 API - options is an object or string with the following defaults:
{
flags: 'r',
encoding: null,
fd: null,
mode: 0o666,
autoClose: true
}
But I've seen highWaterMark property being used to set Buffer size. But API didn't put it on the option. So I'm wondering is there more options that API didn't write on the document. If so where I can find the full option list?
And API didn't talk about flags, So I would like to know what flags dose in this case and what's the difference between
flags: r
flags: w
flags: r+
I tried to find those answer but I didn't find any helpful information. I would really appreciate if somebody help me to understand this topic.
Thanks.
At the time of writing this answer the explanation in streams context still seem to be missing from the documentation, so it's unclear as to what options there can be for a readable stream. As far as I can tell the flags are most likely the same flags as specified for other fs operations like fs.open.
From the docs:
https://nodejs.org/api/fs.html#fs_fs_open_path_flags_mode_callback
r - Open file for reading. An exception occurs if the file does not exist.
r+ - Open file for reading and writing. An exception occurs if the file does not exist.
rs+ - Open file for reading and writing in synchronous mode. Instructs the operating system to bypass the local file system cache.
This is primarily useful for opening files on NFS mounts as it allows skipping the potentially stale local cache. It has a very real impact on I/O performance so using this flag is not recommended unless it is needed.
w - Open file for writing. The file is created (if it does not exist) or truncated (if it exists).
wx - Like 'w' but fails if path exists.
w+ - Open file for reading and writing. The file is created (if it does not exist) or truncated (if it exists).
wx+ - Like 'w+' but fails if path exists.
a - Open file for appending. The file is created if it does not exist.
ax - Like 'a' but fails if path exists.
a+ - Open file for reading and appending. The file is created if it does not exist.
ax+ - Like 'a+' but fails if path exists.

Backtrace with function-name,file-name and line-no information

We have an application software running on Suse linux. What I want is that whenever there is a crash/fault in the software, a backtrace is generated with call stack information for the current thread(which faults).
We are currently using "backtrace()" and "backtrace_symbols_fd()" to try to get the trace but there is not much useful information. It does not give function names, line no. and filename.
Therefore, I starting looking for alternate options to use and found "libunwind". Wrote a small function to get backtrace and it does print function name with other register values(ip,sp). But still I can not get the filename and linenumbers. Is there a way I can programmatically do that ? What happens if I strip my binary file? Can I still get the filename/lineno info ?

How to zip list of files + append custom string to each file on Linux on the fly

I need a Linux solution as I've figured out a way to do this on Windows by modifying a C# implementation but I am not sure where to start on Linux. I would like to be able to do the following from the command line:
Run a command providing a list of files to be zipped, an output path, and a custom string
The custom string should be automatically appended to the end of the internal data of each file but not written to the original file. I want it all handled in-stream / in memory.
The data stream is fed to the zip utility and zip file is created at the output location with 0 compression (store only)
Explanation: this custom string is used as a watermark to uniquely identify the files in the zip.

Proper way to differentiate pst and dbx files in bash shell

I want to identify the file-format of the input file given to my shell script - whether a .pst or a .dbx file. I checked How to check the extension of a filename in a bash script?. That one deals with txt files and two methods are given there -
check if the extension is txt
check if the mime type is application/text etc.
I tried file -ib <filename> on a .pst and a .dbx file and it showed application/octet-stream for both. However, if I just do file <filename>, then I get
this for the dbx file -
file1.dbx: Microsoft Outlook Express DBX File Message database
and this for the pst file -
file2.pst: Microsoft Outlook binary email folder (Outlook >=2003)
So, my questions are -
is it better to use mime type detection everytime when the output can be anything and we need a proper check?
How to apply mime type check in this case - both returning "application/octet-stream"?
Update
I didn't want to do an extension based detection because it seems we just can't be sure on a Unix system, that a .dbx file truly is a dbx file. Since file <filename> returns a line which contains the correct information of the file (e.g. "Microsoft Outlook Express DBX File Message database"). That means the file command is able to identify the file type properly. Then why does it not get the correct information in file -ib <filename> command?
Will parsing the string output of file <filename> be fine? Is it advisable assuming I only need to identify a narrow set of data storage files of outlook family (MS Outlook Express, MS Office Outlook 2003,2007,2010 etc.). A small text identifier like application/dbx which could be compared would be all I need.
The file command relies on having a file type detection database which includes rules for the file types that you expect to encounter. It may not be possible to recognize these file types if the file content doesn't have a unique code near the beginning of the file.
Note that the -i option to emit mime types actually uses a separate "magic" numbers file to recognize file types rather than translating long descriptions to file types. It is quite possible for these two databases to be out of sync. If your application really needs to recognize these two file types I suggest that you look at the Linux source code for "file" to see how they recognize them and then code this recognition algorithm right into your app.
If you want to do the equivalent of DOS file type detection, then strip the extension off the filename (everything after the last period) and look up that string in your own table where you define the types that you need.

Resources