• Aucun résultat trouvé

The File System

Dans le document Operating System Reference Manual (Page 22-56)

2_1 File N8I1leS ___________________________________________________________________ 2-1 2.2 The Working Directmy _____________________________________________________ 2-2 2.3 De\lices ___________________________________ . ___________________________________ 2-3 2_4 storage Devices _________________________ . ___________________________________ 2-3 2..5 The Volwne catal()Q ________ • ___________ . ___________________________ . _______ 2-4 2_6 LftI)els _____________________ . ___________________________________________________ 2-4 2_7 Logical and ~ical End of File _________________________________________ 2-4 2_6 File Access ______________ . ___________________________________________________ 2-5 2.9 Pipes ______________________________________________________ . _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 2-6 2_10 File Symem Calls _______________ . ___________________________________________ 2-7 2.10.1 MAKE FILE and MAKE PIPE ... 2-8 2.10.2 KILL_OBJECT ... -: ... 2-10 2.10.3 UNKILL FILE ._ ... 2-11 2.10.4 RENAME_ENTRY ... '" ., ... 2-12 2.10.5 LOOKUP ... _ ... 2-13 2.10.6 INFO ... 2-16 2.10.7 SET FILE INFO ... 2-17 2.10.8 OPEN ... :-: ... 2-18 2.10.9 CLOSE_OBJECT ... _ .... 2-19 2.10.10 READ_DATA and WRITE_DATA ... 2-20 2.10.11 READ LABEL and WRITE LABEL ... 2-23 2.10.12 DEVICE_CONTROL ... :-: ... 2-24 2.10.12.1 Setting Device-Control Information ... 2-24 2.10.12.2 Obtaining Device-Control Information ... 2-29 2.10.13 ALLOCATE ... 2-34 2.10.14 COMPACT ... 2-35 2.10.15 TRUNCATE ... 2-36 2.10.16 FLUSH ... 2-37 2.10.17 SET_SAFETy ... 2-38 2.10.18 SET_WORKING_DIR and GET_WORKING_DIR ... '" 2-39 2.10.19 RESET_CATALOG,. RESET_SUBTREE .. GET_NEXT_ENTRY,.

and LOOKUP _NEXT_ENTRy ... 2-40 2.10.20 MOUNT and UNMOUNT ... 2-41

The File System

The File System provides device-independent 110, storage with access protection, and uniform fUe'-namlng conventions.

DevIce Independence means that all I/O Is performed In the same way, catalog contains an entry describIng the flle's attrIbutes, InclUding the length of the fUe .. its position on the disk .. and the last backup copy date. Arbitrary block-structured devices, programs can make I/O requests in whole-block increments in order to improve program performance. redundant information about the files on storage devices. Duplicate copies of critical information are stored in different forms and in different places on

qJe18ting system Reference MantIal The FIle system by the Character "-". Because the top catalog In the system has no name, all complete paUYlames begin with "-".

For example,

are predefined: Certain device names

RS232A

bOOt voll.l1le c11rectory.

You can find out what the working directory Is with GET_wmKII'G_DIR.

You can Change to a new workIng Olrectory with SET _ WCRKlN3_DIR.

qJeratJng System RefeJ1!l7CfJ f'18ntI81 me FIle system

Keyboard, mouse, battery-powered clOCk

10 ms system timer

CRT vertical retrace interrupt Parallel port

Diskette 1 (UPPER)

DiSkette 2 (LOWER) VideO screen

The deVice driver associated with a device contains information aboUt the device's physical characteristics sUCh as sector size and interleave factors for disks.

Q:Jerat/ng System Reference ManusJ The FIle System Information aboUt each fUe InclUding:

Name

cperatlng System Reference Manual TIle File System

The FHe System provIdes a devIce-independent bytestream interface. As far as an appl1cation program Is concerned, a specl fled number of bytes is transferred eIther relative to the fUe marker or at a spec1f1ed byte location in the flIe. The physical attribUtes of the device or fne are not important to

the appl1catlon, except tnat devIces tnat do not support posl tlonlng can perform only sequential operations. Programs can sometimes improve performance, however, by taking advantage of a device's phys1cal characteristics.

cperatlng System Reference M8I7()81 The FIle System

