iPXE
nfs_uri.h File Reference

Network File System protocol URI handling functions. More...

#include <ipxe/uri.h>

Go to the source code of this file.

Data Structures

struct  nfs_uri

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
int nfs_uri_init (struct nfs_uri *nfs_uri, const struct uri *uri)
int nfs_uri_next_mountpoint (struct nfs_uri *uri)
int nfs_uri_symlink (struct nfs_uri *uri, const char *symlink_value)
char * nfs_uri_mountpoint (const struct nfs_uri *uri)
char * nfs_uri_next_path_component (struct nfs_uri *uri)
void nfs_uri_free (struct nfs_uri *uri)

Detailed Description

Network File System protocol URI handling functions.

Definition in file nfs_uri.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ nfs_uri_init()

int nfs_uri_init ( struct nfs_uri * nfs_uri,
const struct uri * uri )

Definition at line 34 of file nfs_uri.c.

34 {
35 if ( ! ( nfs_uri->mountpoint = strdup ( uri->path ) ) )
36 return -ENOMEM;
37
39 if ( strchr ( uri->path, '/' ) != NULL )
41
42 if ( nfs_uri->filename[0] == '\0' ) {
44 return -EINVAL;
45 }
46
47 if ( ! ( nfs_uri->path = strdup ( nfs_uri->filename ) ) ) {
49 return -ENOMEM;
50 }
52
53 return 0;
54}
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
char * basename(char *path)
Return base name from path.
Definition basename.c:43
char * dirname(char *path)
Return directory name from path.
Definition basename.c:58
#define EINVAL
Invalid argument.
Definition errno.h:429
#define ENOMEM
Not enough space.
Definition errno.h:535
static void(* free)(struct refcnt *refcnt))
Definition refcnt.h:55
char * strchr(const char *src, int character)
Find character within a string.
Definition string.c:272
char * strdup(const char *src)
Duplicate string.
Definition string.c:394
char * filename
Definition nfs_uri.h:16
char * path
Definition nfs_uri.h:17
char * lookup_pos
Definition nfs_uri.h:18
char * mountpoint
Definition nfs_uri.h:15
A Uniform Resource Identifier.
Definition uri.h:65
const char * path
Path (after URI decoding)
Definition uri.h:81

References basename(), dirname(), EINVAL, ENOMEM, nfs_uri::filename, free, nfs_uri::lookup_pos, nfs_uri::mountpoint, NULL, nfs_uri::path, uri::path, strchr(), and strdup().

Referenced by nfs_parse_uri().

◆ nfs_uri_next_mountpoint()

int nfs_uri_next_mountpoint ( struct nfs_uri * uri)

Definition at line 64 of file nfs_uri.c.

64 {
65 char *sep;
66
67 if ( uri->mountpoint + 1 == uri->filename ||
68 uri->mountpoint == uri->filename )
69 return -ENOENT;
70
71 sep = strrchr ( uri->mountpoint, '/' );
72 uri->filename[-1] = '/';
73 uri->filename = sep + 1;
74 *sep = '\0';
75
76 free ( uri->path );
77 if ( ! ( uri->path = strdup ( uri->filename ) ) ) {
78 uri->path = NULL;
79 return -ENOMEM;
80 }
81 uri->lookup_pos = uri->path;
82
83 return 0;
84}
#define ENOENT
No such file or directory.
Definition errno.h:515
char * strrchr(const char *src, int character)
Find rightmost character within a string.
Definition string.c:290

References ENOENT, ENOMEM, free, NULL, uri::path, strdup(), and strrchr().

Referenced by nfs_mount_deliver().

◆ nfs_uri_symlink()

int nfs_uri_symlink ( struct nfs_uri * uri,
const char * symlink_value )

Definition at line 86 of file nfs_uri.c.

86 {
87 size_t len;
88 char *new_path;
89
90 if ( ! uri->path )
91 return -EINVAL;
92
93 if ( *symlink == '/' )
94 {
95 if ( strncmp ( symlink, uri->mountpoint,
96 strlen ( uri->mountpoint ) ) != 0 )
97 return -EINVAL;
98
99 len = strlen ( uri->lookup_pos ) + strlen ( symlink ) - \
100 strlen ( uri->mountpoint );
101 if ( ! ( new_path = malloc ( len * sizeof ( char ) ) ) )
102 return -ENOMEM;
103
104 strcpy ( new_path, symlink + strlen ( uri->mountpoint ) );
105 strcpy ( new_path + strlen ( new_path ), uri->lookup_pos );
106
107 } else {
108 len = strlen ( uri->lookup_pos ) + strlen ( symlink );
109 if ( ! ( new_path = malloc ( len * sizeof ( char ) ) ) )
110 return -ENOMEM;
111
112
113 strcpy ( new_path, symlink );
114 strcpy ( new_path + strlen ( new_path ), uri->lookup_pos );
115 }
116
117 free ( uri->path );
118 uri->lookup_pos = uri->path = new_path;
119
120 return 0;
121}
ring len
Length.
Definition dwmac.h:226
void * malloc(size_t size)
Allocate memory.
Definition malloc.c:621
int strncmp(const char *first, const char *second, size_t max)
Compare strings.
Definition string.c:187
char * strcpy(char *dest, const char *src)
Copy string.
Definition string.c:347
size_t strlen(const char *src)
Get length of string.
Definition string.c:244

References EINVAL, ENOMEM, free, len, malloc(), uri::path, strcpy(), strlen(), and strncmp().

Referenced by nfs_deliver().

◆ nfs_uri_mountpoint()

char * nfs_uri_mountpoint ( const struct nfs_uri * uri)

Definition at line 56 of file nfs_uri.c.

56 {
57 if ( uri->mountpoint + 1 == uri->filename ||
58 uri->mountpoint == uri->filename )
59 return "/";
60
61 return uri->mountpoint;
62}

Referenced by nfs_mount_deliver(), nfs_mount_step(), and nfs_parse_uri().

◆ nfs_uri_next_path_component()

char * nfs_uri_next_path_component ( struct nfs_uri * uri)

Definition at line 123 of file nfs_uri.c.

123 {
124 char *sep;
125 char *start;
126
127 if ( ! uri->path )
128 return NULL;
129
130 for ( sep = uri->lookup_pos ; *sep != '\0' && *sep != '/'; sep++ )
131 ;
132
133 start = uri->lookup_pos;
134 uri->lookup_pos = sep;
135 if ( *sep != '\0' ) {
136 uri->lookup_pos++;
137 *sep = '\0';
138 if ( *start == '\0' )
140 }
141
142 return start;
143}
uint32_t start
Starting offset.
Definition netvsc.h:1
char * nfs_uri_next_path_component(struct nfs_uri *uri)
Definition nfs_uri.c:123

References nfs_uri_next_path_component(), NULL, uri::path, and start.

Referenced by nfs_step(), and nfs_uri_next_path_component().

◆ nfs_uri_free()

void nfs_uri_free ( struct nfs_uri * uri)

Definition at line 145 of file nfs_uri.c.

145 {
146 free ( uri->mountpoint );
147 free ( uri->path );
148 uri->mountpoint = NULL;
149 uri->path = NULL;
150}

References free, NULL, and uri::path.

Referenced by nfs_free(), nfs_open(), and nfs_parse_uri().