Minix 3.2.1 Modifying do_mkdir to print the absolute file path - minix

I want to modify do_mkdir in /usr/src/servers/vfs/open.c in order to when i try to use mkdir command to print in terminal the absolute path to the directory i created.How can i achive that ? Any ideas?
I tried the getcwd but i got a undefined reference error .

The full path is in the variable fullpath defined in the beginning of the do_mkdir function. Also the access rights are on the variables listed in the code below
printf("New dir -> %s, ", fullpath);
printf( (bits & S_IRUSR) ? "r" : "-");
printf( (bits & S_IWUSR) ? "w" : "-");
printf( (bits & S_IXUSR) ? "x" : "-");
printf( (bits & S_IRGRP) ? "r" : "-");
printf( (bits & S_IWGRP) ? "w" : "-");
printf( (bits & S_IXGRP) ? "x" : "-");
printf( (bits & S_IROTH) ? "r" : "-");
printf( (bits & S_IWOTH) ? "w" : "-");
printf( (bits & S_IXOTH) ? "x\n" : "-\n");
Put this code in the end of the do_mkdir just before the unlock_vnode(vp); line and you are done!
Έχεις κάνει τα υπόλοιπα ερωτήματα??

I believe that simply printing the fullpath variable doesn't work.
Actually, I tested this out and it seems to print only the name of the directory created. Any clues?

Related

What's a way to retrive the "path" portion of dxlHere() and go up two dirs?

We are regularly setting up new DOORS installations on standalone networks, and each of these networks use slightly different drive mappings and installation directories. We have a set of DXL scripts that we copy over to each network that uses DOORS, but these DXL scripts reference some Microsoft Word templates that are used as the basis for custom-developed module export scripts.
We no longer have a DXL expert in-house, and I'm trying to make the scripts more portable so that they no
longer contain hard-coded file paths. Because we copy all of the templates and DXL files in a pre-defined directory structure, I can use the dxlHere() function to figure out the execution path of the DXL script, which would print something like this:
<C:\path\to\include\file\includeFile.inc:123>
<C:\path\to\include\file\includeFile.inc:321>
<Line:2>
<Line:5>
<Line:8>
What I'd like to do is extract everything before file\includeFile.inc:123>, excluding the starting <. Then I want to append templates\template.dotx.
For example, the final result would be:
C:\path\to\inclue\template.dotx
Are there any built-in DXL functions to handle string manipulation like this? Is regex the way to go? If so, what regexp would be appropriate to handle this?
Thanks!
I got this... kind of working.
dxlHere is something I don't work with much, but this seems to work- as long as it's saved to a an actual dxl or inc file (i.e. not just run from the editor)
string s = dxlHere()
string s2 = null
string s3 = null
Regexp r = regexp2 ( "\\..*:.*> $" )
Regexp r2 = regexp2 ( "/" )
if ( r s ) {
s2 = s[ 1 : ( ( start ( 0 ) ) - 1 ) ]
s3 = s[ 1 : ( ( start ( 0 ) ) - 1 ) ]
int x = 0
while ( r2 s2 ) {
x++
s2 = s2[ ( ( start ( 0 ) ) + 1 ) : ]
}
int z = 0
for ( y = 0; y <= length( s3 ); y++ ){
if ( s3[y] == '/' ) {
z++
if ( z == ( x - 2 ) ) {
s = s3[ 0 : y ]
break
}
}
}
}
print s
So we're doing a single regexp to check if we have a valid 'location', then running through it to find ever '/' character, then leaving off the last 2 of them.
Hope this helps!

Foreach command ,initiation error