refnums .. hOwever, always have different flIe markers, whether or not tnose refnums were Obtained with GlobaCRefrUn

A fUe can also be opened In private mOde .. which specifIes that no other CPEN provided for interprocess communication. This mechanism is called a pipe Pipes are simllar to the other objects In the FHe System -- they are named

qJerating System Reference Mant/81 me File System until data are wrItten or untll all the wrIters close the pIpe. SImllarly, If the

write pointer catches up wIth the read pointer, a writing process blocks until the pIpe reader frees up some space or until the reader closes the pIpe.

Because pipes have this structure, there are restrictions on some operations.

These restrIctions are dIscussed wIth the relevant Flle System calls.

Processes can never make read or wrIte requests bIgger than half the size of

the pipe because the q>erating system always fully satisfies each read or wrIte request before returnIng to the program. In other words, If a process asks for 100 bytes of data from a pipe, the q:>erating System walts until there are 100 bytes of data in the pipe and then completes the call. Slmllarly, if a process tries to write 100 bytes of data into a pipe, the ~rating System walts until toore Is room for too full 100 bytes before wrIting anything into the pipe. If processes were allowed to make write or read requests for greater than half of a particular pipe, it would be possible for a reader and a wri ter to deadlock, with neither having room in the pIpe to satisfy Its

requests.

2.10 File System calls

ThIs section describeS all the ~rating system calls that pertaIn to the Flle System. A summary of all the ~ratlng System calls can be found in Appendix A The followIng specIal types are used In the FIle System calls:

Patmame

=

STRINi[MaX_PattYlClOO]; (* MaX_Pattf8ne

=

255 *) E_tQne = STRINi(MaX_EncJIE]; (* tIaX_EtQne

=

32 tt)

Accesses = (Dread, Dwrite, ~, Private, Global_RefrUn);

