| 1 |
/*=========================================================================== |
| 2 |
Copyright (C) 1987-2009 European Southern Observatory (ESO) |
| 3 |
|
| 4 |
This program is free software; you can redistribute it and/or |
| 5 |
modify it under the terms of the GNU General Public License as |
| 6 |
published by the Free Software Foundation; either version 2 of |
| 7 |
the License, or (at your option) any later version. |
| 8 |
|
| 9 |
This program is distributed in the hope that it will be useful, |
| 10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
GNU General Public License for more details. |
| 13 |
|
| 14 |
You should have received a copy of the GNU General Public |
| 15 |
License along with this program; if not, write to the Free |
| 16 |
Software Foundation, Inc., 675 Massachusetss Ave, Cambridge, |
| 17 |
MA 02139, USA. |
| 18 |
|
| 19 |
Corresponding concerning ESO-MIDAS should be addressed as follows: |
| 20 |
Internet e-mail: [email protected] |
| 21 |
Postal address: European Southern Observatory |
| 22 |
Data Management Division |
| 23 |
Karl-Schwarzschild-Strasse 2 |
| 24 |
D 85748 Garching bei Muenchen |
| 25 |
GERMANY |
| 26 |
===========================================================================*/ |
| 27 |
|
| 28 |
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| 29 |
.TYPE Module |
| 30 |
.NAME filop.c |
| 31 |
.LANGUAGE C |
| 32 |
.AUTHOR Francois Ochsenbein [ESO-IPG] |
| 33 |
.CATEGORY File Management |
| 34 |
.ENVIRONMENT VMS / UNIX |
| 35 |
.COMMENTS Here are utilities to create / delete / rename / change |
| 36 |
protection of files. |
| 37 |
.VERSION 1.0 05-Mar-1987: Creation |
| 38 |
.VERSION 1.1 23-Jun-1989: Allow file translation |
| 39 |
|
| 40 |
090831 last modif |
| 41 |
----------------*/ |
| 42 |
|
| 43 |
#define PM_LEVEL LEVEL_FI /* The Monitoring level for this file */ |
| 44 |
|
| 45 |
#define DEBUG 0 /* Debugging option */ |
| 46 |
|
| 47 |
#include <osfile.h> |
| 48 |
#include <midas_def.h> |
| 49 |
#include <macrogen.h> |
| 50 |
#include <trace.h> |
| 51 |
#include <levels.h> |
| 52 |
#include <error.h> |
| 53 |
#include <ok.h> |
| 54 |
|
| 55 |
|
| 56 |
extern int pm_enter(), pm_trace(), pm_iexit(), pm_ed_trace(); |
| 57 |
extern int eh_ed_as(); |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
/*==========================================================================*/ |
| 62 |
int fi_create(name, nobyt, protec) |
| 63 |
/*++++++++ |
| 64 |
.PURPOSE Creates a NEW file. |
| 65 |
The argument protec gives the file protection code, in UNIX |
| 66 |
convention: it is made of 3 octal digits `OGW' for Owner / |
| 67 |
Group / World; each octal digit is made of 3 bits `rwe' |
| 68 |
for read / write (delete) / execute protection set to 1 to |
| 69 |
PERMIT access. As an example, 755 allows read / execute |
| 70 |
to everybody, but rewriting the file is only allowed to the owner. |
| 71 |
The protection code of 0 converted to default protection |
| 72 |
(defined as PROTECTION in osparms.h) |
| 73 |
.RETURNS OK / NOK . |
| 74 |
Note that trying to create a new file with the same |
| 75 |
name as an existing file is an error. |
| 76 |
.REMARKS |
| 77 |
-------------------------*/ |
| 78 |
char *name; /* IN : Filename */ |
| 79 |
long nobyt; /* IN : number of bytes to be allocated */ |
| 80 |
int protec; /* IN : protection code `OGW' (3 octal digits) */ |
| 81 |
{ |
| 82 |
int status; |
| 83 |
char *phname; |
| 84 |
|
| 85 |
ENTER("fi_create"); |
| 86 |
|
| 87 |
TRACE(name); |
| 88 |
|
| 89 |
phname = osftr(name); /* Physical Name */ |
| 90 |
status = osfcreate(phname, nobyt, protec); |
| 91 |
if (status < 0) ERR_ED_STRING(osmsg(), name), status = NOK; |
| 92 |
else status = OK; |
| 93 |
|
| 94 |
EXIT(status); |
| 95 |
} |
| 96 |
|
| 97 |
/*==========================================================================*/ |
| 98 |
int fi_chmod(name, protec) |
| 99 |
/*++++++++ |
| 100 |
.PURPOSE Change the protection of a file. |
| 101 |
The argument protec has the same Unix conventions as |
| 102 |
fi_create. |
| 103 |
.RETURNS OK / NOK . |
| 104 |
.REMARKS |
| 105 |
-------------------------*/ |
| 106 |
char *name; /* IN : Filename */ |
| 107 |
int protec; /* IN : protection code `OGW' (3 octal digits) */ |
| 108 |
{ |
| 109 |
int status; |
| 110 |
char *phname; |
| 111 |
|
| 112 |
ENTER("fi_chmod"); |
| 113 |
|
| 114 |
TRACE(name); |
| 115 |
|
| 116 |
phname = osftr(name); /* Physical Name */ |
| 117 |
status = osfcontrol(phname, CHMOD, protec, 0); |
| 118 |
if (status < 0) ERR_ED_STRING(osmsg(), name), status = NOK; |
| 119 |
else status = OK; |
| 120 |
|
| 121 |
EXIT(status); |
| 122 |
} |
| 123 |
|
| 124 |
/*==========================================================================*/ |
| 125 |
int fi_delete(name) |
| 126 |
/*++++++++ |
| 127 |
.PURPOSE Delete a file. |
| 128 |
.RETURNS OK / NOK . |
| 129 |
.REMARKS |
| 130 |
-------------------------*/ |
| 131 |
char *name; /* IN : File to delete */ |
| 132 |
{ |
| 133 |
int status; |
| 134 |
char *phname; |
| 135 |
|
| 136 |
ENTER("fi_delete"); |
| 137 |
|
| 138 |
TRACE(name); |
| 139 |
|
| 140 |
phname = osftr(name); /* Physical Name */ |
| 141 |
status = osfdelete(phname); |
| 142 |
if (status < 0) ERR_ED_STRING(osmsg(), name), status = NOK; |
| 143 |
else status = OK; |
| 144 |
|
| 145 |
EXIT(status); |
| 146 |
} |
| 147 |
|
| 148 |
/*==========================================================================*/ |
| 149 |
int fi_rename(name, newname) |
| 150 |
/*++++++++ |
| 151 |
.PURPOSE Change name of a file. |
| 152 |
.RETURNS OK / NOK . |
| 153 |
.REMARKS |
| 154 |
-------------------------*/ |
| 155 |
char *name; /* IN : old filename */ |
| 156 |
char *newname; /* IN : new filename */ |
| 157 |
{ |
| 158 |
int status; |
| 159 |
|
| 160 |
ENTER("fi_rename"); |
| 161 |
|
| 162 |
TRACE_ED_STRING("Old name: ", name); |
| 163 |
TRACE_ED_STRING("New name: ", name); |
| 164 |
|
| 165 |
status = osfrename(name, newname); |
| 166 |
if (status < 0) ERR_ED_STRING(osmsg(), name), status = NOK; |
| 167 |
else status = OK; |
| 168 |
|
| 169 |
EXIT(status); |
| 170 |
} |
| 171 |
|
| 172 |
/*==========================================================================*/ |
| 173 |
long fi_size(name) |
| 174 |
/*++++++++ |
| 175 |
.PURPOSE Retrieve size (bytes) of a file. |
| 176 |
.RETURNS Size in bytes / 0 if file does not exist or error |
| 177 |
.REMARKS |
| 178 |
-------------------------*/ |
| 179 |
char *name; /* IN : file name */ |
| 180 |
{ |
| 181 |
long size; |
| 182 |
char *phname; |
| 183 |
|
| 184 |
ENTER(".fi_size"); |
| 185 |
|
| 186 |
TRACE_ED_STRING("File name: ", name); |
| 187 |
|
| 188 |
phname = osftr(name); /* Physical Name */ |
| 189 |
size = osfsize(phname); |
| 190 |
if (size == -1) |
| 191 |
size = 0, ERR_ED_STRING(osmsg(), name), size = 0; |
| 192 |
|
| 193 |
EXITl(size); |
| 194 |
} |
| 195 |
|
| 196 |
/*==========================================================================*/ |
| 197 |
long fi_date(name) |
| 198 |
/*++++++++ |
| 199 |
.PURPOSE Retrieve last modification date of a file (seconds elapsed since |
| 200 |
January 1, 1970) |
| 201 |
.RETURNS Date in seconds, or 0 for error (message logged) |
| 202 |
.REMARKS |
| 203 |
-------------------------*/ |
| 204 |
char *name; /* IN : file name */ |
| 205 |
{ |
| 206 |
long date; |
| 207 |
char *phname; |
| 208 |
|
| 209 |
ENTER(".fi_date"); |
| 210 |
|
| 211 |
TRACE_ED_STRING("File name: ", name); |
| 212 |
|
| 213 |
phname = osftr(name); /* Physical Name */ |
| 214 |
date = osfdate(phname); |
| 215 |
if (date == -1) |
| 216 |
date = 0, ERR_ED_STRING(osmsg(), name), date = 0; |
| 217 |
|
| 218 |
EXITl(date); |
| 219 |
} |
| 220 |
|