This is the list i have
set session_list [list ../../TIMING_ANALYSIS_CRPR/FUNC_ss28_0.85V_0.95V_0.85V_125C_RCmax/reports.15_03_10-22/SAVED_SESSION
../../TIMING_ANALYSIS_CRPR/FUNC_ff28_0.85V_0.95V_0.85V_m40C_Cmin/reports.15_03_10-22/SAVED_SESSION]
foreach j $session_list {
set x [string trimleft $j "../../TIMING_ANALYSIS_CRPR/ "]
}
foreach item $x {
puts "create_scenario -name $item "
}
so what i want is my output to the list be given out as :
create_scenario -name FUNC_ss28_0.85V_0.95V_0.85V_125C_RCmax/reports.15_03_10-22/SAVED_SESSION
create_scenario -name FUNC_ff28_0.85V_0.95V_0.85V_m40C_Cmin/reports.15_03_10-22/SAVED_SESSION
IN the top stated code ,it does not read the first foreach command and does not display the whole list
You are setting the value of x in each loop which will cause the x value to get overwritten.
You have to use lappend command
foreach j $session_list {
lappend x [string trimleft $j "../../TIMING_ANALYSIS_CRPR/ "]
}
foreach item $x {
puts "create_scenario -name $item "
}
Output :
create_scenario -name FUNC_ss28_0.85V_0.95V_0.85V_125C_RCmax/reports.15_03_10-22/SAVED_SESSION
create_scenario -name FUNC_ff28_0.85V_0.95V_0.85V_m40C_Cmin/reports.15_03_10-22/SAVED_SESSION
Reference : lappend
[string trimleft] doesn't do what you think it does. The line:
string trimleft $j "../../TIMING_ANALYSIS_CRPR/ "
basically means: remove the characters . and / and T and I and M and N and G and _ and A and N and L and Y and S and C and R and P and (single space) form the left of the string.
What you want instead is regsub:
regsub {^../../TIMING_ANALYSIS_CRPR/} $j ""

Lua gsub second instance

I'm using
local mystring = 'Thats a really nice house.'
string.gsub(mystring,"% ", "/",1)
to replace the first white space character with an slash.
But how to replace only the second occurrence of the white space?
You can use a function as replacement value in string.gsub and count the matches yourself:
local mystring = "Thats a really nice house."
local cnt = 0
print( string.gsub( mystring, " ", function( m )
cnt = cnt + 1
if cnt == 2 then
return "/"
end
end ) )
Try string.gsub(mystring,"(.- .-) ", "%1/",1).
You can replace the first instance with something else (assuming the replacement is not present in the string itself, which you can check), then replace it back:
print(mystring:gsub("% ", "\1",1):gsub("% ", "/",1):gsub("\1","% ", 1))
This prints: Thats a/really nice house.. Also, you don't need to escape spaces with %.

Search a section of text, which occurs regularly in tcl

I have a file called log_file with following text:
....some text....
line wire (1)
mode : 2pair , annex : a
coding : abcd
rate : 1024
status : up
....some text....
line wire (2)
mode : 4pair , annex : b
coding : xyz
rate : 1024
status : down
....some text....
The values may differ but the attributes are always the same. Is there a way to find each line wire and display their attributes? The number of line wires also may differ.
EDIT: File doesn't have any blank lines. There are more attributes but only these are needed. Can I get like the first "n" lines, instead of searching for every line? i.e if there is line wire (1), copy that line plus the next 4 lines.
And I am copying the searched lines to a output file $fout, which I have used earlier in the script with the same $line.
Given your sample:
set fh [open log_file r]
while {[gets $fh line] != -1} {
switch -glob -- $line {
{line wire*} {puts $line}
{mode : *} -
{coding : *} -
{rate : *} -
{status : *} {puts " $line"}
}
}
close $fh
outputs
line wire (1)
mode : 2pair , annex : a
coding : abcd
rate : 1024
status : up
line wire (2)
mode : 4pair , annex : b
coding : xyz
rate : 1024
status : down
Edit: print the next "n" lines following the "line wire" line to a file
set in [open log_file r]
set out [open log_file_filtered w]
set n 4
while {[gets $in line] != -1} {
if {[string match {line wire*} $line]} {
puts $line
for {set i 1} {$i <= $n} {incr i} {
if {[gets $in line] != -1} {
puts $out " $line"
}
}
}
}
close $fh

How to log a bit mask

I am calling [[UIApplication sharedApplication] enabledRemoteNotifications] which returns a bitmask. How do I NSLog the bitmask to understand how the bitmask is composed and which notifications are on/off?
You need to print it as binary value so you get a one or zero for each bit. Here is a question that answers how to log a binary value:
NSInteger to binary (string) value in 8bit format
If you want to log the bits symbolically, it takes some programming:
NSLog(#"MASK_A = %s, MASK_B = %s, MASK_C =%s", mask & MASK_A ? "YES" : "NO", mask & MASK_B ? "YES" : "NO", mask & MASK_C ? "YES" : "NO");
Or:
NSLog(#"mask = ( %s%s%s)", mask & MASK_A ? "MASK_A " : "", mask & MASK_B ? "MASK_B " : "", mask & MASK_C ? "MASK_C " : "");

Resources