t1Set = SET (F Accesses;

IottxJe = (AbSOlute, Relative, sequential);

The FS_InfO record and its associated types are described under the LOO<.lP call. The Dctype record Is described under the CEVICE_aNTRCL call.

q;erat/ng System Reference fvIl¥JtIal

2.10.1 MAKE_FILE md MAKEYIPE FlIe System calls

MAKE_FILE (var ECOde:Integer;

Var Path: Patl'1'lclle;

Label_Slze:Integer) MAKEYIPE (var ECOde:Integer;

var

Path :PatI'1'aIe;

Label_Slze:Integer) Ecode: Error indication Path: Nafre of new object

me File System

Label_Size: Number of bytes for the Object1s label

MAKE_FILE and MAKE_PIPE create the specIfied type of Object with the given name. If the pathname does not specify a directory name (more specifiCally, If the pathname does not begin with a dash), the working directory is used. Label_Size specifies the initial size in bytes of the label.

It must be less than or equal to 128 bytes. The label can grow to contain up to 128 bytes no matter what its initial size. My error indication is returned in ECOde.

Pipes will not be supported In future releases of the qJeratlng System.

00 not use the pipe mechanism if you want your software to be upward-compatible.

The· MAKE_FILE example on the next page checks to see Whether the specified fUe exists before opening It

qJeratfng system Reference fvI8nlIaI

(lH)T F1leExlsts

=

890;

YM F1leReftuq, Erro1'Code:INTEGER;

F1leNcJIE: Patt1&re;

Happy: E01.ENf;

Response:DM;

EEGIN

Happy: =fAlSE;

MULE tilT Happy 00 fEGIN

The File system

REPEAT (* get a file name *)

IRITE('File name: ");

READLN(FileName);

UNTIL LENGTH(F1leName»0;

tW<E_FILE(Errorcode, FileNcIE, 0); (*no lctlel for this file-) IF (ErrorDode<>O) THEN (* does file already exist? *)

IF (ErrorCode=FileExists) TI£N (* yes *)

~GIN

IRITE(FileNcIE,' already exists. overwrite?');

REAIl.N(Response );

Happy:=(Response IN rye, ·V·]); (*gO ahead CI1d overwrite-) EN)

ELSE .ulELN(· Error ., ErrorCOde,' While creating file.') ELSE HaWY:

=

TRLE;

EN>;

(JlEN(Errol'Code, F1leNalE, F1leReflOQ, (OWl1 te 1);

EN>;

qJeratlng System Reference Manual

2.102 KlLL_£B.:ECT File System Call KILL_(JU:CT (var ECOde:IntegeT;

Var Path: Pattwlle) Ecode: Error indicator

Path: Narre of object to be deleted

T/7e FIle System

K1lL_£lU::CT deletes the object given in Path from the File System. {])jects with the safety switch on cannot be deleted. If a fHe or pipe Is open at the time of the KILL_CB.J::CT call, its actual deletion Is postponed until it has been closed by all processes that have it open. DurIng this period no new processes are allowed to open it. The object to be deleted need not be open at the time of the KILL tRECT call. A KILL (B.ECT call can be reversed by LN<D...L_FILE, as

long

as the object is a file and is still open.

The fOllowIng program fragment deletes flIes untll RETURN Is pressed:

CONST FileNOtFound=894;

VAR FileNare :Pattfble;

Errol'Code: INlEGER;

EEGIN REPEAT

IRITE('Flle to delete: ');

REAOlN(FileName);

If (fileName<> I ' ) THEN BEGIN

KILL_(JU:CT(ElTOI'Code,fileNale);

IF (Errol'Code<>O) TI-EN

If (Errorcooe=filett>tfOllld) THEN IRITELN(flleNaoo,' not fot.rld. I )

ELSE lIRITELN(' Error ',ErrorCOde,' lIlile deletirYJ file. ' ) ELSE IRITELN(f11eName,' deleted. ');

EN>

UNTIL (FileName=");

EN>;

t:peratlng

system

RefeJ1JfICe Mant/al

2.10.3 LN<ILL_FILE File System Call IN<Ill_FIlE (var ECOde:Integer;

ReflOn : Integer;

Var NeIflaE:e_f'lCIIe) Ecode: Error indicator

RefNum: Refnum Of the Killed and open file NeIllf1alre: New narre for the file being restored

The File

system

LN<ILL_FILE reverses the effect of KILL_«R:ECT as long as the killed Object is a fUe that Is still open. A new catalog entry Is created for the file with the name given in Newncme. Newncme Is not a full pathname: the

resurrected file remains In the same directory.

cperatlng System Reference H817t18l 2.10.4 RENAI"'E_ENTRY Flle System Call

RENNE_ENTRY (var Erode: Integer;

Var Path:Patt11alE;

Var NeWlCJE :E_ NcDe) Ecode: Error indicator Path: Object's old nane

NelJJf)~: Object's ne", naroo

TI1e File System

RENAfvE_ENTRY Changes the name of an Object in the FUe System.

Newncme cannot be a full pathname. The name of the object is changed, bUt the object remains In the same directory. The following program fragment Changes the file name of FCRMATTER.LIST to NEWFCRMAT.TEXT.

VAA OI(J800 :Pattflane;

NewNaoo: E NciM;

Errorcode:INTEGER f£GIN

OldName:=°-LlSA-FORMATTER.LISTo;

~:=°tt:"ORMAT. TEXT";

RENAtE_EN1RY(ErrOI'COde,OI(fbe,~);

EN);

The fUe's full pathname after renaming Is -LISA-NEWFCRMAT. TEXT

Volume names can be renamed by specifying only the volume name in Path.

Here is a sample program fragment which changes a volume name. Note that

the leading dash (-), given in CDd\icme, Is not given in NewNcme.

YM Ol(J6re :PathNare;

NewNane: E NciM;

Errorcode:INTEGER E£GIN

OldName:="-thomas";

Ne~: =' steams' ;

REtW£ _ENTRY (Errorcode, Ol<Rl1e, Ne~);

EN);

cperat/ng system Reference HantIal

2.10.5 UD<LP File System call lOO<t.P (Var Ecooe:lnteger;

Var Path :Patmalne;

Var AttribUtes:Fs_InfO) fcode: Error indicator Path: Object to lOOkup

AttribUtes: Information returned about path

T/1e File system fields of Attributes contain meaningful values; otherwise, some values are undefined.

tnID.Ilt J8ld1ng: BOCl..EM;

volrane,

password: e_nellle;

fsversim, wIid,

voIrun: INlEGER;

t:pemting System Reference Manual The File System

protected:BOOlEAN);(* F1le copy protected? *)

cpeJat/ng system Reference Manual me File system

UI0

=

INTEGER;

Info_Type = (oovice_t, VOlllE_t, object_t);

Devtype = (Oi5l<00\I, pascaltxL seqdeV, biW<t, roo_io);

Filetype = (t.rldefined, tro=file, rootcat, freelist,

bcdllod<s" sysdata spooL exec" usercat" p1pe"

bOOtfile, swapdata s~, mnap, userfile, kl11edOOject);

Entrytype... (eR1>tyentry, catentry, linkentry, fileentry, plpeentry"ecentry, kl11edentry);

Ttle eof field of the FS_InfO record is set after an attempt to read more bytes than are avallable from the fUe marker to the logical end of the fUe, or after an attempt to wrIte wnen no dISk space Is available. If the flIe marKer is at the twentieth byte of a twenty-five byte f11e, for example, you can read up to 5 bytes withOUt setting eat, bUt If you try to read 6 bytes, the F11e System gives you only 5 bytes of data and eat 1s set.

The following program reports hOw many bytes of data a gl van fUe has:

VAR Inf~:Fs_Info; (*information returned by UXJ<t,P cn1 Itf=O*) FiletOe :PatnNane;

ErrorGOOe: INTEGER;

BEGIN

~ITE("Fl1e: .);

REAIl..N(Filetbne );

LOOKUP(Errorcode,FlleName"InfoRec);

IF (ErroI'COde<>O) llEN

~ITELN(" camt lOOl<~ ., Fl1eNa1e) ELSE

~ITELN(FlleNcIRe,' has ., InfCfleC.Slze,· bytes of data •• );

00;

t:perating System Reference M817t181

2.10.6 IN=O File System call IW-O (Val' Ecode : Integer;

Rema: Integer;

Val' RefInfO:fS_InfO)

Ecode: Error indicator

me FIle System

RefNum:

Refinfo: Reference nuntJer of object in Flle System Information returned about RefNum's Object If'.FO serves a function slmllar to that of Ul:KLP bUt Is applicable only to Objects in the File System that are open. The definition Of the FS_InfO

record Is given under LOCKLP and iri Appendix A.

qJerat/ng System Reference MantI8l

2.10.7 SET_FILE_K'O File system Call SETJILE_IN=O ( Var Ecode:Integer;

Reflt.ln : Integer;

fs1 :fS_InfO) Ecode: Error indicator

T/7e File System

RefNum:

Fsi: Reference nUf1t)er of object in File system New information abOUt the object

SET_FILE_JN=O changes the status information associated with a given Object.

This call works In exactly the opposite way that LOO<lP and If\FO work, In that the status information Is given by your program to SET_FILE_JN=a The Fsi argument Is the same type of information record as that returned by UD<LP

ana ua

The Object must be open at the time this call is made.

The followIng fleldS of the Information report may be Changed:

file_scavenged file_clOsed by_OS file_left_open

user_t~

user_St.tltype

t:penJtJng System ReFerence M8f1(J8}

2.1D.8 (FEN File system Call (PEN (Var Ecode:lnteger;

Var Path: PattrlalJB; Reference number for oDject set of access types overwrIting eaCh other's data

Pipes cannot be opened for l'.)fIrlte access. You must use ~ if you want to wrlte Into the pIpe. To set up a private pIpe .. the reader process opens the

pipe first" specifying Dread mode; the wrIter process then opens the pipe wIth

~ PrIvate access mocJe.

cperatJng System Reference Manual

2.10.9 Q,OOE_m.:ECT FUe System call (1.OSE_lRECT (Var ECOde:lnteger;

ReftUl: Integer) Ecode: Error indicator

RefNum: Reference number of object to be closed

lFEN(Erro1'Code, flleNcIE, fileReftt.lq, [mead]);

IF (ErroI'Code>O) Tt£N

If (ActualBytes<512) THEN

IRlTE('()11y read ',ActualBytes,' byteS from ',FileNclne);

CUlSEJR:ECT(EITOJ'Code, FileReftun);

00;

EN>;

t:perat/ng system Reference Manual

2.10.10 RE,AD_DATA em WRITE_DATA FHe System Calls

READ_DATA (var Ecode:Integer;

RefltIn: Integer;

~11E_OATA (Var ECOde:Integer;

RefltIn: Integer;

EcOde: Error indicator

RefNum: Reference number of object for 1/0

TIle File System

Data_Addr: Address of data (source or destination) Count: Number of bytes of data to be transferred Actual: Actual number of bytes transferred Hode : 110 fOOCIe flle, the ~rat1ng System automatically allocates enough additional space to contain the data. This new space, may not be contiguous with the previous

tperat/ng System Reference Manllal T/Je File System

USES (*Syscall.(I)j*) sy5Call;

TYPE By te=-128 .. 127;

VAR OldFile,NewFile:PathName;

01(Jleftt.ln, Ne~ftUn: INTEGER;

BytesRead, Byteslr1 tten : LtN3INT ;

ErrorCOde : INTEGER;

lFEN(ErrorGode, 01(1=11e, 01~ [mead]);

IF (Errol'COOe>O) ll£N

tW<E fILE(ErrorGode, NewF11e, 0);

£FEN(ErrorGode, NewFl1e, Ne~ftt.In, [DWri te]);

REPEAT

8ytesRead, Bytes~1 tten, 8e(J.Iential, 0);

lIfTIL (BytesReOO=O) m (ByteSlrltten=O) m (Errorcooe>O);

t:peratJng System Reference M8/7I,/8} TI1e File System

IF (Errol'Code>O) TlEN

~ITELN('Fl1e copy enoot.Iltered error '"Errorcooe);

llJlSE_oo:ECT(ErrorCode, Ne~);

ll.OSEJRECT(ErrorCOde" Ol~ftUR);

00.

qJeratlng System Reference I'1anlIal

2.10.11 READ_LABEL em WRITE_LABEL Flle system calls READ_LABEL (var Ecode:lnteger;

Var Path:PatlnlE;

oata

_Addr :LOf'YJint;

COlrlt: LaYJInt;

Var Actual:Longlnt)

IRITE_LABEl. (var Ecode:lnteger;

Var Path:PattJlaJB;

oata

_Adm": Longlnt;

COlrlt : LaYJlnt;

var Actual:LongInt) ECOde: Error indicator

Path: Name of Object containing the label Data Addr: Source or destination of 1/0

Count: Number of bytes to transfer Actual: Actual number of bytes transferred

Tile File system

These calls read or write the label of an object in the File System. 110

always starts at the beglmlng of the label. COUlt is the number of bytes the process wants transferred to or from Data_Addr, and Actual Is the actual number of bytes transferred. M error is returned if you attempt to read more than the maximum label size, 128 bytes.

Operating S}·'Stem Reference ,v18lUlBl

2.10.12 DEVICE_CONTROL File System Call IEVICE_ettmU.. (Var Ecode: Integer;

Var Path :Pathnale;

Var CPanI : Dctype ) Ecode: Error indicator

Path: Device to be controlled

The File ~·S'tem

CParm: A record of information for the device driver DEVICE_CONTROL is used to send device-specific information to a device driver or to obtain device-specific information from a device driver.

Regardless of whether you are setting device-control parameters or requesting information .. you always use a record of type Dctype. The structure of Oct.ype is:

Dctype

=

REJlR)

deVer-sion: INTEIiER·

deCode: ~;

dd>ata: MRAY[O .. 9] Of UNiINT EH>;.

dcVersion: currently 2

deCode: control code for device driver dcData: specific control or data parameters 2.10.12.1 Setting Device-Cortrol Information

Before you use a device .. you call DEVICE_CONTROL to set the device driver. Once you begin using the device .. you call DEVICE_CONTROL as necessary.

Table 2-1 shows which groups of device-control funct~ons must be set before using each type of device. Table 2-2 shows which characteristics are contained in each group. For example .. you must set Group A for RS-232 input. As you see in Table 2-2, Group A indicates the type of parity used with the device. Each group requires a separate call to DEVICE_CONTROl, and you can set only one characteristic from each group. If you set more than one from the same group for a pmticular device .. the last one set will apply.

Operating System F;teference ,..1anua}

Table 2-1

DEVICE_CONTROL Functions Required betm-e Ui:ing a Device cparmdcdab(Ol Other parameters require that you also set cparm.dcdat.e[l]

and cparm.dcdata[2l They are set in a similar manner.

Operating System Refel""ence "-1al11181 The File System

Table 2-2 shows how to set cparm.dccode, cparm.dcdatf(0l cparm..dcdatf(11 and cparm.dcdat8[2] for the various available attributes. Note that any values in cparm.dcdata past cparm.dcdata[2] are ignored when you are setting attributes documented here.

Table 2-2

DEVICE_CONTROL Output Ftn::tional Groups

flI£Tlm .decode .dcdatAOl .dcdaterl1 .dcdeW21

Group A, Pari ty :

XONIXOFF handshake 8

Group f3, Input typeahead buffer:

flush only 9 -1 -2 -2

flush and resize 9 bytes -2 -2

flush, resize,

Operating Sl/stem Reference fo,1anuaJ The File S).oS'tem

Table 2-2 (ctriinued)

FlJ£TIOi .decode .dcdataOl .dcdattll1 .dcdrU21 Group G, Disconnect Detection:

none 10 0 0

Group I, Automatic linefeed insertion:

disabled 17 0

Operating System Reference ft.181U18J The File S}·'Stem

L'Using Group C, you can set baud to any standard rate. However" 3600,

7200~ and 19200 baud are available only on the RS232B port.

2. In Group E~ to specify no input handshake, first make the call with the device control code 7, then call again with the device control code 9, as shown.

3. Low and Hi under Group F set the low and high threshold in the typeahead input. buffer. When Hi or more bytes are in the input buffer, XOFF is sent or DTR is dropped. When Low or fewer bytes remain in the typeahead

buffer~ XON is sent or DTR is reasserted. The size of the typeahead buffer (bytes) can be any value between 0 and 1024 bytes inclusive.

4. In Group J~ enabling disk sparing lets the device driver to relocate blocks of data from areas of the disl< that are found to be bad. Enabling disk rewrite allows the Operating System to rewrite data that it had trouble reading, but finally managed to read. This condition is referred to as a soft

error. Enabling disk reread tells the Operating System to read data after they are written to make certain that they were written correctly.

5. When sending a break command~ as shown in Group K~ any device control from Group A removes the break condition even if the allotted time has not yet elapsed. Also~ sending a break will disrupt transmission of any other character still being sent. If you want to make certain that enough time has elapsed for the last character to be transmitted, call WRITE_DATA with a single null character (equal to 0) just prior to calling DEVICE_CONTROL to send the break.

6. In Group N.. reco'/ery is the minimum number of milliseconds required by the modem between calls. Cerrier is t.he number of milliseconds without.

cm·rier detect, before the driver disconnects from the line. Connect is the maximum number of seconds the driver will wait. when Group P

Device_Control is subsequently issued.

Operating System Reference f\1anu81 The File S}.'Stem

Table 2-3 gives a list of mnemonic constants that you can use in place of explicit numbers when setting Decode. These mnemonics are provided in the SysCall unit for convenience.

Decode

2.10.12.2 Obtaining Device-Control Information

Mnemonic

cp&r1I. decode : = 20;

£E.VlCEJlJfllll...( errn., path, CP8l1l};

WITH Cp8I1l 00

NUlELH (dcdata[O], dcdata[1]1 dedata[2t dcdata[3t dedata[4], dcdata[51, dcdata[6]) which indicate events:

o =

no event

Oper8ting System Reference "'18m1a1 The Fl1e System

Decode Devices

18 RS232.. Modem A

19 RS232.. Modem A

Table 2-4 (contiooed) Returned in Dcdata

Read and clear input error counters [0] contains count of framing errors [1] contains count of parity errors [2] contains count of overrun errors [3] is count of buffer overflow errors

Read and clear input error counters [0] contains count of framing errors [1] contains count of parity errors [2] contains count of overrun errors [3] is count of buffer overflow errors

Dans le document Operating System Reference Manual (Page 22-56)

Documents relatifs