001    /**
002     * Licensed to the Apache Software Foundation (ASF) under one
003     * or more contributor license agreements.  See the NOTICE file
004     * distributed with this work for additional information
005     * regarding copyright ownership.  The ASF licenses this file
006     * to you under the Apache License, Version 2.0 (the
007     * "License"); you may not use this file except in compliance
008     * with the License.  You may obtain a copy of the License at
009     *
010     *     http://www.apache.org/licenses/LICENSE-2.0
011     *
012     * Unless required by applicable law or agreed to in writing, software
013     * distributed under the License is distributed on an "AS IS" BASIS,
014     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015     * See the License for the specific language governing permissions and
016     * limitations under the License.
017     */
018    package org.apache.hadoop.fs.viewfs;
019    
020    import static org.apache.hadoop.fs.viewfs.Constants.PERMISSION_RRR;
021    
022    import java.io.FileNotFoundException;
023    import java.io.IOException;
024    import java.net.URI;
025    import java.net.URISyntaxException;
026    import java.util.ArrayList;
027    import java.util.HashSet;
028    import java.util.List;
029    import java.util.Set;
030    import java.util.StringTokenizer;
031    import java.util.Map.Entry;
032    
033    import org.apache.hadoop.classification.InterfaceAudience;
034    import org.apache.hadoop.classification.InterfaceStability;
035    import org.apache.hadoop.conf.Configuration;
036    import org.apache.hadoop.fs.BlockLocation;
037    import org.apache.hadoop.fs.ContentSummary;
038    import org.apache.hadoop.fs.FSDataInputStream;
039    import org.apache.hadoop.fs.FSDataOutputStream;
040    import org.apache.hadoop.fs.FileAlreadyExistsException;
041    import org.apache.hadoop.fs.FileChecksum;
042    import org.apache.hadoop.fs.FileStatus;
043    import org.apache.hadoop.fs.FileSystem;
044    import org.apache.hadoop.fs.FsConstants;
045    import org.apache.hadoop.fs.FsServerDefaults;
046    import org.apache.hadoop.fs.InvalidPathException;
047    import org.apache.hadoop.fs.Path;
048    import org.apache.hadoop.fs.UnsupportedFileSystemException;
049    import org.apache.hadoop.fs.permission.FsPermission;
050    import org.apache.hadoop.fs.viewfs.InodeTree.INode;
051    import org.apache.hadoop.fs.viewfs.InodeTree.INodeLink;
052    import org.apache.hadoop.io.Text;
053    import org.apache.hadoop.security.AccessControlException;
054    import org.apache.hadoop.security.Credentials;
055    import org.apache.hadoop.security.UserGroupInformation;
056    import org.apache.hadoop.security.token.Token;
057    import org.apache.hadoop.util.Progressable;
058    
059    /**
060     * ViewFileSystem (extends the FileSystem interface) implements a client-side
061     * mount table. Its spec and implementation is identical to {@link ViewFs}.
062     */
063    
064    @InterfaceAudience.Public
065    @InterfaceStability.Evolving /*Evolving for a release,to be changed to Stable */
066    public class ViewFileSystem extends FileSystem {
067      static AccessControlException readOnlyMountTable(final String operation,
068          final String p) {
069        return new AccessControlException( 
070            "InternalDir of ViewFileSystem is readonly; operation=" + operation + 
071            "Path=" + p);
072      }
073      static AccessControlException readOnlyMountTable(final String operation,
074          final Path p) {
075        return readOnlyMountTable(operation, p.toString());
076      }
077      
078      static public class MountPoint {
079        private Path src;       // the src of the mount
080        private URI[] targets; //  target of the mount; Multiple targets imply mergeMount
081        MountPoint(Path srcPath, URI[] targetURIs) {
082          src = srcPath;
083          targets = targetURIs;
084        }
085        Path getSrc() {
086          return src;
087        }
088        URI[] getTargets() {
089          return targets;
090        }
091      }
092      
093      final long creationTime; // of the the mount table
094      final UserGroupInformation ugi; // the user/group of user who created mtable
095      URI myUri;
096      private Path workingDir;
097      Configuration config;
098      InodeTree<FileSystem> fsState;  // the fs state; ie the mount table
099      Path homeDir = null;
100      
101      /**
102       * Prohibits names which contain a ".", "..", ":" or "/" 
103       */
104      private static boolean isValidName(final String src) {
105        // Check for ".." "." ":" "/"
106        final StringTokenizer tokens = new StringTokenizer(src, Path.SEPARATOR);
107        while(tokens.hasMoreTokens()) {
108          String element = tokens.nextToken();
109          if (element.equals("..") ||
110              element.equals(".")  ||
111              (element.indexOf(":") >= 0)) {
112            return false;
113          }
114        }
115        return true;
116      }
117      
118      /**
119       * Make the path Absolute and get the path-part of a pathname.
120       * Checks that URI matches this file system 
121       * and that the path-part is a valid name.
122       * 
123       * @param p path
124       * @return path-part of the Path p
125       */
126      private String getUriPath(final Path p) {
127        checkPath(p);
128        String s = makeAbsolute(p).toUri().getPath();
129        if (!isValidName(s)) {
130          throw new InvalidPathException("Path part " + s + " from URI" + p
131              + " is not a valid filename.");
132        }
133        return s;
134      }
135      
136      private Path makeAbsolute(final Path f) {
137        return f.isAbsolute() ? f : new Path(workingDir, f);
138      }
139      
140      /**
141       * This is the  constructor with the signature needed by
142       * {@link FileSystem#createFileSystem(URI, Configuration)}
143       * 
144       * After this constructor is called initialize() is called.
145       * @throws IOException 
146       */
147      public ViewFileSystem() throws IOException {
148        ugi = UserGroupInformation.getCurrentUser();
149        creationTime = System.currentTimeMillis();
150      }
151    
152      /**
153       * Return the protocol scheme for the FileSystem.
154       * <p/>
155       *
156       * @return <code>viewfs</code>
157       */
158      @Override
159      public String getScheme() {
160        return "viewfs";
161      }
162    
163      /**
164       * Called after a new FileSystem instance is constructed.
165       * @param theUri a uri whose authority section names the host, port, etc. for
166       *          this FileSystem
167       * @param conf the configuration
168       */
169      public void initialize(final URI theUri, final Configuration conf)
170          throws IOException {
171        super.initialize(theUri, conf);
172        setConf(conf);
173        config = conf;
174        // Now build  client side view (i.e. client side mount table) from config.
175        final String authority = theUri.getAuthority();
176        try {
177          myUri = new URI(FsConstants.VIEWFS_SCHEME, authority, "/", null, null);
178          fsState = new InodeTree<FileSystem>(conf, authority) {
179    
180            @Override
181            protected
182            FileSystem getTargetFileSystem(final URI uri)
183              throws URISyntaxException, IOException {
184                return new ChRootedFileSystem(uri, config);
185            }
186    
187            @Override
188            protected
189            FileSystem getTargetFileSystem(final INodeDir<FileSystem> dir)
190              throws URISyntaxException {
191              return new InternalDirOfViewFs(dir, creationTime, ugi, myUri);
192            }
193    
194            @Override
195            protected
196            FileSystem getTargetFileSystem(URI[] mergeFsURIList)
197                throws URISyntaxException, UnsupportedFileSystemException {
198              throw new UnsupportedFileSystemException("mergefs not implemented");
199              // return MergeFs.createMergeFs(mergeFsURIList, config);
200            }
201          };
202          workingDir = this.getHomeDirectory();
203        } catch (URISyntaxException e) {
204          throw new IOException("URISyntax exception: " + theUri);
205        }
206    
207      }
208      
209      
210      /**
211       * Convenience Constructor for apps to call directly
212       * @param theUri which must be that of ViewFileSystem
213       * @param conf
214       * @throws IOException
215       */
216      ViewFileSystem(final URI theUri, final Configuration conf)
217        throws IOException {
218        this();
219        initialize(theUri, conf);
220      }
221      
222      /**
223       * Convenience Constructor for apps to call directly
224       * @param conf
225       * @throws IOException
226       */
227      public ViewFileSystem(final Configuration conf) throws IOException {
228        this(FsConstants.VIEWFS_URI, conf);
229      }
230      
231      public Path getTrashCanLocation(final Path f) throws FileNotFoundException {
232        final InodeTree.ResolveResult<FileSystem> res = 
233          fsState.resolve(getUriPath(f), true);
234        return res.isInternalDir() ? null : res.targetFileSystem.getHomeDirectory();
235      }
236      
237      @Override
238      public String getCanonicalServiceName() {
239        return null;
240      }
241    
242      @Override
243      public URI getUri() {
244        return myUri;
245      }
246      
247      @Override
248      public Path resolvePath(final Path f)
249          throws IOException {
250        final InodeTree.ResolveResult<FileSystem> res;
251          res = fsState.resolve(getUriPath(f), true);
252        if (res.isInternalDir()) {
253          return f;
254        }
255        return res.targetFileSystem.resolvePath(res.remainingPath);
256      }
257      
258      @Override
259      public Path getHomeDirectory() {
260        if (homeDir == null) {
261          String base = fsState.getHomeDirPrefixValue();
262          if (base == null) {
263            base = "/user";
264          }
265          homeDir = 
266            this.makeQualified(new Path(base + "/" + ugi.getShortUserName()));
267        }
268        return homeDir;
269      }
270      
271      @Override
272      public Path getWorkingDirectory() {
273        return workingDir;
274      }
275    
276      @Override
277      public void setWorkingDirectory(final Path new_dir) {
278        getUriPath(new_dir); // this validates the path
279        workingDir = makeAbsolute(new_dir);
280      }
281      
282      @Override
283      public FSDataOutputStream append(final Path f, final int bufferSize,
284          final Progressable progress) throws IOException {
285        InodeTree.ResolveResult<FileSystem> res = 
286          fsState.resolve(getUriPath(f), true);
287        return res.targetFileSystem.append(res.remainingPath, bufferSize, progress);
288      }
289      
290      @Override
291      public FSDataOutputStream create(final Path f, final FsPermission permission,
292          final boolean overwrite, final int bufferSize, final short replication,
293          final long blockSize, final Progressable progress) throws IOException {
294        InodeTree.ResolveResult<FileSystem> res;
295        try {
296          res = fsState.resolve(getUriPath(f), false);
297        } catch (FileNotFoundException e) {
298            throw readOnlyMountTable("create", f);
299        }
300        assert(res.remainingPath != null);
301        return res.targetFileSystem.create(res.remainingPath, permission,
302             overwrite, bufferSize, replication, blockSize, progress);
303      }
304    
305      
306      @Override
307      public boolean delete(final Path f, final boolean recursive)
308          throws AccessControlException, FileNotFoundException,
309          IOException {
310        InodeTree.ResolveResult<FileSystem> res = 
311          fsState.resolve(getUriPath(f), true);
312        // If internal dir or target is a mount link (ie remainingPath is Slash)
313        if (res.isInternalDir() || res.remainingPath == InodeTree.SlashPath) {
314          throw readOnlyMountTable("delete", f);
315        }
316        return res.targetFileSystem.delete(res.remainingPath, recursive);
317      }
318      
319      @Override
320      @SuppressWarnings("deprecation")
321      public boolean delete(final Path f)
322          throws AccessControlException, FileNotFoundException,
323          IOException {
324          return delete(f, true);
325      }
326      
327      @Override
328      public BlockLocation[] getFileBlockLocations(FileStatus fs, 
329          long start, long len) throws IOException {
330        final InodeTree.ResolveResult<FileSystem> res = 
331          fsState.resolve(getUriPath(fs.getPath()), true);
332        return res.targetFileSystem.getFileBlockLocations(
333              new ViewFsFileStatus(fs, res.remainingPath), start, len);
334      }
335    
336      @Override
337      public FileChecksum getFileChecksum(final Path f)
338          throws AccessControlException, FileNotFoundException,
339          IOException {
340        InodeTree.ResolveResult<FileSystem> res = 
341          fsState.resolve(getUriPath(f), true);
342        return res.targetFileSystem.getFileChecksum(res.remainingPath);
343      }
344    
345      @Override
346      public FileStatus getFileStatus(final Path f) throws AccessControlException,
347          FileNotFoundException, IOException {
348        InodeTree.ResolveResult<FileSystem> res = 
349          fsState.resolve(getUriPath(f), true);
350        
351        // FileStatus#getPath is a fully qualified path relative to the root of 
352        // target file system.
353        // We need to change it to viewfs URI - relative to root of mount table.
354        
355        // The implementors of RawLocalFileSystem were trying to be very smart.
356        // They implement FileStatus#getOwener lazily -- the object
357        // returned is really a RawLocalFileSystem that expect the
358        // FileStatus#getPath to be unchanged so that it can get owner when needed.
359        // Hence we need to interpose a new ViewFileSystemFileStatus that 
360        // works around.
361        FileStatus status =  res.targetFileSystem.getFileStatus(res.remainingPath);
362        return new ViewFsFileStatus(status, this.makeQualified(f));
363      }
364      
365      
366      @Override
367      public FileStatus[] listStatus(final Path f) throws AccessControlException,
368          FileNotFoundException, IOException {
369        InodeTree.ResolveResult<FileSystem> res =
370          fsState.resolve(getUriPath(f), true);
371        
372        FileStatus[] statusLst = res.targetFileSystem.listStatus(res.remainingPath);
373        if (!res.isInternalDir()) {
374          // We need to change the name in the FileStatus as described in
375          // {@link #getFileStatus }
376          ChRootedFileSystem targetFs;
377          targetFs = (ChRootedFileSystem) res.targetFileSystem;
378          int i = 0;
379          for (FileStatus status : statusLst) {
380              String suffix = targetFs.stripOutRoot(status.getPath());
381              statusLst[i++] = new ViewFsFileStatus(status, this.makeQualified(
382                  suffix.length() == 0 ? f : new Path(res.resolvedPath, suffix)));
383          }
384        }
385        return statusLst;
386      }
387    
388      @Override
389      public boolean mkdirs(final Path dir, final FsPermission permission)
390          throws IOException {
391        InodeTree.ResolveResult<FileSystem> res = 
392          fsState.resolve(getUriPath(dir), false);
393       return  res.targetFileSystem.mkdirs(res.remainingPath, permission);
394      }
395    
396      @Override
397      public FSDataInputStream open(final Path f, final int bufferSize)
398          throws AccessControlException, FileNotFoundException,
399          IOException {
400        InodeTree.ResolveResult<FileSystem> res = 
401            fsState.resolve(getUriPath(f), true);
402        return res.targetFileSystem.open(res.remainingPath, bufferSize);
403      }
404    
405      
406      @Override
407      public boolean rename(final Path src, final Path dst) throws IOException {
408        // passing resolveLastComponet as false to catch renaming a mount point to 
409        // itself. We need to catch this as an internal operation and fail.
410        InodeTree.ResolveResult<FileSystem> resSrc = 
411          fsState.resolve(getUriPath(src), false); 
412      
413        if (resSrc.isInternalDir()) {
414          throw readOnlyMountTable("rename", src);
415        }
416          
417        InodeTree.ResolveResult<FileSystem> resDst = 
418          fsState.resolve(getUriPath(dst), false);
419        if (resDst.isInternalDir()) {
420              throw readOnlyMountTable("rename", dst);
421        }
422        /**
423        // Alternate 1: renames within same file system - valid but we disallow
424        // Alternate 2: (as described in next para - valid but we have disallowed it
425        //
426        // Note we compare the URIs. the URIs include the link targets. 
427        // hence we allow renames across mount links as long as the mount links
428        // point to the same target.
429        if (!resSrc.targetFileSystem.getUri().equals(
430                  resDst.targetFileSystem.getUri())) {
431          throw new IOException("Renames across Mount points not supported");
432        }
433        */
434        
435        //
436        // Alternate 3 : renames ONLY within the the same mount links.
437        //
438        if (resSrc.targetFileSystem !=resDst.targetFileSystem) {
439          throw new IOException("Renames across Mount points not supported");
440        }
441        return resSrc.targetFileSystem.rename(resSrc.remainingPath,
442            resDst.remainingPath);
443      }
444      
445      @Override
446      public void setOwner(final Path f, final String username,
447          final String groupname) throws AccessControlException,
448          FileNotFoundException,
449          IOException {
450        InodeTree.ResolveResult<FileSystem> res = 
451          fsState.resolve(getUriPath(f), true);
452        res.targetFileSystem.setOwner(res.remainingPath, username, groupname); 
453      }
454    
455      @Override
456      public void setPermission(final Path f, final FsPermission permission)
457          throws AccessControlException, FileNotFoundException,
458          IOException {
459        InodeTree.ResolveResult<FileSystem> res = 
460          fsState.resolve(getUriPath(f), true);
461        res.targetFileSystem.setPermission(res.remainingPath, permission); 
462      }
463    
464      @Override
465      public boolean setReplication(final Path f, final short replication)
466          throws AccessControlException, FileNotFoundException,
467          IOException {
468        InodeTree.ResolveResult<FileSystem> res = 
469          fsState.resolve(getUriPath(f), true);
470        return res.targetFileSystem.setReplication(res.remainingPath, replication);
471      }
472    
473      @Override
474      public void setTimes(final Path f, final long mtime, final long atime)
475          throws AccessControlException, FileNotFoundException,
476          IOException {
477        InodeTree.ResolveResult<FileSystem> res = 
478          fsState.resolve(getUriPath(f), true);
479        res.targetFileSystem.setTimes(res.remainingPath, mtime, atime); 
480      }
481    
482      @Override
483      public void setVerifyChecksum(final boolean verifyChecksum) { 
484        List<InodeTree.MountPoint<FileSystem>> mountPoints = 
485            fsState.getMountPoints();
486        for (InodeTree.MountPoint<FileSystem> mount : mountPoints) {
487          mount.target.targetFileSystem.setVerifyChecksum(verifyChecksum);
488        }
489      }
490      
491      @Override
492      public long getDefaultBlockSize() {
493        throw new NotInMountpointException("getDefaultBlockSize");
494      }
495    
496      @Override
497      public short getDefaultReplication() {
498        throw new NotInMountpointException("getDefaultReplication");
499      }
500    
501      @Override
502      public FsServerDefaults getServerDefaults() throws IOException {
503        throw new NotInMountpointException("getServerDefaults");
504      }
505    
506      @Override
507      public long getDefaultBlockSize(Path f) {
508        try {
509          InodeTree.ResolveResult<FileSystem> res =
510            fsState.resolve(getUriPath(f), true);
511          return res.targetFileSystem.getDefaultBlockSize(res.remainingPath);
512        } catch (FileNotFoundException e) {
513          throw new NotInMountpointException(f, "getDefaultBlockSize"); 
514        }
515      }
516    
517      @Override
518      public short getDefaultReplication(Path f) {
519        try {
520          InodeTree.ResolveResult<FileSystem> res =
521            fsState.resolve(getUriPath(f), true);
522          return res.targetFileSystem.getDefaultReplication(res.remainingPath);
523        } catch (FileNotFoundException e) {
524          throw new NotInMountpointException(f, "getDefaultReplication"); 
525        }
526      }
527    
528      @Override
529      public FsServerDefaults getServerDefaults(Path f) throws IOException {
530        InodeTree.ResolveResult<FileSystem> res =
531          fsState.resolve(getUriPath(f), true);
532        return res.targetFileSystem.getServerDefaults(res.remainingPath);    
533      }
534    
535      @Override
536      public ContentSummary getContentSummary(Path f) throws IOException {
537        InodeTree.ResolveResult<FileSystem> res = 
538          fsState.resolve(getUriPath(f), true);
539        return res.targetFileSystem.getContentSummary(res.remainingPath);
540      }
541    
542      @Override
543      public void setWriteChecksum(final boolean writeChecksum) { 
544        List<InodeTree.MountPoint<FileSystem>> mountPoints = 
545            fsState.getMountPoints();
546        for (InodeTree.MountPoint<FileSystem> mount : mountPoints) {
547          mount.target.targetFileSystem.setWriteChecksum(writeChecksum);
548        }
549      }
550    
551      public MountPoint[] getMountPoints() {
552        List<InodeTree.MountPoint<FileSystem>> mountPoints = 
553                      fsState.getMountPoints();
554        
555        MountPoint[] result = new MountPoint[mountPoints.size()];
556        for ( int i = 0; i < mountPoints.size(); ++i ) {
557          result[i] = new MountPoint(new Path(mountPoints.get(i).src), 
558                                  mountPoints.get(i).target.targetDirLinkList);
559        }
560        return result;
561      }
562      
563     
564      @Override
565      public List<Token<?>> getDelegationTokens(String renewer) throws IOException {
566        List<InodeTree.MountPoint<FileSystem>> mountPoints = 
567                    fsState.getMountPoints();
568        int initialListSize  = 0;
569        for (InodeTree.MountPoint<FileSystem> im : mountPoints) {
570          initialListSize += im.target.targetDirLinkList.length; 
571        }
572        List<Token<?>> result = new ArrayList<Token<?>>(initialListSize);
573        for ( int i = 0; i < mountPoints.size(); ++i ) {
574          List<Token<?>> tokens = 
575            mountPoints.get(i).target.targetFileSystem.getDelegationTokens(renewer);
576          if (tokens != null) {
577            result.addAll(tokens);
578          }
579        }
580        return result;
581      }
582    
583      @Override
584      public List<Token<?>> getDelegationTokens(String renewer,
585          Credentials credentials) throws IOException {
586        List<InodeTree.MountPoint<FileSystem>> mountPoints =
587            fsState.getMountPoints();
588        int initialListSize = 0;
589        for (InodeTree.MountPoint<FileSystem> im : mountPoints) {
590          initialListSize += im.target.targetDirLinkList.length;
591        }
592        Set<String> seenServiceNames = new HashSet<String>();
593        List<Token<?>> result = new ArrayList<Token<?>>(initialListSize);
594        for (int i = 0; i < mountPoints.size(); ++i) {
595          String serviceName =
596              mountPoints.get(i).target.targetFileSystem.getCanonicalServiceName();
597          if (serviceName == null || seenServiceNames.contains(serviceName)) {
598            continue;
599          }
600          seenServiceNames.add(serviceName);
601          Token<?> knownToken = credentials.getToken(new Text(serviceName));
602          if (knownToken != null) {
603            result.add(knownToken);
604          } else {
605            List<Token<?>> tokens =
606                mountPoints.get(i).target.targetFileSystem
607                    .getDelegationTokens(renewer);
608            if (tokens != null) {
609              result.addAll(tokens);
610            }
611          }
612        }
613        return result;
614      }
615    
616      /*
617       * An instance of this class represents an internal dir of the viewFs 
618       * that is internal dir of the mount table.
619       * It is a read only mount tables and create, mkdir or delete operations
620       * are not allowed.
621       * If called on create or mkdir then this target is the parent of the
622       * directory in which one is trying to create or mkdir; hence
623       * in this case the path name passed in is the last component. 
624       * Otherwise this target is the end point of the path and hence
625       * the path name passed in is null. 
626       */
627      static class InternalDirOfViewFs extends FileSystem {
628        final InodeTree.INodeDir<FileSystem>  theInternalDir;
629        final long creationTime; // of the the mount table
630        final UserGroupInformation ugi; // the user/group of user who created mtable
631        final URI myUri;
632        
633        public InternalDirOfViewFs(final InodeTree.INodeDir<FileSystem> dir,
634            final long cTime, final UserGroupInformation ugi, URI uri)
635          throws URISyntaxException {
636          myUri = uri;
637          try {
638            initialize(myUri, new Configuration());
639          } catch (IOException e) {
640            throw new RuntimeException("Cannot occur");
641          }
642          theInternalDir = dir;
643          creationTime = cTime;
644          this.ugi = ugi;
645        }
646    
647        static private void checkPathIsSlash(final Path f) throws IOException {
648          if (f != InodeTree.SlashPath) {
649            throw new IOException (
650            "Internal implementation error: expected file name to be /" );
651          }
652        }
653        
654        @Override
655        public URI getUri() {
656          return myUri;
657        }
658    
659        @Override
660        public Path getWorkingDirectory() {
661          throw new RuntimeException (
662          "Internal impl error: getWorkingDir should not have been called" );
663        }
664    
665        @Override
666        public void setWorkingDirectory(final Path new_dir) {
667          throw new RuntimeException (
668          "Internal impl error: getWorkingDir should not have been called" ); 
669        }
670    
671        @Override
672        public FSDataOutputStream append(final Path f, final int bufferSize,
673            final Progressable progress) throws IOException {
674          throw readOnlyMountTable("append", f);
675        }
676    
677        @Override
678        public FSDataOutputStream create(final Path f,
679            final FsPermission permission, final boolean overwrite,
680            final int bufferSize, final short replication, final long blockSize,
681            final Progressable progress) throws AccessControlException {
682          throw readOnlyMountTable("create", f);
683        }
684    
685        @Override
686        public boolean delete(final Path f, final boolean recursive)
687            throws AccessControlException, IOException {
688          checkPathIsSlash(f);
689          throw readOnlyMountTable("delete", f);
690        }
691        
692        @Override
693        @SuppressWarnings("deprecation")
694        public boolean delete(final Path f)
695            throws AccessControlException, IOException {
696          return delete(f, true);
697        }
698    
699        @Override
700        public BlockLocation[] getFileBlockLocations(final FileStatus fs,
701            final long start, final long len) throws 
702            FileNotFoundException, IOException {
703          checkPathIsSlash(fs.getPath());
704          throw new FileNotFoundException("Path points to dir not a file");
705        }
706    
707        @Override
708        public FileChecksum getFileChecksum(final Path f)
709            throws FileNotFoundException, IOException {
710          checkPathIsSlash(f);
711          throw new FileNotFoundException("Path points to dir not a file");
712        }
713    
714        @Override
715        public FileStatus getFileStatus(Path f) throws IOException {
716          checkPathIsSlash(f);
717          return new FileStatus(0, true, 0, 0, creationTime, creationTime,
718              PERMISSION_RRR, ugi.getUserName(), ugi.getGroupNames()[0],
719    
720              new Path(theInternalDir.fullPath).makeQualified(
721                  myUri, null));
722        }
723        
724    
725        @Override
726        public FileStatus[] listStatus(Path f) throws AccessControlException,
727            FileNotFoundException, IOException {
728          checkPathIsSlash(f);
729          FileStatus[] result = new FileStatus[theInternalDir.children.size()];
730          int i = 0;
731          for (Entry<String, INode<FileSystem>> iEntry : 
732                                              theInternalDir.children.entrySet()) {
733            INode<FileSystem> inode = iEntry.getValue();
734            if (inode instanceof INodeLink ) {
735              INodeLink<FileSystem> link = (INodeLink<FileSystem>) inode;
736    
737              result[i++] = new FileStatus(0, false, 0, 0,
738                creationTime, creationTime, PERMISSION_RRR,
739                ugi.getUserName(), ugi.getGroupNames()[0],
740                link.getTargetLink(),
741                new Path(inode.fullPath).makeQualified(
742                    myUri, null));
743            } else {
744              result[i++] = new FileStatus(0, true, 0, 0,
745                creationTime, creationTime, PERMISSION_RRR,
746                ugi.getUserName(), ugi.getGroupNames()[0],
747                new Path(inode.fullPath).makeQualified(
748                    myUri, null));
749            }
750          }
751          return result;
752        }
753    
754        @Override
755        public boolean mkdirs(Path dir, FsPermission permission)
756            throws AccessControlException, FileAlreadyExistsException {
757          if (theInternalDir.isRoot & dir == null) {
758            throw new FileAlreadyExistsException("/ already exits");
759          }
760          // Note dir starts with /
761          if (theInternalDir.children.containsKey(dir.toString().substring(1))) {
762            return true; // this is the stupid semantics of FileSystem
763          }
764          throw readOnlyMountTable("mkdirs",  dir);
765        }
766    
767        @Override
768        public FSDataInputStream open(Path f, int bufferSize)
769            throws AccessControlException, FileNotFoundException, IOException {
770          checkPathIsSlash(f);
771          throw new FileNotFoundException("Path points to dir not a file");
772        }
773    
774        @Override
775        public boolean rename(Path src, Path dst) throws AccessControlException,
776            IOException {
777          checkPathIsSlash(src);
778          checkPathIsSlash(dst);
779          throw readOnlyMountTable("rename", src);     
780        }
781    
782        @Override
783        public void setOwner(Path f, String username, String groupname)
784            throws AccessControlException, IOException {
785          checkPathIsSlash(f);
786          throw readOnlyMountTable("setOwner", f);
787        }
788    
789        @Override
790        public void setPermission(Path f, FsPermission permission)
791            throws AccessControlException, IOException {
792          checkPathIsSlash(f);
793          throw readOnlyMountTable("setPermission", f);    
794        }
795    
796        @Override
797        public boolean setReplication(Path f, short replication)
798            throws AccessControlException, IOException {
799          checkPathIsSlash(f);
800          throw readOnlyMountTable("setReplication", f);
801        }
802    
803        @Override
804        public void setTimes(Path f, long mtime, long atime)
805            throws AccessControlException, IOException {
806          checkPathIsSlash(f);
807          throw readOnlyMountTable("setTimes", f);    
808        }
809    
810        @Override
811        public void setVerifyChecksum(boolean verifyChecksum) {
812          // Noop for viewfs
813        }
814    
815        @Override
816        public FsServerDefaults getServerDefaults(Path f) throws IOException {
817          throw new NotInMountpointException(f, "getServerDefaults");
818        }
819        
820        @Override
821        public long getDefaultBlockSize(Path f) {
822          throw new NotInMountpointException(f, "getDefaultBlockSize");
823        }
824    
825        @Override
826        public short getDefaultReplication(Path f) {
827          throw new NotInMountpointException(f, "getDefaultReplication");
828        }
829      }
830    }