Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2006-09

RE: Linux Questions

6 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Wolfe, Robert
to Rainer Stratmann: does someone know how to lock the console output in Linux? Here is a program that uses…
Show quoted text 6 lines
-----Original Message----- From: [mailto:fpc-pascal- On Behalf Of Rainer Stratmann Sent: Tuesday, September 19, 2006 9:12 AM To: FPC-Pascal users discussions Subject: [fpc-pascal] Linux Questions
Show quoted text 10 lines
does someone know how to lock the console output in Linux? Here is a program that uses Framebuffer (Linux Runlevel 2). It works, but it would be good to lock the console bevor writing to the framebuffer and then to unlock the console at the end of the program. I googled, but can not find a solution. Has it to do with ioctl() calls on "/dev/tty" ? Second question is how to mount and umount for example "/dev/sda1" in a fpc program.

In answer to your second question, the simplest way I can think of doing this is to use something similar to the following:

procedure format
{M$ 2000,0, 0}
uses dos;
var forpar : text; {forpar steht for format parameter} begin
write (´Parameter:´);
readln (forpar);
swapvector
exec (´A:\format.com´ , forpar)
swapvector
end;

The section in question I am really pointing out here is:

swapvector
exec (´A:\format.com´ , forpar)
swapvector

Hope this helps.

Robert Wolfe ( / )
Computer Programmer/Analyst & Web Programmer
SRDAR, Roswell Park Cancer Institute, Buffalo, New York 716-845-5788 | http://www.srdar.org

This email message may contain legally privileged and/or confidential information. If you are not the intended recipient(s), or the employee or agent responsible for the delivery of this message to the intended recipient(s), you are hereby notified that any disclosure, copying, distribution, or use of this email message is prohibited. If you have received this message in error, please notify the sender immediately by e-mail and delete this email message from your computer. Thank you.

Reply by email

Jonas Maebe
to Rainer Stratmann: does someone know how to lock the console output in Linux? Here is a program that uses…
Rainer Stratmann wrote
Second question is how to mount and umount for example "/dev/sda1" in a fpc program.

Generic solution to this sort of problem:
a) look up how it has to be done in C
b) if it's a "standard" C function, just translate the prototype to Pascal and call it.

In this case, "man 2 mount" gives:

#include <sys/mount.h>
int mount(const char *source, const char *target, const char
*filesystemtype, unsigned long mountflags, const void *data);

So this becomes

uses ctypes;
{$linklib c}
function mount(source, target, filesystemtype: pchar; mountflags:
culong; data: pointer); cdecl; external;

For the flags values, look in /usr/include/sys/mount. It contains

enum
{
MS_RDONLY = 1, /* Mount read-only. */ #define MS_RDONLY MS_RDONLY
MS_NOSUID = 2, /* Ignore suid and sgid bits. */ #define MS_NOSUID MS_NOSUID
etc.

So that becomes

const
   MS_RDONLY = 1;
   MS_NOSUID = 2;
etc.

You can also try running h2pas on it, but I don't know if it can cope with an "enum" definition like that (and if it translates it into a Pascal enumeration, you won't be able to "or" the values together).

If you are allergic to linking to libc, you can also try to translate it to a syscall.

The easiest solution is probably however simply calling the command line utility "mount" from within your program. That's the least likely to break, does not require libc linking either, the simplest to implement and does not require any C knowledge whatsoever.

Jonas

Reply by email

Rainer Stratmann

Hello,

does someone know how to lock the console output in Linux? Here is a program that uses Framebuffer (Linux Runlevel 2). It works, but it would be good to lock the console bevor writing to the framebuffer and then to unlock the console at the end of the program. I googled, but can not find a solution.
Has it to do with ioctl() calls on "/dev/tty" ?

Second question is how to mount and umount for example "/dev/sda1" in a fpc program.

Thanks.
Rainer

Reply by email

Marc Santhoff
to Jonas Maebe: Generic solution to this sort of problem: a) look up how it has to be done in C b) if…
Jonas Maebe wrote 19 lines
enum { MS_RDONLY = 1, /* Mount read-only. */ #define MS_RDONLY MS_RDONLY MS_NOSUID = 2, /* Ignore suid and sgid bits. */ #define MS_NOSUID MS_NOSUID etc. So that becomes const MS_RDONLY = 1; MS_NOSUID = 2; etc. You can also try running h2pas on it, but I don't know if it can cope with an "enum" definition like that (and if it translates it into a Pascal enumeration, you won't be able to "or" the values together).

h2pas -E

does translate enum's to constants.

Marc

Reply by email

Marc Santhoff
to Marc Santhoff
Marc Santhoff wrote 25 lines
Am Dienstag, den 19.09.2006, 15:11 +0200 schrieb Jonas Maebe: > enum > { > MS_RDONLY = 1, /* Mount read-only. */ > #define MS_RDONLY MS_RDONLY > MS_NOSUID = 2, /* Ignore suid and sgid bits. */ > #define MS_NOSUID MS_NOSUID > etc. > > So that becomes > > const > MS_RDONLY = 1; > MS_NOSUID = 2; > etc. > > You can also try running h2pas on it, but I don't know if it can > cope > with an "enum" definition like that (and if it translates it into a > Pascal enumeration, you won't be able to "or" the values together). h2pas -E does translate enum's to constants.

No, in fact it is

h2pas -e

but it works.

Sorry for confusion,
Marc

Reply by email

Rainer Stratmann
to Marc Santhoff
Marc Santhoff wrote 13 lines
[...] > h2pas -E > > does translate enum's to constants. No, in fact it is h2pas -e but it works. Sorry for confusion, Marc

I will try to mount a device with a direct systemcall. In my view it is the best way because of independency of any libs and tools. The Program which needs mount and umount is a program in an embedded environment.

Rainer

Reply by email